Merge 7903ee12c0 into c423ad1bfc
This commit is contained in:
commit
847df89f71
9 changed files with 288 additions and 83 deletions
|
|
@ -285,26 +285,26 @@ impl cosmic::Application for App {
|
||||||
(
|
(
|
||||||
"hi 1".into(),
|
"hi 1".into(),
|
||||||
vec![
|
vec![
|
||||||
menu::Item::Button("hi 12", None, Action::Hi),
|
menu::Item::button("hi 12", None, Action::Hi),
|
||||||
menu::Item::Button("hi 13", None, Action::Hi2),
|
menu::Item::button("hi 13", None, Action::Hi2),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"hi 2".into(),
|
"hi 2".into(),
|
||||||
vec![
|
vec![
|
||||||
menu::Item::Button("hi 21", None, Action::Hi),
|
menu::Item::button("hi 21", None, Action::Hi),
|
||||||
menu::Item::Button("hi 22", None, Action::Hi2),
|
menu::Item::button("hi 22", None, Action::Hi2),
|
||||||
menu::Item::Folder(
|
menu::Item::folder(
|
||||||
"nest 3 2 >".into(),
|
"nest 3 2 >".into(),
|
||||||
vec![
|
vec![
|
||||||
menu::Item::Button("21", None, Action::Hi),
|
menu::Item::button("21", None, Action::Hi),
|
||||||
menu::Item::Button("242", None, Action::Hi2),
|
menu::Item::button("242", None, Action::Hi2),
|
||||||
menu::Item::Button("2443", None, Action::Hi3),
|
menu::Item::button("2443", None, Action::Hi3),
|
||||||
menu::Item::Folder(
|
menu::Item::folder(
|
||||||
"nest 4 2 >".into(),
|
"nest 4 2 >".into(),
|
||||||
vec![
|
vec![
|
||||||
menu::Item::Button("243", None, Action::Hi2),
|
menu::Item::button("243", None, Action::Hi2),
|
||||||
menu::Item::Button("2444", None, Action::Hi),
|
menu::Item::button("2444", None, Action::Hi),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
@ -314,34 +314,34 @@ impl cosmic::Application for App {
|
||||||
(
|
(
|
||||||
"hi 3".into(),
|
"hi 3".into(),
|
||||||
vec![
|
vec![
|
||||||
menu::Item::Button("hi 31", None, Action::Hi),
|
menu::Item::button("hi 31", None, Action::Hi),
|
||||||
menu::Item::Button("hi 332", None, Action::Hi2),
|
menu::Item::button("hi 332", None, Action::Hi2),
|
||||||
menu::Item::Button("hi 3333", None, Action::Hi3),
|
menu::Item::button("hi 3333", None, Action::Hi3),
|
||||||
menu::Item::Button("hi 33334", None, Action::Hi3),
|
menu::Item::button("hi 33334", None, Action::Hi3),
|
||||||
menu::Item::Button("hi 333335", None, Action::Hi3),
|
menu::Item::button("hi 333335", None, Action::Hi3),
|
||||||
menu::Item::Button("hi 3333336", None, Action::Hi3),
|
menu::Item::button("hi 3333336", None, Action::Hi3),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"hiiiiiiiiiiiiiiiiiii 4".into(),
|
"hiiiiiiiiiiiiiiiiiii 4".into(),
|
||||||
vec![
|
vec![
|
||||||
menu::Item::Button("hi 4", None, Action::Hi),
|
menu::Item::button("hi 4", None, Action::Hi),
|
||||||
menu::Item::Button("hi 44", None, Action::Hi2),
|
menu::Item::button("hi 44", None, Action::Hi2),
|
||||||
menu::Item::Button("hi 444", None, Action::Hi3),
|
menu::Item::button("hi 444", None, Action::Hi3),
|
||||||
menu::Item::Folder(
|
menu::Item::folder(
|
||||||
"nest 4 >".into(),
|
"nest 4 >".into(),
|
||||||
vec![
|
vec![
|
||||||
menu::Item::Button("hi 41", None, Action::Hi),
|
menu::Item::button("hi 41", None, Action::Hi),
|
||||||
menu::Item::Button("hi 442", None, Action::Hi2),
|
menu::Item::button("hi 442", None, Action::Hi2),
|
||||||
menu::Item::Folder(
|
menu::Item::folder(
|
||||||
"nest 3 4 >".into(),
|
"nest 3 4 >".into(),
|
||||||
vec![
|
vec![
|
||||||
menu::Item::Button("hi 443", None, Action::Hi2),
|
menu::Item::button("hi 443", None, Action::Hi2),
|
||||||
menu::Item::Button("hi 4444", None, Action::Hi),
|
menu::Item::button("hi 4444", None, Action::Hi),
|
||||||
menu::Item::Button("hi 44444", None, Action::Hi3),
|
menu::Item::button("hi 44444", None, Action::Hi3),
|
||||||
menu::Item::Button("hi 444445", None, Action::Hi3),
|
menu::Item::button("hi 444445", None, Action::Hi3),
|
||||||
menu::Item::Button("hi 4444446", None, Action::Hi3),
|
menu::Item::button("hi 4444446", None, Action::Hi3),
|
||||||
menu::Item::Button("hi 44444447", None, Action::Hi3),
|
menu::Item::button("hi 44444447", None, Action::Hi3),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -122,19 +122,21 @@ impl App {
|
||||||
Some(menu::items(
|
Some(menu::items(
|
||||||
&HashMap::new(),
|
&HashMap::new(),
|
||||||
vec![
|
vec![
|
||||||
menu::Item::Button("New window", None, ContextMenuAction::WindowNew),
|
menu::Item::button("New window", None, ContextMenuAction::WindowNew),
|
||||||
menu::Item::Divider,
|
menu::Item::divider(),
|
||||||
menu::Item::Folder(
|
menu::Item::folder(
|
||||||
"View",
|
"View",
|
||||||
vec![menu::Item::CheckBox(
|
vec![menu::Item::checkbox(
|
||||||
"Hide content",
|
"Hide content",
|
||||||
None,
|
None,
|
||||||
self.hide_content,
|
self.hide_content,
|
||||||
ContextMenuAction::ToggleHideContent,
|
ContextMenuAction::ToggleHideContent,
|
||||||
)],
|
)],
|
||||||
),
|
)
|
||||||
menu::Item::Divider,
|
.width(200)
|
||||||
menu::Item::Button("Quit", None, ContextMenuAction::WindowClose),
|
.min_width(180),
|
||||||
|
menu::Item::divider(),
|
||||||
|
menu::Item::button("Quit", None, ContextMenuAction::WindowClose),
|
||||||
],
|
],
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -160,23 +160,26 @@ pub fn menu_bar<'a>(config: &Config, key_binds: &HashMap<KeyBind, Action>) -> El
|
||||||
menu::items(
|
menu::items(
|
||||||
key_binds,
|
key_binds,
|
||||||
vec![
|
vec![
|
||||||
menu::Item::Button(
|
menu::Item::button(
|
||||||
"New window",
|
"New window",
|
||||||
Some(cosmic::widget::icon::from_name("screenshot-window-symbolic").into()),
|
Some(cosmic::widget::icon::from_name("screenshot-window-symbolic").into()),
|
||||||
Action::WindowNew,
|
Action::WindowNew,
|
||||||
),
|
),
|
||||||
menu::Item::Divider,
|
menu::Item::divider(),
|
||||||
menu::Item::Folder(
|
menu::Item::folder(
|
||||||
"View",
|
"View",
|
||||||
vec![menu::Item::CheckBox(
|
vec![menu::Item::checkbox(
|
||||||
"Hide content",
|
"Hide content",
|
||||||
Some(cosmic::widget::icon::from_name("view-conceal-symbolic").into()),
|
Some(cosmic::widget::icon::from_name("view-conceal-symbolic").into()),
|
||||||
config.hide_content,
|
config.hide_content,
|
||||||
Action::ToggleHideContent,
|
Action::ToggleHideContent,
|
||||||
)],
|
)],
|
||||||
),
|
)
|
||||||
menu::Item::Divider,
|
.width(280)
|
||||||
menu::Item::Button(
|
.min_width(200)
|
||||||
|
.max_width(300),
|
||||||
|
menu::Item::divider(),
|
||||||
|
menu::Item::button(
|
||||||
"Quit",
|
"Quit",
|
||||||
Some(cosmic::widget::icon::from_name("window-close-symbolic").into()),
|
Some(cosmic::widget::icon::from_name("window-close-symbolic").into()),
|
||||||
Action::WindowClose,
|
Action::WindowClose,
|
||||||
|
|
|
||||||
|
|
@ -135,9 +135,9 @@ impl cosmic::Application for App {
|
||||||
Some(menu::items(
|
Some(menu::items(
|
||||||
&HashMap::new(),
|
&HashMap::new(),
|
||||||
vec![
|
vec![
|
||||||
menu::Item::Button("Move Up", None, NavMenuAction::MoveUp(id)),
|
menu::Item::button("Move Up", None, NavMenuAction::MoveUp(id)),
|
||||||
menu::Item::Button("Move Down", None, NavMenuAction::MoveDown(id)),
|
menu::Item::button("Move Down", None, NavMenuAction::MoveDown(id)),
|
||||||
menu::Item::Button("Delete", None, NavMenuAction::Delete(id)),
|
menu::Item::button("Delete", None, NavMenuAction::Delete(id)),
|
||||||
],
|
],
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -212,7 +212,7 @@ impl cosmic::Application for App {
|
||||||
.item_context(move |item| {
|
.item_context(move |item| {
|
||||||
Some(widget::menu::items(
|
Some(widget::menu::items(
|
||||||
&HashMap::new(),
|
&HashMap::new(),
|
||||||
vec![widget::menu::Item::Button(
|
vec![widget::menu::Item::button(
|
||||||
format!("Action on {}", item.name.to_string()),
|
format!("Action on {}", item.name.to_string()),
|
||||||
None,
|
None,
|
||||||
Action::None,
|
Action::None,
|
||||||
|
|
@ -227,7 +227,7 @@ impl cosmic::Application for App {
|
||||||
.item_context(|item| {
|
.item_context(|item| {
|
||||||
Some(widget::menu::items(
|
Some(widget::menu::items(
|
||||||
&HashMap::new(),
|
&HashMap::new(),
|
||||||
vec![widget::menu::Item::Button(
|
vec![widget::menu::Item::button(
|
||||||
format!("Action on {}", item.name),
|
format!("Action on {}", item.name),
|
||||||
None,
|
None,
|
||||||
Action::None,
|
Action::None,
|
||||||
|
|
@ -238,12 +238,12 @@ impl cosmic::Application for App {
|
||||||
Some(widget::menu::items(
|
Some(widget::menu::items(
|
||||||
&HashMap::new(),
|
&HashMap::new(),
|
||||||
vec![
|
vec![
|
||||||
widget::menu::Item::Button(
|
widget::menu::Item::button(
|
||||||
format!("Action on {} category", category.to_string()),
|
format!("Action on {} category", category.to_string()),
|
||||||
None,
|
None,
|
||||||
Action::None,
|
Action::None,
|
||||||
),
|
),
|
||||||
widget::menu::Item::Button(
|
widget::menu::Item::button(
|
||||||
format!("Other action on {} category", category.to_string()),
|
format!("Other action on {} category", category.to_string()),
|
||||||
None,
|
None,
|
||||||
Action::None,
|
Action::None,
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,8 @@ pub use menu_bar::{MenuBar, menu_bar as bar};
|
||||||
mod menu_inner;
|
mod menu_inner;
|
||||||
mod menu_tree;
|
mod menu_tree;
|
||||||
pub use menu_tree::{
|
pub use menu_tree::{
|
||||||
MenuItem as Item, MenuTree as Tree, menu_button, menu_items as items, menu_root as root,
|
MenuItem as Item, MenuItemKind as ItemKind, MenuTree as Tree, menu_button, menu_items as items,
|
||||||
|
menu_root as root,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use crate::style::menu_bar::{Appearance, StyleSheet};
|
pub use crate::style::menu_bar::{Appearance, StyleSheet};
|
||||||
|
|
|
||||||
|
|
@ -1686,7 +1686,12 @@ fn get_children_layout<Message>(
|
||||||
) -> (Size, Vec<f32>, Vec<Size>) {
|
) -> (Size, Vec<f32>, Vec<Size>) {
|
||||||
let width = match item_width {
|
let width = match item_width {
|
||||||
ItemWidth::Uniform(u) => f32::from(u),
|
ItemWidth::Uniform(u) => f32::from(u),
|
||||||
ItemWidth::Static(s) => f32::from(menu_tree.width.unwrap_or(s)),
|
ItemWidth::Static(s) => {
|
||||||
|
let base = f32::from(menu_tree.width.unwrap_or(s));
|
||||||
|
let min = menu_tree.min_width.map(f32::from).unwrap_or(0.0);
|
||||||
|
let max = menu_tree.max_width.map(f32::from).unwrap_or(f32::MAX);
|
||||||
|
base.clamp(min, max)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let child_sizes: Vec<Size> = match item_height {
|
let child_sizes: Vec<Size> = match item_height {
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,10 @@ pub struct MenuTree<Message> {
|
||||||
pub(crate) children: Vec<MenuTree<Message>>,
|
pub(crate) children: Vec<MenuTree<Message>>,
|
||||||
/// The width of the menu tree
|
/// The width of the menu tree
|
||||||
pub(crate) width: Option<u16>,
|
pub(crate) width: Option<u16>,
|
||||||
|
/// The min width of the menu tree
|
||||||
|
pub(crate) min_width: Option<u16>,
|
||||||
|
/// The max width of the menu tree
|
||||||
|
pub(crate) max_width: Option<u16>,
|
||||||
/// The height of the menu tree
|
/// The height of the menu tree
|
||||||
pub(crate) height: Option<u16>,
|
pub(crate) height: Option<u16>,
|
||||||
}
|
}
|
||||||
|
|
@ -48,6 +52,8 @@ impl<Message: Clone + 'static> MenuTree<Message> {
|
||||||
item: item.into(),
|
item: item.into(),
|
||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
width: None,
|
width: None,
|
||||||
|
min_width: None,
|
||||||
|
max_width: None,
|
||||||
height: None,
|
height: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -62,6 +68,8 @@ impl<Message: Clone + 'static> MenuTree<Message> {
|
||||||
item: item.into(),
|
item: item.into(),
|
||||||
children: children.into_iter().map(Into::into).collect(),
|
children: children.into_iter().map(Into::into).collect(),
|
||||||
width: None,
|
width: None,
|
||||||
|
min_width: None,
|
||||||
|
max_width: None,
|
||||||
height: None,
|
height: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -76,6 +84,18 @@ impl<Message: Clone + 'static> MenuTree<Message> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the min width of the menu tree.
|
||||||
|
pub fn min_width(mut self, min: u16) -> Self {
|
||||||
|
self.min_width = Some(min);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the max width of the menu tree.
|
||||||
|
pub fn max_width(mut self, max: u16) -> Self {
|
||||||
|
self.max_width = Some(max);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the height of the menu tree.
|
/// Sets the height of the menu tree.
|
||||||
/// See [`ItemHeight`]
|
/// See [`ItemHeight`]
|
||||||
///
|
///
|
||||||
|
|
@ -155,24 +175,12 @@ where
|
||||||
.class(theme::Button::MenuItem)
|
.class(theme::Button::MenuItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The type of menu item
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
/// Represents a menu item that performs an action when selected or a separator between menu items.
|
pub enum MenuItemKind<A: MenuAction, L: Into<Cow<'static, str>>> {
|
||||||
///
|
|
||||||
/// - `Action` - Represents a menu item that performs an action when selected.
|
|
||||||
/// - `L` - The label of the menu item.
|
|
||||||
/// - `A` - The action to perform when the menu item is selected, the action must implement the `MenuAction` trait.
|
|
||||||
/// - `CheckBox` - Represents a checkbox menu item.
|
|
||||||
/// - `L` - The label of the menu item.
|
|
||||||
/// - `bool` - The state of the checkbox.
|
|
||||||
/// - `A` - The action to perform when the menu item is selected, the action must implement the `MenuAction` trait.
|
|
||||||
/// - `Folder` - Represents a folder menu item.
|
|
||||||
/// - `L` - The label of the menu item.
|
|
||||||
/// - `Vec<MenuItem<A, L>>` - A vector of menu items.
|
|
||||||
/// - `Divider` - Represents a divider between menu items.
|
|
||||||
pub enum MenuItem<A: MenuAction, L: Into<Cow<'static, str>>> {
|
|
||||||
/// Represents a button menu item.
|
/// Represents a button menu item.
|
||||||
Button(L, Option<icon::Handle>, A),
|
Button(L, Option<icon::Handle>, A),
|
||||||
/// Represents a button menu item that is disabled.
|
/// Represents a button menu item that's disabled.
|
||||||
ButtonDisabled(L, Option<icon::Handle>, A),
|
ButtonDisabled(L, Option<icon::Handle>, A),
|
||||||
/// Represents a checkbox menu item.
|
/// Represents a checkbox menu item.
|
||||||
CheckBox(L, Option<icon::Handle>, bool, A),
|
CheckBox(L, Option<icon::Handle>, bool, A),
|
||||||
|
|
@ -182,6 +190,118 @@ pub enum MenuItem<A: MenuAction, L: Into<Cow<'static, str>>> {
|
||||||
Divider,
|
Divider,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A menu item with optional width configuration.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```ignore
|
||||||
|
/// use cosmic::widget::menu;
|
||||||
|
///
|
||||||
|
/// // Simple button
|
||||||
|
/// menu::Item::button("Save", None, Action::Save);
|
||||||
|
///
|
||||||
|
/// // Button with icon
|
||||||
|
/// menu::Item::button(
|
||||||
|
/// "Open",
|
||||||
|
/// Some(cosmic::widget::icon::from_name("document-open-symbolic").into()),
|
||||||
|
/// Action::Open,
|
||||||
|
/// );
|
||||||
|
///
|
||||||
|
/// // Checkbox
|
||||||
|
/// menu::Item::checkbox("Show Hidden", None, true, Action::ToggleHidden);
|
||||||
|
///
|
||||||
|
/// // Folder with custom width
|
||||||
|
/// menu::Item::folder("Recent", vec![
|
||||||
|
/// menu::Item::button("file1.txt", None, Action::OpenRecent(0)),
|
||||||
|
/// ]).width(300);
|
||||||
|
///
|
||||||
|
/// // Divider
|
||||||
|
/// menu::Item::divider();
|
||||||
|
///
|
||||||
|
/// // Folder with custom width constraints
|
||||||
|
/// menu::Item::folder("Recent", vec![
|
||||||
|
/// menu::Item::button("file1.txt", None, Action::OpenRecent(0)),
|
||||||
|
/// ]).width(300).min_width(200).max_width(400);
|
||||||
|
///
|
||||||
|
/// // Using min_width to ensure a minimum size
|
||||||
|
/// menu::Item::button("Short", None, Action::Short).min_width(150);
|
||||||
|
///
|
||||||
|
/// // Using max_width to cap the size
|
||||||
|
/// menu::Item::button("Very Long Label Here", None, Action::Long).max_width(200);
|
||||||
|
/// ```
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct MenuItem<A: MenuAction, L: Into<Cow<'static, str>>> {
|
||||||
|
/// Kind of menu item.
|
||||||
|
kind: MenuItemKind<A, L>,
|
||||||
|
/// Optional width override for this item.
|
||||||
|
width: Option<u16>,
|
||||||
|
/// Optional min width for this item.
|
||||||
|
min_width: Option<u16>,
|
||||||
|
/// Optional max width for this item.
|
||||||
|
max_width: Option<u16>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<A: MenuAction, L: Into<Cow<'static, str>>> MenuItem<A, L> {
|
||||||
|
/// Create from a kind with no width set
|
||||||
|
pub fn new(kind: MenuItemKind<A, L>) -> Self {
|
||||||
|
Self {
|
||||||
|
kind,
|
||||||
|
width: None,
|
||||||
|
min_width: None,
|
||||||
|
max_width: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Builder method to set width
|
||||||
|
pub fn width(mut self, width: u16) -> Self {
|
||||||
|
self.width = Some(width);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Builder method to set minimum width
|
||||||
|
pub fn min_width(mut self, min: u16) -> Self {
|
||||||
|
self.min_width = Some(min);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Builder method to set max width
|
||||||
|
pub fn max_width(mut self, max: u16) -> Self {
|
||||||
|
self.max_width = Some(max);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a button menu item.
|
||||||
|
pub fn button(label: L, icon: Option<icon::Handle>, action: A) -> Self {
|
||||||
|
Self::new(MenuItemKind::Button(label, icon, action))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a disabled button menu item.
|
||||||
|
pub fn button_disabled(label: L, icon: Option<icon::Handle>, action: A) -> Self {
|
||||||
|
Self::new(MenuItemKind::ButtonDisabled(label, icon, action))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a checkbox menu item.
|
||||||
|
pub fn checkbox(label: L, icon: Option<icon::Handle>, checked: bool, action: A) -> Self {
|
||||||
|
Self::new(MenuItemKind::CheckBox(label, icon, checked, action))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a folder (submenu) menu item.
|
||||||
|
pub fn folder(label: L, children: Vec<MenuItem<A, L>>) -> Self {
|
||||||
|
Self::new(MenuItemKind::Folder(label, children))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a divider between menu items.
|
||||||
|
pub fn divider() -> Self {
|
||||||
|
Self::new(MenuItemKind::Divider)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<A: MenuAction, L: Into<Cow<'static, str>>> From<MenuItemKind<A, L>> for MenuItem<A, L> {
|
||||||
|
fn from(kind: MenuItemKind<A, L>) -> Self {
|
||||||
|
Self::new(kind)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a root menu item.
|
/// Create a root menu item.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
|
@ -246,9 +366,12 @@ pub fn menu_items<
|
||||||
.flat_map(|(i, item)| {
|
.flat_map(|(i, item)| {
|
||||||
let mut trees = vec![];
|
let mut trees = vec![];
|
||||||
let spacing = crate::theme::spacing();
|
let spacing = crate::theme::spacing();
|
||||||
|
let item_width = item.width;
|
||||||
|
let item_min_width = item.min_width;
|
||||||
|
let item_max_width = item.max_width;
|
||||||
|
|
||||||
match item {
|
match item.kind {
|
||||||
MenuItem::Button(label, icon, action) => {
|
MenuItemKind::Button(label, icon, action) => {
|
||||||
let l: Cow<'static, str> = label.into();
|
let l: Cow<'static, str> = label.into();
|
||||||
let key = find_key(&action, key_binds);
|
let key = find_key(&action, key_binds);
|
||||||
let mut items = vec![
|
let mut items = vec![
|
||||||
|
|
@ -276,9 +399,24 @@ pub fn menu_items<
|
||||||
|
|
||||||
let menu_button = menu_button(items).on_press(action.message());
|
let menu_button = menu_button(items).on_press(action.message());
|
||||||
|
|
||||||
trees.push(MenuTree::<Message>::from(Element::from(menu_button)));
|
// Add a user designated width
|
||||||
|
let mut tree = MenuTree::<Message>::from(Element::from(menu_button));
|
||||||
|
|
||||||
|
if let Some(width) = item_width {
|
||||||
|
tree = tree.width(width);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(min_width) = item_min_width {
|
||||||
|
tree = tree.min_width(min_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(max_width) = item_max_width {
|
||||||
|
tree = tree.max_width(max_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
trees.push(tree);
|
||||||
}
|
}
|
||||||
MenuItem::ButtonDisabled(label, icon, action) => {
|
MenuItemKind::ButtonDisabled(label, icon, action) => {
|
||||||
let l: Cow<'static, str> = label.into();
|
let l: Cow<'static, str> = label.into();
|
||||||
|
|
||||||
let key = find_key(&action, key_binds);
|
let key = find_key(&action, key_binds);
|
||||||
|
|
@ -308,9 +446,23 @@ pub fn menu_items<
|
||||||
|
|
||||||
let menu_button = menu_button(items);
|
let menu_button = menu_button(items);
|
||||||
|
|
||||||
trees.push(MenuTree::<Message>::from(Element::from(menu_button)));
|
let mut tree = MenuTree::<Message>::from(Element::from(menu_button));
|
||||||
|
|
||||||
|
if let Some(width) = item_width {
|
||||||
|
tree = tree.width(width);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(min_width) = item_min_width {
|
||||||
|
tree = tree.min_width(min_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(max_width) = item_max_width {
|
||||||
|
tree = tree.max_width(max_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
trees.push(tree);
|
||||||
}
|
}
|
||||||
MenuItem::CheckBox(label, icon, value, action) => {
|
MenuItemKind::CheckBox(label, icon, value, action) => {
|
||||||
let key = find_key(&action, key_binds);
|
let key = find_key(&action, key_binds);
|
||||||
let mut items = vec![
|
let mut items = vec![
|
||||||
if value {
|
if value {
|
||||||
|
|
@ -353,14 +505,28 @@ pub fn menu_items<
|
||||||
items.insert(2, widget::icon::icon(icon).size(14).into());
|
items.insert(2, widget::icon::icon(icon).size(14).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
trees.push(MenuTree::from(Element::from(
|
let mut tree = MenuTree::from(Element::from(
|
||||||
menu_button(items).on_press(action.message()),
|
menu_button(items).on_press(action.message()),
|
||||||
)));
|
));
|
||||||
|
|
||||||
|
if let Some(width) = item_width {
|
||||||
|
tree = tree.width(width);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(min_width) = item_min_width {
|
||||||
|
tree = tree.min_width(min_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(max_width) = item_max_width {
|
||||||
|
tree = tree.max_width(max_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
trees.push(tree);
|
||||||
}
|
}
|
||||||
MenuItem::Folder(label, children) => {
|
MenuItemKind::Folder(label, children) => {
|
||||||
let l: Cow<'static, str> = label.into();
|
let l: Cow<'static, str> = label.into();
|
||||||
|
|
||||||
trees.push(MenuTree::<Message>::with_children(
|
let mut tree = MenuTree::<Message>::with_children(
|
||||||
RcElementWrapper::new(crate::Element::from(
|
RcElementWrapper::new(crate::Element::from(
|
||||||
menu_button::<'static, _>(vec![
|
menu_button::<'static, _>(vec![
|
||||||
widget::text(l.clone())
|
widget::text(l.clone())
|
||||||
|
|
@ -386,13 +552,41 @@ pub fn menu_items<
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
menu_items(key_binds, children),
|
menu_items(key_binds, children),
|
||||||
));
|
);
|
||||||
|
|
||||||
|
if let Some(width) = item_width {
|
||||||
|
tree = tree.width(width);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(min_width) = item_min_width {
|
||||||
|
tree = tree.min_width(min_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(max_width) = item_max_width {
|
||||||
|
tree = tree.max_width(max_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
trees.push(tree);
|
||||||
}
|
}
|
||||||
MenuItem::Divider => {
|
MenuItemKind::Divider => {
|
||||||
if i != size - 1 {
|
if i != size - 1 {
|
||||||
trees.push(MenuTree::<Message>::from(Element::from(
|
let mut tree = MenuTree::<Message>::from(Element::from(
|
||||||
widget::divider::horizontal::light(),
|
widget::divider::horizontal::light(),
|
||||||
)));
|
));
|
||||||
|
|
||||||
|
if let Some(width) = item_width {
|
||||||
|
tree = tree.width(width);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(min_width) = item_min_width {
|
||||||
|
tree = tree.min_width(min_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(max_width) = item_max_width {
|
||||||
|
tree = tree.max_width(max_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
trees.push(tree);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ impl ResponsiveMenuBar {
|
||||||
key_binds,
|
key_binds,
|
||||||
trees
|
trees
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|mt| menu::Item::Folder(mt.0, mt.1))
|
.map(|mt| menu::Item::folder(mt.0, mt.1))
|
||||||
.collect(),
|
.collect(),
|
||||||
)
|
)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue