Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
lib: Allow widgets to be reset
Erik Kundt committed 1 year ago
commit 1f6d5f9196d5882b6e321719c35ff90a80b3f954
parent 4596d0b8b0aadc5a0351b4c8b6a4b6b418412661
1 file changed +8 -0
modified src/ui/widget.rs
@@ -128,6 +128,9 @@ pub trait View {
        None
    }

+
    /// Should reset the internal state and call `reset` on all children.
+
    fn reset(&mut self) {}
+

    /// Should handle key events and call `handle_event` on all children.
    fn handle_event(&mut self, _props: Option<&ViewProps>, _key: Key) -> Option<Self::Message> {
        None
@@ -168,6 +171,11 @@ impl<S: 'static, M: 'static> Widget<S, M> {
        }
    }

+
    /// Calls `reset` on the wrapped view.
+
    pub fn reset(&mut self) {
+
        self.view.reset()
+
    }
+

    /// Calls `handle_event` on the wrapped view as well as the `on_event` callback.
    /// Sends any message returned by either the view or the callback.
    pub fn handle_event(&mut self, key: Key) {