From 5af9c7e17b69db103eff899417ab5a055d635776 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Wed, 15 Jan 2020 10:19:21 -0800 Subject: [PATCH] every composite will automatically be scrollable if needed. simplify API. --- ezgui/src/managed.rs | 23 +---------------------- ezgui/src/widgets/wizard.rs | 2 +- game/src/common/info.rs | 2 +- game/src/edit/traffic_signals.rs | 2 +- game/src/render/traffic_signal.rs | 2 +- game/src/sandbox/dashboards.rs | 2 +- 6 files changed, 6 insertions(+), 27 deletions(-) diff --git a/ezgui/src/managed.rs b/ezgui/src/managed.rs index a0d775e2e6..6824211e54 100644 --- a/ezgui/src/managed.rs +++ b/ezgui/src/managed.rs @@ -769,27 +769,6 @@ impl CompositeBuilder { clip_rect: None, }; c.recompute_layout(ctx); - c.contents_dims = ScreenDims::new(c.top_level.rect.width(), c.top_level.rect.height()); - c.container_dims = c.contents_dims.clone(); - ctx.fake_mouseover(|ctx| assert!(c.event(ctx).is_none())); - c - } - pub fn build_scrollable(self, ctx: &mut EventCtx) -> Composite { - let mut c = Composite { - top_level: self.top_level, - layout: self.layout, - sliders: self.sliders, - menus: self.menus, - fillers: self.fillers, - - scrollable_x: false, - scrollable_y: false, - contents_dims: ScreenDims::new(0.0, 0.0), - container_dims: ScreenDims::new(0.0, 0.0), - clip_rect: None, - }; - // If the panel fits without a scrollbar, don't add one. - c.recompute_layout(ctx); c.contents_dims = ScreenDims::new(c.top_level.rect.width(), c.top_level.rect.height()); c.container_dims = ScreenDims::new( @@ -809,6 +788,7 @@ impl CompositeBuilder { }, ); + // If the panel fits without a scrollbar, don't add one. let top_left = ctx .canvas .align_window(c.container_dims, c.layout.horiz, c.layout.vert); @@ -836,7 +816,6 @@ impl CompositeBuilder { .abs(top_left.x + c.container_dims.width, top_left.y), ]); } - if c.scrollable_x || c.scrollable_y { c.recompute_layout(ctx); c.clip_rect = Some(ScreenRectangle::top_left(top_left, c.container_dims)); diff --git a/ezgui/src/widgets/wizard.rs b/ezgui/src/widgets/wizard.rs index 68e09e8387..b478f04b4e 100644 --- a/ezgui/src/widgets/wizard.rs +++ b/ezgui/src/widgets/wizard.rs @@ -295,7 +295,7 @@ impl<'a, 'b> WrappedWizard<'a, 'b> { self.ctx, ), ) - .build_scrollable(self.ctx), + .build(self.ctx), ); } diff --git a/game/src/common/info.rs b/game/src/common/info.rs index 3c971f9b46..44f376476a 100644 --- a/game/src/common/info.rs +++ b/game/src/common/info.rs @@ -90,7 +90,7 @@ impl InfoPanel { VerticalAlignment::Percent(0.2), ) .size_percent(30, 60) - .build_scrollable(ctx), + .build(ctx), } } } diff --git a/game/src/edit/traffic_signals.rs b/game/src/edit/traffic_signals.rs index 34ecdb4df1..bd7ad96228 100644 --- a/game/src/edit/traffic_signals.rs +++ b/game/src/edit/traffic_signals.rs @@ -535,7 +535,7 @@ fn make_diagram( ezgui::Composite::new(ManagedWidget::col(col).bg(Color::hex("#545454"))) .aligned(HorizontalAlignment::Left, VerticalAlignment::Top) - .build_scrollable(ctx) + .build(ctx) } fn change_traffic_signal(signal: ControlTrafficSignal, ui: &mut UI, ctx: &mut EventCtx) { diff --git a/game/src/render/traffic_signal.rs b/game/src/render/traffic_signal.rs index 6f6d95155d..7361033b0e 100644 --- a/game/src/render/traffic_signal.rs +++ b/game/src/render/traffic_signal.rs @@ -321,5 +321,5 @@ fn make_diagram(i: IntersectionID, selected: usize, ui: &UI, ctx: &mut EventCtx) Composite::new(ManagedWidget::col(col).bg(Color::hex("#545454"))) .aligned(HorizontalAlignment::Left, VerticalAlignment::Top) - .build_scrollable(ctx) + .build(ctx) } diff --git a/game/src/sandbox/dashboards.rs b/game/src/sandbox/dashboards.rs index 3fe764d4c9..fdd748be5a 100644 --- a/game/src/sandbox/dashboards.rs +++ b/game/src/sandbox/dashboards.rs @@ -63,7 +63,7 @@ pub fn make(ctx: &mut EventCtx, ui: &UI, tab: Tab) -> Box { content, ])) .fullscreen() - .build_scrollable(ctx), + .build(ctx), ) .cb("BACK", Box::new(|_, _| Some(Transition::Pop))); for (t, label) in tab_data {