From d7129073924643e94e6bebdd251e3e2595e3062e Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Fri, 26 Jul 2024 17:08:52 +0200 Subject: [PATCH] Fix clippy issues Signed-off-by: Pierre Fenoll --- examples/demo.rs | 8 +------- src/appctx.rs | 37 ++++++++++++++++++------------------- src/framebuffer/draw.rs | 2 +- src/framebuffer/graphics.rs | 16 ++++++++-------- src/framebuffer/mod.rs | 22 +++++++++++----------- src/input/mod.rs | 4 ++-- 6 files changed, 41 insertions(+), 48 deletions(-) diff --git a/examples/demo.rs b/examples/demo.rs index 73cb315..f9c3b82 100644 --- a/examples/demo.rs +++ b/examples/demo.rs @@ -402,13 +402,7 @@ fn change_brush_width(app: &mut appctx::ApplicationContext<'_>, delta: i32) { let current = G_DRAW_MODE.load(Ordering::Relaxed); let current_size = current.get_size() as i32; let proposed_size = current_size + delta; - let new_size = if proposed_size < 1 { - 1 - } else if proposed_size > 99 { - 99 - } else { - proposed_size - }; + let new_size = proposed_size.clamp(1, 99); if new_size == current_size { return; } diff --git a/src/appctx.rs b/src/appctx.rs index a695b3b..623c109 100644 --- a/src/appctx.rs +++ b/src/appctx.rs @@ -490,22 +490,21 @@ impl<'a> ApplicationContext<'a> { while self.running.load(Ordering::Relaxed) { let event = self.input_rx.recv(); match event { - Err(e) => println!("Error in input event consumer: {0}", e), + Err(e) => eprintln!("Error in input event consumer: {e}"), Ok(event) => { - if let InputEvent::MultitouchEvent { event } = event { + if let InputEvent::MultitouchEvent { + event: MultitouchEvent::Press { finger } | MultitouchEvent::Move { finger }, + } = event + { // Check for and notify clickable active regions for multitouch events - if let MultitouchEvent::Press { finger } - | MultitouchEvent::Move { finger } = event - { - let gseq = finger.tracking_id; - if last_active_region_gesture_id != gseq { - if let Some((h, _)) = - self.find_active_region(finger.pos.y, finger.pos.x) - { - (h.handler)(appref, h.element.clone()); - } - last_active_region_gesture_id = gseq; + let gseq = finger.tracking_id; + if last_active_region_gesture_id != gseq { + if let Some((h, _)) = + self.find_active_region(finger.pos.y, finger.pos.x) + { + (h.handler)(appref, h.element.clone()); } + last_active_region_gesture_id = gseq; } } @@ -522,13 +521,13 @@ impl<'a> ApplicationContext<'a> { self.running.store(true, Ordering::Relaxed); if self.running.load(Ordering::Relaxed) { - if let InputEvent::MultitouchEvent { event } = event { + if let InputEvent::MultitouchEvent { + event: MultitouchEvent::Press { finger } | MultitouchEvent::Move { finger }, + } = event + { // Check for and notify clickable active regions for multitouch events - if let MultitouchEvent::Press { finger } | MultitouchEvent::Move { finger } = event - { - if let Some((h, _)) = self.find_active_region(finger.pos.y, finger.pos.x) { - (h.handler)(appref, h.element.clone()); - } + if let Some((h, _)) = self.find_active_region(finger.pos.y, finger.pos.x) { + (h.handler)(appref, h.element.clone()); } } } diff --git a/src/framebuffer/draw.rs b/src/framebuffer/draw.rs index b13c083..d2df6da 100644 --- a/src/framebuffer/draw.rs +++ b/src/framebuffer/draw.rs @@ -245,7 +245,7 @@ impl framebuffer::FramebufferDraw for core::Framebuffer { unsafe { libc::memset( self.frame.as_mut_ptr() as *mut libc::c_void, - std::i32::MAX, + i32::MAX, line_length * h, ); } diff --git a/src/framebuffer/graphics.rs b/src/framebuffer/graphics.rs index a35d9da..aabc237 100644 --- a/src/framebuffer/graphics.rs +++ b/src/framebuffer/graphics.rs @@ -174,12 +174,12 @@ where let (min_xy, max_xy) = points.iter().fold( ( Point2 { - y: std::i32::MAX, - x: std::i32::MAX, + y: i32::MAX, + x: i32::MAX, }, Point2 { - y: std::i32::MIN, - x: std::i32::MIN, + y: i32::MIN, + x: i32::MIN, }, ), |acc, p| { @@ -239,12 +239,12 @@ where let mut left_edge = Vec::>::new(); let mut right_edge = Vec::>::new(); let mut prev_left_pt = Point2 { - x: std::i32::MIN, - y: std::i32::MIN, + x: i32::MIN, + y: i32::MIN, }; let mut prev_right_pt = Point2 { - x: std::i32::MIN, - y: std::i32::MIN, + x: i32::MIN, + y: i32::MIN, }; for (t, pt) in sample_bezier(startpt.0, ctrlpt.0, endpt.0, samples) { // interpolate width diff --git a/src/framebuffer/mod.rs b/src/framebuffer/mod.rs index 8463192..e7ea421 100644 --- a/src/framebuffer/mod.rs +++ b/src/framebuffer/mod.rs @@ -175,21 +175,21 @@ pub trait FramebufferRefresh { /// Some additional points to note: /// /// 1) PxP must process 8x8 pixel blocks, and all pixels in each block - /// are considered for auto-waveform mode selection. If the - /// update region is not 8x8 aligned, additional unwanted pixels - /// will be considered in auto-waveform mode selection. + /// are considered for auto-waveform mode selection. If the + /// update region is not 8x8 aligned, additional unwanted pixels + /// will be considered in auto-waveform mode selection. /// /// 2) PxP input must be 32-bit aligned, so any update - /// address not 32-bit aligned must be shifted to meet the - /// 32-bit alignment. The PxP will thus end up processing pixels - /// outside of the update region to satisfy this alignment restriction, - /// which can affect auto-waveform mode selection. + /// address not 32-bit aligned must be shifted to meet the + /// 32-bit alignment. The PxP will thus end up processing pixels + /// outside of the update region to satisfy this alignment restriction, + /// which can affect auto-waveform mode selection. /// /// 3) If input fails 32-bit alignment, and the resulting expansion - /// of the processed region would add at least 8 pixels more per - /// line than the original update line width, the EPDC would - /// cause screen artifacts by incorrectly handling the 8+ pixels - /// at the end of each line. + /// of the processed region would add at least 8 pixels more per + /// line than the original update line width, the EPDC would + /// cause screen artifacts by incorrectly handling the 8+ pixels + /// at the end of each line. #[allow(clippy::too_many_arguments)] fn partial_refresh( &self, diff --git a/src/input/mod.rs b/src/input/mod.rs index 46bfd78..6db888d 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -132,8 +132,8 @@ impl Default for Finger { Finger { tracking_id: -1, // -1 should never be seen by a InputEvent receiver pos: cgmath::Point2 { - x: u16::max_value(), - y: u16::max_value(), + x: u16::MAX, + y: u16::MAX, }, pos_updated: false, last_pressed: false,