From 35fea093445e9ad7964cec4b7f2b213ff4ca63c4 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Mon, 4 Dec 2023 16:27:56 +0100 Subject: [PATCH] fix(flex_row): missing child nodes in layout --- src/widget/flex_row/layout.rs | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/widget/flex_row/layout.rs b/src/widget/flex_row/layout.rs index 5227cb84..b1b75b28 100644 --- a/src/widget/flex_row/layout.rs +++ b/src/widget/flex_row/layout.rs @@ -24,7 +24,7 @@ pub fn resolve( let mut current_row_width = 0.0f32; let mut current_row_height = 0.0f32; - let mut row_buffer = Vec::with_capacity(8); + let mut row_buffer = Vec::::with_capacity(8); for child in items { // Calculate the dimensions of the item. @@ -40,12 +40,7 @@ pub fn resolve( }; // If it fits, add it to the current row, or create a new one. - if current_row_width + required_width <= max_flex_width { - current_row_width += required_width; - current_row_height = current_row_height.max(size.height); - - row_buffer.push(child_node); - } else { + if current_row_width + required_width > max_flex_width { if flex_height != 0.0f32 { flex_height += column_spacing; } @@ -61,8 +56,32 @@ pub fn resolve( flex_height += current_row_height; flex_width = flex_width.max(current_row_width); - current_row_width = 0.0f32; + + current_row_width = 0.0; } + + current_row_width += required_width; + current_row_height = current_row_height.max(size.height); + + row_buffer.push(child_node); + } + + if !row_buffer.is_empty() { + if flex_height != 0.0f32 { + flex_height += column_spacing; + } + + let mut pos_x = 0.0f32; + let pos_y = flex_height; + + for mut child_node in row_buffer.drain(..) { + child_node.move_to(Point::new(pos_x, pos_y)); + pos_x += row_spacing + child_node.size().width; + nodes.push(child_node); + } + + flex_height += current_row_height; + flex_width = flex_width.max(current_row_width); } let flex_size = limits.resolve(Size::new(flex_width, flex_height));