summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-11-21 14:41:22 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-11-21 14:41:22 +0100
commit25006b9c6f2ae909d86871d3a13631d518c07158 (patch)
treee4bf993c1073cde4c6a847e38f8165f6efcecb21 /core/src
parent7dd32f3be43c72e11dac5e07918e9ad6d36b6555 (diff)
downloadiced-25006b9c6f2ae909d86871d3a13631d518c07158.tar.gz
iced-25006b9c6f2ae909d86871d3a13631d518c07158.tar.bz2
iced-25006b9c6f2ae909d86871d3a13631d518c07158.zip
Fix `Overlay` composition
Translations were not easily composable.
Diffstat (limited to 'core/src')
-rw-r--r--core/src/overlay.rs3
-rw-r--r--core/src/overlay/element.rs20
-rw-r--r--core/src/overlay/group.rs9
3 files changed, 23 insertions, 9 deletions
diff --git a/core/src/overlay.rs b/core/src/overlay.rs
index f71f25f7..af10afee 100644
--- a/core/src/overlay.rs
+++ b/core/src/overlay.rs
@@ -11,7 +11,7 @@ use crate::mouse;
use crate::renderer;
use crate::widget;
use crate::widget::Tree;
-use crate::{Clipboard, Layout, Point, Rectangle, Shell, Size};
+use crate::{Clipboard, Layout, Point, Rectangle, Shell, Size, Vector};
/// An interactive component that can be displayed on top of other widgets.
pub trait Overlay<Message, Renderer>
@@ -29,6 +29,7 @@ where
renderer: &Renderer,
bounds: Size,
position: Point,
+ translation: Vector,
) -> layout::Node;
/// Draws the [`Overlay`] using the associated `Renderer`.
diff --git a/core/src/overlay/element.rs b/core/src/overlay/element.rs
index 3dd58f9b..a279fe28 100644
--- a/core/src/overlay/element.rs
+++ b/core/src/overlay/element.rs
@@ -13,6 +13,7 @@ use std::any::Any;
#[allow(missing_debug_implementations)]
pub struct Element<'a, Message, Renderer> {
position: Point,
+ translation: Vector,
overlay: Box<dyn Overlay<Message, Renderer> + 'a>,
}
@@ -25,7 +26,11 @@ where
position: Point,
overlay: Box<dyn Overlay<Message, Renderer> + 'a>,
) -> Self {
- Self { position, overlay }
+ Self {
+ position,
+ overlay,
+ translation: Vector::ZERO,
+ }
}
/// Returns the position of the [`Element`].
@@ -36,6 +41,7 @@ where
/// Translates the [`Element`].
pub fn translate(mut self, translation: Vector) -> Self {
self.position = self.position + translation;
+ self.translation = self.translation + translation;
self
}
@@ -48,6 +54,7 @@ where
{
Element {
position: self.position,
+ translation: self.translation,
overlay: Box::new(Map::new(self.overlay, f)),
}
}
@@ -59,8 +66,12 @@ where
bounds: Size,
translation: Vector,
) -> layout::Node {
- self.overlay
- .layout(renderer, bounds, self.position + translation)
+ self.overlay.layout(
+ renderer,
+ bounds,
+ self.position + translation,
+ self.translation + translation,
+ )
}
/// Processes a runtime [`Event`].
@@ -154,8 +165,9 @@ where
renderer: &Renderer,
bounds: Size,
position: Point,
+ translation: Vector,
) -> layout::Node {
- self.content.layout(renderer, bounds, position)
+ self.content.layout(renderer, bounds, position, translation)
}
fn operate(
diff --git a/core/src/overlay/group.rs b/core/src/overlay/group.rs
index dccf6dba..e1e9727a 100644
--- a/core/src/overlay/group.rs
+++ b/core/src/overlay/group.rs
@@ -4,7 +4,9 @@ use crate::mouse;
use crate::overlay;
use crate::renderer;
use crate::widget;
-use crate::{Clipboard, Event, Layout, Overlay, Point, Rectangle, Shell, Size};
+use crate::{
+ Clipboard, Event, Layout, Overlay, Point, Rectangle, Shell, Size, Vector,
+};
/// An [`Overlay`] container that displays multiple overlay [`overlay::Element`]
/// children.
@@ -64,10 +66,9 @@ where
&mut self,
renderer: &Renderer,
bounds: Size,
- position: Point,
+ _position: Point,
+ translation: Vector,
) -> layout::Node {
- let translation = position - Point::ORIGIN;
-
layout::Node::with_children(
bounds,
self.children