Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add menu_height method to PickList and ComboBox widgets. #2699

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions widget/src/combo_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ pub struct ComboBox<
menu_class: <Theme as menu::Catalog>::Class<'a>,
padding: Padding,
size: Option<f32>,
menu_height: Length,
}

impl<'a, T, Message, Theme, Renderer> ComboBox<'a, T, Message, Theme, Renderer>
Expand Down Expand Up @@ -190,6 +191,7 @@ where
menu_class: <Theme as Catalog>::default_menu(),
padding: text_input::DEFAULT_PADDING,
size: None,
menu_height: Length::Shrink,
}
}

Expand Down Expand Up @@ -272,6 +274,12 @@ where
}
}

/// Sets the height of the menu of the [`ComboBox`].
pub fn menu_height(mut self, menu_height: impl Into<Length>) -> Self {
self.menu_height = menu_height.into();
self
}

/// Sets the style of the input of the [`ComboBox`].
#[must_use]
pub fn input_style(
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion widget/src/overlay/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)))
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -212,7 +215,8 @@ where
text_shaping,
padding,
class,
});
})
.height(menu_height);

state.tree.diff(&list as &dyn Widget<_, _, _>);

Expand Down
14 changes: 13 additions & 1 deletion widget/src/pick_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ pub struct PickList<
class: <Theme as Catalog>::Class<'a>,
menu_class: <Theme as menu::Catalog>::Class<'a>,
last_status: Option<Status>,
menu_height: Length,
}

impl<'a, T, L, V, Message, Theme, Renderer>
Expand Down Expand Up @@ -210,6 +211,7 @@ where
class: <Theme as Catalog>::default(),
menu_class: <Theme as Catalog>::default_menu(),
last_status: None,
menu_height: Length::Shrink,
}
}

Expand All @@ -225,6 +227,12 @@ where
self
}

/// Sets the height of the [`Menu`].
pub fn menu_height(mut self, menu_height: impl Into<Length>) -> Self {
self.menu_height = menu_height.into();
self
}

/// Sets the [`Padding`] of the [`PickList`].
pub fn padding<P: Into<Padding>>(mut self, padding: P) -> Self {
self.padding = padding.into();
Expand Down Expand Up @@ -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
}
Expand Down
Loading