diff options
-rw-r--r-- | src/main.odin | 65 | ||||
-rw-r--r-- | src/tafl/tafl.odin | 83 |
2 files changed, 120 insertions, 28 deletions
diff --git a/src/main.odin b/src/main.odin index 4ff1038..750f3b7 100644 --- a/src/main.odin +++ b/src/main.odin @@ -2,7 +2,6 @@ package main import t "tafl" - main :: proc() { width, height : i32 = 1920, 1080 @@ -20,12 +19,12 @@ main :: proc() { sizing_width=t.FIXED(int(width)), sizing_height=t.FIXED(int(height)), layout=.LEFT_TO_RIGHT, - color={1,.0,.0, 1}, - padding={300,300,300,300}, - child_gap=30, + color=colors.background, + padding={5,5,5,5}, + child_gap=5, ) - { // Blue left bar - t.tafl(color={.1,.2,.3, 1}, + { // Left bar + t.tafl(color=colors.panel_blackground, sizing_height=t.GROW, sizing_width=t.FIT, layout=.TOP_TO_BOTTOM) @@ -33,25 +32,50 @@ main :: proc() { sizing_height=t.GROW, sizing_width=t.GROW)} {t.tafl( - padding={4,4,4,4}, + padding={8,8,8,8}, child_gap=4, color={.0, .0, .0, 0.4}, ) button() button() button() - button() } } { // Middle section - t.tafl(color={.2,.2,.2, 1}, + t.tafl(color=colors.panel_blackground, sizing_width=t.GROW, - sizing_height=t.GROW) + sizing_height=t.GROW, + position_horizontal=.MIDDLE, + position_vertical=.MIDDLE, + child_gap=5, + layout=.TOP_TO_BOTTOM,) + {// Red square + t.tafl(color={1,0,0,1}, + sizing_width=t.FIXED(300), + sizing_height=t.FIXED(300), + padding={1,1,1,1},) + { + t.tafl(color={0,0,0,0.5}, + sizing_width=t.GROW, + sizing_height=t.GROW) + } + } + {// Red square + t.tafl(color={1,0,0,1}, + sizing_width=t.FIXED(200), + sizing_height=t.FIXED(200), + padding={1,1,1,1},) + { + t.tafl(color={0,0,0,0.5}, + sizing_width=t.GROW, + sizing_height=t.GROW) + } + } } - { // Green right bar - t.tafl(color={.1,.4,.1, 1}, + { // Right bar + t.tafl(color=colors.panel_blackground, sizing_width=t.FIXED(300), sizing_height=t.GROW, child_gap=20, @@ -84,11 +108,24 @@ main :: proc() { button :: proc() { - t.tafl(sizing_width=t.FIXED(100), + t.tafl(sizing_width=t.FIXED(140), sizing_height=t.FIXED(40), - color={.1, .5, 1, 1}, + color=colors.button_outline, padding={2,2,2,2}) t.tafl(sizing_width=t.GROW, sizing_height=t.GROW, color={.1,.1,.1, 1}) +} + + +Color_Scheme :: struct { + background : t.Color, + panel_blackground : t.Color, + button_outline : t.Color, +} + +colors : Color_Scheme = { + background = {.1, .1, .1, 1}, + panel_blackground = {.2, .2, .2, 1}, + button_outline = {.1, .5, 1, 1}, }
\ No newline at end of file diff --git a/src/tafl/tafl.odin b/src/tafl/tafl.odin index adcb11d..9faf7a4 100644 --- a/src/tafl/tafl.odin +++ b/src/tafl/tafl.odin @@ -30,6 +30,8 @@ tafl :: proc( y : int = 0,*/ sizing_width : Sizing_Dimension = FIT, sizing_height : Sizing_Dimension = FIT, + position_horizontal : Position = .START, + position_vertical : Position = .START, layout : Layout = .LEFT_TO_RIGHT, padding : Sides = {0,0,0,0}, child_gap : int = 0, @@ -51,6 +53,8 @@ tafl :: proc( padding = padding, child_gap = child_gap, + positioning = {position_horizontal, position_vertical}, + color = color, parent = parent_ptr, @@ -208,17 +212,63 @@ grow_children_height :: proc(parent : ^Tafl) { position_children :: proc(parent: ^Tafl) { switch parent.layout { case .LEFT_TO_RIGHT: + + childrens_width := max(0, parent.children.len-1) * parent.child_gap + for child in children_of(parent) { + childrens_width += child.width + } + left_offset : int = parent.x + parent.padding.left + switch parent.positioning.horizontal { + case .START: + // nothing needs to be done + case .MIDDLE: + left_offset += int(f64(parent.width - childrens_width) * 0.5) + case .END: + left_offset += parent.width - childrens_width + } + for child in children_of(parent) { child.x = left_offset child.y = parent.padding.top + parent.y + switch parent.positioning.horizontal { + case .START: + // nothing + case .MIDDLE: + child.y += int(f64(parent.height - child.height) * 0.5) + case .END: + child.y += parent.height - child.height + } left_offset += child.width + parent.child_gap } case .TOP_TO_BOTTOM: + + childrens_height := max(0, parent.children.len-1) * parent.child_gap + for child in children_of(parent) { + childrens_height += child.height + } + top_offset : int = parent.y + parent.padding.top + switch parent.positioning.vertical { + case .START: + // nothing needs to be done + case .MIDDLE: + top_offset += int(f64(parent.height - childrens_height) * 0.5) + case .END: + top_offset += parent.height - childrens_height + } + for child in children_of(parent) { child.y = top_offset child.x = parent.padding.left + parent.x + switch parent.positioning.vertical { + case .START: + // nothing + case .MIDDLE: + child.x += int(f64(parent.width - child.width) * 0.5) + case .END: + child.x += parent.width - child.width + } top_offset += child.height + parent.child_gap } @@ -301,6 +351,11 @@ Layout :: enum { LEFT_TO_RIGHT, TOP_TO_BOTTOM, } +Position :: enum { + START, + MIDDLE, + END, +} Sides :: struct { top, bottom, left, right : int @@ -314,15 +369,26 @@ Tafl :: struct { width, height : int, x, y : int, - own_index : int, // Delete me - own_depth : int, // Delete me + own_index : int, // Don't ship this + own_depth : int, // Don't ship this parent : ^Tafl, children : struct { index, len : int }, - using style : Tafl_Style, + sizing : struct { + width : Sizing_Dimension, + height : Sizing_Dimension, + }, + positioning : struct { + horizontal : Position, + vertical : Position, + }, + layout : Layout, + padding : Sides, + child_gap : int, + color : Color, } __child_iterator_index : int = 0 // TODO: NOT THIS @@ -339,17 +405,6 @@ children_of :: proc(tafl: ^Tafl) -> (child: ^Tafl, ok: bool) { return child, true } -Tafl_Style :: struct { - sizing : struct { - width : Sizing_Dimension, - height : Sizing_Dimension, - }, - layout : Layout, - padding : Sides, - child_gap : int, - color : Color, -} - indent :: proc(x : int) { for _ in 0..<x { fmt.print("│ ") |