From 2a77856cb8edb21a25cb54a3075044f2056f6d34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20H=C3=BCbner?= Date: Tue, 4 Mar 2025 12:25:02 +0100 Subject: [PATCH] Revert from lifetimes --- src/elements/button.rs | 76 +++++++--------- src/elements/fill_type.rs | 16 ++-- src/elements/grid.rs | 126 +++++++++++++-------------- src/elements/icon.rs | 44 +++++----- src/elements/label.rs | 42 ++++----- src/elements/mod.rs | 2 +- src/elements/multi_line_label.rs | 42 ++++----- src/elements/multi_line_textfield.rs | 59 ++++++------- src/elements/progress_bar.rs | 34 ++++---- src/elements/textfield.rs | 38 ++++---- src/elements/traits.rs | 36 ++++---- src/elements/ui_element.rs | 32 +++---- src/elements/wrapper.rs | 28 +++--- src/gui_handler/elements.rs | 10 +-- src/gui_handler/gui/clickable.rs | 12 ++- src/gui_handler/gui/colorable.rs | 10 +-- src/gui_handler/gui/displayable.rs | 10 +-- src/gui_handler/gui/executable.rs | 10 +-- src/gui_handler/gui/framable.rs | 24 ++--- src/gui_handler/gui/hoverable.rs | 6 +- src/gui_handler/gui/iconizable.rs | 10 +-- src/gui_handler/gui/selectable.rs | 57 ++++++------ src/gui_handler/gui/textable.rs | 26 +++--- src/gui_handler/gui/writeable.rs | 38 ++++---- src/gui_handler/gui_handler.rs | 59 +++++++------ src/keyboard/mod.rs | 2 +- 26 files changed, 403 insertions(+), 446 deletions(-) diff --git a/src/elements/button.rs b/src/elements/button.rs index 4152020..539058c 100644 --- a/src/elements/button.rs +++ b/src/elements/button.rs @@ -116,7 +116,7 @@ impl ButtonBuilder { self } - pub fn build<'a>(self, gui_handler: &mut GuiHandler<'_>) -> Result>> { + pub fn build(self, gui_handler: &mut GuiHandler) -> Result> { let framable = Framable::new(gui_handler.width(), gui_handler.height(), false)?; let normal = FillType::new( @@ -256,10 +256,10 @@ pub enum ButtonSelectMode { Bigger, } -pub struct Button<'a> { +pub struct Button { clickable: Arc, hoverable: Arc, - selectable: Arc>, + selectable: Arc, framable: Arc, iconizable: IconizableWrapper, textable: TextableWrapper, @@ -271,7 +271,7 @@ pub struct Button<'a> { _hover_sound: Option>, click_executable: Arc>, - select_executable: Arc, bool)>>, + select_executable: Arc>, on_select_executable: Arc>, normal: FillType, @@ -283,7 +283,7 @@ pub struct Button<'a> { visible: AtomicBool, } -impl<'a> Button<'a> { +impl Button { pub fn builder() -> ButtonBuilder { ButtonBuilder { icon: None, @@ -308,7 +308,7 @@ impl<'a> Button<'a> { } } - pub fn select(&self, gui_handler: &mut GuiHandler<'a>) -> Result<()> { + pub fn select(&self, gui_handler: &mut GuiHandler) -> Result<()> { self.selectable.select(gui_handler) } @@ -316,14 +316,15 @@ impl<'a> Button<'a> { where F: Fn() -> Result<()> + Send + Sync + 'static, { - self.click_executable.set_callback(move |_| callback()); + self.click_executable.set_callback(move |_, _| callback()); } pub fn set_select_callback(&self, callback: F) where F: Fn(bool) -> Result<()> + Send + Sync + 'static, { - self.on_select_executable.set_callback(callback); + self.on_select_executable + .set_callback(|_m, select| callback(select)); } pub fn set_custom_callback(&self, callback: F) @@ -333,19 +334,19 @@ impl<'a> Button<'a> { self.selectable.set_custom_callback(callback); } - pub fn set_text(&self, gui_handler: &mut GuiHandler<'_>, text: impl ToString) -> Result<()> { + pub fn set_text(&self, gui_handler: &mut GuiHandler, text: impl ToString) -> Result<()> { self.textable.set_text(gui_handler, text, self.visible()) } - pub fn set_icon(&self, gui_handler: &mut GuiHandler<'_>, icon: &Arc) -> Result<()> { + pub fn set_icon(&self, gui_handler: &mut GuiHandler, icon: &Arc) -> Result<()> { self.iconizable.set_icon(gui_handler, icon, self.visible()) } - pub fn set_icon_margon(&self, gui_handler: &mut GuiHandler<'_>, margin: u32) -> Result<()> { + pub fn set_icon_margon(&self, gui_handler: &mut GuiHandler, margin: u32) -> Result<()> { self.iconizable.set_margin(gui_handler, margin) } - pub fn clear_icon(&self, gui_handler: &mut GuiHandler<'_>) -> Result<()> { + pub fn clear_icon(&self, gui_handler: &mut GuiHandler) -> Result<()> { self.iconizable.clear_icon(gui_handler, self.visible()) } @@ -353,15 +354,11 @@ impl<'a> Button<'a> { self.iconizable.icon() } - pub fn set_info_icon( - &self, - gui_handler: &mut GuiHandler<'_>, - button: &Arc, - ) -> Result<()> { + pub fn set_info_icon(&self, gui_handler: &mut GuiHandler, button: &Arc) -> Result<()> { self.info_icon.set_icon(gui_handler, button, self.visible()) } - pub fn clear_info_icon(&self, gui_handler: &mut GuiHandler<'_>) -> Result<()> { + pub fn clear_info_icon(&self, gui_handler: &mut GuiHandler) -> Result<()> { self.info_icon.clear_icon(gui_handler, self.visible()) } @@ -369,18 +366,11 @@ impl<'a> Button<'a> { self.textable.text() } - pub fn set_text_color( - &self, - gui_handler: &mut GuiHandler<'_>, - text_color: Color, - ) -> Result<()> { + pub fn set_text_color(&self, gui_handler: &mut GuiHandler, text_color: Color) -> Result<()> { self.textable.set_text_color(gui_handler, text_color) } - pub fn try_from( - gui_handler: &mut GuiHandler<'_>, - button_info: &ButtonInfo, - ) -> Result> { + pub fn try_from(gui_handler: &mut GuiHandler, button_info: &ButtonInfo) -> Result> { let mut button_builder = Button::builder() .set_select_mode(button_info.select_mode) .set_isolate(button_info.isolate); @@ -437,8 +427,8 @@ impl<'a> Button<'a> { } } -impl<'a> GuiElementTraits<'a> for Button<'a> { - fn gridable(&self) -> Option<&dyn Gridable<'a>> { +impl GuiElementTraits for Button { + fn gridable(&self) -> Option<&dyn Gridable> { Some(self) } @@ -446,17 +436,17 @@ impl<'a> GuiElementTraits<'a> for Button<'a> { Some(self) } - fn downcast(&'a self) -> Option> { + fn downcast<'a>(&'a self) -> Option> { Some(GuiElement::Button(self)) } } -impl<'a> Visibility for Button<'a> { +impl Visibility for Button { fn visible(&self) -> bool { self.visible.load(SeqCst) } - fn set_visibility(&self, gui_handler: &mut GuiHandler<'_>, visibility: bool) -> Result<()> { + fn set_visibility(&self, gui_handler: &mut GuiHandler, visibility: bool) -> Result<()> { if visibility != self.visible.load(SeqCst) { self.visible.store(visibility, SeqCst); @@ -483,10 +473,10 @@ impl<'a> Visibility for Button<'a> { } } -impl<'a> Gridable<'a> for Button<'a> { +impl Gridable for Button { fn set_frame( &self, - gui_handler: &mut GuiHandler<'_>, + gui_handler: &mut GuiHandler, x: i32, y: i32, w: u32, @@ -510,7 +500,7 @@ impl<'a> Gridable<'a> for Button<'a> { Ok(()) } - fn selectable(&self) -> Option<&Arc>> { + fn selectable(&self) -> Option<&Arc> { Some(&self.selectable) } @@ -539,7 +529,7 @@ impl<'a> Gridable<'a> for Button<'a> { } // private -impl<'a> Button<'a> { +impl Button { // fn create_hovered_changed_callback(button: Arc