diff --git a/crates/story/src/popup_story.rs b/crates/story/src/popup_story.rs index 2705b844..d6ad2cb3 100644 --- a/crates/story/src/popup_story.rs +++ b/crates/story/src/popup_story.rs @@ -180,6 +180,7 @@ impl Render for PopupStory { .menu("Copy", Box::new(Copy)) .menu("Paste", Box::new(Paste)) .separator() + .label("This is a label") .menu_with_check("Toggle Check", checked, Box::new(ToggleCheck)) .separator() .submenu("Settings", window, cx, move |menu, _, _| { @@ -307,7 +308,10 @@ 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().max_h(px(300.)); + let mut this = this + .scrollable() + .max_h(px(300.)) + .label(format!("Total {} items", 100)); for i in 0..100 { this = this.menu( SharedString::from(format!("Item {}", i)), diff --git a/crates/story/src/title_bar.rs b/crates/story/src/title_bar.rs index b6d0e42e..934665e6 100644 --- a/crates/story/src/title_bar.rs +++ b/crates/story/src/title_bar.rs @@ -279,37 +279,42 @@ impl Render for FontSizeSelector { .ghost() .icon(IconName::Settings2) .popup_menu(move |this, _, _| { - this.menu_with_check( - "Font Large", - font_size == 18, - Box::new(SelectFont(18)), - ) - .menu_with_check("Font Default", font_size == 16, Box::new(SelectFont(16))) - .menu_with_check("Font Small", font_size == 14, Box::new(SelectFont(14))) - .separator() - .menu_with_check("Radius 8px", radius == 8, Box::new(SelectRadius(8))) - .menu_with_check( - "Radius 4px (default)", - radius == 4, - Box::new(SelectRadius(4)), - ) - .menu_with_check("Radius 0px", radius == 0, Box::new(SelectRadius(0))) - .separator() - .menu_with_check( - "Scrolling to show Scrollbar", - scroll_show == ScrollbarShow::Scrolling, - Box::new(SelectScrollbarShow(ScrollbarShow::Scrolling)), - ) - .menu_with_check( - "Hover to show Scrollbar", - scroll_show == ScrollbarShow::Hover, - Box::new(SelectScrollbarShow(ScrollbarShow::Hover)), - ) - .menu_with_check( - "Always show Scrollbar", - scroll_show == ScrollbarShow::Always, - Box::new(SelectScrollbarShow(ScrollbarShow::Always)), - ) + this.scrollable() + .max_h(px(480.)) + .label("Font Size") + .menu_with_check("Large", font_size == 18, Box::new(SelectFont(18))) + .menu_with_check( + "Medium (default)", + font_size == 16, + Box::new(SelectFont(16)), + ) + .menu_with_check("Small", font_size == 14, Box::new(SelectFont(14))) + .separator() + .label("Border Radius") + .menu_with_check("8px", radius == 8, Box::new(SelectRadius(8))) + .menu_with_check( + "4px (default)", + radius == 4, + Box::new(SelectRadius(4)), + ) + .menu_with_check("0px", radius == 0, Box::new(SelectRadius(0))) + .separator() + .label("Scrollbar") + .menu_with_check( + "Scrolling to show", + scroll_show == ScrollbarShow::Scrolling, + Box::new(SelectScrollbarShow(ScrollbarShow::Scrolling)), + ) + .menu_with_check( + "Hover to show", + scroll_show == ScrollbarShow::Hover, + Box::new(SelectScrollbarShow(ScrollbarShow::Hover)), + ) + .menu_with_check( + "Always show", + scroll_show == ScrollbarShow::Always, + Box::new(SelectScrollbarShow(ScrollbarShow::Always)), + ) }) .anchor(Corner::TopRight), ) diff --git a/crates/ui/src/popup_menu.rs b/crates/ui/src/popup_menu.rs index ce564bdc..43c90a38 100644 --- a/crates/ui/src/popup_menu.rs +++ b/crates/ui/src/popup_menu.rs @@ -61,6 +61,7 @@ impl PopupMenuExt for Button {} enum PopupMenuItem { Separator, + Label(SharedString), Item { icon: Option, label: SharedString, @@ -191,6 +192,12 @@ impl PopupMenu { self } + /// Add label + pub fn label(mut self, label: impl Into) -> Self { + self.menu_items.push(PopupMenuItem::Label(label.into())); + self + } + /// Add Menu to open link pub fn link(self, label: impl Into, href: impl Into) -> Self { self.link_with_disabled(label, href, false) @@ -690,6 +697,14 @@ impl PopupMenu { .my_0p5() .bg(cx.theme().muted), ), + PopupMenuItem::Label(label) => this.disabled(true).cursor_default().child( + h_flex() + .cursor_default() + .items_center() + .gap_x_1() + .children(Self::render_icon(has_icon, None, window, cx)) + .child(label.clone()), + ), PopupMenuItem::ElementItem { render, icon,