Skip to content

Commit

Permalink
Fix issue where first/last parent-directed child was being computed i…
Browse files Browse the repository at this point in the history
…ncorrectly (#31)

* enumerate before filter to fix child_space issue

* Bump minor version

* fmt
  • Loading branch information
geom3trik committed Nov 8, 2023
1 parent 5bd6926 commit a2da20d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "morphorm"
version = "0.6.2"
version = "0.6.3"
edition = "2021"
author = "George Atkinson <geom3trik@vizia.dev>"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion ecs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description = "A mini ECS used for testing the morphorm crate."
license = "MIT"

[dependencies]
morphorm = {version = "0.6.2", path = "../"}
morphorm = {version = "0.6.3", path = "../"}
femtovg = {version = "0.7.1", default-features = false}
rand = "0.8.5"
slotmap = "1.0.6"
13 changes: 7 additions & 6 deletions src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ where

let mut node_children = node
.children(tree)
.filter(|child| child.position_type(store).unwrap_or_default() == PositionType::ParentDirected)
.filter(|child| child.visible(store))
.enumerate()
.filter(|(_, child)| child.position_type(store).unwrap_or_default() == PositionType::ParentDirected)
.peekable();

// Compute space and size of non-flexible parent-directed children.
Expand Down Expand Up @@ -353,9 +353,9 @@ where
// Compute flexible space and size on the cross-axis for parent-directed children.
for (index, child) in children
.iter_mut()
.filter(|child| child.node.position_type(store).unwrap_or_default() == PositionType::ParentDirected)
.filter(|child| !child.node.cross(store, layout_type).is_auto())
.enumerate()
.filter(|(_, child)| child.node.position_type(store).unwrap_or_default() == PositionType::ParentDirected)
.filter(|(_, child)| !child.node.cross(store, layout_type).is_auto())
{
let mut child_cross_before = child.node.cross_before(store, layout_type);
let child_cross = child.node.cross(store, layout_type);
Expand Down Expand Up @@ -570,7 +570,8 @@ where

// 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()
for (index, child) in
children.iter_mut().enumerate().filter(|(_, child)| child.node.cross(store, layout_type).is_auto())
{
let mut child_cross_before = child.node.cross_before(store, layout_type);
let mut child_cross_after = child.node.cross_after(store, layout_type);
Expand Down Expand Up @@ -781,8 +782,8 @@ where
// Compute flexible space and size on the cross-axis for self-directed nodes.
for (index, child) in children
.iter_mut()
.filter(|child| child.node.position_type(store).unwrap_or_default() == PositionType::SelfDirected)
.enumerate()
.filter(|(_, child)| child.node.position_type(store).unwrap_or_default() == PositionType::SelfDirected)
{
let mut child_cross_before = child.node.cross_before(store, layout_type);
let child_cross = child.node.cross(store, layout_type);
Expand Down Expand Up @@ -932,8 +933,8 @@ where
// Compute flexible space and size on the main-axis for self-directed nodes.
for (index, child) in children
.iter_mut()
.filter(|child| child.node.position_type(store).unwrap_or_default() == PositionType::SelfDirected)
.enumerate()
.filter(|(_, child)| child.node.position_type(store).unwrap_or_default() == PositionType::SelfDirected)
{
let mut child_main_before = child.node.main_before(store, layout_type);
let child_main = child.node.main(store, layout_type);
Expand Down

0 comments on commit a2da20d

Please sign in to comment.