lib: Pass event to event callback

This commit is contained in:
Erik Kundt
2024-05-21 17:30:34 +02:00
parent a29d1d6895
commit 0b1da2af78
6 changed files with 11 additions and 5 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ use ratatui::widgets::Cell;
pub type BoxedWidget<S, M> = Box<dyn Widget<State = S, Message = M>>;
pub type UpdateCallback<S> = fn(&S) -> Box<dyn Any>;
pub type EventCallback = fn(&mut dyn Any);
pub type EventCallback = fn(&mut dyn Any, Key);
/// A `WidgetBase` provides common functionality to a `Widget`. It's used to store
/// event and update callbacks as well sending messages to the UI's message channel.
+1 -1
View File
@@ -554,7 +554,7 @@ where
}
if let Some(on_event) = self.base.on_event {
(on_event)(self);
(on_event)(self, key);
}
}
+1 -1
View File
@@ -172,7 +172,7 @@ where
}
if let Some(on_event) = self.base.on_event {
(on_event)(self);
(on_event)(self, key);
}
}
+1 -1
View File
@@ -198,7 +198,7 @@ where
}
if let Some(on_event) = self.base.on_event {
(on_event)(self);
(on_event)(self, key);
}
}
+1 -1
View File
@@ -186,7 +186,7 @@ where
}
if let Some(on_event) = self.base.on_event {
(on_event)(self);
(on_event)(self, key);
}
}
+6
View File
@@ -57,6 +57,8 @@ where
impl<'a, S, M, Id> Widget for Window<S, M, Id>
where
'a: 'static,
S: 'static,
M: 'static,
Id: Clone + Hash + Eq + PartialEq + 'static,
{
type Message = M;
@@ -83,6 +85,10 @@ where
if let Some(page) = page {
page.handle_event(key);
}
if let Some(on_event) = self.base.on_event {
(on_event)(self, key);
}
}
fn update(&mut self, state: &S) {