diff --git a/emigui/src/types.rs b/emigui/src/types.rs index a7ec6222..3b20340b 100644 --- a/emigui/src/types.rs +++ b/emigui/src/types.rs @@ -110,6 +110,17 @@ impl GuiResponse { } } +impl Into for GuiResponse { + fn into(self) -> InteractInfo { + InteractInfo { + hovered: self.hovered, + clicked: self.clicked, + active: self.active, + rect: self.rect, + } + } +} + // ---------------------------------------------------------------------------- /// What sort of interaction is a widget sensitive to? diff --git a/emigui/src/ui.rs b/emigui/src/ui.rs index 02b4bf88..27a0e417 100644 --- a/emigui/src/ui.rs +++ b/emigui/src/ui.rs @@ -490,7 +490,8 @@ impl Ui { // Addding Widgets pub fn add(&mut self, widget: impl Widget) -> GuiResponse { - widget.ui(self) + let interact = widget.ui(self); + self.response(interact) } // Convenience functions: diff --git a/emigui/src/widgets.rs b/emigui/src/widgets.rs index 23e9e098..1abe4b1c 100644 --- a/emigui/src/widgets.rs +++ b/emigui/src/widgets.rs @@ -1,6 +1,6 @@ #![allow(clippy::new_without_default)] -use crate::{layout::Direction, GuiResponse, *}; +use crate::{layout::Direction, *}; mod slider; pub mod text_edit; @@ -11,7 +11,7 @@ pub use {paint::*, slider::*, text_edit::*}; /// Anything implementing Widget can be added to a Ui with `Ui::add` pub trait Widget { - fn ui(self, ui: &mut Ui) -> GuiResponse; + fn ui(self, ui: &mut Ui) -> InteractInfo; } // ---------------------------------------------------------------------------- @@ -106,11 +106,11 @@ macro_rules! label { } impl Widget for Label { - fn ui(self, ui: &mut Ui) -> GuiResponse { + fn ui(self, ui: &mut Ui) -> InteractInfo { let galley = self.layout(ui); let rect = ui.allocate_space(galley.size); self.paint_galley(ui, rect.min, galley); - ui.response(ui.interact_hover(rect)) + ui.interact_hover(rect) } } @@ -150,7 +150,7 @@ impl Hyperlink { } impl Widget for Hyperlink { - fn ui(self, ui: &mut Ui) -> GuiResponse { + fn ui(self, ui: &mut Ui) -> InteractInfo { let Hyperlink { url, text } = self; let color = color::LIGHT_BLUE; @@ -185,7 +185,7 @@ impl Widget for Hyperlink { ui.add_galley(interact.rect.min, galley, text_style, Some(color)); - ui.response(interact) + interact } } @@ -226,7 +226,7 @@ impl Button { } impl Widget for Button { - fn ui(self, ui: &mut Ui) -> GuiResponse { + fn ui(self, ui: &mut Ui) -> InteractInfo { let Button { text, text_color, @@ -253,7 +253,7 @@ impl Widget for Button { let stroke_color = ui.style().interact(&interact).stroke_color; let text_color = text_color.unwrap_or(stroke_color); ui.add_galley(text_cursor, galley, text_style, Some(text_color)); - ui.response(interact) + interact } } @@ -282,7 +282,7 @@ impl<'a> Checkbox<'a> { } impl<'a> Widget for Checkbox<'a> { - fn ui(self, ui: &mut Ui) -> GuiResponse { + fn ui(self, ui: &mut Ui) -> InteractInfo { let Checkbox { checked, text, @@ -328,7 +328,7 @@ impl<'a> Widget for Checkbox<'a> { let text_color = text_color.unwrap_or(stroke_color); ui.add_galley(text_cursor, galley, text_style, Some(text_color)); - ui.response(interact) + interact } } @@ -361,7 +361,7 @@ pub fn radio(checked: bool, text: impl Into) -> RadioButton { } impl Widget for RadioButton { - fn ui(self, ui: &mut Ui) -> GuiResponse { + fn ui(self, ui: &mut Ui) -> InteractInfo { let RadioButton { checked, text, @@ -403,7 +403,7 @@ impl Widget for RadioButton { let text_color = text_color.unwrap_or(stroke_color); ui.add_galley(text_cursor, galley, text_style, Some(text_color)); - ui.response(interact) + interact } } @@ -449,7 +449,7 @@ impl Separator { } impl Widget for Separator { - fn ui(self, ui: &mut Ui) -> GuiResponse { + fn ui(self, ui: &mut Ui) -> InteractInfo { let Separator { line_width, min_spacing, @@ -488,6 +488,6 @@ impl Widget for Separator { color: color, width: line_width, }); - ui.response(ui.interact_hover(rect)) + ui.interact_hover(rect) } } diff --git a/emigui/src/widgets/slider.rs b/emigui/src/widgets/slider.rs index 95801119..20491387 100644 --- a/emigui/src/widgets/slider.rs +++ b/emigui/src/widgets/slider.rs @@ -99,7 +99,7 @@ impl<'a> Slider<'a> { } impl<'a> Widget for Slider<'a> { - fn ui(mut self, ui: &mut Ui) -> GuiResponse { + fn ui(mut self, ui: &mut Ui) -> InteractInfo { let text_style = TextStyle::Button; let font = &ui.fonts()[text_style]; @@ -131,7 +131,7 @@ impl<'a> Widget for Slider<'a> { ui.add(Label::new(full_text).multiline(false)); }); - slider_response + slider_response.into() }) } } else { @@ -189,7 +189,7 @@ impl<'a> Widget for Slider<'a> { }); } - ui.response(interact) + interact } } } diff --git a/emigui/src/widgets/text_edit.rs b/emigui/src/widgets/text_edit.rs index d4d35d53..47db1a71 100644 --- a/emigui/src/widgets/text_edit.rs +++ b/emigui/src/widgets/text_edit.rs @@ -49,7 +49,7 @@ impl<'t> TextEdit<'t> { } impl<'t> Widget for TextEdit<'t> { - fn ui(self, ui: &mut Ui) -> GuiResponse { + fn ui(self, ui: &mut Ui) -> InteractInfo { let TextEdit { text, id, @@ -145,7 +145,7 @@ impl<'t> Widget for TextEdit<'t> { ui.add_galley(interact.rect.min, galley, text_style, text_color); ui.memory().text_edit.insert(id, state); - ui.response(interact) + interact } }