lib: Improve props downcasting

This commit is contained in:
Erik Kundt
2024-04-17 13:52:53 +02:00
parent a92e684308
commit 4e69e0ad74
2 changed files with 5 additions and 7 deletions
+3 -5
View File
@@ -101,7 +101,7 @@ impl<'a: 'static, S, A> View<S, A> for Header<'a, S, A> {
fn update(&mut self, state: &S) {
if let Some(on_update) = self.on_update {
if let Some(props) = (on_update)(state).downcast_ref::<HeaderProps<'_>>() {
if let Some(props) = (on_update)(state).downcast_ref::<HeaderProps>() {
self.props = props.clone();
}
}
@@ -264,7 +264,7 @@ impl<'a: 'static, S, A> View<S, A> for Footer<'a, S, A> {
fn update(&mut self, state: &S) {
if let Some(on_update) = self.on_update {
if let Some(props) = (on_update)(state).downcast_ref::<FooterProps<'_>>() {
if let Some(props) = (on_update)(state).downcast_ref::<FooterProps>() {
self.props = props.clone();
}
}
@@ -306,9 +306,7 @@ where
B: Backend,
{
fn render(&self, frame: &mut ratatui::Frame, area: Rect, props: &dyn Any) {
let props = props
.downcast_ref::<FooterProps<'_>>()
.unwrap_or(&self.props);
let props = props.downcast_ref::<FooterProps>().unwrap_or(&self.props);
let widths = props
.columns
+2 -2
View File
@@ -167,7 +167,7 @@ impl<'a: 'static, S, A> View<S, A> for Paragraph<'a, S, A> {
fn update(&mut self, state: &S) {
if let Some(on_update) = self.on_update {
if let Some(props) = (on_update)(state).downcast_ref::<ParagraphProps<'_>>() {
if let Some(props) = (on_update)(state).downcast_ref::<ParagraphProps>() {
self.props = props.clone();
}
}
@@ -211,7 +211,7 @@ where
{
fn render(&self, frame: &mut ratatui::Frame, area: Rect, props: &dyn Any) {
let props = props
.downcast_ref::<ParagraphProps<'_>>()
.downcast_ref::<ParagraphProps>()
.unwrap_or(&self.props);
let block = Block::default()