From 9780050cf7675e575145e9c787ad0145cf1a4a96 Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Fri, 5 Sep 2025 05:44:00 +0200 Subject: Further work, currently got a funny bug with the growing pass --- build.bat | 2 +- src/main.odin | 88 +++++++++++++++++++++++++++++++++--------------------- src/tafl/tafl.odin | 88 +++++++++++++++++++++++++++++++----------------------- 3 files changed, 105 insertions(+), 73 deletions(-) diff --git a/build.bat b/build.bat index 141af62..6508620 100644 --- a/build.bat +++ b/build.bat @@ -1 +1 @@ -odin run src/ -debug -out:main.out \ No newline at end of file +odin run src/ -debug -out:tafl-test.exe \ No newline at end of file diff --git a/src/main.odin b/src/main.odin index 0cc699f..ce57985 100644 --- a/src/main.odin +++ b/src/main.odin @@ -16,59 +16,79 @@ main :: proc() { } { - t.tafl( + t.tafl( // ROOT tafl sizing_width=t.FIXED(int(width)), sizing_height=t.FIXED(int(height)), layout=.LEFT_TO_RIGHT, - color={.0,.0,.0, 1}, + color={1,.0,.0, 1}, padding={16,16,16,16}, - child_gap=16, + child_gap=30, ) - { - t.tafl(color={.3,.6,.9, 1}, + { // Blue left bar + t.tafl(color={.1,.2,.3, 1}, sizing_height=t.GROW, - sizing_width=t.FIXED(500)) - - { - t.tafl(color={.1,.1,.1, 1}) - - { - t.tafl(color={.1,.1,.1, 1}) - } - { - t.tafl(color={.1,.1,.1, 1}) - } - { - t.tafl(color={.1,.1,.1, 1}) - } + sizing_width=t.FIT, + layout=.TOP_TO_BOTTOM) + {t.tafl(color={0,0,0,0}, + sizing_height=t.GROW, + sizing_width=t.GROW)} + {t.tafl( + padding={4,4,4,4}, + child_gap=4, + color={.0, .0, .0, 0.4}, + ) + button() + button() + button() + button() } - { - t.tafl(color={.1,.1,.1, 1}) - } } - { + { // Middle section t.tafl(color={.2,.2,.2, 1}, sizing_width=t.GROW, sizing_height=t.GROW) } - { - t.tafl(color={.1,.8,.2, 1}, + { // Green right bar + t.tafl(color={.1,.4,.1, 1}, sizing_width=t.FIXED(300), - sizing_height=t.GROW,) - /*{ - t.tafl(color={.1,.1,.1, 1}) - } + sizing_height=t.GROW, + child_gap=20, + layout=.TOP_TO_BOTTOM) + { - t.tafl(color={.1,.1,.1, 1}) - }*/ + {t.tafl(color={.5, .5, .5, 1}, + sizing_height=t.FIXED(100), + sizing_width=t.GROW, + )} + {t.tafl(color={.5, .5, .5, 1}, + sizing_height=t.FIXED(100), + sizing_width=t.GROW, + )} + {t.tafl(color={.5, .5, .8, 1}, + sizing_height=t.GROW, + sizing_width=t.GROW, + )} + {t.tafl(color={.5, .5, .5, 1}, + sizing_height=t.FIXED(100), + sizing_width=t.GROW, + )} + } } - /*{ - t.tafl(color={.1,.1,.1, 1}) - }*/ } t.render() } } + + +button :: proc() { + t.tafl(sizing_width=t.FIXED(100), + sizing_height=t.FIXED(40), + color={.1, .5, 1, 1}, + padding={2,2,2,2}) + t.tafl(sizing_width=t.GROW, + sizing_height=t.GROW, + color={.1,.1,.1, 1}) +} \ No newline at end of file diff --git a/src/tafl/tafl.odin b/src/tafl/tafl.odin index 0f719ea..e17a5b7 100644 --- a/src/tafl/tafl.odin +++ b/src/tafl/tafl.odin @@ -28,12 +28,12 @@ tafl :: proc( height : int = 0, x : int = 0, y : int = 0,*/ - sizing_width : Sizing_Dimension = {.FIT, 0, 0}, - sizing_height : Sizing_Dimension = {.FIT, 0, 0}, + sizing_width : Sizing_Dimension = FIT, + sizing_height : Sizing_Dimension = FIT, layout : Layout = .LEFT_TO_RIGHT, padding : Sides = {0,0,0,0}, child_gap : int = 0, - color : Color = {1,1,0,1}, + color : Color = {0,0,0,0}, ) -> ^Tafl{ parent_ptr : ^Tafl = nil @@ -69,8 +69,10 @@ tafl :: proc( this_tafl.own_depth = tafl_stack_depth this_tafl.children.index = temp_child_buffer_len + /* indent(this_tafl.own_depth) fmt.printfln("┌ Opened tafl {}", this_tafl.own_index) + */ tafl_elements_count += 1 tafl_stack_depth += 1 @@ -81,9 +83,16 @@ tafl :: proc( __tafl_close :: proc(tafl : ^Tafl) { - parent := tafl.parent + total_child_gap := max(tafl.children.len - 1, 0) * tafl.child_gap + switch tafl.layout { + case .LEFT_TO_RIGHT: + tafl.width += total_child_gap + case .TOP_TO_BOTTOM: + tafl.height += total_child_gap + } + + parent : ^Tafl = tafl.parent if parent != nil { - tafl.width += tafl.padding.left + tafl.padding.right tafl.height += tafl.padding.top + tafl.padding.bottom @@ -93,21 +102,18 @@ __tafl_close :: proc(tafl : ^Tafl) { // // ALSO: Wtf? Why are we basing this off of the tafls number of siblings? // I do not understand this. - total_child_gap := max(tafl.children.len - 1, 0) * tafl.child_gap switch parent.layout { case .LEFT_TO_RIGHT: - tafl.width += total_child_gap - parent.width = min(parent.width+tafl.width, parent.sizing.width.max) + parent.width = min(parent.width + tafl.width, parent.sizing.width.max) parent.height = min(max(tafl.height, parent.height), parent.sizing.height.max) case .TOP_TO_BOTTOM: - tafl.height += total_child_gap - parent.height = min(parent.height+tafl.height, parent.sizing.height.max) + parent.height = min(parent.height + tafl.height, parent.sizing.height.max) parent.width = min(max(tafl.width, parent.width), parent.sizing.width.max) } - } + for i in 0.. (child: ^Tafl, ok: bool) { if __child_iterator_index >= tafl.children.len { __child_iterator_index = 0 -- cgit v1.2.1