mirror of
https://github.com/penpot/penpot.git
synced 2026-11-26 21:00:32 +00:00
🐛 Count hidden children in render-wasm grid auto-size
A grid takes its size from its tracks, so, like CLJS, it skips auto-size only when every child is absolute. Flex still skips hidden children, since its line building leaves them out. Refs #12763 AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
f807e749db
commit
76adaf86b1
@ -1785,6 +1785,11 @@ impl Shape {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether flex layout places this shape: neither absolute nor hidden.
|
||||
pub fn is_in_flow(&self) -> bool {
|
||||
!self.is_absolute() && !self.hidden()
|
||||
}
|
||||
|
||||
pub fn z_index(&self) -> i32 {
|
||||
match &self.layout_item {
|
||||
Some(LayoutItem {
|
||||
|
||||
@ -1261,6 +1261,7 @@ mod tests {
|
||||
use Child::*;
|
||||
assert_size(auto_frame_size(TestLayout::Grid, InFlow), (200.0, 50.0));
|
||||
assert_size(auto_frame_size(TestLayout::Grid, Absolute), (500.0, 300.0));
|
||||
assert_size(auto_frame_size(TestLayout::Grid, Hidden), (500.0, 300.0));
|
||||
// Grid takes its size from its tracks; hidden children still count.
|
||||
assert_size(auto_frame_size(TestLayout::Grid, Hidden), (200.0, 50.0));
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,11 +15,19 @@ impl GetBounds for HashMap<Uuid, Bounds> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a layout has a child that takes part in the flow (neither absolute
|
||||
/// nor hidden). Without one there is no content to auto-size the layout to.
|
||||
/// Whether a flex layout has a child it places (see `Shape::is_in_flow`).
|
||||
pub fn has_in_flow_children(shape: &Shape, shapes: ShapesPoolRef) -> bool {
|
||||
shape
|
||||
.children_ids_iter(true)
|
||||
.filter_map(|id| shapes.get(id))
|
||||
.any(|child| !child.is_absolute() && !child.hidden())
|
||||
.any(Shape::is_in_flow)
|
||||
}
|
||||
|
||||
/// Whether a layout has a child that is not absolute. Hidden children count,
|
||||
/// as in the CLJS layout.
|
||||
pub fn has_non_absolute_children(shape: &Shape, shapes: ShapesPoolRef) -> bool {
|
||||
shape
|
||||
.children_ids_iter(true)
|
||||
.filter_map(|id| shapes.get(id))
|
||||
.any(|child| !child.is_absolute())
|
||||
}
|
||||
|
||||
@ -202,7 +202,7 @@ fn initialize_tracks(
|
||||
continue;
|
||||
};
|
||||
|
||||
if child.is_absolute() || child.hidden() {
|
||||
if !child.is_in_flow() {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -686,8 +686,8 @@ pub fn reflow_flex_layout(
|
||||
}
|
||||
}
|
||||
|
||||
// Like the CLJS layout, keep the size when there is no content to fit:
|
||||
// auto-sizing to padding only would collapse the frame.
|
||||
// With nothing to place, keep the size instead of collapsing to padding.
|
||||
// CLJS would also size to hidden children; flex here leaves them out.
|
||||
if (layout_axis.is_auto_across || layout_axis.is_auto_main)
|
||||
&& has_in_flow_children(shape, shapes)
|
||||
{
|
||||
|
||||
@ -10,7 +10,7 @@ use crate::uuid::Uuid;
|
||||
|
||||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
|
||||
use super::common::{has_in_flow_children, GetBounds};
|
||||
use super::common::{has_non_absolute_children, GetBounds};
|
||||
|
||||
const MIN_SIZE: f32 = 0.01;
|
||||
const MAX_SIZE: f32 = f32::INFINITY;
|
||||
@ -890,10 +890,10 @@ pub fn reflow_grid_layout(
|
||||
}
|
||||
}
|
||||
|
||||
// Like the CLJS layout, keep the size when there is no content to fit:
|
||||
// auto-sizing to empty tracks would collapse the frame.
|
||||
// Like the CLJS layout, skip auto-size when every child is absolute: the
|
||||
// size comes from the tracks, and hidden children still count.
|
||||
if (shape.is_layout_horizontal_auto() || shape.is_layout_vertical_auto())
|
||||
&& has_in_flow_children(shape, shapes)
|
||||
&& has_non_absolute_children(shape, shapes)
|
||||
{
|
||||
let width = layout_bounds.width();
|
||||
let height = layout_bounds.height();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user