Support max_width and text::Alignment for canvas::Text

This commit is contained in:
Héctor Ramón Jiménez 2025-04-30 04:19:15 +02:00
parent 6ebf386249
commit 97b4ed0d84
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
13 changed files with 139 additions and 127 deletions

View file

@ -187,9 +187,15 @@ impl geometry::frame::Backend for Frame {
&& scale_x > 0.0
&& scale_y > 0.0
{
let (position, size, line_height) = if self.transform.is_identity()
{
(text.position, text.size, text.line_height)
let (bounds, size, line_height) = if self.transform.is_identity() {
(
Rectangle::new(
text.position,
Size::new(text.max_width, f32::INFINITY),
),
text.size,
text.line_height,
)
} else {
let mut position = [tiny_skia::Point {
x: text.position.x,
@ -210,19 +216,17 @@ impl geometry::frame::Backend for Frame {
};
(
Point::new(position[0].x, position[0].y),
Rectangle {
x: position[0].x,
y: position[0].y,
width: text.max_width * scale_x,
height: f32::INFINITY,
},
size.into(),
line_height,
)
};
let bounds = Rectangle {
x: position.x,
y: position.y,
width: f32::INFINITY,
height: f32::INFINITY,
};
// TODO: Honor layering!
self.text.push(Text::Cached {
content: text.content,
@ -231,7 +235,7 @@ impl geometry::frame::Backend for Frame {
size,
line_height: line_height.to_absolute(size),
font: text.font,
align_x: text.align_x.into(),
align_x: text.align_x,
align_y: text.align_y,
shaping: text.shaping,
clip_bounds: Rectangle::with_size(Size::INFINITY),

View file

@ -108,8 +108,8 @@ impl Pipeline {
size: Pixels,
line_height: Pixels,
font: Font,
horizontal_alignment: Alignment,
vertical_alignment: alignment::Vertical,
align_x: Alignment,
align_y: alignment::Vertical,
shaping: Shaping,
pixels: &mut tiny_skia::PixmapMut<'_>,
clip_mask: Option<&tiny_skia::Mask>,
@ -127,6 +127,7 @@ impl Pipeline {
size: size.into(),
line_height,
shaping,
align_x,
};
let (_, entry) = self.cache.get_mut().allocate(font_system, key);
@ -144,8 +145,8 @@ impl Pipeline {
..bounds
},
color,
horizontal_alignment,
vertical_alignment,
align_x,
align_y,
pixels,
clip_mask,
transformation,