Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
lib: Introduce boxed builder for props
Erik Kundt committed 2 years ago
commit c5800738411a8d11e0501d5fae378097b937c98c
parent 3e2fe1541bc207ab97fe88d29cab4560923656f2
6 files changed +70 -56
modified bin/commands/inbox/select/ui.rs
@@ -77,7 +77,9 @@ impl<'a: 'static, B: Backend + 'a> View<State, Action> for ListPage<B> {
            help: Help::new(state, action_tx.clone()).to_boxed(),
            shortcuts: Shortcuts::new(state, action_tx.clone())
                .on_update(|state| {
-
                    Box::new(ShortcutsProps::default().shortcuts(&state.shortcuts()))
+
                    ShortcutsProps::default()
+
                        .shortcuts(&state.shortcuts())
+
                        .to_boxed()
                })
                .to_boxed(),
            on_update: None,
@@ -485,12 +487,11 @@ impl<B: Backend> View<State, Action> for Search<B> {
                });
            })
            .on_update(|state| {
-
                Box::new(
-
                    TextFieldProps::default()
-
                        .text(&state.search.read().to_string())
-
                        .title("Search")
-
                        .inline(true),
-
                )
+
                TextFieldProps::default()
+
                    .text(&state.search.read().to_string())
+
                    .title("Search")
+
                    .inline(true)
+
                    .to_boxed()
            })
            .to_boxed();
        Self {
@@ -718,12 +719,11 @@ impl<'a, B: Backend> View<State, Action> for Help<'a, B> {
                .on_update(|state| {
                    let props = HelpProps::from(state);

-
                    Box::new(
-
                        ParagraphProps::default()
-
                            .text(&props.content)
-
                            .page_size(props.page_size)
-
                            .focus(props.focus),
-
                    )
+
                    ParagraphProps::default()
+
                        .text(&props.content)
+
                        .page_size(props.page_size)
+
                        .focus(props.focus)
+
                        .to_boxed()
                })
                .to_boxed(),
            footer: Footer::new(state, action_tx).to_boxed(),
modified bin/commands/issue/select/ui.rs
@@ -83,7 +83,9 @@ where
            help: Help::new(state, action_tx.clone()).to_boxed(),
            shortcuts: Shortcuts::new(state, action_tx.clone())
                .on_update(|state| {
-
                    Box::new(ShortcutsProps::default().shortcuts(&state.shortcuts()))
+
                    ShortcutsProps::default()
+
                        .shortcuts(&state.shortcuts())
+
                        .to_boxed()
                })
                .to_boxed(),
            on_update: None,
@@ -274,14 +276,13 @@ where
                    .on_update(|state| {
                        let props = IssuesProps::from(state);

-
                        Box::new(
-
                            TableProps::default()
-
                                .columns(props.columns)
-
                                .items(state.issues())
-
                                .footer(!state.ui.show_search)
-
                                .page_size(state.ui.page_size)
-
                                .cutoff(props.cutoff, props.cutoff_after),
-
                        )
+
                        TableProps::default()
+
                            .columns(props.columns)
+
                            .items(state.issues())
+
                            .footer(!state.ui.show_search)
+
                            .page_size(state.ui.page_size)
+
                            .cutoff(props.cutoff, props.cutoff_after)
+
                            .to_boxed()
                    }),
            ),
            footer: Footer::new(state, action_tx).to_boxed(),
@@ -508,12 +509,11 @@ impl<B: Backend> View<State, Action> for Search<B> {
                });
            })
            .on_update(|state| {
-
                Box::new(
-
                    TextFieldProps::default()
-
                        .text(&state.search.read().to_string())
-
                        .title("Search")
-
                        .inline(true),
-
                )
+
                TextFieldProps::default()
+
                    .text(&state.search.read().to_string())
+
                    .title("Search")
+
                    .inline(true)
+
                    .to_boxed()
            })
            .to_boxed();
        Self {
@@ -741,12 +741,11 @@ impl<'a, B: Backend> View<State, Action> for Help<'a, B> {
                .on_update(|state| {
                    let props = HelpProps::from(state);

-
                    Box::new(
-
                        ParagraphProps::default()
-
                            .text(&props.content)
-
                            .page_size(props.page_size)
-
                            .focus(props.focus),
-
                    )
+
                    ParagraphProps::default()
+
                        .text(&props.content)
+
                        .page_size(props.page_size)
+
                        .focus(props.focus)
+
                        .to_boxed()
                })
                .to_boxed(),
            footer: Footer::new(state, action_tx).to_boxed(),
modified bin/commands/patch/select/ui.rs
@@ -81,7 +81,9 @@ impl<'a: 'static, B: Backend + 'a> View<State, Action> for ListPage<B> {
            help: Help::new(state, action_tx.clone()).to_boxed(),
            shortcuts: Shortcuts::new(state, action_tx.clone())
                .on_update(|state| {
-
                    Box::new(ShortcutsProps::default().shortcuts(&state.shortcuts()))
+
                    ShortcutsProps::default()
+
                        .shortcuts(&state.shortcuts())
+
                        .to_boxed()
                })
                .to_boxed(),
            on_update: None,
@@ -274,14 +276,13 @@ where
                    .on_update(|state| {
                        let props = PatchesProps::from(state);

-
                        Box::new(
-
                            TableProps::default()
-
                                .columns(props.columns)
-
                                .items(state.patches())
-
                                .footer(!state.ui.show_search)
-
                                .page_size(state.ui.page_size)
-
                                .cutoff(props.cutoff, props.cutoff_after),
-
                        )
+
                        TableProps::default()
+
                            .columns(props.columns)
+
                            .items(state.patches())
+
                            .footer(!state.ui.show_search)
+
                            .page_size(state.ui.page_size)
+
                            .cutoff(props.cutoff, props.cutoff_after)
+
                            .to_boxed()
                    }),
            ),
            footer: Footer::new(state, action_tx).to_boxed(),
@@ -539,12 +540,11 @@ impl<B: Backend> View<State, Action> for Search<B> {
                });
            })
            .on_update(|state| {
-
                Box::new(
-
                    TextFieldProps::default()
-
                        .text(&state.search.read().to_string())
-
                        .title("Search")
-
                        .inline(true),
-
                )
+
                TextFieldProps::default()
+
                    .text(&state.search.read().to_string())
+
                    .title("Search")
+
                    .inline(true)
+
                    .to_boxed()
            })
            .to_boxed();
        Self {
@@ -780,12 +780,11 @@ impl<'a, B: Backend> View<State, Action> for Help<'a, B> {
                .on_update(|state| {
                    let props = HelpProps::from(state);

-
                    Box::new(
-
                        ParagraphProps::default()
-
                            .text(&props.content)
-
                            .page_size(props.page_size)
-
                            .focus(props.focus),
-
                    )
+
                    ParagraphProps::default()
+
                        .text(&props.content)
+
                        .page_size(props.page_size)
+
                        .focus(props.focus)
+
                        .to_boxed()
                })
                .to_boxed(),
            footer: Footer::new(state, action_tx).to_boxed(),
modified src/ui/widget.rs
@@ -50,7 +50,7 @@ pub trait Widget<B, S, A>: View<S, A>
where
    B: Backend,
{
-
    fn render(&self, frame: &mut Frame, area: Rect, _props: &dyn Any);
+
    fn render(&self, frame: &mut Frame, area: Rect, props: &dyn Any);
}

pub trait ToRow {
@@ -85,6 +85,10 @@ impl ShortcutsProps {
        }
        self
    }
+

+
    pub fn to_boxed(self) -> Box<Self> {
+
        Box::new(self)
+
    }
}

pub struct Shortcuts<S, A> {
@@ -285,6 +289,10 @@ where
        self.page_size = page_size;
        self
    }
+

+
    pub fn to_boxed(self) -> Box<Self> {
+
        Box::new(self)
+
    }
}

pub struct Table<'a, B, S, A, R>
modified src/ui/widget/input.rs
@@ -38,6 +38,10 @@ impl TextFieldProps {
        self.inline_label = inline;
        self
    }
+

+
    pub fn to_boxed(self) -> Box<Self> {
+
        Box::new(self)
+
    }
}

impl Default for TextFieldProps {
modified src/ui/widget/text.rs
@@ -37,6 +37,10 @@ impl<'a> ParagraphProps<'a> {
        self.focus = focus;
        self
    }
+

+
    pub fn to_boxed(self) -> Box<Self> {
+
        Box::new(self)
+
    }
}

impl<'a> Default for ParagraphProps<'a> {