From 68b712acc609132d42223e17b81b023d20b4e53d Mon Sep 17 00:00:00 2001 From: Ed_ Date: Mon, 30 Dec 2024 19:37:36 -0500 Subject: [PATCH] Fix to ui_box_tranverse_next_depth_first not taking into account a parent limit For non-root traversal --- code/sectr/ui/core/box.odin | 20 ++++++++++++++------ code/sectr/ui/core/layout_compute.odin | 14 +++++++------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/code/sectr/ui/core/box.odin b/code/sectr/ui/core/box.odin index 819a7be..b3f9c07 100644 --- a/code/sectr/ui/core/box.odin +++ b/code/sectr/ui/core/box.odin @@ -118,7 +118,8 @@ ui_prev_cached_box :: #force_inline proc( box : ^UI_Box ) -> ^UI_Box { return hm // TODO(Ed): Rename to ui_box_tranverse_view_next // Traveral pritorizes immeidate children -ui_box_tranverse_next_depth_first :: #force_inline proc "contextless" (box: ^UI_Box, bypass_intersection_test := false, ctx: ^UI_State = nil) -> ^UI_Box { +ui_box_tranverse_next_depth_first :: #force_inline proc "contextless" (box : ^UI_Box, parent_limit : ^UI_Box = nil, bypass_intersection_test := false, ctx: ^UI_State = nil) -> ^UI_Box +{ state := get_state(); using state ctx := ctx if ctx != nil else ui_context @@ -136,11 +137,18 @@ ui_box_tranverse_next_depth_first :: #force_inline proc "contextless" (box: ^UI_ // No more siblings, traverse up the tree parent := box.parent - for parent != nil { - if parent.next != nil { - return parent.next - } - parent = parent.parent + for parent != nil + { + if parent_limit != nil && parent_limit == parent { + // We've reached the end of the parent_limit's tree. + return nil + } + + if parent.next != nil { + return parent.next + } + + parent = parent.parent } // We've reached the end of the tree diff --git a/code/sectr/ui/core/layout_compute.odin b/code/sectr/ui/core/layout_compute.odin index 787877b..ffe948c 100644 --- a/code/sectr/ui/core/layout_compute.odin +++ b/code/sectr/ui/core/layout_compute.odin @@ -124,11 +124,11 @@ ui_box_compute_layout :: proc( box : ^UI_Box, } if .Min_Size_To_Content_Y in layout.flags { children_bounds := ui_compute_children_overall_bounds(box) - resolved_bounds := range2( - children_bounds.min - { layout.padding.left, layout.padding.bottom } - border_offset, - children_bounds.max + { layout.padding.right, layout.padding.top } + border_offset, - ) - adjusted_size.y = size_range2(resolved_bounds).y + // resolved_bounds := range2( + // children_bounds.min - { layout.padding.left, layout.padding.bottom } - border_offset, + // children_bounds.max + { layout.padding.right, layout.padding.top } + border_offset, + // ) + adjusted_size.y = size_range2(children_bounds).y } // 5. Determine relative position @@ -207,7 +207,7 @@ ui_box_compute_layout :: proc( box : ^UI_Box, ui_compute_children_overall_bounds :: proc ( box : ^UI_Box ) -> ( children_bounds : Range2 ) { - for current := box.first; current != nil && current.prev != box; current = ui_box_tranverse_next_depth_first( current ) + for current := box.first; current != nil && current.prev != box; current = ui_box_tranverse_next_depth_first( current, parent_limit = box ) { if current == box do return if ! current.computed.fresh do ui_box_compute_layout( current ) @@ -222,7 +222,7 @@ ui_compute_children_overall_bounds :: proc ( box : ^UI_Box ) -> ( children_bound ui_box_compute_layout_children :: proc( box : ^UI_Box ) { - for current := box.first; current != nil && current.prev != box; current = ui_box_tranverse_next_depth_first( current ) + for current := box.first; current != nil && current.prev != box; current = ui_box_tranverse_next_depth_first( current, parent_limit = box ) { if current == box do return if current.computed.fresh do continue