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

@ -301,9 +301,16 @@ impl geometry::frame::Backend for Frame {
&& scale_x > 0.0
&& scale_y > 0.0
{
let (position, size, line_height) =
let (bounds, size, line_height) =
if self.transforms.current.is_identity() {
(text.position, text.size, text.line_height)
(
Rectangle::new(
text.position,
Size::new(text.max_width, f32::INFINITY),
),
text.size,
text.line_height,
)
} else {
let position =
self.transforms.current.transform_point(text.position);
@ -319,16 +326,16 @@ impl geometry::frame::Backend for Frame {
}
};
(position, size, line_height)
(
Rectangle::new(
position,
Size::new(text.max_width, f32::INFINITY),
),
size,
line_height,
)
};
let bounds = Rectangle {
x: position.x,
y: position.y,
width: f32::INFINITY,
height: f32::INFINITY,
};
self.text.push(Text::Cached {
content: text.content,
bounds,
@ -336,7 +343,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: self.clip_bounds,

View file

@ -479,6 +479,7 @@ fn prepare(
line_height,
font,
shaping,
align_x,
..
} => {
let (key, _) = buffer_cache.allocate(
@ -488,6 +489,7 @@ fn prepare(
size: f32::from(*size),
line_height: f32::from(*line_height),
font: *font,
align_x: *align_x,
bounds: Size {
width: bounds.width,
height: bounds.height,