From c818b6f88f2d3aa390a62b9aeb5abb9cde8aadfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bel=C3=A9n=20Albeza?= Date: Thu, 14 Aug 2025 15:03:59 +0200 Subject: [PATCH] :bug: Fix layout and constraints not being cleared --- frontend/src/app/render_wasm/api.cljs | 38 ++++++++++++++++++------- frontend/src/app/render_wasm/shape.cljs | 12 ++++---- render-wasm/src/shapes.rs | 12 ++++++++ render-wasm/src/wasm/layout.rs | 14 +++++++++ 4 files changed, 60 insertions(+), 16 deletions(-) diff --git a/frontend/src/app/render_wasm/api.cljs b/frontend/src/app/render_wasm/api.cljs index 55623c1457..93b3feb9e5 100644 --- a/frontend/src/app/render_wasm/api.cljs +++ b/frontend/src/app/render_wasm/api.cljs @@ -350,6 +350,12 @@ (when constraint (h/call wasm/internal-module "_set_shape_constraint_v" (sr/translate-constraint-v constraint)))) +(defn set-shape-constraints + [constraint-h constraint-v] + (h/call wasm/internal-module "_clear_shape_constraints") + (set-constraints-h constraint-h) + (set-constraints-v constraint-v)) + (defn set-shape-hidden [hidden] (h/call wasm/internal-module "_set_shape_hidden" hidden)) @@ -588,6 +594,24 @@ is-absolute z-index))) +(defn clear-layout + [] + (h/call wasm/internal-module "_clear_shape_layout")) + +(defn- set-shape-layout + [shape objects] + (clear-layout) + + (when (or (ctl/any-layout? shape) + (ctl/any-layout-immediate-child? objects shape)) + (set-layout-child shape)) + + (when (ctl/flex-layout? shape) + (set-flex-layout shape)) + + (when (ctl/grid-layout? shape) + (set-grid-layout shape))) + (defn set-shape-shadows [shadows] (h/call wasm/internal-module "_clear_shape_shadows") @@ -711,8 +735,8 @@ (set-parent-id parent-id) (set-shape-type type) (set-shape-clip-content clip-content) - (set-constraints-h constraint-h) - (set-constraints-v constraint-v) + (set-shape-constraints constraint-h constraint-v) + (set-shape-rotation rotation) (set-shape-transform transform) (set-shape-blend-mode blend-mode) @@ -738,15 +762,7 @@ (when (= type :text) (set-shape-grow-type grow-type)) - (when (or (ctl/any-layout? shape) - (ctl/any-layout-immediate-child? objects shape)) - (set-layout-child shape)) - - (when (ctl/flex-layout? shape) - (set-flex-layout shape)) - - (when (ctl/grid-layout? shape) - (set-grid-layout shape)) + (set-shape-layout shape objects) (set-shape-selrect selrect) diff --git a/frontend/src/app/render_wasm/shape.cljs b/frontend/src/app/render_wasm/shape.cljs index 466d8afefa..7bd0ba042c 100644 --- a/frontend/src/app/render_wasm/shape.cljs +++ b/frontend/src/app/render_wasm/shape.cljs @@ -209,12 +209,14 @@ :layout-wrap-type :layout-padding-type :layout-padding) - (cond - (ctl/grid-layout? shape) - (api/set-grid-layout-data shape) + (do + (api/clear-layout) + (cond + (ctl/grid-layout? shape) + (api/set-grid-layout-data shape) - (ctl/flex-layout? shape) - (api/set-flex-layout shape)) + (ctl/flex-layout? shape) + (api/set-flex-layout shape))) nil))) diff --git a/render-wasm/src/shapes.rs b/render-wasm/src/shapes.rs index 1af6f24419..a0cdf314c9 100644 --- a/render-wasm/src/shapes.rs +++ b/render-wasm/src/shapes.rs @@ -347,6 +347,11 @@ impl Shape { self.vertical_align } + pub fn clear_constraints(&mut self) { + self.constraint_h = None; + self.constraint_v = None; + } + pub fn set_constraint_h(&mut self, constraint: Option) { self.constraint_h = constraint; } @@ -402,6 +407,13 @@ impl Shape { }); } + pub fn clear_layout(&mut self) { + self.layout_item = None; + if let Type::Frame(data) = &mut self.shape_type { + data.layout = None; + } + } + // FIXME: These arguments could be grouped or simplified #[allow(clippy::too_many_arguments)] pub fn set_flex_layout_data( diff --git a/render-wasm/src/wasm/layout.rs b/render-wasm/src/wasm/layout.rs index 52e097ec69..2eb7139433 100644 --- a/render-wasm/src/wasm/layout.rs +++ b/render-wasm/src/wasm/layout.rs @@ -16,6 +16,13 @@ pub extern "C" fn set_shape_constraint_v(constraint: u8) { }); } +#[no_mangle] +pub extern "C" fn clear_shape_constraints() { + with_current_shape_mut!(state, |shape: &mut Shape| { + shape.clear_constraints(); + }); +} + #[no_mangle] pub extern "C" fn set_shape_vertical_align(align: u8) { with_current_shape_mut!(state, |shape: &mut Shape| { @@ -23,6 +30,13 @@ pub extern "C" fn set_shape_vertical_align(align: u8) { }); } +#[no_mangle] +pub extern "C" fn clear_shape_layout() { + with_current_shape_mut!(state, |shape: &mut Shape| { + shape.clear_layout(); + }); +} + #[no_mangle] pub extern "C" fn set_flex_layout_data( dir: u8,