Fix layout translation in overlay::Group
This bug produced improper positioning of overlays of elements inside a `Scrollable`.
This commit is contained in:
parent
a28bc3eaf0
commit
a50cc32d09
7 changed files with 33 additions and 18 deletions
|
|
@ -15,6 +15,11 @@ impl<T> Vector<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Vector {
|
||||||
|
/// The zero [`Vector`].
|
||||||
|
pub const ZERO: Self = Self::new(0.0, 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> std::ops::Add for Vector<T>
|
impl<T> std::ops::Add for Vector<T>
|
||||||
where
|
where
|
||||||
T: std::ops::Add<Output = T>,
|
T: std::ops::Add<Output = T>,
|
||||||
|
|
|
||||||
|
|
@ -455,9 +455,9 @@ where
|
||||||
position: Point,
|
position: Point,
|
||||||
) -> layout::Node {
|
) -> layout::Node {
|
||||||
self.with_overlay_maybe(|overlay| {
|
self.with_overlay_maybe(|overlay| {
|
||||||
let vector = position - overlay.position();
|
let translation = position - overlay.position();
|
||||||
|
|
||||||
overlay.layout(renderer, bounds).translate(vector)
|
overlay.layout(renderer, bounds, translation)
|
||||||
})
|
})
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -313,9 +313,9 @@ where
|
||||||
position: Point,
|
position: Point,
|
||||||
) -> layout::Node {
|
) -> layout::Node {
|
||||||
self.with_overlay_maybe(|overlay| {
|
self.with_overlay_maybe(|overlay| {
|
||||||
let vector = position - overlay.position();
|
let translation = position - overlay.position();
|
||||||
|
|
||||||
overlay.layout(renderer, bounds).translate(vector)
|
overlay.layout(renderer, bounds, translation)
|
||||||
})
|
})
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -356,9 +356,9 @@ where
|
||||||
position: Point,
|
position: Point,
|
||||||
) -> layout::Node {
|
) -> layout::Node {
|
||||||
self.with_overlay_maybe(|overlay| {
|
self.with_overlay_maybe(|overlay| {
|
||||||
let vector = position - overlay.position();
|
let translation = position - overlay.position();
|
||||||
|
|
||||||
overlay.layout(renderer, bounds).translate(vector)
|
overlay.layout(renderer, bounds, translation)
|
||||||
})
|
})
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,14 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the layout of the [`Element`] in the given bounds.
|
/// Computes the layout of the [`Element`] in the given bounds.
|
||||||
pub fn layout(&self, renderer: &Renderer, bounds: Size) -> layout::Node {
|
pub fn layout(
|
||||||
self.overlay.layout(renderer, bounds, self.position)
|
&self,
|
||||||
|
renderer: &Renderer,
|
||||||
|
bounds: Size,
|
||||||
|
translation: Vector,
|
||||||
|
) -> layout::Node {
|
||||||
|
self.overlay
|
||||||
|
.layout(renderer, bounds, self.position + translation)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Processes a runtime [`Event`].
|
/// Processes a runtime [`Event`].
|
||||||
|
|
|
||||||
|
|
@ -66,13 +66,15 @@ where
|
||||||
&self,
|
&self,
|
||||||
renderer: &Renderer,
|
renderer: &Renderer,
|
||||||
bounds: Size,
|
bounds: Size,
|
||||||
_position: Point,
|
position: Point,
|
||||||
) -> layout::Node {
|
) -> layout::Node {
|
||||||
|
let translation = position - Point::ORIGIN;
|
||||||
|
|
||||||
layout::Node::with_children(
|
layout::Node::with_children(
|
||||||
bounds,
|
bounds,
|
||||||
self.children
|
self.children
|
||||||
.iter()
|
.iter()
|
||||||
.map(|child| child.layout(renderer, bounds))
|
.map(|child| child.layout(renderer, bounds, translation))
|
||||||
.collect(),
|
.collect(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,9 @@ use crate::mouse;
|
||||||
use crate::renderer;
|
use crate::renderer;
|
||||||
use crate::widget;
|
use crate::widget;
|
||||||
use crate::window;
|
use crate::window;
|
||||||
use crate::{Clipboard, Element, Layout, Point, Rectangle, Shell, Size};
|
use crate::{
|
||||||
|
Clipboard, Element, Layout, Point, Rectangle, Shell, Size, Vector,
|
||||||
|
};
|
||||||
|
|
||||||
/// A set of interactive graphical elements with a specific [`Layout`].
|
/// A set of interactive graphical elements with a specific [`Layout`].
|
||||||
///
|
///
|
||||||
|
|
@ -203,7 +205,7 @@ where
|
||||||
let bounds = self.bounds;
|
let bounds = self.bounds;
|
||||||
|
|
||||||
let mut overlay = manual_overlay.as_mut().unwrap();
|
let mut overlay = manual_overlay.as_mut().unwrap();
|
||||||
let mut layout = overlay.layout(renderer, bounds);
|
let mut layout = overlay.layout(renderer, bounds, Vector::ZERO);
|
||||||
let mut event_statuses = Vec::new();
|
let mut event_statuses = Vec::new();
|
||||||
|
|
||||||
for event in events.iter().cloned() {
|
for event in events.iter().cloned() {
|
||||||
|
|
@ -252,7 +254,7 @@ where
|
||||||
overlay = manual_overlay.as_mut().unwrap();
|
overlay = manual_overlay.as_mut().unwrap();
|
||||||
|
|
||||||
shell.revalidate_layout(|| {
|
shell.revalidate_layout(|| {
|
||||||
layout = overlay.layout(renderer, bounds);
|
layout = overlay.layout(renderer, bounds, Vector::ZERO);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -434,10 +436,9 @@ where
|
||||||
.as_widget_mut()
|
.as_widget_mut()
|
||||||
.overlay(&mut self.state, Layout::new(&self.base), renderer)
|
.overlay(&mut self.state, Layout::new(&self.base), renderer)
|
||||||
{
|
{
|
||||||
let overlay_layout = self
|
let overlay_layout = self.overlay.take().unwrap_or_else(|| {
|
||||||
.overlay
|
overlay.layout(renderer, self.bounds, Vector::ZERO)
|
||||||
.take()
|
});
|
||||||
.unwrap_or_else(|| overlay.layout(renderer, self.bounds));
|
|
||||||
|
|
||||||
let new_cursor_position =
|
let new_cursor_position =
|
||||||
if overlay_layout.bounds().contains(cursor_position) {
|
if overlay_layout.bounds().contains(cursor_position) {
|
||||||
|
|
@ -538,7 +539,8 @@ where
|
||||||
renderer,
|
renderer,
|
||||||
) {
|
) {
|
||||||
if self.overlay.is_none() {
|
if self.overlay.is_none() {
|
||||||
self.overlay = Some(overlay.layout(renderer, self.bounds));
|
self.overlay =
|
||||||
|
Some(overlay.layout(renderer, self.bounds, Vector::ZERO));
|
||||||
}
|
}
|
||||||
|
|
||||||
overlay.operate(
|
overlay.operate(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue