menu: Add label item to PopupMenu. (#733)
<img width="883" alt="image" src="https://github.com/user-attachments/assets/06071f62-ddd3-4f9e-ae2f-82b583089792" />
This commit is contained in:
parent
f759cc5023
commit
e0f4a7d3cd
3 changed files with 56 additions and 32 deletions
|
|
@ -180,6 +180,7 @@ impl Render for PopupStory {
|
||||||
.menu("Copy", Box::new(Copy))
|
.menu("Copy", Box::new(Copy))
|
||||||
.menu("Paste", Box::new(Paste))
|
.menu("Paste", Box::new(Paste))
|
||||||
.separator()
|
.separator()
|
||||||
|
.label("This is a label")
|
||||||
.menu_with_check("Toggle Check", checked, Box::new(ToggleCheck))
|
.menu_with_check("Toggle Check", checked, Box::new(ToggleCheck))
|
||||||
.separator()
|
.separator()
|
||||||
.submenu("Settings", window, cx, move |menu, _, _| {
|
.submenu("Settings", window, cx, move |menu, _, _| {
|
||||||
|
|
@ -307,7 +308,10 @@ 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().max_h(px(300.));
|
let mut this = this
|
||||||
|
.scrollable()
|
||||||
|
.max_h(px(300.))
|
||||||
|
.label(format!("Total {} items", 100));
|
||||||
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)),
|
||||||
|
|
|
||||||
|
|
@ -279,37 +279,42 @@ impl Render for FontSizeSelector {
|
||||||
.ghost()
|
.ghost()
|
||||||
.icon(IconName::Settings2)
|
.icon(IconName::Settings2)
|
||||||
.popup_menu(move |this, _, _| {
|
.popup_menu(move |this, _, _| {
|
||||||
this.menu_with_check(
|
this.scrollable()
|
||||||
"Font Large",
|
.max_h(px(480.))
|
||||||
font_size == 18,
|
.label("Font Size")
|
||||||
Box::new(SelectFont(18)),
|
.menu_with_check("Large", font_size == 18, Box::new(SelectFont(18)))
|
||||||
)
|
.menu_with_check(
|
||||||
.menu_with_check("Font Default", font_size == 16, Box::new(SelectFont(16)))
|
"Medium (default)",
|
||||||
.menu_with_check("Font Small", font_size == 14, Box::new(SelectFont(14)))
|
font_size == 16,
|
||||||
.separator()
|
Box::new(SelectFont(16)),
|
||||||
.menu_with_check("Radius 8px", radius == 8, Box::new(SelectRadius(8)))
|
)
|
||||||
.menu_with_check(
|
.menu_with_check("Small", font_size == 14, Box::new(SelectFont(14)))
|
||||||
"Radius 4px (default)",
|
.separator()
|
||||||
radius == 4,
|
.label("Border Radius")
|
||||||
Box::new(SelectRadius(4)),
|
.menu_with_check("8px", radius == 8, Box::new(SelectRadius(8)))
|
||||||
)
|
.menu_with_check(
|
||||||
.menu_with_check("Radius 0px", radius == 0, Box::new(SelectRadius(0)))
|
"4px (default)",
|
||||||
.separator()
|
radius == 4,
|
||||||
.menu_with_check(
|
Box::new(SelectRadius(4)),
|
||||||
"Scrolling to show Scrollbar",
|
)
|
||||||
scroll_show == ScrollbarShow::Scrolling,
|
.menu_with_check("0px", radius == 0, Box::new(SelectRadius(0)))
|
||||||
Box::new(SelectScrollbarShow(ScrollbarShow::Scrolling)),
|
.separator()
|
||||||
)
|
.label("Scrollbar")
|
||||||
.menu_with_check(
|
.menu_with_check(
|
||||||
"Hover to show Scrollbar",
|
"Scrolling to show",
|
||||||
scroll_show == ScrollbarShow::Hover,
|
scroll_show == ScrollbarShow::Scrolling,
|
||||||
Box::new(SelectScrollbarShow(ScrollbarShow::Hover)),
|
Box::new(SelectScrollbarShow(ScrollbarShow::Scrolling)),
|
||||||
)
|
)
|
||||||
.menu_with_check(
|
.menu_with_check(
|
||||||
"Always show Scrollbar",
|
"Hover to show",
|
||||||
scroll_show == ScrollbarShow::Always,
|
scroll_show == ScrollbarShow::Hover,
|
||||||
Box::new(SelectScrollbarShow(ScrollbarShow::Always)),
|
Box::new(SelectScrollbarShow(ScrollbarShow::Hover)),
|
||||||
)
|
)
|
||||||
|
.menu_with_check(
|
||||||
|
"Always show",
|
||||||
|
scroll_show == ScrollbarShow::Always,
|
||||||
|
Box::new(SelectScrollbarShow(ScrollbarShow::Always)),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.anchor(Corner::TopRight),
|
.anchor(Corner::TopRight),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ impl PopupMenuExt for Button {}
|
||||||
|
|
||||||
enum PopupMenuItem {
|
enum PopupMenuItem {
|
||||||
Separator,
|
Separator,
|
||||||
|
Label(SharedString),
|
||||||
Item {
|
Item {
|
||||||
icon: Option<Icon>,
|
icon: Option<Icon>,
|
||||||
label: SharedString,
|
label: SharedString,
|
||||||
|
|
@ -191,6 +192,12 @@ impl PopupMenu {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add label
|
||||||
|
pub fn label(mut self, label: impl Into<SharedString>) -> Self {
|
||||||
|
self.menu_items.push(PopupMenuItem::Label(label.into()));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Add Menu to open link
|
/// Add Menu to open link
|
||||||
pub fn link(self, label: impl Into<SharedString>, href: impl Into<String>) -> Self {
|
pub fn link(self, label: impl Into<SharedString>, href: impl Into<String>) -> Self {
|
||||||
self.link_with_disabled(label, href, false)
|
self.link_with_disabled(label, href, false)
|
||||||
|
|
@ -690,6 +697,14 @@ impl PopupMenu {
|
||||||
.my_0p5()
|
.my_0p5()
|
||||||
.bg(cx.theme().muted),
|
.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 {
|
PopupMenuItem::ElementItem {
|
||||||
render,
|
render,
|
||||||
icon,
|
icon,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue