From 3e2fe1541bc207ab97fe88d29cab4560923656f2 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Wed, 17 Apr 2024 13:55:23 +0200 Subject: [PATCH] bin: Various small rendering refactorings --- bin/commands/inbox/select/ui.rs | 28 ++++++++++++++-------------- bin/commands/issue/select/ui.rs | 20 +++++++++----------- bin/commands/patch/select/ui.rs | 16 +++++++--------- 3 files changed, 30 insertions(+), 34 deletions(-) diff --git a/bin/commands/inbox/select/ui.rs b/bin/commands/inbox/select/ui.rs index 3d02fdb4..5cf0169b 100644 --- a/bin/commands/inbox/select/ui.rs +++ b/bin/commands/inbox/select/ui.rs @@ -281,15 +281,7 @@ where ) }), ), - footer: Footer::new(state, action_tx) - .on_update(|state| { - let props = NotificationsProps::from(state); - - Box::>::new( - FooterProps::default().columns(Self::build_footer(&props, props.selected)), - ) - }) - .to_boxed(), + footer: Footer::new(state, action_tx).to_boxed(), on_update: None, on_change: None, } @@ -436,7 +428,11 @@ impl<'a: 'static, B> Widget for Notifications<'a, B> where B: Backend + 'a, { - fn render(&self, frame: &mut ratatui::Frame, area: Rect, _props: &dyn Any) { + fn render(&self, frame: &mut ratatui::Frame, area: Rect, props: &dyn Any) { + let props = props + .downcast_ref::() + .unwrap_or(&self.props); + let header_height = 3_usize; let page_size = if self.props.show_search { @@ -447,7 +443,11 @@ where let layout = Layout::vertical([Constraint::Min(1), Constraint::Length(3)]).split(area); self.table.render(frame, layout[0], &()); - self.footer.render(frame, layout[1], &()); + self.footer.render( + frame, + layout[1], + &FooterProps::default().columns(Self::build_footer(props, props.selected)), + ); (area.height as usize).saturating_sub(header_height) }; @@ -485,7 +485,7 @@ impl View for Search { }); }) .on_update(|state| { - Box::::new( + Box::new( TextFieldProps::default() .text(&state.search.read().to_string()) .title("Search") @@ -718,7 +718,7 @@ impl<'a, B: Backend> View for Help<'a, B> { .on_update(|state| { let props = HelpProps::from(state); - Box::>::new( + Box::new( ParagraphProps::default() .text(&props.content) .page_size(props.page_size) @@ -770,7 +770,7 @@ where B: Backend, { fn render(&self, frame: &mut ratatui::Frame, area: Rect, props: &dyn Any) { - let props = props.downcast_ref::>().unwrap_or(&self.props); + let props = props.downcast_ref::().unwrap_or(&self.props); let [header_area, content_area, footer_area] = Layout::vertical([ Constraint::Length(3), diff --git a/bin/commands/issue/select/ui.rs b/bin/commands/issue/select/ui.rs index 036130b7..3516fb5b 100644 --- a/bin/commands/issue/select/ui.rs +++ b/bin/commands/issue/select/ui.rs @@ -265,7 +265,7 @@ where .to_boxed(), ) .on_change(|props, action_tx| { - if let Some(props) = props.downcast_ref::>() { + if let Some(props) = props.downcast_ref::>() { let _ = action_tx.send(Action::Select { selected: props.selected, }); @@ -274,7 +274,7 @@ where .on_update(|state| { let props = IssuesProps::from(state); - Box::>::new( + Box::new( TableProps::default() .columns(props.columns) .items(state.issues()) @@ -454,13 +454,11 @@ where B: Backend + 'a, { fn render(&self, frame: &mut ratatui::Frame, area: Rect, props: &dyn Any) { - let props = props - .downcast_ref::>() - .unwrap_or(&self.props); + let props = props.downcast_ref::().unwrap_or(&self.props); let header_height = 3_usize; - let page_size = if self.props.show_search { + let page_size = if props.show_search { self.table.render(frame, area, &()); (area.height as usize).saturating_sub(header_height) @@ -471,13 +469,13 @@ where self.footer.render( frame, layout[1], - &FooterProps::default().columns(Self::build_footer(&props, props.selected)), + &FooterProps::default().columns(Self::build_footer(props, props.selected)), ); (area.height as usize).saturating_sub(header_height) }; - if page_size != self.props.page_size { + if page_size != props.page_size { let _ = self.action_tx.send(Action::PageSize(page_size)); } } @@ -510,7 +508,7 @@ impl View for Search { }); }) .on_update(|state| { - Box::::new( + Box::new( TextFieldProps::default() .text(&state.search.read().to_string()) .title("Search") @@ -743,7 +741,7 @@ impl<'a, B: Backend> View for Help<'a, B> { .on_update(|state| { let props = HelpProps::from(state); - Box::>::new( + Box::new( ParagraphProps::default() .text(&props.content) .page_size(props.page_size) @@ -795,7 +793,7 @@ where B: Backend, { fn render(&self, frame: &mut ratatui::Frame, area: Rect, props: &dyn Any) { - let props = props.downcast_ref::>().unwrap_or(&self.props); + let props = props.downcast_ref::().unwrap_or(&self.props); let [header_area, content_area, footer_area] = Layout::vertical([ Constraint::Length(3), diff --git a/bin/commands/patch/select/ui.rs b/bin/commands/patch/select/ui.rs index ce3b0bd7..c2ff5b48 100644 --- a/bin/commands/patch/select/ui.rs +++ b/bin/commands/patch/select/ui.rs @@ -274,7 +274,7 @@ where .on_update(|state| { let props = PatchesProps::from(state); - Box::>::new( + Box::new( TableProps::default() .columns(props.columns) .items(state.patches()) @@ -485,13 +485,11 @@ where B: Backend + 'a, { fn render(&self, frame: &mut ratatui::Frame, area: Rect, props: &dyn Any) { - let props = props - .downcast_ref::>() - .unwrap_or(&self.props); + let props = props.downcast_ref::().unwrap_or(&self.props); let header_height = 3_usize; - let page_size = if self.props.show_search { + let page_size = if props.show_search { self.table.render(frame, area, &()); (area.height as usize).saturating_sub(header_height) @@ -502,13 +500,13 @@ where self.footer.render( frame, layout[1], - &FooterProps::default().columns(Self::build_footer(&props, props.selected)), + &FooterProps::default().columns(Self::build_footer(props, props.selected)), ); (area.height as usize).saturating_sub(header_height) }; - if page_size != self.props.page_size { + if page_size != props.page_size { let _ = self.action_tx.send(Action::PageSize(page_size)); } } @@ -541,7 +539,7 @@ impl View for Search { }); }) .on_update(|state| { - Box::::new( + Box::new( TextFieldProps::default() .text(&state.search.read().to_string()) .title("Search") @@ -782,7 +780,7 @@ impl<'a, B: Backend> View for Help<'a, B> { .on_update(|state| { let props = HelpProps::from(state); - Box::>::new( + Box::new( ParagraphProps::default() .text(&props.content) .page_size(props.page_size)