mirror of
https://github.com/italicsjenga/rust_minifb.git
synced 2024-12-23 11:21:30 +11:00
Fix clippy lints under windows (#275)
This commit is contained in:
parent
9a435460b0
commit
c25b5d114a
|
@ -24,7 +24,7 @@ impl FromStr for Icon {
|
||||||
type Err = &'static str;
|
type Err = &'static str;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
if s.len() == 0 {
|
if s.is_empty() {
|
||||||
return Err("Path to icon cannot be empty!");
|
return Err("Path to icon cannot be empty!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ impl TryFrom<&[u64]> for Icon {
|
||||||
type Error = &'static str;
|
type Error = &'static str;
|
||||||
|
|
||||||
fn try_from(value: &[u64]) -> Result<Self, Self::Error> {
|
fn try_from(value: &[u64]) -> Result<Self, Self::Error> {
|
||||||
if value.len() == 0 {
|
if value.is_empty() {
|
||||||
return Err("ARGB buffer cannot be empty!");
|
return Err("ARGB buffer cannot be empty!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -256,7 +256,7 @@ unsafe extern "system" fn wnd_proc(
|
||||||
|
|
||||||
winuser::WM_PAINT => {
|
winuser::WM_PAINT => {
|
||||||
// if we have nothing to draw here we return the default function
|
// if we have nothing to draw here we return the default function
|
||||||
if wnd.draw_params.buffer == std::ptr::null() {
|
if wnd.draw_params.buffer.is_null() {
|
||||||
return winuser::DefWindowProcW(window, msg, wparam, lparam);
|
return winuser::DefWindowProcW(window, msg, wparam, lparam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,7 +400,7 @@ unsafe extern "system" fn wnd_proc(
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
return winuser::DefWindowProcW(window, msg, wparam, lparam);
|
winuser::DefWindowProcW(window, msg, wparam, lparam)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_wstring(str: &str) -> Vec<u16> {
|
fn to_wstring(str: &str) -> Vec<u16> {
|
||||||
|
@ -568,7 +568,7 @@ impl Window {
|
||||||
|
|
||||||
winuser::ShowWindow(handle, winuser::SW_NORMAL);
|
winuser::ShowWindow(handle, winuser::SW_NORMAL);
|
||||||
|
|
||||||
return Some(handle);
|
Some(handle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -705,7 +705,7 @@ impl Window {
|
||||||
unsafe {
|
unsafe {
|
||||||
winuser::SetWindowPos(
|
winuser::SetWindowPos(
|
||||||
self.window.unwrap(),
|
self.window.unwrap(),
|
||||||
if topmost == true {
|
if topmost {
|
||||||
winuser::HWND_TOPMOST
|
winuser::HWND_TOPMOST
|
||||||
} else {
|
} else {
|
||||||
winuser::HWND_TOP
|
winuser::HWND_TOP
|
||||||
|
@ -819,7 +819,7 @@ impl Window {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_open(&self) -> bool {
|
pub fn is_open(&self) -> bool {
|
||||||
return self.is_open;
|
self.is_open
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generic_update(&mut self, window: windef::HWND) {
|
fn generic_update(&mut self, window: windef::HWND) {
|
||||||
|
@ -846,25 +846,22 @@ impl Window {
|
||||||
while winuser::PeekMessageW(&mut msg, std::ptr::null_mut(), 0, 0, winuser::PM_REMOVE)
|
while winuser::PeekMessageW(&mut msg, std::ptr::null_mut(), 0, 0, winuser::PM_REMOVE)
|
||||||
!= 0
|
!= 0
|
||||||
{
|
{
|
||||||
|
let acc_condition = winuser::TranslateAcceleratorW(
|
||||||
|
msg.hwnd,
|
||||||
|
mem::transmute(self.accel_table),
|
||||||
|
&mut msg,
|
||||||
|
) == 0;
|
||||||
|
|
||||||
// Make this code a bit nicer
|
// Make this code a bit nicer
|
||||||
if self.accel_table == ptr::null_mut() {
|
if self.accel_table.is_null() || acc_condition {
|
||||||
winuser::TranslateMessage(&mut msg);
|
winuser::TranslateMessage(&msg);
|
||||||
winuser::DispatchMessageW(&mut msg);
|
winuser::DispatchMessageW(&msg);
|
||||||
} else {
|
|
||||||
if winuser::TranslateAcceleratorW(
|
|
||||||
msg.hwnd,
|
|
||||||
mem::transmute(self.accel_table),
|
|
||||||
&mut msg,
|
|
||||||
) == 0
|
|
||||||
{
|
|
||||||
winuser::TranslateMessage(&mut msg);
|
|
||||||
winuser::DispatchMessageW(&mut msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::identity_op)]
|
||||||
pub fn set_background_color(&mut self, color: u32) {
|
pub fn set_background_color(&mut self, color: u32) {
|
||||||
unsafe {
|
unsafe {
|
||||||
wingdi::DeleteObject(self.clear_brush as *mut winapi::ctypes::c_void);
|
wingdi::DeleteObject(self.clear_brush as *mut winapi::ctypes::c_void);
|
||||||
|
@ -921,11 +918,7 @@ impl Window {
|
||||||
match self.window {
|
match self.window {
|
||||||
Some(hwnd) => {
|
Some(hwnd) => {
|
||||||
let active = unsafe { winapi::um::winuser::GetActiveWindow() };
|
let active = unsafe { winapi::um::winuser::GetActiveWindow() };
|
||||||
if !active.is_null() && active == hwnd {
|
!active.is_null() && active == hwnd
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None => false,
|
None => false,
|
||||||
}
|
}
|
||||||
|
@ -960,7 +953,7 @@ impl Window {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return factor;
|
factor
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -988,11 +981,11 @@ impl Window {
|
||||||
|
|
||||||
for menu in self.menus.iter() {
|
for menu in self.menus.iter() {
|
||||||
for item in menu.accel_table.iter() {
|
for item in menu.accel_table.iter() {
|
||||||
temp_accel_table.push(item.clone());
|
temp_accel_table.push(*item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.accel_table != ptr::null_mut() {
|
if !self.accel_table.is_null() {
|
||||||
winuser::DestroyAcceleratorTable(self.accel_table);
|
winuser::DestroyAcceleratorTable(self.accel_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1007,7 +1000,7 @@ impl Window {
|
||||||
let window = self.window.unwrap();
|
let window = self.window.unwrap();
|
||||||
let mut main_menu = winuser::GetMenu(window);
|
let mut main_menu = winuser::GetMenu(window);
|
||||||
|
|
||||||
if main_menu == ptr::null_mut() {
|
if main_menu.is_null() {
|
||||||
main_menu = winuser::CreateMenu();
|
main_menu = winuser::CreateMenu();
|
||||||
winuser::SetMenu(window, main_menu);
|
winuser::SetMenu(window, main_menu);
|
||||||
Self::adjust_window_size_for_menu(window);
|
Self::adjust_window_size_for_menu(window);
|
||||||
|
@ -1208,7 +1201,7 @@ impl Menu {
|
||||||
fn format_name(menu_item: &MenuItem, key_name: &'static str) -> String {
|
fn format_name(menu_item: &MenuItem, key_name: &'static str) -> String {
|
||||||
let mut name = menu_item.label.clone();
|
let mut name = menu_item.label.clone();
|
||||||
|
|
||||||
name.push_str("\t");
|
name.push('\t');
|
||||||
|
|
||||||
if (menu_item.modifier & MENU_KEY_WIN) == MENU_KEY_WIN {
|
if (menu_item.modifier & MENU_KEY_WIN) == MENU_KEY_WIN {
|
||||||
name.push_str("Win-");
|
name.push_str("Win-");
|
||||||
|
|
Loading…
Reference in a new issue