diff --git a/widget/src/combo_box.rs b/widget/src/combo_box.rs index 500d2bec56..a956c2e592 100644 --- a/widget/src/combo_box.rs +++ b/widget/src/combo_box.rs @@ -154,6 +154,7 @@ pub struct ComboBox< menu_class: ::Class<'a>, padding: Padding, size: Option, + menu_height: Length, } impl<'a, T, Message, Theme, Renderer> ComboBox<'a, T, Message, Theme, Renderer> @@ -190,6 +191,7 @@ where menu_class: ::default_menu(), padding: text_input::DEFAULT_PADDING, size: None, + menu_height: Length::Shrink, } } @@ -272,6 +274,12 @@ where } } + /// Sets the height of the menu of the [`ComboBox`]. + pub fn menu_height(mut self, menu_height: impl Into) -> Self { + self.menu_height = menu_height.into(); + self + } + /// Sets the style of the input of the [`ComboBox`]. #[must_use] pub fn input_style( @@ -890,12 +898,11 @@ where menu = menu.text_size(size); } - Some( - menu.overlay( - layout.position() + translation, - bounds.height, - ), - ) + Some(menu.overlay( + layout.position() + translation, + bounds.height, + self.menu_height, + )) } } else { None diff --git a/widget/src/overlay/menu.rs b/widget/src/overlay/menu.rs index 611476ce36..b261f37cae 100644 --- a/widget/src/overlay/menu.rs +++ b/widget/src/overlay/menu.rs @@ -128,11 +128,13 @@ where self, position: Point, target_height: f32, + menu_height: Length, ) -> overlay::Element<'a, Message, Theme, Renderer> { overlay::Element::new(Box::new(Overlay::new( position, self, target_height, + menu_height, ))) } } @@ -182,6 +184,7 @@ where position: Point, menu: Menu<'a, 'b, T, Message, Theme, Renderer>, target_height: f32, + menu_height: Length, ) -> Self where T: Clone + ToString, @@ -212,7 +215,8 @@ where text_shaping, padding, class, - }); + }) + .height(menu_height); state.tree.diff(&list as &dyn Widget<_, _, _>); diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs index 6708e7cd14..42007a92e1 100644 --- a/widget/src/pick_list.rs +++ b/widget/src/pick_list.rs @@ -174,6 +174,7 @@ pub struct PickList< class: ::Class<'a>, menu_class: ::Class<'a>, last_status: Option, + menu_height: Length, } impl<'a, T, L, V, Message, Theme, Renderer> @@ -210,6 +211,7 @@ where class: ::default(), menu_class: ::default_menu(), last_status: None, + menu_height: Length::Shrink, } } @@ -225,6 +227,12 @@ where self } + /// Sets the height of the [`Menu`]. + pub fn menu_height(mut self, menu_height: impl Into) -> Self { + self.menu_height = menu_height.into(); + self + } + /// Sets the [`Padding`] of the [`PickList`]. pub fn padding>(mut self, padding: P) -> Self { self.padding = padding.into(); @@ -721,7 +729,11 @@ where menu = menu.text_size(text_size); } - Some(menu.overlay(layout.position() + translation, bounds.height)) + Some(menu.overlay( + layout.position() + translation, + bounds.height, + self.menu_height, + )) } else { None }