lib: Improve content function types in imUI

This commit is contained in:
Erik Kundt
2024-09-13 15:38:08 +02:00
parent 3b4f2951e0
commit c4ed134483
2 changed files with 10 additions and 6 deletions
+4 -2
View File
@@ -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);
+6 -4
View File
@@ -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,