popup_menu: Add max_h to set the height of menu (#570)
This commit is contained in:
parent
e03a0d4f4e
commit
1ff84a9943
2 changed files with 16 additions and 4 deletions
|
|
@ -302,7 +302,7 @@ impl Render for PopupStory {
|
||||||
Button::new("popup-menu-11112")
|
Button::new("popup-menu-11112")
|
||||||
.label("Scrollable Menu")
|
.label("Scrollable Menu")
|
||||||
.popup_menu_with_anchor(Corner::TopRight, move |this, _| {
|
.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 {
|
for i in 0..100 {
|
||||||
this = this.menu(
|
this = this.menu(
|
||||||
SharedString::from(format!("Item {}", i)),
|
SharedString::from(format!("Item {}", i)),
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,7 @@ pub struct PopupMenu {
|
||||||
selected_index: Option<usize>,
|
selected_index: Option<usize>,
|
||||||
min_width: Pixels,
|
min_width: Pixels,
|
||||||
max_width: Pixels,
|
max_width: Pixels,
|
||||||
|
max_height: Option<Pixels>,
|
||||||
hovered_menu_ix: Option<usize>,
|
hovered_menu_ix: Option<usize>,
|
||||||
bounds: Bounds<Pixels>,
|
bounds: Bounds<Pixels>,
|
||||||
|
|
||||||
|
|
@ -131,6 +132,7 @@ impl PopupMenu {
|
||||||
selected_index: None,
|
selected_index: None,
|
||||||
min_width: px(120.),
|
min_width: px(120.),
|
||||||
max_width: px(500.),
|
max_width: px(500.),
|
||||||
|
max_height: None,
|
||||||
has_icon: false,
|
has_icon: false,
|
||||||
hovered_menu_ix: None,
|
hovered_menu_ix: None,
|
||||||
bounds: Bounds::default(),
|
bounds: Bounds::default(),
|
||||||
|
|
@ -162,6 +164,12 @@ impl PopupMenu {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set max height of the popup menu, default is half of the window height
|
||||||
|
pub fn max_h(mut self, height: impl Into<Pixels>) -> Self {
|
||||||
|
self.max_height = Some(height.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Set the menu to be scrollable to show vertical scrollbar.
|
/// Set the menu to be scrollable to show vertical scrollbar.
|
||||||
///
|
///
|
||||||
/// NOTE: If this is true, the sub-menus will cannot be support.
|
/// 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 items_count = self.menu_items.len();
|
||||||
let max_width = self.max_width;
|
let max_width = self.max_width;
|
||||||
let bounds = self.bounds;
|
let bounds = self.bounds;
|
||||||
|
let max_height = self.max_height.map_or_else(
|
||||||
let window_haft_height = cx.window_bounds().get_bounds().size.height * 0.5;
|
|| {
|
||||||
let max_height = window_haft_height.min(px(450.));
|
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.);
|
const ITEM_HEIGHT: Pixels = px(26.);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue