🐛 Fix paragraph layout width on autowidth

This commit is contained in:
Elena Torro
2025-08-22 10:00:23 +02:00
parent c0c2c9489c
commit 46b3e174ed
7 changed files with 99 additions and 107 deletions

View File

@@ -14,10 +14,17 @@ pub fn render(
let canvas = render_state
.surfaces
.canvas(surface_id.unwrap_or(SurfaceId::Fills));
let container_height = shape.selrect().height();
// Calculate total height for vertical alignment
let total_content_height = calculate_all_paragraphs_height(paragraphs, shape.bounds().width());
// Width
let paragraph_width = if let crate::shapes::Type::Text(text_content) = &shape.shape_type {
text_content.get_width()
} else {
shape.width()
};
// Height
let container_height = shape.selrect().height();
let total_content_height = calculate_all_paragraphs_height(paragraphs, paragraph_width);
let mut global_offset_y = match shape.vertical_align() {
VerticalAlign::Center => (container_height - total_content_height) / 2.0,
VerticalAlign::Bottom => container_height - total_content_height,
@@ -48,8 +55,7 @@ pub fn render(
continue;
}
skia_paragraph.layout(shape.bounds().width());
skia_paragraph.layout(paragraph_width);
let paragraph_height = skia_paragraph.height();
let xy = (shape.selrect().x(), shape.selrect().y() + group_offset_y);
skia_paragraph.paint(canvas, xy);
@@ -126,7 +132,7 @@ pub fn render(
// For stroke groups (multiple elements), increment global_offset_y once per group
if group_len > 1 {
let mut first_paragraph = group[0].build();
first_paragraph.layout(shape.bounds().width());
first_paragraph.layout(paragraph_width);
global_offset_y += first_paragraph.height();
} else {
// For regular paragraphs, global_offset_y was already incremented inside the loop