summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2023-12-02 16:10:42 +0100
committerLibravatar GitHub <noreply@github.com>2023-12-02 16:10:42 +0100
commit8727b3fc50ec251d9c117c51ca1289be5ba9b117 (patch)
tree802fef9f0b54b6f9cbbeedff14d7f57169db7d6b /wgpu
parent7f8b17604a31e00becc43130ec516c1a53552c88 (diff)
parentb526ce4958b28208395276dd4078ffe0d780e1d7 (diff)
downloadiced-8727b3fc50ec251d9c117c51ca1289be5ba9b117.tar.gz
iced-8727b3fc50ec251d9c117c51ca1289be5ba9b117.tar.bz2
iced-8727b3fc50ec251d9c117c51ca1289be5ba9b117.zip
Merge pull request #2154 from iced-rs/fix/text-clipping
Fix text clipping
Diffstat (limited to '')
-rw-r--r--wgpu/src/geometry.rs15
-rw-r--r--wgpu/src/layer.rs7
-rw-r--r--wgpu/src/layer/text.rs5
-rw-r--r--wgpu/src/text.rs23
4 files changed, 35 insertions, 15 deletions
diff --git a/wgpu/src/geometry.rs b/wgpu/src/geometry.rs
index 655362b7..e0bff67e 100644
--- a/wgpu/src/geometry.rs
+++ b/wgpu/src/geometry.rs
@@ -328,15 +328,17 @@ impl Frame {
Point::new(transformed.x, transformed.y)
};
+ let bounds = Rectangle {
+ x: position.x,
+ y: position.y,
+ width: f32::INFINITY,
+ height: f32::INFINITY,
+ };
+
// TODO: Use vectorial text instead of primitive
self.primitives.push(Primitive::Text {
content: text.content,
- bounds: Rectangle {
- x: position.x,
- y: position.y,
- width: f32::INFINITY,
- height: f32::INFINITY,
- },
+ bounds,
color: text.color,
size: text.size,
line_height: text.line_height,
@@ -344,6 +346,7 @@ impl Frame {
horizontal_alignment: text.horizontal_alignment,
vertical_alignment: text.vertical_alignment,
shaping: text.shaping,
+ clip_bounds: Rectangle::with_size(Size::INFINITY),
});
}
diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs
index 98e49f1a..557a7633 100644
--- a/wgpu/src/layer.rs
+++ b/wgpu/src/layer.rs
@@ -75,6 +75,7 @@ impl<'a> Layer<'a> {
horizontal_alignment: alignment::Horizontal::Left,
vertical_alignment: alignment::Vertical::Top,
shaping: core::text::Shaping::Basic,
+ clip_bounds: Rectangle::with_size(Size::INFINITY),
};
overlay.text.push(Text::Cached(text.clone()));
@@ -123,6 +124,7 @@ impl<'a> Layer<'a> {
paragraph,
position,
color,
+ clip_bounds,
} => {
let layer = &mut layers[current_layer];
@@ -130,12 +132,14 @@ impl<'a> Layer<'a> {
paragraph: paragraph.clone(),
position: *position + translation,
color: *color,
+ clip_bounds: *clip_bounds + translation,
});
}
Primitive::Editor {
editor,
position,
color,
+ clip_bounds,
} => {
let layer = &mut layers[current_layer];
@@ -143,6 +147,7 @@ impl<'a> Layer<'a> {
editor: editor.clone(),
position: *position + translation,
color: *color,
+ clip_bounds: *clip_bounds + translation,
});
}
Primitive::Text {
@@ -155,6 +160,7 @@ impl<'a> Layer<'a> {
horizontal_alignment,
vertical_alignment,
shaping,
+ clip_bounds,
} => {
let layer = &mut layers[current_layer];
@@ -168,6 +174,7 @@ impl<'a> Layer<'a> {
horizontal_alignment: *horizontal_alignment,
vertical_alignment: *vertical_alignment,
shaping: *shaping,
+ clip_bounds: *clip_bounds + translation,
}));
}
Primitive::Quad {
diff --git a/wgpu/src/layer/text.rs b/wgpu/src/layer/text.rs
index 66417cec..df2f2875 100644
--- a/wgpu/src/layer/text.rs
+++ b/wgpu/src/layer/text.rs
@@ -13,6 +13,7 @@ pub enum Text<'a> {
paragraph: paragraph::Weak,
position: Point,
color: Color,
+ clip_bounds: Rectangle,
},
/// An editor.
#[allow(missing_docs)]
@@ -20,6 +21,7 @@ pub enum Text<'a> {
editor: editor::Weak,
position: Point,
color: Color,
+ clip_bounds: Rectangle,
},
/// A cached text.
Cached(Cached<'a>),
@@ -53,4 +55,7 @@ pub struct Cached<'a> {
/// The shaping strategy of the text.
pub shaping: text::Shaping,
+
+ /// The clip bounds of the text.
+ pub clip_bounds: Rectangle,
}
diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs
index 08a8bea6..888b1924 100644
--- a/wgpu/src/text.rs
+++ b/wgpu/src/text.rs
@@ -120,9 +120,13 @@ impl Pipeline {
horizontal_alignment,
vertical_alignment,
color,
+ clip_bounds,
) = match section {
Text::Paragraph {
- position, color, ..
+ position,
+ color,
+ clip_bounds,
+ ..
} => {
use crate::core::text::Paragraph as _;
@@ -137,10 +141,14 @@ impl Pipeline {
paragraph.horizontal_alignment(),
paragraph.vertical_alignment(),
*color,
+ *clip_bounds,
)
}
Text::Editor {
- position, color, ..
+ position,
+ color,
+ clip_bounds,
+ ..
} => {
use crate::core::text::Editor as _;
@@ -155,6 +163,7 @@ impl Pipeline {
alignment::Horizontal::Left,
alignment::Vertical::Top,
*color,
+ *clip_bounds,
)
}
Text::Cached(text) => {
@@ -173,6 +182,7 @@ impl Pipeline {
text.horizontal_alignment,
text.vertical_alignment,
text.color,
+ text.clip_bounds,
)
}
};
@@ -195,13 +205,8 @@ impl Pipeline {
alignment::Vertical::Bottom => bounds.y - bounds.height,
};
- let section_bounds = Rectangle {
- x: left,
- y: top,
- ..bounds
- };
-
- let clip_bounds = layer_bounds.intersection(&section_bounds)?;
+ let clip_bounds =
+ layer_bounds.intersection(&(clip_bounds * scale_factor))?;
Some(glyphon::TextArea {
buffer,