Skip to content

Commit

Permalink
clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Nov 6, 2022
1 parent 84597fc commit 1f39099
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
Cargo.lock
/.vscode
1 change: 1 addition & 0 deletions examples/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Empty file added src/error.rs
Empty file.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 10 additions & 8 deletions src/platform_impl/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Accel>);

/// A generic child in a menu
///
/// Be careful when cloning this item and treat it as read-only
Expand All @@ -55,7 +57,7 @@ struct MenuChild {
hmenu: HMENU,
hpopupmenu: HMENU,
children: Option<Vec<Rc<RefCell<MenuChild>>>>,
root_menu_haccel: Option<Vec<Rc<RefCell<(HACCEL, Vec<Accel>)>>>>,
root_menu_haccel: Option<Vec<Rc<RefCell<AccelWrapper>>>>,
}

impl MenuChild {
Expand All @@ -67,7 +69,7 @@ impl MenuChild {
}
fn text(&self) -> String {
self.parents_hemnu
.get(0)
.first()
.map(|hmenu| {
let mut label = Vec::<u16>::new();

Expand All @@ -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) {
Expand All @@ -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::<MENUITEMINFOW>() as _;
Expand Down Expand Up @@ -131,15 +133,15 @@ 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::<MENUITEMINFOW>() as _;
info.fMask = MIIM_STATE;

unsafe { GetMenuItemInfoW(*hmenu, self.id(), false.into(), &mut info) };

!((info.fState & MFS_CHECKED) == 0)
(info.fState & MFS_CHECKED) != 0
})
.unwrap_or(self.enabled)
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 1f39099

Please sign in to comment.