From 81c3d54c01e85800be7a2988533902b3db4cddfa Mon Sep 17 00:00:00 2001 From: George Atkinson Date: Sun, 22 Oct 2023 18:37:50 +0100 Subject: [PATCH] Revert auto-min-size --- src/layout.rs | 438 ++++++++++++++++++++------------------ tests/size_constraints.rs | 225 -------------------- 2 files changed, 236 insertions(+), 427 deletions(-) diff --git a/src/layout.rs b/src/layout.rs index f3248497..64b39734 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -103,11 +103,11 @@ where let main = node.main(store, parent_layout_type); let cross = node.cross(store, parent_layout_type); - let mut min_main = node.min_main(store, parent_layout_type).to_px(parent_main, DEFAULT_MIN); + let min_main = node.min_main(store, parent_layout_type).to_px(parent_main, DEFAULT_MIN); let max_main = node.max_main(store, parent_layout_type).to_px(parent_main, DEFAULT_MAX); // TODO: Need parent_cross to compute this correctly - let mut min_cross = node.min_cross(store, parent_layout_type).to_px(cross_size, DEFAULT_MIN); + let min_cross = node.min_cross(store, parent_layout_type).to_px(cross_size, DEFAULT_MIN); let max_cross = node.max_cross(store, parent_layout_type).to_px(cross_size, DEFAULT_MAX); // Compute main-axis size. @@ -130,10 +130,12 @@ where let border_cross_after = node.border_cross_after(store, parent_layout_type).to_px(computed_cross, DEFAULT_BORDER_WIDTH); - // Get the total number of visible children of the node. - let num_children = node.children(tree).filter(|child| child.visible(store)).count(); + let node_children = node.children(tree).filter(|child| child.visible(store)); - // Get the total number of visible parent-directed children of the node. + // Get the total number of children of the node. + let num_children = node_children.count(); + + // Get the total number of parent-directed children of the node. let num_parent_directed_children = node .children(tree) .filter(|child| child.position_type(store).unwrap_or_default() == PositionType::ParentDirected) @@ -152,7 +154,9 @@ where } // Apply main-axis size constraints for pixels and percentage. - computed_main = computed_main.min(max_main).max(min_main); + if !main.is_stretch() { + computed_main = computed_main.min(max_main).max(min_main); + } // TODO: Figure out how to constrain content size on cross axis. @@ -342,14 +346,10 @@ where } // Determine cross-size of auto node from children. - if num_parent_directed_children != 0 - && (node.cross(store, layout_type).is_auto() || node.min_cross(store, layout_type).is_auto()) - { - min_cross = cross_max + border_cross_before + border_cross_after + if num_parent_directed_children != 0 && node.cross(store, layout_type) == Auto { + parent_cross = (cross_max + border_cross_before + border_cross_after).min(max_cross).max(min_cross); } - parent_cross = parent_cross.min(max_cross).max(min_cross); - // Compute flexible space and size on the cross-axis for parent-directed children. for (index, child) in children .iter_mut() @@ -441,18 +441,6 @@ where for item in cross_axis.iter_mut().filter(|item| !item.frozen) { let actual_cross = (item.factor * child_cross_free_space / cross_flex_sum).round(); - if item.item_type == ItemType::Size && !child.node.main(store, layout_type).is_stretch() { - let child_size = - layout(child.node, layout_type, parent_main, actual_cross, cache, tree, store, sublayout); - child.main = child_size.main; - - main_sum += child.main; - - if child.node.min_cross(store, layout_type).is_auto() { - item.min = child_size.cross; - } - } - let clamped = actual_cross.min(item.max).max(item.min); item.violation = clamped - actual_cross; total_violation += item.violation; @@ -473,9 +461,33 @@ where cross_flex_sum -= item.factor; match item.item_type { - ItemType::Size => child.cross = item.computed, - ItemType::Before => child.cross_before = item.computed, - ItemType::After => child.cross_after = item.computed, + ItemType::Size => { + child.cross = item.computed; + if !child.node.main(store, layout_type).is_stretch() { + let child_size = layout( + child.node, + layout_type, + parent_main, + item.computed, + cache, + tree, + store, + sublayout, + ); + child.main = child_size.main; + child.cross = child_size.cross; + + main_sum += child.main; + } + } + + ItemType::Before => { + child.cross_before = item.computed; + } + + ItemType::After => { + child.cross_after = item.computed; + } } } } @@ -485,14 +497,10 @@ where } // Determine main-size of auto node from children. - if num_parent_directed_children != 0 - && (node.main(store, layout_type).is_auto() || node.min_main(store, layout_type).is_auto()) - { - min_main = parent_main.max(main_sum) + border_main_before + border_main_after + if num_parent_directed_children != 0 && node.main(store, layout_type) == Auto { + parent_main = (parent_main.max(main_sum) + border_main_before + border_main_after).min(max_main).max(min_main); } - parent_main = parent_main.min(max_main).max(min_main); - // Compute flexible space and size on the main axis for parent-directed children. if !main_axis.is_empty() { loop { @@ -508,18 +516,6 @@ where for item in main_axis.iter_mut().filter(|item| !item.frozen) { let actual_main = (item.factor * free_main_space / main_flex_sum).round(); - let child = &mut children[item.index]; - - if item.item_type == ItemType::Size { - let child_size = - layout(child.node, layout_type, actual_main, child.cross, cache, tree, store, sublayout); - child.cross = child_size.cross; - cross_max = cross_max.max(child.cross_before + child.cross + child.cross_after); - - if child.node.min_main(store, layout_type).is_auto() { - item.min = child_size.main; - } - } let clamped = actual_main.min(item.max).max(item.min); item.violation = clamped - actual_main; @@ -543,21 +539,159 @@ where main_sum += item.computed; match item.item_type { - ItemType::Before => child.main_before = item.computed, - ItemType::Size => child.main = item.computed, - ItemType::After => child.main_after = item.computed, + ItemType::Size => { + let child_size = layout( + child.node, + layout_type, + item.computed, + child.cross, + cache, + tree, + store, + sublayout, + ); + child.main = child_size.main; + child.cross = child_size.cross; + cross_max = cross_max.max(child.cross_before + child.cross + child.cross_after); + } + + ItemType::Before => { + child.main_before = item.computed; + } + + ItemType::After => { + child.main_after = item.computed; + } } } } } } - // Compute space and size of non-flexible self-directed children. - for child in node + // Compute stretch cross_before and stretch cross_after for auto cross children. + // TODO: I think this only needs to be done for parent-directed children... + for (index, child) in children.iter_mut().filter(|child| child.node.cross(store, layout_type).is_auto()).enumerate() + { + let mut child_cross_before = child.node.cross_before(store, layout_type); + let mut child_cross_after = child.node.cross_after(store, layout_type); + + // Apply child_space overrides. + if child_cross_before == Units::Auto { + child_cross_before = node_child_cross_before; + } + + if child_cross_after == Units::Auto { + child_cross_after = node_child_cross_after; + } + + let mut cross_flex_sum = 0.0; + + // Collect stretch cross items. + let mut cross_axis = SmallVec::<[StretchItem; 3]>::new(); + if let Stretch(factor) = child_cross_before { + let child_min_cross_before = + child.node.min_cross_before(store, layout_type).to_px(parent_cross, DEFAULT_MIN); + let child_max_cross_before = + child.node.max_cross_before(store, layout_type).to_px(parent_cross, DEFAULT_MAX); + + cross_flex_sum += factor; + + child.cross_before = 0.0; + + cross_axis.push(StretchItem::new( + index, + factor, + ItemType::Before, + child_min_cross_before, + child_max_cross_before, + )); + } + + if let Stretch(factor) = child_cross_after { + let child_min_cross_after = child.node.min_cross_after(store, layout_type).to_px(parent_cross, DEFAULT_MIN); + let child_max_cross_after = child.node.max_cross_after(store, layout_type).to_px(parent_cross, DEFAULT_MAX); + + cross_flex_sum += factor; + + child.cross_after = 0.0; + + cross_axis.push(StretchItem::new( + index, + factor, + ItemType::After, + child_min_cross_after, + child_max_cross_after, + )); + } + + let child_position_type = child.node.position_type(store).unwrap_or_default(); + + loop { + // If all stretch items are frozen, exit the loop. + if cross_axis.iter().all(|item| item.frozen) { + break; + } + + // Compute free space in the cross axis. + let child_cross_free_space = parent_cross + - border_cross_before + - border_cross_after + - child.cross_before + - child.cross + - child.cross_after; + + // Total size violation in the cross axis. + let mut total_violation = 0.0; + + for item in cross_axis.iter_mut().filter(|item| !item.frozen) { + let actual_cross = (item.factor * child_cross_free_space / cross_flex_sum).round(); + + let clamped = actual_cross.min(item.max).max(item.min); + item.violation = clamped - actual_cross; + total_violation += item.violation; + + item.computed = clamped; + } + + for item in cross_axis.iter_mut().filter(|item| !item.frozen) { + // Freeze over-stretched items. + item.frozen = match total_violation { + v if v > 0.0 => item.violation > 0.0, + v if v < 0.0 => item.violation < 0.0, + _ => true, + }; + + // If the item is frozen, adjust the used_space and sum of cross stretch factors. + if item.frozen { + cross_flex_sum -= item.factor; + + match item.item_type { + ItemType::Before => { + child.cross_before = item.computed; + } + + ItemType::After => { + child.cross_after = item.computed; + } + + _ => {} + } + } + } + } + + if child_position_type == PositionType::ParentDirected { + cross_max = cross_max.max(child.cross_before + child.cross + child.cross_after); + } + } + + let node_children = node .children(tree) .filter(|child| child.position_type(store).unwrap_or_default() == PositionType::SelfDirected) - .filter(|child| child.visible(store)) - { + .filter(|child| child.visible(store)); + + // Compute space and size of non-flexible self-directed children. + for child in node_children { // Get desired space and size. let mut child_main_before = child.main_before(store, layout_type); let child_main = child.main(store, layout_type); @@ -714,6 +848,8 @@ where )); } + let child_position_type = child.node.position_type(store).unwrap_or_default(); + loop { // If all stretch items are frozen, exit the loop. if cross_axis.iter().all(|item| item.frozen) { @@ -734,17 +870,6 @@ where for item in cross_axis.iter_mut().filter(|item| !item.frozen) { let actual_cross = (item.factor * child_cross_free_space / cross_flex_sum).round(); - if item.item_type == ItemType::Size && !child.node.main(store, layout_type).is_stretch() { - let child_size = - layout(child.node, layout_type, parent_main, actual_cross, cache, tree, store, sublayout); - - if child.node.min_cross(store, layout_type).is_auto() { - item.min = child_size.cross; - } - - child.main = child_size.main; - } - let clamped = actual_cross.min(item.max).max(item.min); item.violation = clamped - actual_cross; total_violation += item.violation; @@ -765,13 +890,43 @@ where cross_flex_sum -= item.factor; match item.item_type { - ItemType::Before => child.cross_before = item.computed, - ItemType::Size => child.cross = item.computed, - ItemType::After => child.cross_after = item.computed, + ItemType::Size => { + child.cross = item.computed; + if !child.node.main(store, layout_type).is_stretch() { + let child_size = layout( + child.node, + layout_type, + parent_main, + item.computed, + cache, + tree, + store, + sublayout, + ); + child.main = child_size.main; + child.cross = child_size.cross; + + if child_position_type == PositionType::ParentDirected { + main_sum += child.main; + } + } + } + + ItemType::Before => { + child.cross_before = item.computed; + } + + ItemType::After => { + child.cross_after = item.computed; + } } } } } + + if child_position_type == PositionType::ParentDirected { + cross_max = cross_max.max(child.cross_before + child.cross + child.cross_after); + } } // Compute flexible space and size on the main-axis for self-directed nodes. @@ -854,17 +1009,6 @@ where for item in main_axis.iter_mut().filter(|item| !item.frozen) { let actual_main = (item.factor * child_main_free_space / child_main_flex_sum).round(); - if item.item_type == ItemType::Size { - let child_size = - layout(child.node, layout_type, actual_main, child.cross, cache, tree, store, sublayout); - - child.cross = child_size.cross; - - if child.node.min_main(store, layout_type).is_auto() { - item.min = child_size.main; - } - } - let clamped = actual_main.min(item.max).max(item.min); item.violation = clamped - actual_main; total_violation += item.violation; @@ -884,129 +1028,22 @@ where child_main_flex_sum -= item.factor; match item.item_type { - ItemType::Before => child.main_before = item.computed, - ItemType::Size => child.main = item.computed, - ItemType::After => child.main_after = item.computed, - } - } - } - } - } - - // Compute stretch cross_before and stretch cross_after for auto cross children. - for (index, child) in children - .iter_mut() - .filter(|child| { - child.node.cross(store, layout_type).is_auto() || child.node.min_cross(store, layout_type).is_auto() - }) - .enumerate() - { - let mut child_cross_before = child.node.cross_before(store, layout_type); - let mut child_cross_after = child.node.cross_after(store, layout_type); - - // Apply child_space overrides. - if child_cross_before == Units::Auto { - child_cross_before = node_child_cross_before; - } - - if child_cross_after == Units::Auto { - child_cross_after = node_child_cross_after; - } - - let mut cross_flex_sum = 0.0; - - // Collect stretch cross items. - let mut cross_axis = SmallVec::<[StretchItem; 2]>::new(); - - if let Stretch(factor) = child_cross_before { - let child_min_cross_before = - child.node.min_cross_before(store, layout_type).to_px(parent_cross, DEFAULT_MIN); - let child_max_cross_before = - child.node.max_cross_before(store, layout_type).to_px(parent_cross, DEFAULT_MAX); - - cross_flex_sum += factor; - - child.cross_before = 0.0; - - cross_axis.push(StretchItem::new( - index, - factor, - ItemType::Before, - child_min_cross_before, - child_max_cross_before, - )); - } - - if let Stretch(factor) = child_cross_after { - let child_min_cross_after = child.node.min_cross_after(store, layout_type).to_px(parent_cross, DEFAULT_MIN); - let child_max_cross_after = child.node.max_cross_after(store, layout_type).to_px(parent_cross, DEFAULT_MAX); - - cross_flex_sum += factor; - - child.cross_after = 0.0; - - cross_axis.push(StretchItem::new( - index, - factor, - ItemType::After, - child_min_cross_after, - child_max_cross_after, - )); - } - - let child_position_type = child.node.position_type(store).unwrap_or_default(); - - loop { - // If all stretch items are frozen, exit the loop. - if cross_axis.iter().all(|item| item.frozen) { - break; - } - - // Compute free space in the cross axis. - let child_cross_free_space = parent_cross - - border_cross_before - - border_cross_after - - child.cross_before - - child.cross - - child.cross_after; - - // Total size violation in the cross axis. - let mut total_violation = 0.0; - - for item in cross_axis.iter_mut().filter(|item| !item.frozen) { - let actual_cross = (item.factor * child_cross_free_space / cross_flex_sum).round(); - - let clamped = actual_cross.min(item.max).max(item.min); - item.violation = clamped - actual_cross; - total_violation += item.violation; - - item.computed = clamped; - } - - for item in cross_axis.iter_mut().filter(|item| !item.frozen) { - // Freeze over-stretched items. - item.frozen = match total_violation { - v if v > 0.0 => item.violation > 0.0, - v if v < 0.0 => item.violation < 0.0, - _ => true, - }; - - // If the item is frozen, adjust the used_space and sum of cross stretch factors. - if item.frozen { - cross_flex_sum -= item.factor; - - match item.item_type { - ItemType::Before => child.cross_before = item.computed, - ItemType::After => child.cross_after = item.computed, - - _ => {} + ItemType::Before => { + child.main_before = item.computed; + } + ItemType::Size => { + child.main = item.computed; + } + ItemType::After => { + child.main_after = item.computed; + } } } } } - if child_position_type == PositionType::ParentDirected { - cross_max = cross_max.max(child.cross_before + child.cross + child.cross_after); + if let Stretch(_) = child_main { + layout(child.node, layout_type, child.main, child.cross, cache, tree, store, sublayout); } } @@ -1050,18 +1087,15 @@ where std::mem::swap(&mut main_sum, &mut cross_max) }; - if main.is_auto() || node.min_main(store, parent_layout_type).is_auto() { - min_main = main_sum; + if main == Auto { + computed_main = main_sum.min(max_main).max(min_main); } - if cross.is_auto() || node.min_cross(store, parent_layout_type).is_auto() { - min_cross = cross_max; + if cross == Auto { + computed_cross = cross_max.min(max_cross).max(min_cross); } } - computed_main = computed_main.min(max_main).max(min_main); - computed_cross = computed_cross.min(max_cross).max(min_cross); - // Return the computed size, propagating it back up the tree. Size { main: computed_main, cross: computed_cross } } diff --git a/tests/size_constraints.rs b/tests/size_constraints.rs index 360e5f96..ed0bb13b 100644 --- a/tests/size_constraints.rs +++ b/tests/size_constraints.rs @@ -193,228 +193,3 @@ fn min_width_percentage_width_auto() { assert_eq!(world.cache.bounds(node), Some(&Rect { posx: 0.0, posy: 0.0, width: 600.0, height: 100.0 })); assert_eq!(world.cache.bounds(node2), Some(&Rect { posx: 0.0, posy: 0.0, width: 200.0, height: 100.0 })); } - -#[test] -fn min_width_auto() { - let mut world = World::default(); - - let root = world.add(None); - world.set_width(root, Units::Pixels(600.0)); - world.set_height(root, Units::Pixels(600.0)); - world.set_child_space(root, Units::Stretch(1.0)); - - let node = world.add(Some(root)); - world.set_width(node, Units::Stretch(1.0)); - world.set_height(node, Units::Stretch(1.0)); - world.set_min_width(node, Units::Auto); - - let node2 = world.add(Some(node)); - world.set_width(node2, Units::Pixels(300.0)); - world.set_height(node2, Units::Pixels(300.0)); - - root.layout(&mut world.cache, &world.tree, &world.store, &mut ()); - - assert_eq!(world.cache.bounds(node), Some(&Rect { posx: 150.0, posy: 200.0, width: 300.0, height: 200.0 })); - assert_eq!(world.cache.bounds(node2), Some(&Rect { posx: 0.0, posy: 0.0, width: 300.0, height: 300.0 })); -} - -#[test] -fn min_height_auto() { - let mut world = World::default(); - - let root = world.add(None); - world.set_width(root, Units::Pixels(600.0)); - world.set_height(root, Units::Pixels(600.0)); - world.set_child_space(root, Units::Stretch(1.0)); - - let node = world.add(Some(root)); - world.set_width(node, Units::Stretch(1.0)); - world.set_height(node, Units::Stretch(1.0)); - world.set_min_height(node, Units::Auto); - - let node2 = world.add(Some(node)); - world.set_width(node2, Units::Pixels(300.0)); - world.set_height(node2, Units::Pixels(300.0)); - - root.layout(&mut world.cache, &world.tree, &world.store, &mut ()); - - assert_eq!(world.cache.bounds(node), Some(&Rect { posx: 200.0, posy: 150.0, width: 200.0, height: 300.0 })); - assert_eq!(world.cache.bounds(node2), Some(&Rect { posx: 0.0, posy: 0.0, width: 300.0, height: 300.0 })); -} - -#[test] -fn min_size_auto() { - let mut world = World::default(); - - let root = world.add(None); - world.set_width(root, Units::Pixels(600.0)); - world.set_height(root, Units::Pixels(600.0)); - world.set_child_space(root, Units::Stretch(1.0)); - - let node = world.add(Some(root)); - world.set_width(node, Units::Stretch(1.0)); - world.set_height(node, Units::Stretch(1.0)); - world.set_min_width(node, Units::Auto); - world.set_min_height(node, Units::Auto); - - let node2 = world.add(Some(node)); - world.set_width(node2, Units::Pixels(300.0)); - world.set_height(node2, Units::Pixels(300.0)); - - root.layout(&mut world.cache, &world.tree, &world.store, &mut ()); - - assert_eq!(world.cache.bounds(node), Some(&Rect { posx: 150.0, posy: 150.0, width: 300.0, height: 300.0 })); - assert_eq!(world.cache.bounds(node2), Some(&Rect { posx: 0.0, posy: 0.0, width: 300.0, height: 300.0 })); -} - -#[test] -fn min_width_auto_self_directed() { - let mut world = World::default(); - - let root = world.add(None); - world.set_width(root, Units::Pixels(600.0)); - world.set_height(root, Units::Pixels(600.0)); - world.set_child_space(root, Units::Stretch(1.0)); - - let node = world.add(Some(root)); - world.set_width(node, Units::Stretch(1.0)); - world.set_height(node, Units::Stretch(1.0)); - world.set_min_width(node, Units::Auto); - world.set_position_type(node, PositionType::SelfDirected); - - let node2 = world.add(Some(node)); - world.set_width(node2, Units::Pixels(300.0)); - world.set_height(node2, Units::Pixels(300.0)); - - root.layout(&mut world.cache, &world.tree, &world.store, &mut ()); - - assert_eq!(world.cache.bounds(node), Some(&Rect { posx: 150.0, posy: 200.0, width: 300.0, height: 200.0 })); - assert_eq!(world.cache.bounds(node2), Some(&Rect { posx: 0.0, posy: 0.0, width: 300.0, height: 300.0 })); -} - -#[test] -fn min_height_auto_self_directed() { - let mut world = World::default(); - - let root = world.add(None); - world.set_width(root, Units::Pixels(600.0)); - world.set_height(root, Units::Pixels(600.0)); - world.set_child_space(root, Units::Stretch(1.0)); - - let node = world.add(Some(root)); - world.set_width(node, Units::Stretch(1.0)); - world.set_height(node, Units::Stretch(1.0)); - world.set_min_height(node, Units::Auto); - world.set_position_type(node, PositionType::SelfDirected); - - let node2 = world.add(Some(node)); - world.set_width(node2, Units::Pixels(300.0)); - world.set_height(node2, Units::Pixels(300.0)); - - root.layout(&mut world.cache, &world.tree, &world.store, &mut ()); - - assert_eq!(world.cache.bounds(node), Some(&Rect { posx: 200.0, posy: 150.0, width: 200.0, height: 300.0 })); - assert_eq!(world.cache.bounds(node2), Some(&Rect { posx: 0.0, posy: 0.0, width: 300.0, height: 300.0 })); -} - -#[test] -fn min_size_auto_self_directed() { - let mut world = World::default(); - - let root = world.add(None); - world.set_width(root, Units::Pixels(600.0)); - world.set_height(root, Units::Pixels(600.0)); - world.set_child_space(root, Units::Stretch(1.0)); - - let node = world.add(Some(root)); - world.set_width(node, Units::Stretch(1.0)); - world.set_height(node, Units::Stretch(1.0)); - world.set_min_width(node, Units::Auto); - world.set_min_height(node, Units::Auto); - world.set_position_type(node, PositionType::SelfDirected); - - let node2 = world.add(Some(node)); - world.set_width(node2, Units::Pixels(300.0)); - world.set_height(node2, Units::Pixels(300.0)); - - root.layout(&mut world.cache, &world.tree, &world.store, &mut ()); - - assert_eq!(world.cache.bounds(node), Some(&Rect { posx: 150.0, posy: 150.0, width: 300.0, height: 300.0 })); - assert_eq!(world.cache.bounds(node2), Some(&Rect { posx: 0.0, posy: 0.0, width: 300.0, height: 300.0 })); -} - -#[test] -fn min_width_auto_child_self_directed() { - let mut world = World::default(); - - let root = world.add(None); - world.set_width(root, Units::Pixels(600.0)); - world.set_height(root, Units::Pixels(600.0)); - world.set_child_space(root, Units::Stretch(1.0)); - - let node = world.add(Some(root)); - world.set_width(node, Units::Stretch(1.0)); - world.set_height(node, Units::Stretch(1.0)); - world.set_min_width(node, Units::Auto); - - let node2 = world.add(Some(node)); - world.set_width(node2, Units::Pixels(300.0)); - world.set_height(node2, Units::Pixels(300.0)); - world.set_position_type(node2, PositionType::SelfDirected); - - root.layout(&mut world.cache, &world.tree, &world.store, &mut ()); - - assert_eq!(world.cache.bounds(node), Some(&Rect { posx: 200.0, posy: 200.0, width: 200.0, height: 200.0 })); - assert_eq!(world.cache.bounds(node2), Some(&Rect { posx: 0.0, posy: 0.0, width: 300.0, height: 300.0 })); -} - -#[test] -fn min_height_auto_child_self_directed() { - let mut world = World::default(); - - let root = world.add(None); - world.set_width(root, Units::Pixels(600.0)); - world.set_height(root, Units::Pixels(600.0)); - world.set_child_space(root, Units::Stretch(1.0)); - - let node = world.add(Some(root)); - world.set_width(node, Units::Stretch(1.0)); - world.set_height(node, Units::Stretch(1.0)); - world.set_min_height(node, Units::Auto); - - let node2 = world.add(Some(node)); - world.set_width(node2, Units::Pixels(300.0)); - world.set_height(node2, Units::Pixels(300.0)); - world.set_position_type(node2, PositionType::SelfDirected); - - root.layout(&mut world.cache, &world.tree, &world.store, &mut ()); - - assert_eq!(world.cache.bounds(node), Some(&Rect { posx: 200.0, posy: 200.0, width: 200.0, height: 200.0 })); - assert_eq!(world.cache.bounds(node2), Some(&Rect { posx: 0.0, posy: 0.0, width: 300.0, height: 300.0 })); -} - -#[test] -fn min_size_auto_child_self_directed() { - let mut world = World::default(); - - let root = world.add(None); - world.set_width(root, Units::Pixels(600.0)); - world.set_height(root, Units::Pixels(600.0)); - world.set_child_space(root, Units::Stretch(1.0)); - - let node = world.add(Some(root)); - world.set_width(node, Units::Stretch(1.0)); - world.set_height(node, Units::Stretch(1.0)); - world.set_min_width(node, Units::Auto); - world.set_min_height(node, Units::Auto); - - let node2 = world.add(Some(node)); - world.set_width(node2, Units::Pixels(300.0)); - world.set_height(node2, Units::Pixels(300.0)); - world.set_position_type(node2, PositionType::SelfDirected); - - root.layout(&mut world.cache, &world.tree, &world.store, &mut ()); - - assert_eq!(world.cache.bounds(node), Some(&Rect { posx: 200.0, posy: 200.0, width: 200.0, height: 200.0 })); - assert_eq!(world.cache.bounds(node2), Some(&Rect { posx: 0.0, posy: 0.0, width: 300.0, height: 300.0 })); -}