From 5d42b9793bb6a6eb379b419959f60868614d766d Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 21 May 2025 10:41:42 +0200 Subject: [PATCH] :bug: Fix some problems with layouts --- .../app/main/ui/workspace/shapes/text/v2_editor.cljs | 4 ++-- frontend/src/app/render_wasm/api.cljs | 5 +++-- render-wasm/src/shapes/modifiers.rs | 4 ++++ render-wasm/src/shapes/modifiers/flex_layout.rs | 10 +++++++++- render-wasm/src/shapes/text.rs | 7 +++++++ render-wasm/src/wasm/text.rs | 7 +++++-- 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/shapes/text/v2_editor.cljs b/frontend/src/app/main/ui/workspace/shapes/text/v2_editor.cljs index 50c0327a0e..1af9cae6a8 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text/v2_editor.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text/v2_editor.cljs @@ -262,10 +262,10 @@ [x y width height] (if (features/active-feature? @st/state "render-wasm/v1") - (let [{:keys [width height]} (wasm.api/text-dimensions shape-id) + (let [{:keys [max-width height]} (wasm.api/text-dimensions shape-id) {:keys [x y]} (:selrect shape)] - [x y width height]) + [x y max-width height]) (let [bounds (gst/shape->rect shape) x (mth/min (dm/get-prop bounds :x) diff --git a/frontend/src/app/render_wasm/api.cljs b/frontend/src/app/render_wasm/api.cljs index cd843009cf..b7bc4eb8cb 100644 --- a/frontend/src/app/render_wasm/api.cljs +++ b/frontend/src/app/render_wasm/api.cljs @@ -620,9 +620,10 @@ (let [offset (h/call wasm/internal-module "_get_text_dimensions") heapf32 (mem/get-heap-f32) width (aget heapf32 (mem/ptr8->ptr32 offset)) - height (aget heapf32 (mem/ptr8->ptr32 (+ offset 4)))] + height (aget heapf32 (mem/ptr8->ptr32 (+ offset 4))) + max-width (aget heapf32 (mem/ptr8->ptr32 (+ offset 8)))] (h/call wasm/internal-module "_free_bytes") - {:width width :height height}))) + {:width width :height height :max-width max-width}))) (defn set-view-box [zoom vbox] diff --git a/render-wasm/src/shapes/modifiers.rs b/render-wasm/src/shapes/modifiers.rs index 798c18d441..6b33dd3f65 100644 --- a/render-wasm/src/shapes/modifiers.rs +++ b/render-wasm/src/shapes/modifiers.rs @@ -210,6 +210,10 @@ pub fn propagate_modifiers( shape_modif.post_concat(&transform); modifiers.insert(shape.id, shape_modif); + if shape.has_layout() { + entries.push_back(Modifier::reflow(shape.id)); + } + if let Some(parent) = shape.parent_id.and_then(|id| shapes.get(&id)) { if parent.has_layout() || parent.is_group_like() { entries.push_back(Modifier::reflow(parent.id)); diff --git a/render-wasm/src/shapes/modifiers/flex_layout.rs b/render-wasm/src/shapes/modifiers/flex_layout.rs index 2dcccda1d8..8e7a47a456 100644 --- a/render-wasm/src/shapes/modifiers/flex_layout.rs +++ b/render-wasm/src/shapes/modifiers/flex_layout.rs @@ -187,7 +187,7 @@ fn initialize_tracks( let mut children = modified_children_ids(shape, structure.get(&shape.id)); let mut first = true; - if !flex_data.is_reverse() { + if flex_data.is_reverse() { children.reverse(); } @@ -497,6 +497,14 @@ fn next_anchor( prev_anchor: Point, total_shapes_size: f32, ) -> Point { + if layout_axis.is_auto_main { + let delta = child_axis.margin_main_start + + child_axis.margin_main_end + + child_axis.main_size + + layout_axis.gap_main; + return prev_anchor + layout_axis.main_v * delta; + } + let delta = child_axis.margin_main_start + child_axis.margin_main_end + match layout_data.justify_content { diff --git a/render-wasm/src/shapes/text.rs b/render-wasm/src/shapes/text.rs index d207eb6160..74a36f636c 100644 --- a/render-wasm/src/shapes/text.rs +++ b/render-wasm/src/shapes/text.rs @@ -551,6 +551,13 @@ pub fn auto_width(paragraphs: &[Vec]) -> f32 { }) } +pub fn max_width(paragraphs: &[Vec]) -> f32 { + paragraphs + .iter() + .flatten() + .fold(0.0, |max_width, p| f32::max(p.max_width(), max_width)) +} + pub fn auto_height(paragraphs: &[Vec]) -> f32 { paragraphs .iter() diff --git a/render-wasm/src/wasm/text.rs b/render-wasm/src/wasm/text.rs index 7642216daa..6619bf0cf8 100644 --- a/render-wasm/src/wasm/text.rs +++ b/render-wasm/src/wasm/text.rs @@ -1,5 +1,5 @@ use crate::mem; -use crate::shapes::{auto_height, auto_width, GrowType, RawTextData, Type}; +use crate::shapes::{auto_height, auto_width, max_width, GrowType, RawTextData, Type}; use crate::STATE; use crate::{with_current_shape, with_state}; @@ -42,6 +42,7 @@ pub extern "C" fn get_text_dimensions() -> *mut u8 { let mut width = 0.01; let mut height = 0.01; + let mut m_width = 0.01; with_current_shape!(state, |shape: &mut Shape| { width = shape.selrect.width(); height = shape.selrect.height(); @@ -49,14 +50,16 @@ pub extern "C" fn get_text_dimensions() -> *mut u8 { if let Type::Text(content) = &shape.shape_type { let paragraphs = content.get_skia_paragraphs(font_col); height = auto_height(¶graphs).ceil(); + m_width = max_width(¶graphs); if content.grow_type() == GrowType::AutoWidth { width = auto_width(¶graphs).ceil(); } } }); - let mut bytes = vec![0; 8]; + let mut bytes = vec![0; 12]; bytes[0..4].clone_from_slice(&width.to_le_bytes()); bytes[4..8].clone_from_slice(&height.to_le_bytes()); + bytes[8..12].clone_from_slice(&m_width.to_le_bytes()); mem::write_bytes(bytes) }