🐛 Fix layout and constraints not being cleared

This commit is contained in:
Belén Albeza 2025-08-14 15:03:59 +02:00
parent 3f3c7905b4
commit c818b6f88f
4 changed files with 60 additions and 16 deletions

View File

@ -350,6 +350,12 @@
(when constraint (when constraint
(h/call wasm/internal-module "_set_shape_constraint_v" (sr/translate-constraint-v 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 (defn set-shape-hidden
[hidden] [hidden]
(h/call wasm/internal-module "_set_shape_hidden" hidden)) (h/call wasm/internal-module "_set_shape_hidden" hidden))
@ -588,6 +594,24 @@
is-absolute is-absolute
z-index))) 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 (defn set-shape-shadows
[shadows] [shadows]
(h/call wasm/internal-module "_clear_shape_shadows") (h/call wasm/internal-module "_clear_shape_shadows")
@ -711,8 +735,8 @@
(set-parent-id parent-id) (set-parent-id parent-id)
(set-shape-type type) (set-shape-type type)
(set-shape-clip-content clip-content) (set-shape-clip-content clip-content)
(set-constraints-h constraint-h) (set-shape-constraints constraint-h constraint-v)
(set-constraints-v constraint-v)
(set-shape-rotation rotation) (set-shape-rotation rotation)
(set-shape-transform transform) (set-shape-transform transform)
(set-shape-blend-mode blend-mode) (set-shape-blend-mode blend-mode)
@ -738,15 +762,7 @@
(when (= type :text) (when (= type :text)
(set-shape-grow-type grow-type)) (set-shape-grow-type grow-type))
(when (or (ctl/any-layout? shape) (set-shape-layout shape objects)
(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-selrect selrect) (set-shape-selrect selrect)

View File

@ -209,12 +209,14 @@
:layout-wrap-type :layout-wrap-type
:layout-padding-type :layout-padding-type
:layout-padding) :layout-padding)
(cond (do
(ctl/grid-layout? shape) (api/clear-layout)
(api/set-grid-layout-data shape) (cond
(ctl/grid-layout? shape)
(api/set-grid-layout-data shape)
(ctl/flex-layout? shape) (ctl/flex-layout? shape)
(api/set-flex-layout shape)) (api/set-flex-layout shape)))
nil))) nil)))

View File

@ -347,6 +347,11 @@ impl Shape {
self.vertical_align 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<ConstraintH>) { pub fn set_constraint_h(&mut self, constraint: Option<ConstraintH>) {
self.constraint_h = constraint; 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 // FIXME: These arguments could be grouped or simplified
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn set_flex_layout_data( pub fn set_flex_layout_data(

View File

@ -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] #[no_mangle]
pub extern "C" fn set_shape_vertical_align(align: u8) { pub extern "C" fn set_shape_vertical_align(align: u8) {
with_current_shape_mut!(state, |shape: &mut Shape| { 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] #[no_mangle]
pub extern "C" fn set_flex_layout_data( pub extern "C" fn set_flex_layout_data(
dir: u8, dir: u8,