Fix missing inverse transformations in float widget
This commit is contained in:
parent
6a1f99e99d
commit
fe95b26d53
2 changed files with 16 additions and 41 deletions
|
|
@ -210,7 +210,6 @@ fn card<'a>(
|
||||||
.content_fit(ContentFit::Cover)
|
.content_fit(ContentFit::Cover)
|
||||||
.opacity(thumbnail.fade_in.interpolate(0.0, 1.0, now)),
|
.opacity(thumbnail.fade_in.interpolate(0.0, 1.0, now)),
|
||||||
)
|
)
|
||||||
.opaque(false)
|
|
||||||
.scale(thumbnail.zoom.interpolate(1.0, 1.1, now))
|
.scale(thumbnail.zoom.interpolate(1.0, 1.1, now))
|
||||||
.translate(move |bounds, viewport| {
|
.translate(move |bounds, viewport| {
|
||||||
bounds.zoom(1.1).offset(&viewport.shrink(10))
|
bounds.zoom(1.1).offset(&viewport.shrink(10))
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ where
|
||||||
content: Element<'a, Message, Theme, Renderer>,
|
content: Element<'a, Message, Theme, Renderer>,
|
||||||
scale: f32,
|
scale: f32,
|
||||||
translate: Option<Box<dyn Fn(Rectangle, Rectangle) -> Vector + 'a>>,
|
translate: Option<Box<dyn Fn(Rectangle, Rectangle) -> Vector + 'a>>,
|
||||||
opaque: bool,
|
|
||||||
class: Theme::Class<'a>,
|
class: Theme::Class<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,7 +36,6 @@ where
|
||||||
content: content.into(),
|
content: content.into(),
|
||||||
scale: 1.0,
|
scale: 1.0,
|
||||||
translate: None,
|
translate: None,
|
||||||
opaque: true,
|
|
||||||
class: Theme::default(),
|
class: Theme::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -61,17 +59,6 @@ where
|
||||||
self
|
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`].
|
/// Sets the style of the [`Float`].
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn style(mut self, style: impl Fn(&Theme) -> Style + 'a) -> Self
|
pub fn style(mut self, style: impl Fn(&Theme) -> Style + 'a) -> Self
|
||||||
|
|
@ -293,7 +280,7 @@ where
|
||||||
Renderer: core::Renderer,
|
Renderer: core::Renderer,
|
||||||
{
|
{
|
||||||
fn layout(&mut self, _renderer: &Renderer, _bounds: Size) -> layout::Node {
|
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())
|
layout::Node::new(bounds.size()).move_to(bounds.position())
|
||||||
}
|
}
|
||||||
|
|
@ -307,17 +294,17 @@ where
|
||||||
clipboard: &mut dyn Clipboard,
|
clipboard: &mut dyn Clipboard,
|
||||||
shell: &mut Shell<'_, Message>,
|
shell: &mut Shell<'_, Message>,
|
||||||
) {
|
) {
|
||||||
let cursor = cursor * self.transformation.inverse();
|
let inverse = self.transformation.inverse();
|
||||||
|
|
||||||
self.float.content.as_widget_mut().update(
|
self.float.content.as_widget_mut().update(
|
||||||
self.state,
|
self.state,
|
||||||
event,
|
event,
|
||||||
self.layout,
|
self.layout,
|
||||||
cursor,
|
cursor * inverse,
|
||||||
renderer,
|
renderer,
|
||||||
clipboard,
|
clipboard,
|
||||||
shell,
|
shell,
|
||||||
&self.viewport,
|
&(self.viewport * inverse),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -326,10 +313,11 @@ where
|
||||||
renderer: &mut Renderer,
|
renderer: &mut Renderer,
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
style: &renderer::Style,
|
style: &renderer::Style,
|
||||||
layout: Layout<'_>,
|
_layout: Layout<'_>,
|
||||||
cursor: mouse::Cursor,
|
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_layer(self.viewport, |renderer| {
|
||||||
renderer.with_transformation(self.transformation, |renderer| {
|
renderer.with_transformation(self.transformation, |renderer| {
|
||||||
|
|
@ -356,8 +344,8 @@ where
|
||||||
theme,
|
theme,
|
||||||
style,
|
style,
|
||||||
self.layout,
|
self.layout,
|
||||||
cursor,
|
cursor * inverse,
|
||||||
&(self.viewport * self.transformation.inverse()),
|
&(self.viewport * inverse),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -373,33 +361,21 @@ where
|
||||||
return mouse::Interaction::None;
|
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.state,
|
||||||
self.layout,
|
self.layout,
|
||||||
cursor * self.transformation.inverse(),
|
cursor * inverse,
|
||||||
&self.viewport,
|
&(self.viewport * inverse),
|
||||||
renderer,
|
renderer,
|
||||||
);
|
)
|
||||||
|
|
||||||
if self.float.opaque && interaction == mouse::Interaction::None {
|
|
||||||
return mouse::Interaction::Idle;
|
|
||||||
}
|
|
||||||
|
|
||||||
interaction
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn index(&self) -> f32 {
|
fn index(&self) -> f32 {
|
||||||
self.float.scale * 0.5
|
self.float.scale * 0.5
|
||||||
}
|
}
|
||||||
|
|
||||||
fn operate(
|
|
||||||
&mut self,
|
|
||||||
_layout: Layout<'_>,
|
|
||||||
_renderer: &Renderer,
|
|
||||||
_operation: &mut dyn widget::Operation,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
fn overlay<'a>(
|
fn overlay<'a>(
|
||||||
&'a mut self,
|
&'a mut self,
|
||||||
_layout: Layout<'_>,
|
_layout: Layout<'_>,
|
||||||
|
|
@ -409,7 +385,7 @@ where
|
||||||
self.state,
|
self.state,
|
||||||
self.layout,
|
self.layout,
|
||||||
renderer,
|
renderer,
|
||||||
&self.viewport,
|
&(self.viewport * self.transformation.inverse()),
|
||||||
self.transformation.translation(),
|
self.transformation.translation(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue