mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-25 22:13:27 +03:00
force override width to make the table look nice
This commit is contained in:
parent
5ba468f4cf
commit
24acb27934
@ -62,6 +62,7 @@ impl Widget {
|
||||
|
||||
// This one is really weird. percent_width should be LESS than the max_size_percent given to
|
||||
// the overall Composite, otherwise weird things happen.
|
||||
// Only makes sense for rows/columns.
|
||||
pub fn flex_wrap(mut self, ctx: &EventCtx, percent_width: usize) -> Widget {
|
||||
self.layout.style.size = Size {
|
||||
width: Dimension::Points(
|
||||
@ -73,6 +74,12 @@ impl Widget {
|
||||
self.layout.style.justify_content = JustifyContent::SpaceAround;
|
||||
self
|
||||
}
|
||||
// Only for rows/columns. Used to force table columns to line up.
|
||||
pub fn force_width(mut self, ctx: &EventCtx, percent_width: usize) -> Widget {
|
||||
self.layout.style.size.width =
|
||||
Dimension::Points((ctx.canvas.window_width * (percent_width as f64) / 100.0) as f32);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn bg(mut self, color: Color) -> Widget {
|
||||
self.layout.bg_color = Some(color);
|
||||
|
@ -40,6 +40,7 @@ pub fn details(ctx: &mut EventCtx, app: &App, trip: TripID, details: &mut Detail
|
||||
let total_trip_time = end_time.unwrap_or_else(|| sim.time()) - phases[0].start_time;
|
||||
|
||||
// Describe this leg of the trip
|
||||
let col_width = 7;
|
||||
let progress_along_path = if let Some(a) = sim.trip_to_agent(trip).ok() {
|
||||
let props = sim.agent_properties(a);
|
||||
// This is different than the entire TripMode, and also not the current TripPhaseType.
|
||||
@ -55,11 +56,9 @@ pub fn details(ctx: &mut EventCtx, app: &App, trip: TripID, details: &mut Detail
|
||||
},
|
||||
};
|
||||
|
||||
// TODO Style needs work. Like, always.
|
||||
|
||||
// TODO Can we change font mid line please?
|
||||
col.push(Widget::row(vec![
|
||||
Line("Trip time").secondary().draw(ctx).margin_right(20),
|
||||
Widget::row(vec![Line("Trip time").secondary().draw(ctx)]).force_width(ctx, col_width),
|
||||
props.total_time.to_string().draw_text(ctx),
|
||||
Line(format!("{} / {} this trip", activity, total_trip_time))
|
||||
.secondary()
|
||||
@ -67,7 +66,7 @@ pub fn details(ctx: &mut EventCtx, app: &App, trip: TripID, details: &mut Detail
|
||||
]));
|
||||
|
||||
col.push(Widget::row(vec![
|
||||
Line("Distance").secondary().draw(ctx).margin_right(20),
|
||||
Widget::row(vec![Line("Distance").secondary().draw(ctx)]).force_width(ctx, col_width),
|
||||
Widget::col(vec![
|
||||
Widget::row(vec![
|
||||
props.dist_crossed.describe_rounded().draw_text(ctx),
|
||||
@ -85,7 +84,7 @@ pub fn details(ctx: &mut EventCtx, app: &App, trip: TripID, details: &mut Detail
|
||||
]));
|
||||
|
||||
col.push(Widget::row(vec![
|
||||
Line("Waiting").secondary().draw(ctx).margin_right(20),
|
||||
Widget::row(vec![Line("Waiting").secondary().draw(ctx)]).force_width(ctx, col_width),
|
||||
Widget::col(vec![
|
||||
format!("{} here", props.waiting_here).draw_text(ctx),
|
||||
Widget::row(vec![
|
||||
@ -107,7 +106,7 @@ pub fn details(ctx: &mut EventCtx, app: &App, trip: TripID, details: &mut Detail
|
||||
} else {
|
||||
// The trip is finished
|
||||
col.push(Widget::row(vec![
|
||||
Line("Trip time").secondary().draw(ctx).margin_right(20),
|
||||
Widget::row(vec![Line("Trip time").secondary().draw(ctx)]).force_width(ctx, col_width),
|
||||
total_trip_time.to_string().draw_text(ctx),
|
||||
]));
|
||||
None
|
||||
|
Loading…
Reference in New Issue
Block a user