From 262ca9abdd184bc499a03c9c1a418c42a8d1baed Mon Sep 17 00:00:00 2001 From: Josh McKinney Date: Fri, 2 Aug 2024 21:02:34 -0700 Subject: [PATCH] fix: clippy lints (#11) --- examples/basic.rs | 6 +++++- src/lib.rs | 27 +++++++++++++++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/examples/basic.rs b/examples/basic.rs index 0297567..d5d2162 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -162,7 +162,11 @@ impl Widget for &mut App { .block(Block::bordered().title("Content").on_black()) .render(main, buf); - "tui-menu".bold().blue().to_centered_line().render(top, buf); + "tui-menu" + .bold() + .blue() + .into_centered_line() + .render(top, buf); // draw menu last, so it renders on top of other content Menu::new().render(top, buf, &mut self.menu); diff --git a/src/lib.rs b/src/lib.rs index bb66564..a9b455c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -110,7 +110,7 @@ impl MenuState { .and_then(|child| child.highlight_child_index()) { // case 1 - Some(idx) if idx == 0 => { + Some(0) => { self.pop(); } _ => { @@ -262,10 +262,8 @@ impl MenuState { if let Some(item) = self.root_item.highlight_mut() { if !item.children.is_empty() { self.push(); - } else { - if let Some(ref data) = item.data { - self.events.push(MenuEvent::Selected(data.clone())); - } + } else if let Some(ref data) = item.data { + self.events.push(MenuEvent::Selected(data.clone())); } } } @@ -361,7 +359,7 @@ impl MenuItem { /// highlight first child fn highlight_first_child(&mut self) -> Option<()> { if !self.children.is_empty() { - if let Some(it) = self.children.iter_mut().nth(0) { + if let Some(it) = self.children.get_mut(0) { it.is_highlight = true; } Some(()) @@ -468,8 +466,7 @@ impl MenuItem { let mut last_but_one = self; while last_but_one .highlight_child_mut() - .map(|x| x.highlight_child_mut()) - .flatten() + .and_then(|x| x.highlight_child_mut()) .is_some() { last_but_one = last_but_one.highlight_child_mut().unwrap(); @@ -533,7 +530,7 @@ impl Menu { y: u16, group: &[MenuItem], buf: &mut ratatui::buffer::Buffer, - depth: usize, + _depth: usize, ) { let area = Rect::new(x, y, self.drop_down_width, group.len() as u16); Clear.render(area, buf); @@ -544,7 +541,7 @@ impl Menu { let is_active = item.is_highlight; buf.set_span( - x as u16, + x, item_y, &Span::styled( item.name(), @@ -564,13 +561,19 @@ impl Menu { item_y, &item.children, buf, - depth + 1, + _depth + 1, ); } } } } +impl Default for Menu { + fn default() -> Self { + Self::new() + } +} + impl StatefulWidget for Menu { type State = MenuState; @@ -594,7 +597,7 @@ impl StatefulWidget for Menu { spans.push(span); if has_children && is_highlight { - self.render_drop_down(group_x_pos as u16, y_pos as u16 + 1, &item.children, buf, 1); + self.render_drop_down(group_x_pos as u16, y_pos + 1, &item.children, buf, 1); } if idx < state.root_item.children.len() - 1 {