Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
lib: Improve content function types in imUI
Erik Kundt committed 1 year ago
commit c4ed134483140d3fbf68c97a03427e2ae1279a52
parent 3b4f2951e0cbe1e5e56e0670b6fe273401b0a67b
2 files changed +10 -6
modified src/ui/im.rs
@@ -25,6 +25,8 @@ use crate::ui::{Column, ToRow};

use crate::ui::im::widget::{HeaderedTable, Widget};

+
use self::widget::AddContentFn;
+

const RENDERING_TICK_RATE: Duration = Duration::from_millis(250);

/// The main UI trait for the ability to render an application.
@@ -406,10 +408,10 @@ where
        self.layout_dyn(layout, Box::new(add_contents))
    }

-
    pub fn layout_dyn<'a, R>(
+
    pub fn layout_dyn<R>(
        &mut self,
        layout: impl Into<Layout>,
-
        add_contents: Box<dyn FnOnce(&mut Self) -> R + 'a>,
+
        add_contents: Box<AddContentFn<M, R>>,
    ) -> InnerResponse<R> {
        let (area, _) = self.next_area().unwrap_or_default();
        let mut child_ui = self.child_ui(area, layout);
modified src/ui/im/widget.rs
@@ -15,6 +15,8 @@ use crate::ui::{Column, ToRow};

use super::{Borders, Context, InnerResponse, Response, Ui};

+
pub type AddContentFn<'a, M, R> = dyn FnOnce(&mut Ui<M>) -> R + 'a;
+

pub trait Widget {
    fn ui<M>(self, ui: &mut Ui<M>, frame: &mut Frame) -> Response
    where
@@ -37,10 +39,10 @@ impl Window {
        self.show_dyn(ctx, Box::new(add_contents))
    }

-
    fn show_dyn<'c, M, R>(
+
    fn show_dyn<M, R>(
        self,
        ctx: &Context<M>,
-
        add_contents: Box<dyn FnOnce(&mut Ui<M>) -> R + 'c>,
+
        add_contents: Box<AddContentFn<M, R>>,
    ) -> Option<InnerResponse<Option<R>>>
    where
        M: Clone,
@@ -111,10 +113,10 @@ impl<'a> Group<'a> {
        self.show_dyn(ui, Box::new(add_contents))
    }

-
    pub fn show_dyn<'c, M, R>(
+
    pub fn show_dyn<M, R>(
        self,
        ui: &mut Ui<M>,
-
        add_contents: Box<dyn FnOnce(&mut Ui<M>) -> R + 'c>,
+
        add_contents: Box<AddContentFn<M, R>>,
    ) -> InnerResponse<R>
    where
        M: Clone,