refactor: include virtual offset in Layout
This commit is contained in:
parent
7120db60ba
commit
5b0468e535
10 changed files with 251 additions and 98 deletions
|
|
@ -12,6 +12,9 @@ use crate::{Length, Padding, Point, Rectangle, Size, Vector};
|
|||
/// The bounds of a [`Node`] and its children, using absolute coordinates.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Layout<'a> {
|
||||
/// The virtual offset of the layout.
|
||||
/// May represent the scroll positions in pixels of a scrollable, for example.
|
||||
virtual_offset: Vector,
|
||||
position: Point,
|
||||
node: &'a Node,
|
||||
}
|
||||
|
|
@ -28,16 +31,29 @@ impl<'a> Layout<'a> {
|
|||
let bounds = node.bounds();
|
||||
|
||||
Self {
|
||||
virtual_offset: Vector::new(0., 0.),
|
||||
position: Point::new(bounds.x, bounds.y) + offset,
|
||||
node,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a new layout with the virtual offset
|
||||
pub fn with_virtual_offset(mut self, virtual_offset: Vector) -> Self {
|
||||
self.virtual_offset = virtual_offset;
|
||||
self
|
||||
}
|
||||
|
||||
/// Returns the position of the [`Layout`].
|
||||
pub fn position(&self) -> Point {
|
||||
self.position
|
||||
}
|
||||
|
||||
/// The virtual offset of the layout.
|
||||
/// May represent the scroll positions in pixels of a scrollable, for example.
|
||||
pub fn virtual_offset(&self) -> Vector {
|
||||
self.virtual_offset
|
||||
}
|
||||
|
||||
/// Returns the bounds of the [`Layout`].
|
||||
///
|
||||
/// The returned [`Rectangle`] describes the position and size of a
|
||||
|
|
|
|||
|
|
@ -120,10 +120,10 @@ where
|
|||
.iter_mut()
|
||||
.zip(&mut tree.children)
|
||||
.zip(layout.children())
|
||||
.filter_map(|((child, state), layout)| {
|
||||
.filter_map(|((child, state), c_layout)| {
|
||||
child.as_widget_mut().overlay(
|
||||
state,
|
||||
layout,
|
||||
c_layout.with_virtual_offset(layout.virtual_offset()),
|
||||
renderer,
|
||||
viewport,
|
||||
translation,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue