From 94501e46998debb1301e8c3b93678eec177f37b3 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 14 May 2021 17:56:01 -0700 Subject: [PATCH] size horizontal-divider WRT its parent size, not absolute window size --- fifteen_min/src/viewer.rs | 2 +- game/src/info/trip.rs | 18 +++++++++--------- game/src/sandbox/gameplay/play_scenario.rs | 4 ++-- osm_viewer/src/viewer.rs | 4 ++-- widgetry/src/event_ctx.rs | 2 +- widgetry/src/widgets/mod.rs | 13 ++++++++++--- 6 files changed, 25 insertions(+), 18 deletions(-) diff --git a/fifteen_min/src/viewer.rs b/fifteen_min/src/viewer.rs index d09a760798..6c5facfdcc 100644 --- a/fifteen_min/src/viewer.rs +++ b/fifteen_min/src/viewer.rs @@ -344,7 +344,7 @@ fn build_panel(ctx: &mut EventCtx, app: &App, start: &Building, isochrone: &Isoc } // Start of toolbar - rows.push(Widget::horiz_separator(ctx, 0.3).margin_above(10)); + rows.push(Widget::horiz_separator(ctx, 1.0).margin_above(10)); rows.push(options_to_controls(ctx, &isochrone.options)); rows.push( diff --git a/game/src/info/trip.rs b/game/src/info/trip.rs index 9d2b6f089d..9138d04016 100644 --- a/game/src/info/trip.rs +++ b/game/src/info/trip.rs @@ -70,7 +70,7 @@ pub fn ongoing( { col.push(Widget::custom_row(vec![ Widget::custom_row(vec![Line("Trip time").secondary().into_widget(ctx)]) - .force_width_pct(ctx, col_width), + .force_width_window_pct(ctx, col_width), Text::from_all(vec![ Line(props.total_time.to_string(&app.opts.units)), Line(format!( @@ -86,7 +86,7 @@ pub fn ongoing( { col.push(Widget::custom_row(vec![ Widget::custom_row(vec![Line("Distance").secondary().into_widget(ctx)]) - .force_width_pct(ctx, col_width), + .force_width_window_pct(ctx, col_width), Text::from_all(vec![ Line(props.dist_crossed.to_string(&app.opts.units)), Line(format!("/{}", props.total_dist.to_string(&app.opts.units))).secondary(), @@ -100,7 +100,7 @@ pub fn ongoing( .secondary() .into_widget(ctx) .container() - .force_width_pct(ctx, col_width), + .force_width_window_pct(ctx, col_width), Widget::col(vec![ format!("{} here", props.waiting_here.to_string(&app.opts.units)).text_widget(ctx), Text::from_all(vec![ @@ -128,7 +128,7 @@ pub fn ongoing( { col.push(Widget::custom_row(vec![ Widget::custom_row(vec![Line("Purpose").secondary().into_widget(ctx)]) - .force_width_pct(ctx, col_width), + .force_width_window_pct(ctx, col_width), Line(trip.purpose.to_string()).secondary().into_widget(ctx), ])); } @@ -311,7 +311,7 @@ pub fn finished( if let Some(end_time) = phases.last().as_ref().and_then(|p| p.end_time) { col.push(Widget::custom_row(vec![ Widget::custom_row(vec![Line("Trip time").secondary().into_widget(ctx)]) - .force_width_pct(ctx, col_width), + .force_width_window_pct(ctx, col_width), (end_time - trip.departure) .to_string(&app.opts.units) .text_widget(ctx), @@ -319,7 +319,7 @@ pub fn finished( } else { col.push(Widget::custom_row(vec![ Widget::custom_row(vec![Line("Trip time").secondary().into_widget(ctx)]) - .force_width_pct(ctx, col_width), + .force_width_window_pct(ctx, col_width), "Trip didn't complete before map changes".text_widget(ctx), ])); } @@ -331,13 +331,13 @@ pub fn finished( Widget::custom_row(vec![Line("Total waiting time") .secondary() .into_widget(ctx)]) - .force_width_pct(ctx, col_width), + .force_width_window_pct(ctx, col_width), waiting.to_string(&app.opts.units).text_widget(ctx), ])); col.push(Widget::custom_row(vec![ Widget::custom_row(vec![Line("Purpose").secondary().into_widget(ctx)]) - .force_width_pct(ctx, col_width), + .force_width_window_pct(ctx, col_width), Line(trip.purpose.to_string()).secondary().into_widget(ctx), ])); } @@ -445,7 +445,7 @@ fn describe_problems( .secondary() .into_widget(ctx) .container() - .force_width_pct(ctx, col_width), + .force_width_window_pct(ctx, col_width), txt.into_widget(ctx), ]) } else { diff --git a/game/src/sandbox/gameplay/play_scenario.rs b/game/src/sandbox/gameplay/play_scenario.rs index 9dd6499e12..defcfa977b 100644 --- a/game/src/sandbox/gameplay/play_scenario.rs +++ b/game/src/sandbox/gameplay/play_scenario.rs @@ -264,7 +264,7 @@ impl EditScenarioModifiers { .text("Repeat schedule multiple days") .build_def(ctx), ])); - rows.push(Widget::horiz_separator(ctx, 0.5)); + rows.push(Widget::horiz_separator(ctx, 1.0)); rows.push( Widget::row(vec![ ctx.style() @@ -418,7 +418,7 @@ impl ChangeMode { "Departing until:".text_widget(ctx), Slider::area(ctx, 0.25 * ctx.canvas.window_width, 0.3).named("depart to"), ]), - Widget::horiz_separator(ctx, 0.5), + Widget::horiz_separator(ctx, 1.0), Widget::row(vec![ "Change to trip type:".text_widget(ctx), Widget::dropdown(ctx, "to_mode", Some(TripMode::Bike), { diff --git a/osm_viewer/src/viewer.rs b/osm_viewer/src/viewer.rs index 9471f70197..59d6812aaf 100644 --- a/osm_viewer/src/viewer.rs +++ b/osm_viewer/src/viewer.rs @@ -78,9 +78,9 @@ impl Viewer { .build_widget(ctx, "search"), ctx.style().btn_plain.text("About").build_def(ctx), ]), - Widget::horiz_separator(ctx, 0.3), + Widget::horiz_separator(ctx, 1.0), self.calculate_tags(ctx, app), - Widget::horiz_separator(ctx, 0.3), + Widget::horiz_separator(ctx, 1.0), if let Some(ref b) = self.businesses { biz_search_panel.unwrap_or_else(|| b.render(ctx).named("Search for businesses")) } else { diff --git a/widgetry/src/event_ctx.rs b/widgetry/src/event_ctx.rs index 37641d4317..f523041c11 100644 --- a/widgetry/src/event_ctx.rs +++ b/widgetry/src/event_ctx.rs @@ -173,7 +173,7 @@ impl<'a> EventCtx<'a> { .bg(Color::BLACK) .padding(15) .outline((5.0, Color::YELLOW)) - .force_width_pct(self, Percent::int(30)) + .force_width_window_pct(self, Percent::int(30)) .margin_below(5), GeomBatch::from(vec![(Color::grey(0.5), Polygon::rectangle(10.0, 100.0))]) .into_widget(self) diff --git a/widgetry/src/widgets/mod.rs b/widgetry/src/widgets/mod.rs index 94fcd6dda9..f121762e8d 100644 --- a/widgetry/src/widgets/mod.rs +++ b/widgetry/src/widgets/mod.rs @@ -204,11 +204,15 @@ impl Widget { self.layout.style.size.width = Dimension::Points(width as f32); self } - pub fn force_width_pct(mut self, ctx: &EventCtx, width: Percent) -> Widget { + pub fn force_width_window_pct(mut self, ctx: &EventCtx, width: Percent) -> Widget { self.layout.style.size.width = Dimension::Points((ctx.canvas.window_width * width.inner()) as f32); self } + pub fn force_width_parent_pct(mut self, width: f64) -> Widget { + self.layout.style.size.width = Dimension::Percent(width as f32); + self + } /// Needed for force_width. pub fn get_width_for_forcing(&self) -> f64 { @@ -510,12 +514,15 @@ impl Widget { (batch, hitbox) } - pub fn horiz_separator(ctx: &mut EventCtx, pct_width: f64) -> Widget { + pub fn horiz_separator(ctx: &mut EventCtx, pct_container_width: f64) -> Widget { GeomBatch::from(vec![( ctx.style().btn_outline.fg, - Polygon::rectangle(pct_width * ctx.canvas.window_width, 2.0), + Polygon::rectangle(0.0, 2.0), )]) .into_widget(ctx) + .container() + .bg(ctx.style().btn_outline.fg) + .force_width_parent_pct(pct_container_width) .centered_horiz() }