summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-10-25 16:16:35 +0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-10-25 16:35:02 +0700
commit4a11cbd99445338619dfaf1f327dbc25b2983cb7 (patch)
tree254598ff97f17cb33e44bd1402323d3b6892cb6b /graphics
parent41394b4e90a81a43c796c070e706e6aa4d8652bc (diff)
downloadiced-4a11cbd99445338619dfaf1f327dbc25b2983cb7.tar.gz
iced-4a11cbd99445338619dfaf1f327dbc25b2983cb7.tar.bz2
iced-4a11cbd99445338619dfaf1f327dbc25b2983cb7.zip
Implement `Widget::mouse_interaction` for `PaneGrid`
... and fix rendering of drag interaction in `PaneGrid` by introducing an explicit `with_translation` method to `Renderer` and simplifying the `with_layer` and `Clip` primitive.
Diffstat (limited to 'graphics')
-rw-r--r--graphics/src/layer.rs9
-rw-r--r--graphics/src/primitive.rs2
-rw-r--r--graphics/src/renderer.rs27
3 files changed, 23 insertions, 15 deletions
diff --git a/graphics/src/layer.rs b/graphics/src/layer.rs
index e5cb64c3..7a32c850 100644
--- a/graphics/src/layer.rs
+++ b/graphics/src/layer.rs
@@ -175,11 +175,7 @@ impl<'a> Layer<'a> {
});
}
}
- Primitive::Clip {
- bounds,
- offset,
- content,
- } => {
+ Primitive::Clip { bounds, content } => {
let layer = &mut layers[current_layer];
let translated_bounds = *bounds + translation;
@@ -192,8 +188,7 @@ impl<'a> Layer<'a> {
Self::process_primitive(
layers,
- translation
- - Vector::new(offset.x as f32, offset.y as f32),
+ translation,
content,
layers.len() - 1,
);
diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs
index 32f8383d..b984feaa 100644
--- a/graphics/src/primitive.rs
+++ b/graphics/src/primitive.rs
@@ -66,8 +66,6 @@ pub enum Primitive {
Clip {
/// The bounds of the clip
bounds: Rectangle,
- /// The offset transformation of the clip
- offset: Vector<u32>,
/// The content of the clip
content: Box<Primitive>,
},
diff --git a/graphics/src/renderer.rs b/graphics/src/renderer.rs
index d90a3f1e..8b6c2217 100644
--- a/graphics/src/renderer.rs
+++ b/graphics/src/renderer.rs
@@ -51,10 +51,26 @@ where
layout
}
- fn with_layer(
+ fn with_layer(&mut self, bounds: Rectangle, f: impl FnOnce(&mut Self)) {
+ let current_primitives =
+ std::mem::replace(&mut self.primitives, Vec::new());
+
+ f(self);
+
+ let layer_primitives =
+ std::mem::replace(&mut self.primitives, current_primitives);
+
+ self.primitives.push(Primitive::Clip {
+ bounds,
+ content: Box::new(Primitive::Group {
+ primitives: layer_primitives,
+ }),
+ });
+ }
+
+ fn with_translation(
&mut self,
- bounds: Rectangle,
- offset: Vector<u32>,
+ translation: Vector,
f: impl FnOnce(&mut Self),
) {
let current_primitives =
@@ -65,9 +81,8 @@ where
let layer_primitives =
std::mem::replace(&mut self.primitives, current_primitives);
- self.primitives.push(Primitive::Clip {
- bounds,
- offset,
+ self.primitives.push(Primitive::Translate {
+ translation,
content: Box::new(Primitive::Group {
primitives: layer_primitives,
}),