From 24acb279348a04533d03d18f0b6e133f9c7d89c1 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Fri, 3 Apr 2020 13:35:20 -0700 Subject: [PATCH] force override width to make the table look nice --- ezgui/src/managed.rs | 7 +++++++ game/src/info/trip.rs | 11 +++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ezgui/src/managed.rs b/ezgui/src/managed.rs index ec0a33e4ca..990be2dc2c 100644 --- a/ezgui/src/managed.rs +++ b/ezgui/src/managed.rs @@ -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); diff --git a/game/src/info/trip.rs b/game/src/info/trip.rs index 91abf96212..61ad84d1ea 100644 --- a/game/src/info/trip.rs +++ b/game/src/info/trip.rs @@ -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