Browse Source

Address some clippy nits.

Kestrel 5 days ago
parent
commit
27dbc8f173
12 changed files with 28 additions and 31 deletions
  1. 1 1
      src/component.rs
  2. 3 3
      src/input.rs
  3. 1 1
      src/layout.rs
  4. 1 1
      src/layout/arr.rs
  5. 4 4
      src/layout/arr/line.rs
  6. 7 5
      src/layout/cache.rs
  7. 1 1
      src/text.rs
  8. 2 4
      src/ui.rs
  9. 2 2
      src/widget/button.rs
  10. 1 2
      src/widget/group.rs
  11. 1 3
      src/widget/label.rs
  12. 4 4
      src/window.rs

+ 1 - 1
src/component.rs

@@ -5,6 +5,6 @@ pub trait Component {
     fn process(&mut self, msg: Self::Msg) -> Vec<Self::ParentMsg>;
 
     fn process_all(&mut self, msgs: impl Iterator<Item = Self::Msg>) -> Vec<Self::ParentMsg> {
-        msgs.map(|msg| self.process(msg)).flatten().collect()
+        msgs.flat_map(|msg| self.process(msg)).collect()
     }
 }

+ 3 - 3
src/input.rs

@@ -15,9 +15,9 @@ pub enum MouseButton {
     ExtraButton4,
 }
 
