diff options
author | 2024-02-01 01:08:21 +0100 | |
---|---|---|
committer | 2024-02-01 01:08:21 +0100 | |
commit | 738aa47547818ebf57dc4f00099386a5a22a86d5 (patch) | |
tree | 4f262c1bc4d9b55f030146ec2a6f9b6cc421a6c5 /examples | |
parent | 7bbe4502170be1942c4e61d222e14401f724aa42 (diff) | |
download | iced-738aa47547818ebf57dc4f00099386a5a22a86d5.tar.gz iced-738aa47547818ebf57dc4f00099386a5a22a86d5.tar.bz2 iced-738aa47547818ebf57dc4f00099386a5a22a86d5.zip |
Remove `position` from `overlay::Element`
Diffstat (limited to 'examples')
-rw-r--r-- | examples/modal/src/main.rs | 23 | ||||
-rw-r--r-- | examples/toast/src/main.rs | 25 |
2 files changed, 23 insertions, 25 deletions
diff --git a/examples/modal/src/main.rs b/examples/modal/src/main.rs index c2a4132c..6fe951ee 100644 --- a/examples/modal/src/main.rs +++ b/examples/modal/src/main.rs @@ -346,16 +346,15 @@ mod modal { state: &'b mut widget::Tree, layout: Layout<'_>, _renderer: &Renderer, + translation: Vector, ) -> Option<overlay::Element<'b, Message, Theme, Renderer>> { - Some(overlay::Element::new( - layout.position(), - Box::new(Overlay { - content: &mut self.modal, - tree: &mut state.children[1], - size: layout.bounds().size(), - on_blur: self.on_blur.clone(), - }), - )) + Some(overlay::Element::new(Box::new(Overlay { + position: layout.position() + translation, + content: &mut self.modal, + tree: &mut state.children[1], + size: layout.bounds().size(), + on_blur: self.on_blur.clone(), + }))) } fn mouse_interaction( @@ -392,6 +391,7 @@ mod modal { } struct Overlay<'a, 'b, Message, Theme, Renderer> { + position: Point, content: &'b mut Element<'a, Message, Theme, Renderer>, tree: &'b mut widget::Tree, size: Size, @@ -409,8 +409,6 @@ mod modal { &mut self, renderer: &Renderer, _bounds: Size, - position: Point, - _translation: Vector, ) -> layout::Node { let limits = layout::Limits::new(Size::ZERO, self.size) .width(Length::Fill) @@ -423,7 +421,7 @@ mod modal { .align(Alignment::Center, Alignment::Center, limits.max()); layout::Node::with_children(self.size, vec![child]) - .move_to(position) + .move_to(self.position) } fn on_event( @@ -530,6 +528,7 @@ mod modal { self.tree, layout.children().next().unwrap(), renderer, + Vector::ZERO, ) } } diff --git a/examples/toast/src/main.rs b/examples/toast/src/main.rs index cc9875d9..af29660a 100644 --- a/examples/toast/src/main.rs +++ b/examples/toast/src/main.rs @@ -456,6 +456,7 @@ mod toast { state: &'b mut Tree, layout: Layout<'_>, renderer: &Renderer, + translation: Vector, ) -> Option<overlay::Element<'b, Message, Theme, Renderer>> { let instants = state.state.downcast_mut::<Vec<Option<Instant>>>(); @@ -465,19 +466,18 @@ mod toast { &mut content_state[0], layout, renderer, + translation, ); let toasts = (!self.toasts.is_empty()).then(|| { - overlay::Element::new( - layout.bounds().position(), - Box::new(Overlay { - toasts: &mut self.toasts, - state: toasts_state, - instants, - on_close: &self.on_close, - timeout_secs: self.timeout_secs, - }), - ) + overlay::Element::new(Box::new(Overlay { + position: layout.bounds().position() + translation, + toasts: &mut self.toasts, + state: toasts_state, + instants, + on_close: &self.on_close, + timeout_secs: self.timeout_secs, + })) }); let overlays = content.into_iter().chain(toasts).collect::<Vec<_>>(); @@ -488,6 +488,7 @@ mod toast { } struct Overlay<'a, 'b, Message> { + position: Point, toasts: &'b mut [Element<'a, Message>], state: &'b mut [Tree], instants: &'b mut [Option<Instant>], @@ -502,8 +503,6 @@ mod toast { &mut self, renderer: &Renderer, bounds: Size, - position: Point, - _translation: Vector, ) -> layout::Node { let limits = layout::Limits::new(Size::ZERO, bounds); @@ -519,7 +518,7 @@ mod toast { self.toasts, self.state, ) - .translate(Vector::new(position.x, position.y)) + .translate(Vector::new(self.position.x, self.position.y)) } fn on_event( |