Remove ContextMenu::element_item
This commit is contained in:
parent
df2f471ddf
commit
d3b976d044
2 changed files with 37 additions and 19 deletions
|
@ -37,6 +37,33 @@ pub enum ContextMenuItemLabel {
|
||||||
Element(ContextMenuItemBuilder),
|
Element(ContextMenuItemBuilder),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Cow<'static, str>> for ContextMenuItemLabel {
|
||||||
|
fn from(s: Cow<'static, str>) -> Self {
|
||||||
|
Self::String(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&'static str> for ContextMenuItemLabel {
|
||||||
|
fn from(s: &'static str) -> Self {
|
||||||
|
Self::String(s.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<String> for ContextMenuItemLabel {
|
||||||
|
fn from(s: String) -> Self {
|
||||||
|
Self::String(s.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> From<T> for ContextMenuItemLabel
|
||||||
|
where
|
||||||
|
T: 'static + Fn(&mut MouseState, &theme::ContextMenuItem) -> AnyElement<ContextMenu>,
|
||||||
|
{
|
||||||
|
fn from(f: T) -> Self {
|
||||||
|
Self::Element(Box::new(f))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub enum ContextMenuItem {
|
pub enum ContextMenuItem {
|
||||||
Item {
|
Item {
|
||||||
label: ContextMenuItemLabel,
|
label: ContextMenuItemLabel,
|
||||||
|
@ -47,16 +74,9 @@ pub enum ContextMenuItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ContextMenuItem {
|
impl ContextMenuItem {
|
||||||
pub fn element_item(label: ContextMenuItemBuilder, action: impl 'static + Action) -> Self {
|
pub fn item(label: impl Into<ContextMenuItemLabel>, action: impl 'static + Action) -> Self {
|
||||||
Self::Item {
|
Self::Item {
|
||||||
label: ContextMenuItemLabel::Element(label),
|
label: label.into(),
|
||||||
action: Box::new(action),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn item(label: impl Into<Cow<'static, str>>, action: impl 'static + Action) -> Self {
|
|
||||||
Self::Item {
|
|
||||||
label: ContextMenuItemLabel::String(label.into()),
|
|
||||||
action: Box::new(action),
|
action: Box::new(action),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -317,8 +317,7 @@ impl CopilotButton {
|
||||||
menu_options.push(ContextMenuItem::Separator);
|
menu_options.push(ContextMenuItem::Separator);
|
||||||
|
|
||||||
let icon_style = settings.theme.copilot.out_link_icon.clone();
|
let icon_style = settings.theme.copilot.out_link_icon.clone();
|
||||||
menu_options.push(ContextMenuItem::element_item(
|
menu_options.push(ContextMenuItem::item(
|
||||||
Box::new(
|
|
||||||
move |state: &mut MouseState, style: &theme::ContextMenuItem| {
|
move |state: &mut MouseState, style: &theme::ContextMenuItem| {
|
||||||
Flex::row()
|
Flex::row()
|
||||||
.with_child(Label::new("Copilot Settings", style.label.clone()))
|
.with_child(Label::new("Copilot Settings", style.label.clone()))
|
||||||
|
@ -326,7 +325,6 @@ impl CopilotButton {
|
||||||
.align_children_center()
|
.align_children_center()
|
||||||
.into_any()
|
.into_any()
|
||||||
},
|
},
|
||||||
),
|
|
||||||
OsOpen::new(COPILOT_SETTINGS_URL),
|
OsOpen::new(COPILOT_SETTINGS_URL),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue