Skip to content

Commit

Permalink
impl From<menu types> for zbus::OwnedValue
Browse files Browse the repository at this point in the history
  • Loading branch information
iovxw committed Feb 27, 2024
1 parent 9e4d7d5 commit 1ad32b1
Showing 1 changed file with 46 additions and 25 deletions.
71 changes: 46 additions & 25 deletions src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ impl<T> RawMenuItem<T> {
filter,
r#type,
"type",
(|r: ItemType| -> Str { r.to_string().into() })
(|r: ItemType| r)
);
if_not_default_then_insert!(
properties,
Expand Down Expand Up @@ -483,30 +483,9 @@ impl<T> RawMenuItem<T> {
.expect("unreachable: Vec<Vec<String>> to OwnedValue")
})
);
if_not_default_then_insert!(
properties,
self,
default,
filter,
toggle_type,
(|r: ToggleType| -> Str { r.to_string().into() })
);
if_not_default_then_insert!(
properties,
self,
default,
filter,
toggle_state,
(|r| r as i32)
);
if_not_default_then_insert!(
properties,
self,
default,
filter,
disposition,
(|r: Disposition| -> Str { r.to_string().into() })
);
if_not_default_then_insert!(properties, self, default, filter, toggle_type);
if_not_default_then_insert!(properties, self, default, filter, toggle_state);
if_not_default_then_insert!(properties, self, default, filter, disposition);

properties
}
Expand Down Expand Up @@ -657,6 +636,17 @@ impl fmt::Display for ItemType {
}
}

impl From<ItemType> for OwnedValue {
fn from(value: ItemType) -> Self {
use ItemType::*;
let s = match value {
Standard => "standard",
Separator => "separator",
};
Str::from_static(s).into()
}
}

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
enum ToggleType {
/// Item is an independent togglable item
Expand All @@ -679,13 +669,31 @@ impl fmt::Display for ToggleType {
}
}

impl From<ToggleType> for OwnedValue {
fn from(value: ToggleType) -> Self {
use ToggleType::*;
let s = match value {
Checkmark => "checkmark",
Radio => "radio",
Null => "",
};
Str::from_static(s).into()
}
}

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
enum ToggleState {
Off = 0,
On = 1,
Indeterminate = -1,
}

impl From<ToggleState> for OwnedValue {
fn from(value: ToggleState) -> Self {
(value as i32).into()
}
}

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum Disposition {
/// A standard menu item
Expand All @@ -712,6 +720,19 @@ impl fmt::Display for Disposition {
}
}

impl From<Disposition> for OwnedValue {
fn from(value: Disposition) -> Self {
use Disposition::*;
let s = match value {
Normal => "normal",
Informative => "informative",
Warning => "warning",
Alert => "alert",
};
Str::from_static(s).into()
}
}

pub(crate) fn menu_flatten<T: 'static>(
items: Vec<MenuItem<T>>,
) -> Vec<(RawMenuItem<T>, Vec<usize>)> {
Expand Down

0 comments on commit 1ad32b1

Please sign in to comment.