-impl Into<u8> for MouseButton {
-    fn into(self) -> u8 {
-        self as u8
+impl From<MouseButton> for u8 {
+    fn from(mb: MouseButton) -> u8 {
+        mb as u8
     }
 }
 

+ 1 - 1
src/layout.rs

@@ -255,7 +255,7 @@ impl LayoutNode {
 /// Accessors
 impl LayoutNode {
     pub fn label(&self) -> Option<&str> {
-        self.label.as_ref().map(String::as_str)
+        self.label.as_deref()
     }
     pub fn set_label(&mut self, to: impl AsRef<str>) {
         self.label = Some(to.as_ref().to_string());

+ 1 - 1
src/layout/arr.rs

@@ -20,7 +20,7 @@ pub use table::TableArrangement;
 /// Calculate the fit of a number of size policies inside a given length.
 ///
 /// Returns the endpoints of each item.
-fn do_fit<'l>(
+fn do_fit(
     total: i32,
     policies: impl Iterator<Item = SizePolicy> + Clone,
 ) -> impl Iterator<Item = i32> {

+ 4 - 4
src/layout/arr/line.rs

@@ -80,9 +80,9 @@ impl ArrangementCalculator for LineArrangement {
         let mut last_offset = 0;
         let fit = do_fit(
             if self.is_column() {
-                inside.height() as i32
+                inside.height()
             } else {
-                inside.width() as i32
+                inside.width()
             },
             policies,
         );
@@ -97,7 +97,7 @@ impl ArrangementCalculator for LineArrangement {
                     },
                     PixelSize {
                         width: inside.width(),
-                        height: (offset - last_offset) as i32,
+                        height: (offset - last_offset),
                         ..Default::default()
                     },
                 )
@@ -109,7 +109,7 @@ impl ArrangementCalculator for LineArrangement {
                         ..Default::default()
                     },
                     PixelSize {
-                        width: (offset - last_offset) as i32,
+                        width: (offset - last_offset),
                         height: inside.height(),
                         ..Default::default()
                     },

+ 7 - 5
src/layout/cache.rs

@@ -44,12 +44,14 @@ impl LayoutCache {
         let mut states = self.states.borrow_mut();
         let parents = self.parents.borrow();
         while let Some(next) = updq.pop() {
-            states.get_mut(&next).map(|v| {
+            if let Some(v) = states.get_mut(&next) {
                 if !v.needs_update {
-                    parents.get(&next).map(|p| updq.push(*p));
+                    if let Some(p) = parents.get(&next) {
+                        updq.push(*p)
+                    }
                     v.needs_update = true;
                 }
-            });
+            }
         }
     }
 
@@ -58,10 +60,10 @@ impl LayoutCache {
         let mut states = self.states.borrow_mut();
 
         while let Some(next) = renq.pop() {
-            states.get_mut(&next).map(|v| {
+            if let Some(v) = states.get_mut(&next) {
                 v.needs_render = true;
                 renq.extend(v.children.iter());
-            });
+            }
         }
     }
 

+ 1 - 1
src/text.rs

@@ -70,7 +70,7 @@ impl<'l> TextLine<'l> {
                 PixelBox::from_size(character_alphamap.size()),
                 PixelPoint::new(
                     metrics.xmin + offset as i32,
-                    baseline as i32 - (metrics.height as i32 + metrics.ymin as i32),
+                    baseline as i32 - (metrics.height as i32 + metrics.ymin),
                 ),
             );
         }

+ 2 - 4
src/ui.rs

@@ -153,8 +153,7 @@ impl<UIC: UIComponent> winit::application::ApplicationHandler<()> for UI<UIC> {
             .state
             .window_states
             .get(&window_id)
-            .map(std::rc::Weak::upgrade)
-            .flatten()
+            .and_then(std::rc::Weak::upgrade)
         else {
             println!("superfluous event: {event:?}");
             return;
@@ -241,6 +240,5 @@ pub fn make_opinionated_ui<'l, WC: WindowComponent<ParentMsg = UIControlMsg>>(
         window: None,
         builder: Some(Box::new(wc)),
     };
-    let ui = UI::new(ouic);
-    ui
+    UI::new(ouic)
 }

+ 2 - 2
src/widget/button.rs

@@ -86,7 +86,7 @@ impl<C: Component> Widget<C> for Button<C> {
                     self.state = ButtonState::Clicked;
                 } else if istate.mouse.released().active(MouseButton::Left) {
                     self.state = ButtonState::Idle;
-                    result.extend(self.hook.as_ref().map(|v| v()).flatten().into_iter());
+                    result.extend(self.hook.as_ref().and_then(|v| v()));
                 } else {
                     self.state = ButtonState::Hovered;
                 }
@@ -97,7 +97,7 @@ impl<C: Component> Widget<C> for Button<C> {
                 self.layout.render_needed();
             }
         }
-        result.extend(self.label.poll(uih, input_state).into_iter());
+        result.extend(self.label.poll(uih, input_state));
         result
     }
 

+ 1 - 2
src/widget/group.rs

@@ -77,8 +77,7 @@ impl<C: Component> Widget<C> for PlainGroup<C> {
     fn poll(&mut self, uih: &mut UIHandle, input_state: Option<&InputState>) -> Vec<C::Msg> {
         self.children
             .iter_mut()
-            .map(|w| w.poll(uih, input_state))
-            .flatten()
+            .flat_map(|w| w.poll(uih, input_state))
             .collect()
     }
     fn render(&self, theme: &Theme, target: &mut kahlo::BitmapMut<RenderFormat>) {

+ 1 - 3
src/widget/label.rs

@@ -36,9 +36,7 @@ impl<C: Component> Label<C> {
     }
 
     pub fn set_text(&mut self, text: &str) {
-        if Some(text) == self.text.as_deref() {
-            return;
-        } else {
+        if Some(text) != self.text.as_deref() {
             self.text = Some(text.to_string());
             self.rendered.take();
         }

+ 4 - 4
src/window.rs

@@ -116,8 +116,8 @@ impl<WC: WindowComponent> WindowState<WC> {
         // now put the pre-render layout dump on the window
         // again, we're doing this the dumb way
         let mut offset = 0;
-        for text in pre_render_dump.split("\n") {
-            if text.len() == 0 {
+        for text in pre_render_dump.split('\n') {
+            if text.is_empty() {
                 continue;
             }
             let line = uih.theme().make_line(text).render_line();
@@ -223,8 +223,8 @@ impl<'r, 'l: 'r> WindowBuilder<'r, 'l> {
             root_node: LayoutNode::new(self.ui_handle.state.layout_cache.clone()),
             window,
             events: Default::default(),
-            istate: InputState::default().into(),
-            surface: surface.into(),
+            istate: InputState::default(),
+            surface,
             bitmap: None.into(),
         }));