diff options
author | 2023-01-30 05:01:28 +0100 | |
---|---|---|
committer | 2023-01-30 05:11:59 +0100 | |
commit | a50cc32d09ddff1d061701074908c28d5c5509ba (patch) | |
tree | c53742f5ce8d958e636b15d74a4781fc99e219be /native | |
parent | a28bc3eaf05d59ef35ae5c182fa68478356364fd (diff) | |
download | iced-a50cc32d09ddff1d061701074908c28d5c5509ba.tar.gz iced-a50cc32d09ddff1d061701074908c28d5c5509ba.tar.bz2 iced-a50cc32d09ddff1d061701074908c28d5c5509ba.zip |
Fix layout translation in `overlay::Group`
This bug produced improper positioning of overlays of elements inside a
`Scrollable`.
Diffstat (limited to 'native')
-rw-r--r-- | native/src/overlay/element.rs | 10 | ||||
-rw-r--r-- | native/src/overlay/group.rs | 6 | ||||
-rw-r--r-- | native/src/user_interface.rs | 18 |
3 files changed, 22 insertions, 12 deletions
diff --git a/native/src/overlay/element.rs b/native/src/overlay/element.rs index bdf7766e..237d25d1 100644 --- a/native/src/overlay/element.rs +++ b/native/src/overlay/element.rs @@ -53,8 +53,14 @@ where } /// Computes the layout of the [`Element`] in the given bounds. - pub fn layout(&self, renderer: &Renderer, bounds: Size) -> layout::Node { - self.overlay.layout(renderer, bounds, self.position) + pub fn layout( + &self, + renderer: &Renderer, + bounds: Size, + translation: Vector, + ) -> layout::Node { + self.overlay + .layout(renderer, bounds, self.position + translation) } /// Processes a runtime [`Event`]. diff --git a/native/src/overlay/group.rs b/native/src/overlay/group.rs index 5c9cf809..1126f0cf 100644 --- a/native/src/overlay/group.rs +++ b/native/src/overlay/group.rs @@ -66,13 +66,15 @@ where &self, renderer: &Renderer, bounds: Size, - _position: Point, + position: Point, ) -> layout::Node { + let translation = position - Point::ORIGIN; + layout::Node::with_children( bounds, self.children .iter() - .map(|child| child.layout(renderer, bounds)) + .map(|child| child.layout(renderer, bounds, translation)) .collect(), ) } diff --git a/native/src/user_interface.rs b/native/src/user_interface.rs index 0def730c..80dece21 100644 --- a/native/src/user_interface.rs +++ b/native/src/user_interface.rs @@ -6,7 +6,9 @@ use crate::mouse; use crate::renderer; use crate::widget; 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`]. /// @@ -203,7 +205,7 @@ where let bounds = self.bounds; 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(); for event in events.iter().cloned() { @@ -252,7 +254,7 @@ where overlay = manual_overlay.as_mut().unwrap(); shell.revalidate_layout(|| { - layout = overlay.layout(renderer, bounds); + layout = overlay.layout(renderer, bounds, Vector::ZERO); }); } @@ -434,10 +436,9 @@ where .as_widget_mut() .overlay(&mut self.state, Layout::new(&self.base), renderer) { - let overlay_layout = self - .overlay - .take() - .unwrap_or_else(|| overlay.layout(renderer, self.bounds)); + let overlay_layout = self.overlay.take().unwrap_or_else(|| { + overlay.layout(renderer, self.bounds, Vector::ZERO) + }); let new_cursor_position = if overlay_layout.bounds().contains(cursor_position) { @@ -538,7 +539,8 @@ where renderer, ) { 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( |