Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
lib: Rename event handling function
Erik Kundt committed 2 years ago
commit 0738ec7543410da0911cadc46f4a7b73235af4ec
parent 4294a5e9532a485f4e35eb04fe417c00ae890523
5 files changed +14 -15
modified src/ui.rs
@@ -97,7 +97,7 @@ impl<A> Frontend<A> {
                // Tick to terminate the select every N milliseconds
                _ = ticker.tick() => (),
                Some(event) = events_rx.recv() => match event {
-
                    Event::Key(key) => root.handle_key_event(key),
+
                    Event::Key(key) => root.handle_event(key),
                    Event::Resize => (),
                },
                // Handle state updates
modified src/ui/widget.rs
@@ -55,7 +55,6 @@ pub trait View<S, A> {
    fn on_update(mut self, callback: UpdateCallback<S>) -> Self
    where
        Self: Sized,
-

    {
        self.base_mut().on_update = Some(callback);
        self
@@ -69,13 +68,14 @@ pub trait View<S, A> {
        Box::new(self)
    }

+
    /// Return a mutable reference to this widgets' base view.
    fn base_mut(&mut self) -> &mut BaseView<S, A>;

-
    /// Should handle key events and call `handle_key_event` on all children.
+
    /// Should handle key events and call `handle_event` on all children.
    ///
    /// After key events have been handled, the custom event handler `on_event` should
    /// be called
-
    fn handle_key_event(&mut self, key: Key);
+
    fn handle_event(&mut self, key: Key);

    /// Should update the internal props of this and all children.
    ///
@@ -201,7 +201,6 @@ where
    fn base_mut(&mut self) -> &mut BaseView<S, A> {
        &mut self.base
    }
-

    fn update(&mut self, state: &S) {
        self.props =
            WindowProps::from_callback(self.base.on_update, state).unwrap_or(self.props.clone());
@@ -217,7 +216,7 @@ where
        }
    }

-
    fn handle_key_event(&mut self, key: termion::event::Key) {
+
    fn handle_event(&mut self, key: termion::event::Key) {
        let page = self
            .props
            .current_page
@@ -225,7 +224,7 @@ where
            .and_then(|id| self.pages.get_mut(id));

        if let Some(page) = page {
-
            page.handle_key_event(key);
+
            page.handle_event(key);
        }
    }
}
@@ -326,7 +325,7 @@ impl<S, A> View<S, A> for Shortcuts<S, A> {
        &mut self.base
    }

-
    fn handle_key_event(&mut self, _key: Key) {}
+
    fn handle_event(&mut self, _key: Key) {}

    fn update(&mut self, state: &S) {
        self.props =
@@ -572,7 +571,7 @@ where
        }
    }

-
    fn handle_key_event(&mut self, key: Key) {
+
    fn handle_event(&mut self, key: Key) {
        match key {
            Key::Up | Key::Char('k') => {
                self.prev();
modified src/ui/widget/container.rs
@@ -101,7 +101,7 @@ impl<'a: 'static, S, A> View<S, A> for Header<'a, S, A> {
            .unwrap_or(self.props.clone());
    }

-
    fn handle_key_event(&mut self, _key: Key) {
+
    fn handle_event(&mut self, _key: Key) {
        if let Some(on_event) = self.base.on_event {
            (on_event)(&self.props, self.base.action_tx.clone());
        }
@@ -258,7 +258,7 @@ impl<'a: 'static, S, A> View<S, A> for Footer<'a, S, A> {
            .unwrap_or(self.props.clone());
    }

-
    fn handle_key_event(&mut self, _key: Key) {
+
    fn handle_event(&mut self, _key: Key) {
        if let Some(on_event) = self.base.on_event {
            (on_event)(&self.props, self.base.action_tx.clone());
        }
@@ -429,9 +429,9 @@ where
        }
    }

-
    fn handle_key_event(&mut self, key: termion::event::Key) {
+
    fn handle_event(&mut self, key: termion::event::Key) {
        if let Some(content) = &mut self.content {
-
            content.handle_key_event(key);
+
            content.handle_event(key);
        }
    }
}
modified src/ui/widget/input.rs
@@ -159,7 +159,7 @@ impl<S, A> View<S, A> for TextField<S, A> {
        }
    }

-
    fn handle_key_event(&mut self, key: Key) {
+
    fn handle_event(&mut self, key: Key) {
        match key {
            Key::Char(to_insert)
                if (key != Key::Alt('\n'))
modified src/ui/widget/text.rs
@@ -170,7 +170,7 @@ impl<'a: 'static, S, A> View<S, A> for Paragraph<'a, S, A> {
            ParagraphProps::from_callback(self.base.on_update, state).unwrap_or(self.props.clone());
    }

-
    fn handle_key_event(&mut self, key: Key) {
+
    fn handle_event(&mut self, key: Key) {
        let len = self.props.content.lines.len() + 1;
        let page_size = self.props.page_size;