From 27912bdaf0db631a9879c574f2b8322111af81c2 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Thu, 2 Jan 2020 12:26:24 -0600 Subject: [PATCH] elide scrollbar if it's not needed --- ezgui/src/managed.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/ezgui/src/managed.rs b/ezgui/src/managed.rs index 65ef98084c..579c556568 100644 --- a/ezgui/src/managed.rs +++ b/ezgui/src/managed.rs @@ -557,17 +557,21 @@ impl Composite { top_level, CompositePosition::Aligned(HorizontalAlignment::Left, VerticalAlignment::Top), ); - c.scrollable = true; - // TODO Height of our panel - c.sliders.insert( - "scrollbar".to_string(), - Slider::vertical(ctx, ctx.canvas.window_height - 100.0), - ); - c.top_level = ManagedWidget::row(vec![c.top_level, ManagedWidget::slider("scrollbar")]); - for (name, menu) in menus { - c.menus.insert(name.to_string(), menu); - } + + // If the panel fits without a scrollbar, don't add one. c.recompute_layout(ctx); + if c.top_level.rect.height() > ctx.canvas.window_height { + c.scrollable = true; + c.sliders.insert( + "scrollbar".to_string(), + Slider::vertical(ctx, ctx.canvas.window_height), + ); + c.top_level = ManagedWidget::row(vec![c.top_level, ManagedWidget::slider("scrollbar")]); + for (name, menu) in menus { + c.menus.insert(name.to_string(), menu); + } + c.recompute_layout(ctx); + } c }