diff --git a/src/ui/im.rs b/src/ui/im.rs index a5144555..a95cf2a7 100644 --- a/src/ui/im.rs +++ b/src/ui/im.rs @@ -141,7 +141,7 @@ impl Context { } pub fn frame_size(&self) -> Rect { - self.frame_size.clone() + self.frame_size } pub fn store_input(&mut self, key: Key) { @@ -196,6 +196,10 @@ impl Layout { } } + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + pub fn split(&self, area: Rect) -> Rc<[Rect]> { match self { Layout::None => Rc::new([]), @@ -241,11 +245,11 @@ pub struct Ui { impl Ui { pub fn input(&mut self, f: impl Fn(Key) -> bool) -> bool { - self.has_focus() && self.ctx.inputs.iter().find(|key| f(**key)).is_some() + self.has_focus() && self.ctx.inputs.iter().any(|key| f(*key)) } pub fn input_global(&mut self, f: impl Fn(Key) -> bool) -> bool { - self.ctx.inputs.iter().find(|key| f(**key)).is_some() + self.ctx.inputs.iter().any(|key| f(*key)) } pub fn input_with_key(&mut self, f: impl Fn(Key) -> bool) -> Option { @@ -288,7 +292,7 @@ impl Ui { let has_focus = self.focus.map(|focus| self.count == focus).unwrap_or(false); let rect = self.layout.split(self.area).get(self.count).cloned(); - self.count = self.count + 1; + self.count += 1; rect.map(|rect| (rect, has_focus)) } @@ -379,7 +383,7 @@ impl Ui { widget::Label::new(content).ui(self, frame) } - pub fn overline<'a>(&mut self, frame: &mut Frame) -> Response { + pub fn overline(&mut self, frame: &mut Frame) -> Response { let overline = String::from("━").repeat(256); self.label(frame, overline) } @@ -420,19 +424,19 @@ impl Ui { widget::Shortcuts::new(shortcuts, divider).ui(self, frame) } - pub fn columns<'a>( + pub fn columns( &mut self, frame: &mut Frame, - columns: Vec>, + columns: Vec>, borders: Option, ) -> Response { widget::Columns::new(columns, borders).ui(self, frame) } - pub fn bar<'a>( + pub fn bar( &mut self, frame: &mut Frame, - columns: Vec>, + columns: Vec>, borders: Option, ) -> Response { widget::Bar::new(columns, borders).ui(self, frame) diff --git a/src/ui/im/widget.rs b/src/ui/im/widget.rs index 36c194fb..6bb9ea33 100644 --- a/src/ui/im/widget.rs +++ b/src/ui/im/widget.rs @@ -68,6 +68,10 @@ impl GroupState { self.len } + pub fn is_empty(&self) -> bool { + self.len == 0 + } + pub fn focus_next(&mut self) { self.focus = self .focus @@ -280,7 +284,7 @@ where let mut state = TableState { internal: { let mut state = ratatui::widgets::TableState::default(); - state.select(self.selected.clone()); + state.select(*self.selected); state }, }; @@ -428,7 +432,7 @@ impl<'a, R, const W: usize> HeaderedTable<'a, R, W> { } pub fn items(&self) -> &Vec { - &self.items + self.items } } @@ -459,11 +463,11 @@ where let table = ui.table( frame, self.selected, - &self.items, + self.items, self.header.to_vec(), Some(Borders::BottomSides), ); - response.changed = table.changed | response.changed; + response.changed |= table.changed; }, );