From fe95b26d53c21c5084f5273b18c6d882f7d30ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sun, 4 May 2025 00:36:56 +0200 Subject: [PATCH] Fix missing inverse transformations in `float` widget --- examples/gallery/src/main.rs | 1 - widget/src/float.rs | 56 +++++++++++------------------------- 2 files changed, 16 insertions(+), 41 deletions(-) diff --git a/examples/gallery/src/main.rs b/examples/gallery/src/main.rs index a1a0edf1..a40df370 100644 --- a/examples/gallery/src/main.rs +++ b/examples/gallery/src/main.rs @@ -210,7 +210,6 @@ fn card<'a>( .content_fit(ContentFit::Cover) .opacity(thumbnail.fade_in.interpolate(0.0, 1.0, now)), ) - .opaque(false) .scale(thumbnail.zoom.interpolate(1.0, 1.1, now)) .translate(move |bounds, viewport| { bounds.zoom(1.1).offset(&viewport.shrink(10)) diff --git a/widget/src/float.rs b/widget/src/float.rs index f58e4f25..129ff0b0 100644 --- a/widget/src/float.rs +++ b/widget/src/float.rs @@ -21,7 +21,6 @@ where content: Element<'a, Message, Theme, Renderer>, scale: f32, translate: Option Vector + 'a>>, - opaque: bool, class: Theme::Class<'a>, } @@ -37,7 +36,6 @@ where content: content.into(), scale: 1.0, translate: None, - opaque: true, class: Theme::default(), } } @@ -61,17 +59,6 @@ where self } - /// Sets whether the [`Float`] contents should be opaque when floating. - /// - /// Disabling opacity will make the mouse pass through the floating content, allowing - /// interaction with whatever is under it. - /// - /// By default, a [`Float`] widget is opaque. - pub fn opaque(mut self, opaque: bool) -> Self { - self.opaque = opaque; - self - } - /// Sets the style of the [`Float`]. #[must_use] pub fn style(mut self, style: impl Fn(&Theme) -> Style + 'a) -> Self @@ -293,7 +280,7 @@ where Renderer: core::Renderer, { fn layout(&mut self, _renderer: &Renderer, _bounds: Size) -> layout::Node { - let bounds = self.layout.bounds(); + let bounds = self.layout.bounds() * self.transformation; layout::Node::new(bounds.size()).move_to(bounds.position()) } @@ -307,17 +294,17 @@ where clipboard: &mut dyn Clipboard, shell: &mut Shell<'_, Message>, ) { - let cursor = cursor * self.transformation.inverse(); + let inverse = self.transformation.inverse(); self.float.content.as_widget_mut().update( self.state, event, self.layout, - cursor, + cursor * inverse, renderer, clipboard, shell, - &self.viewport, + &(self.viewport * inverse), ); } @@ -326,10 +313,11 @@ where renderer: &mut Renderer, theme: &Theme, style: &renderer::Style, - layout: Layout<'_>, + _layout: Layout<'_>, cursor: mouse::Cursor, ) { - let bounds = layout.bounds(); + let bounds = self.layout.bounds(); + let inverse = self.transformation.inverse(); renderer.with_layer(self.viewport, |renderer| { renderer.with_transformation(self.transformation, |renderer| { @@ -356,8 +344,8 @@ where theme, style, self.layout, - cursor, - &(self.viewport * self.transformation.inverse()), + cursor * inverse, + &(self.viewport * inverse), ); }); }); @@ -373,33 +361,21 @@ where return mouse::Interaction::None; } - let interaction = self.float.content.as_widget().mouse_interaction( + let inverse = self.transformation.inverse(); + + self.float.content.as_widget().mouse_interaction( self.state, self.layout, - cursor * self.transformation.inverse(), - &self.viewport, + cursor * inverse, + &(self.viewport * inverse), renderer, - ); - - if self.float.opaque && interaction == mouse::Interaction::None { - return mouse::Interaction::Idle; - } - - interaction + ) } fn index(&self) -> f32 { self.float.scale * 0.5 } - fn operate( - &mut self, - _layout: Layout<'_>, - _renderer: &Renderer, - _operation: &mut dyn widget::Operation, - ) { - } - fn overlay<'a>( &'a mut self, _layout: Layout<'_>, @@ -409,7 +385,7 @@ where self.state, self.layout, renderer, - &self.viewport, + &(self.viewport * self.transformation.inverse()), self.transformation.translation(), ) }