summaryrefslogtreecommitdiffstats
path: root/tiny_skia
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-02-11 04:03:01 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-02-11 04:03:01 +0100
commitc6cf2bc5210d606a00ade5ecf53237cacd4a92f5 (patch)
tree72e3dcd803abf10d3f8706e5fcef4bea7b5f98f0 /tiny_skia
parent52bd0d41389527d606c2e21cb402b73ca43a713a (diff)
downloadiced-c6cf2bc5210d606a00ade5ecf53237cacd4a92f5.tar.gz
iced-c6cf2bc5210d606a00ade5ecf53237cacd4a92f5.tar.bz2
iced-c6cf2bc5210d606a00ade5ecf53237cacd4a92f5.zip
Fix clipping of text in `iced_tiny_skia`
Diffstat (limited to 'tiny_skia')
-rw-r--r--tiny_skia/src/backend.rs88
1 files changed, 50 insertions, 38 deletions
diff --git a/tiny_skia/src/backend.rs b/tiny_skia/src/backend.rs
index 44f5c151..5d3a7a6f 100644
--- a/tiny_skia/src/backend.rs
+++ b/tiny_skia/src/backend.rs
@@ -1,11 +1,9 @@
-use tiny_skia::Size;
-
use crate::core::{
- Background, Color, Gradient, Rectangle, Transformation, Vector,
+ Background, Color, Gradient, Rectangle, Size, Transformation, Vector,
};
use crate::graphics::backend;
use crate::graphics::text;
-use crate::graphics::Viewport;
+use crate::graphics::{Damage, Viewport};
use crate::primitive::{self, Primitive};
use std::borrow::Cow;
@@ -219,31 +217,34 @@ impl Backend {
(x..x + width).map(move |x| (x as f32, y as f32))
})
.filter_map(|(x, y)| {
- Size::from_wh(half_width, half_height).map(|size| {
- let shadow_distance = rounded_box_sdf(
- Vector::new(
- x - physical_bounds.position().x
- - (shadow.offset.x * scale_factor)
- - half_width,
- y - physical_bounds.position().y
- - (shadow.offset.y * scale_factor)
- - half_height,
- ),
- size,
- &radii,
- );
- let shadow_alpha = 1.0
- - smoothstep(
- -shadow.blur_radius * scale_factor,
- shadow.blur_radius * scale_factor,
- shadow_distance,
+ tiny_skia::Size::from_wh(half_width, half_height)
+ .map(|size| {
+ let shadow_distance = rounded_box_sdf(
+ Vector::new(
+ x - physical_bounds.position().x
+ - (shadow.offset.x
+ * scale_factor)
+ - half_width,
+ y - physical_bounds.position().y
+ - (shadow.offset.y
+ * scale_factor)
+ - half_height,
+ ),
+ size,
+ &radii,
);
-
- let mut color = into_color(shadow.color);
- color.apply_opacity(shadow_alpha);
-
- color.to_color_u8().premultiply()
- })
+ let shadow_alpha = 1.0
+ - smoothstep(
+ -shadow.blur_radius * scale_factor,
+ shadow.blur_radius * scale_factor,
+ shadow_distance,
+ );
+
+ let mut color = into_color(shadow.color);
+ color.apply_opacity(shadow_alpha);
+
+ color.to_color_u8().premultiply()
+ })
})
.collect();
@@ -447,10 +448,12 @@ impl Backend {
paragraph,
position,
color,
- clip_bounds: text_clip_bounds,
+ clip_bounds: _, // TODO: Support text clip bounds
} => {
let physical_bounds =
- *text_clip_bounds * transformation * scale_factor;
+ Rectangle::new(*position, paragraph.min_bounds)
+ * transformation
+ * scale_factor;
if !clip_bounds.intersects(&physical_bounds) {
return;
@@ -473,10 +476,11 @@ impl Backend {
editor,
position,
color,
- clip_bounds: text_clip_bounds,
+ clip_bounds: _, // TODO: Support text clip bounds
} => {
- let physical_bounds =
- (*text_clip_bounds * transformation) * scale_factor;
+ let physical_bounds = Rectangle::new(*position, editor.bounds)
+ * transformation
+ * scale_factor;
if !clip_bounds.intersects(&physical_bounds) {
return;
@@ -505,10 +509,10 @@ impl Backend {
horizontal_alignment,
vertical_alignment,
shaping,
- clip_bounds: text_clip_bounds,
+ clip_bounds: _, // TODO: Support text clip bounds
} => {
let physical_bounds =
- *text_clip_bounds * transformation * scale_factor;
+ primitive.bounds() * transformation * scale_factor;
if !clip_bounds.intersects(&physical_bounds) {
return;
@@ -537,14 +541,18 @@ impl Backend {
buffer,
position,
color,
- clip_bounds: text_clip_bounds,
+ clip_bounds: _, // TODO: Support text clip bounds
}) => {
let Some(buffer) = buffer.upgrade() else {
return;
};
+ let (width, height) = buffer.size();
+
let physical_bounds =
- *text_clip_bounds * transformation * scale_factor;
+ Rectangle::new(*position, Size::new(width, height))
+ * transformation
+ * scale_factor;
if !clip_bounds.intersects(&physical_bounds) {
return;
@@ -963,7 +971,11 @@ fn smoothstep(a: f32, b: f32, x: f32) -> f32 {
x * x * (3.0 - 2.0 * x)
}
-fn rounded_box_sdf(to_center: Vector, size: Size, radii: &[f32]) -> f32 {
+fn rounded_box_sdf(
+ to_center: Vector,
+ size: tiny_skia::Size,
+ radii: &[f32],
+) -> f32 {
let radius = match (to_center.x > 0.0, to_center.y > 0.0) {
(true, true) => radii[2],
(true, false) => radii[1],