diff --git a/crates/story/src/popup_story.rs b/crates/story/src/popup_story.rs index 5a8a512b..35a3180d 100644 --- a/crates/story/src/popup_story.rs +++ b/crates/story/src/popup_story.rs @@ -302,7 +302,7 @@ impl Render for PopupStory { Button::new("popup-menu-11112") .label("Scrollable Menu") .popup_menu_with_anchor(Corner::TopRight, move |this, _| { - let mut this = this.scrollable(); + let mut this = this.scrollable().max_h(px(300.)); for i in 0..100 { this = this.menu( SharedString::from(format!("Item {}", i)), diff --git a/crates/ui/src/popup_menu.rs b/crates/ui/src/popup_menu.rs index 42332f01..f2004cff 100644 --- a/crates/ui/src/popup_menu.rs +++ b/crates/ui/src/popup_menu.rs @@ -101,6 +101,7 @@ pub struct PopupMenu { selected_index: Option, min_width: Pixels, max_width: Pixels, + max_height: Option, hovered_menu_ix: Option, bounds: Bounds, @@ -131,6 +132,7 @@ impl PopupMenu { selected_index: None, min_width: px(120.), max_width: px(500.), + max_height: None, has_icon: false, hovered_menu_ix: None, bounds: Bounds::default(), @@ -162,6 +164,12 @@ impl PopupMenu { self } + /// Set max height of the popup menu, default is half of the window height + pub fn max_h(mut self, height: impl Into) -> Self { + self.max_height = Some(height.into()); + self + } + /// Set the menu to be scrollable to show vertical scrollbar. /// /// NOTE: If this is true, the sub-menus will cannot be support. @@ -498,9 +506,13 @@ impl Render for PopupMenu { let items_count = self.menu_items.len(); let max_width = self.max_width; let bounds = self.bounds; - - let window_haft_height = cx.window_bounds().get_bounds().size.height * 0.5; - let max_height = window_haft_height.min(px(450.)); + let max_height = self.max_height.map_or_else( + || { + let window_half_height = cx.window_bounds().get_bounds().size.height * 0.5; + window_half_height.min(px(450.)) + }, + |height| height, + ); const ITEM_HEIGHT: Pixels = px(26.);