popup_menu: Add popup_menu_with_anchor method to control the Anchor for PopupMenu. (#378)
This commit is contained in:
parent
b8c8ddd8f5
commit
b7a1292d07
2 changed files with 12 additions and 1 deletions
|
|
@ -302,7 +302,7 @@ impl Render for PopupStory {
|
|||
.child(
|
||||
Button::new("popup-menu-11112")
|
||||
.label("Scrollable Menu")
|
||||
.popup_menu(move |this, _| {
|
||||
.popup_menu_with_anchor(AnchorCorner::TopRight, move |this, _| {
|
||||
let mut this = this.scrollable();
|
||||
for i in 0..100 {
|
||||
this = this.menu(
|
||||
|
|
|
|||
|
|
@ -32,14 +32,25 @@ pub fn init(cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
pub trait PopupMenuExt: Selectable + IntoElement + 'static {
|
||||
/// Create a popup menu with the given items, anchored to the TopLeft corner
|
||||
fn popup_menu(
|
||||
self,
|
||||
f: impl Fn(PopupMenu, &mut ViewContext<PopupMenu>) -> PopupMenu + 'static,
|
||||
) -> Popover<PopupMenu> {
|
||||
self.popup_menu_with_anchor(AnchorCorner::TopLeft, f)
|
||||
}
|
||||
|
||||
/// Create a popup menu with the given items, anchored to the given corner
|
||||
fn popup_menu_with_anchor(
|
||||
self,
|
||||
anchor: impl Into<AnchorCorner>,
|
||||
f: impl Fn(PopupMenu, &mut ViewContext<PopupMenu>) -> PopupMenu + 'static,
|
||||
) -> Popover<PopupMenu> {
|
||||
let element_id = self.element_id();
|
||||
Popover::new(SharedString::from(format!("popup-menu:{:?}", element_id)))
|
||||
.no_style()
|
||||
.trigger(self)
|
||||
.anchor(anchor.into())
|
||||
.content(move |cx| PopupMenu::build(cx, |menu, cx| f(menu, cx)))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue