From c4ed134483140d3fbf68c97a03427e2ae1279a52 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Mon, 9 Sep 2024 15:54:52 +0200 Subject: [PATCH] lib: Improve content function types in imUI --- src/ui/im.rs | 6 ++++-- src/ui/im/widget.rs | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/ui/im.rs b/src/ui/im.rs index 088c79e0..75be277c 100644 --- a/src/ui/im.rs +++ b/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( &mut self, layout: impl Into, - add_contents: Box R + 'a>, + add_contents: Box>, ) -> InnerResponse { let (area, _) = self.next_area().unwrap_or_default(); let mut child_ui = self.child_ui(area, layout); diff --git a/src/ui/im/widget.rs b/src/ui/im/widget.rs index 8be94d6e..e9f1c0d3 100644 --- a/src/ui/im/widget.rs +++ b/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) -> R + 'a; + pub trait Widget { fn ui(self, ui: &mut Ui, 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( self, ctx: &Context, - add_contents: Box) -> R + 'c>, + add_contents: Box>, ) -> Option>> 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( self, ui: &mut Ui, - add_contents: Box) -> R + 'c>, + add_contents: Box>, ) -> InnerResponse where M: Clone,