diff options
author | San Jacobs | 2025-09-05 05:44:00 +0200 |
---|---|---|
committer | San Jacobs | 2025-09-05 05:44:00 +0200 |
commit | 9780050cf7675e575145e9c787ad0145cf1a4a96 (patch) | |
tree | 5a0eaf15d89275b08d6d25fa438fe63d1f4bf5f1 | |
parent | 092fa99765309e99bf51902748aaa8a02287db57 (diff) | |
download | tafl-master.tar.gz tafl-master.tar.bz2 tafl-master.zip |
-rw-r--r-- | build.bat | 2 | ||||
-rw-r--r-- | src/main.odin | 88 | ||||
-rw-r--r-- | src/tafl/tafl.odin | 88 |
3 files changed, 105 insertions, 73 deletions
@@ -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..<tafl.children.len { child_index_buffer[child_index_buffer_len+i] = temp_child_buffer[tafl.children.index+i] temp_child_buffer_len -= 1 @@ -127,8 +133,13 @@ __tafl_close :: proc(tafl : ^Tafl) { tafl_stack_depth -= 1 - indent(tafl.own_depth) - fmt.printfln("└ Closed tafl {}\t\tchild_buffer:{}\t\ttemp_child_buffer:{}\tchild_index:{} {}", tafl.own_index, child_index_buffer[0:child_index_buffer_len], temp_child_buffer[0:temp_child_buffer_len], tafl.children.index, tafl.children.len) + /*indent(tafl.own_depth) + fmt.printfln("└ Closed tafl {}\t\tchild_buffer:{}\t\ttemp_child_buffer:{}\tchild_index:{} {}", + tafl.own_index, + child_index_buffer[0:child_index_buffer_len], + temp_child_buffer[0:temp_child_buffer_len], + tafl.children.index, + tafl.children.len)*/ } // TODO: Make sure the fit sizing mode actually works, and make min and max sizes work with it @@ -155,10 +166,8 @@ grow_children :: proc(parent : ^Tafl) { padding_x = parent.padding.top + parent.padding.bottom padding_y = parent.padding.left + parent.padding.right } - remaining_x : int = parent_x^ - remaining_y : int = parent_y^ - remaining_x -= padding_x - remaining_y -= padding_y + remaining_x : int = parent_x^ - padding_x + remaining_y : int = parent_y^ - padding_y for child in children_of(parent) { switch parent.layout { @@ -168,26 +177,27 @@ grow_children :: proc(parent : ^Tafl) { remaining_x -= child.height } } - // Do we need to make sure this isn't negative??? - remaining_x -= (parent.children.len - 1) * parent.child_gap + // THE FUCK? + // v + remaining_x -= max(parent.children.len - 1, 0) * parent.child_gap switch parent.layout { case .LEFT_TO_RIGHT: - for child in children_of(parent) { - if child.sizing.width.type == .GROW { - child.width += remaining_x + for child_again in children_of(parent) { + if child_again.sizing.width.type == .GROW { + child_again.width += remaining_x } - if child.sizing.height.type == .GROW { - child.height += remaining_y - child.height + if child_again.sizing.height.type == .GROW { + child_again.height += remaining_y - child_again.height } } case .TOP_TO_BOTTOM: - for child in children_of(parent) { - if child.sizing.width.type == .GROW { - child.width += remaining_y - child.width + for child_again in children_of(parent) { + if child_again.sizing.width.type == .GROW { + child_again.width += remaining_y - child_again.width } - if child.sizing.height.type == .GROW { - child.height += remaining_x + if child_again.sizing.height.type == .GROW { + child_again.height += remaining_x } } } @@ -196,18 +206,18 @@ grow_children :: proc(parent : ^Tafl) { position_children :: proc(parent: ^Tafl) { switch parent.layout { case .LEFT_TO_RIGHT: - left_offset : int = parent.padding.left + left_offset : int = parent.x + parent.padding.left for child in children_of(parent) { child.x = left_offset - child.y = parent.padding.top + child.y = parent.padding.top + parent.y left_offset += child.width + parent.child_gap } case .TOP_TO_BOTTOM: - top_offset : int = parent.padding.top + top_offset : int = parent.y + parent.padding.top for child in children_of(parent) { - child.x = top_offset - child.y = parent.padding.left - top_offset += child.width + parent.child_gap + child.y = top_offset + child.x = parent.padding.left + parent.x + top_offset += child.height + parent.child_gap } } @@ -221,9 +231,11 @@ render :: proc() { rl.BeginDrawing() rl.ClearBackground({255,0,0,255}) + //fmt.println("\n") + #reverse for tafl_index in child_index_buffer[:child_index_buffer_len] { tafl := tafl_elements[tafl_index] - color : rl.Color = {u8(tafl.color.r*255.0), + color : rl.Color = {u8(tafl.color.r*255.0), u8(tafl.color.g*255.0), u8(tafl.color.b*255.0), u8(tafl.color.a*255.0),} @@ -251,7 +263,7 @@ position_pass :: proc() { } } -start_window :: proc(width, height : i32, title : cstring, fps_target : int = 60) { +start_window :: proc(width, height : i32, title : cstring, fps_target : int = 60) { rl.SetWindowMinSize(800,600) rl.SetTargetFPS(60) rl.SetConfigFlags({.WINDOW_RESIZABLE}) @@ -307,7 +319,7 @@ Tafl :: struct { using style : Tafl_Style, } -__child_iterator_index : int = 0 +__child_iterator_index : int = 0 // TODO: NOT THIS children_of :: proc(tafl: ^Tafl) -> (child: ^Tafl, ok: bool) { if __child_iterator_index >= tafl.children.len { __child_iterator_index = 0 |