Compare commits

...

1 Commits

Author SHA1 Message Date
Alejandro Alonso
5eae47515f WIP 2026-01-28 11:39:12 +01:00
3 changed files with 32 additions and 13 deletions

View File

@@ -183,11 +183,12 @@ fn propagate_transform(
let mut transform = entry.transform;
// Only check the text layout when the width/height changes
if !is_close_to(shape_bounds_before.width(), shape_bounds_after.width())
|| !is_close_to(shape_bounds_before.height(), shape_bounds_after.height())
{
if let Type::Text(text_content) = &mut shape.shape_type.clone() {
let size_changed = !is_close_to(shape_bounds_before.width(), shape_bounds_after.width())
|| !is_close_to(shape_bounds_before.height(), shape_bounds_after.height());
if let Type::Text(text_content) = &mut shape.shape_type.clone() {
let needs_layout = text_content.needs_update_layout();
if size_changed || needs_layout {
let resized_selrect = math::Rect::from_xywh(
shape.selrect.left(),
shape.selrect.top(),
@@ -196,11 +197,10 @@ fn propagate_transform(
);
match text_content.grow_type() {
GrowType::AutoHeight => {
// For auto-height, always update layout when width changes
// because the new width affects how text wraps
// For auto-height, update layout when width changes or content changed
let width_changed =
!is_close_to(shape_bounds_before.width(), shape_bounds_after.width());
if width_changed || text_content.needs_update_layout() {
if width_changed || needs_layout {
text_content.update_layout(resized_selrect);
}
let height = text_content.size.height;
@@ -214,11 +214,10 @@ fn propagate_transform(
transform.post_concat(&resize_transform);
}
GrowType::AutoWidth => {
// For auto-width, always update layout when height changes
// because the new height affects how text flows
// For auto-width, update layout when height changes or content changed
let height_changed =
!is_close_to(shape_bounds_before.height(), shape_bounds_after.height());
if height_changed || text_content.needs_update_layout() {
if height_changed || needs_layout {
text_content.update_layout(resized_selrect);
}
let width = text_content.width();

View File

@@ -309,7 +309,12 @@ impl TextContent {
}
pub fn add_paragraph(&mut self, paragraph: Paragraph) {
println!("add_paragraph: {:?}", paragraph);
self.paragraphs.push(paragraph);
// Content changed; drop cached layout to force recompute.
self.layout = TextContentLayout::new();
println!("grow_type: {:?}", self.grow_type);
}
pub fn paragraphs(&self) -> &[Paragraph] {

View File

@@ -365,8 +365,23 @@ pub extern "C" fn intersect_position_in_shape(
fn update_text_layout(shape: &mut Shape) {
if let Type::Text(text_content) = &mut shape.shape_type {
text_content.update_layout(shape.selrect);
shape.invalidate_extrect();
let size = text_content.update_layout(shape.selrect);
match text_content.grow_type() {
GrowType::AutoWidth => {
let left = shape.selrect.left();
let top = shape.selrect.top();
shape.set_selrect(left, top, left + size.width, top + size.height);
}
GrowType::AutoHeight => {
let left = shape.selrect.left();
let top = shape.selrect.top();
let width = shape.selrect.width();
shape.set_selrect(left, top, left + width, top + size.height);
}
GrowType::Fixed => {
shape.invalidate_extrect();
}
}
}
}