From 75d14f82b4397de4b44d383b648bbfd4b33845b0 Mon Sep 17 00:00:00 2001 From: Antoine Beyeler Date: Tue, 30 Apr 2024 18:04:45 +0200 Subject: [PATCH] Change the way closure are defined --- .../re_ui/src/list_item2/property_content.rs | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/crates/re_ui/src/list_item2/property_content.rs b/crates/re_ui/src/list_item2/property_content.rs index 04547d31e54c..1ff14f0d0822 100644 --- a/crates/re_ui/src/list_item2/property_content.rs +++ b/crates/re_ui/src/list_item2/property_content.rs @@ -4,21 +4,12 @@ use eframe::emath::{Align, Align2}; use eframe::epaint::text::TextWrapping; use egui::{NumExt, Response, Ui}; -/// Closure to draw the property value (right column). -pub trait PropertyValueFn: - FnOnce(&ReUi, &mut egui::Ui, egui::style::WidgetVisuals) -> Option -{ -} - -impl Option> - PropertyValueFn for F -{ -} - /// Closure to draw an icon left of the label. -pub trait IconFn: FnOnce(&ReUi, &mut egui::Ui, egui::Rect, egui::style::WidgetVisuals) {} +type IconFn<'a> = dyn FnOnce(&ReUi, &mut egui::Ui, egui::Rect, egui::style::WidgetVisuals) + 'a; -impl IconFn for F {} +/// Closure to draw the right column of the property. +type PropertyValueFn<'a> = + dyn FnOnce(&ReUi, &mut egui::Ui, egui::style::WidgetVisuals) -> Option + 'a; struct PropertyActionButton<'a> { icon: &'static crate::icons::Icon, @@ -30,9 +21,9 @@ struct PropertyActionButton<'a> { /// value (which may be editable). pub struct PropertyContent<'a> { label: egui::WidgetText, - icon_fn: Option>, + icon_fn: Option>>, summary_only: bool, - value_fn: Option>, + value_fn: Option>>, //TODO(ab): in the future, that should be a `Vec`, with some auto expanding mini-toolbar action_buttons: Option>, /**/ @@ -61,7 +52,10 @@ impl<'a> PropertyContent<'a> { /// Provide a custom closure to draw an icon on the left of the item. #[inline] - pub fn with_icon_fn(mut self, icon_fn: impl IconFn + 'a) -> Self { + pub fn with_icon_fn(mut self, icon_fn: F) -> Self + where + F: FnOnce(&ReUi, &mut egui::Ui, egui::Rect, egui::style::WidgetVisuals) + 'a, + { self.icon_fn = Some(Box::new(icon_fn)); self } @@ -101,7 +95,10 @@ impl<'a> PropertyContent<'a> { /// Provide a closure to draw the content of the right column. #[inline] - pub fn value_fn(mut self, value_fn: impl PropertyValueFn + 'a) -> Self { + pub fn value_fn(mut self, value_fn: F) -> Self + where + F: FnOnce(&ReUi, &mut egui::Ui, egui::style::WidgetVisuals) -> Option + 'a, + { self.value_fn = Some(Box::new(value_fn)); self }