From 76f6f71e02979c8d48a4d5fa3e04cb54d527818b Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 6 Nov 2025 17:33:33 +0100 Subject: [PATCH] :bug: Fix z-ordering for flex elements --- render-wasm/src/render.rs | 4 ++++ render-wasm/src/shapes.rs | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/render-wasm/src/render.rs b/render-wasm/src/render.rs index 80fc974fef..22b58b098c 100644 --- a/render-wasm/src/render.rs +++ b/render-wasm/src/render.rs @@ -1472,6 +1472,10 @@ impl RenderState { // Z-index ordering on Layouts if element.has_layout() { + if element.is_flex() && !element.is_flex_reverse() { + children_ids.reverse(); + } + children_ids.sort_by(|id1, id2| { let z1 = tree.get(id1).map_or_else(|| 0, |s| s.z_index()); let z2 = tree.get(id2).map_or_else(|| 0, |s| s.z_index()); diff --git a/render-wasm/src/shapes.rs b/render-wasm/src/shapes.rs index e727bba0c5..d0792c9060 100644 --- a/render-wasm/src/shapes.rs +++ b/render-wasm/src/shapes.rs @@ -328,6 +328,28 @@ impl Shape { ) } + pub fn is_flex(&self) -> bool { + matches!( + self.shape_type, + Type::Frame(Frame { + layout: Some(layouts::Layout::FlexLayout(_, _)), + .. + }) + ) + } + + pub fn is_flex_reverse(&self) -> bool { + matches!( + self.shape_type, + Type::Frame(Frame { + layout: Some(layouts::Layout::FlexLayout(_, FlexData { + direction: layouts::FlexDirection::RowReverse | layouts::FlexDirection::ColumnReverse, .. + })), + .. + }) + ) + } + pub fn set_selrect(&mut self, left: f32, top: f32, right: f32, bottom: f32) { self.invalidate_bounds(); self.invalidate_extrect();