diff --git a/.gitignore b/.gitignore index 96ef6c0b..6bfa6c97 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target Cargo.lock +/.vscode \ No newline at end of file diff --git a/examples/winit.rs b/examples/winit.rs index e236ca1b..cf83f954 100644 --- a/examples/winit.rs +++ b/examples/winit.rs @@ -151,6 +151,7 @@ fn main() { if let Ok(event) = menu_channel.try_recv() { if event.id == custom_i_1.id() { + dbg!(check_custom_i_1.is_checked()); file_m.insert(&MenuItem::new("asdasd", false, None), 2); } println!("{:?}", event); diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 00000000..e69de29b diff --git a/src/lib.rs b/src/lib.rs index 688ab849..b84cad09 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,12 +76,14 @@ //! //! See [`Menu::init_for_hwnd`] for more details +pub use self::error::*; use accelerator::Accelerator; use crossbeam_channel::{unbounded, Receiver, Sender}; use once_cell::sync::Lazy; use predefined::PredfinedMenuItemType; pub mod accelerator; +mod error; mod platform_impl; mod predefined; mod util; diff --git a/src/platform_impl/windows/mod.rs b/src/platform_impl/windows/mod.rs index b647d0f7..ebafb566 100644 --- a/src/platform_impl/windows/mod.rs +++ b/src/platform_impl/windows/mod.rs @@ -30,6 +30,8 @@ use windows_sys::Win32::{ const COUNTER_START: u32 = 1000; static COUNTER: Counter = Counter::new_with_start(COUNTER_START); +type AccelWrapper = (HACCEL, Vec); + /// A generic child in a menu /// /// Be careful when cloning this item and treat it as read-only @@ -55,7 +57,7 @@ struct MenuChild { hmenu: HMENU, hpopupmenu: HMENU, children: Option>>>, - root_menu_haccel: Option)>>>>, + root_menu_haccel: Option>>>, } impl MenuChild { @@ -67,7 +69,7 @@ impl MenuChild { } fn text(&self) -> String { self.parents_hemnu - .get(0) + .first() .map(|hmenu| { let mut label = Vec::::new(); @@ -86,7 +88,7 @@ impl MenuChild { let text = decode_wide(info.dwTypeData); text.split('\t').next().unwrap().to_string() }) - .unwrap_or(self.text.clone()) + .unwrap_or_else(|| self.text.clone()) } fn set_text(&mut self, text: &str) { @@ -103,7 +105,7 @@ impl MenuChild { fn is_enabled(&self) -> bool { self.parents_hemnu - .get(0) + .first() .map(|hmenu| { let mut info: MENUITEMINFOW = unsafe { std::mem::zeroed() }; info.cbSize = std::mem::size_of::() as _; @@ -131,7 +133,7 @@ impl MenuChild { fn is_checked(&self) -> bool { self.parents_hemnu - .get(0) + .first() .map(|hmenu| { let mut info: MENUITEMINFOW = unsafe { std::mem::zeroed() }; info.cbSize = std::mem::size_of::() as _; @@ -139,7 +141,7 @@ impl MenuChild { unsafe { GetMenuItemInfoW(*hmenu, self.id(), false.into(), &mut info) }; - !((info.fState & MFS_CHECKED) == 0) + (info.fState & MFS_CHECKED) != 0 }) .unwrap_or(self.enabled) } @@ -264,7 +266,7 @@ impl Menu { let accel_str = accelerator.to_string(); let accel = accelerator.to_accel(child_.id() as u16); - text.push_str("\t"); + text.push('\t'); text.push_str(&accel_str); let mut haccel = self.haccel.borrow_mut(); @@ -598,7 +600,7 @@ impl Submenu { let accel_str = accelerator.to_string(); let accel = accelerator.to_accel(child_.id() as u16); - text.push_str("\t"); + text.push('\t'); text.push_str(&accel_str); for root_menu in self_.root_menu_haccel.as_mut().unwrap() {