aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.odin23
-rw-r--r--src/tafl/tafl.odin65
2 files changed, 77 insertions, 11 deletions
diff --git a/src/main.odin b/src/main.odin
index 750f3b7..caae860 100644
--- a/src/main.odin
+++ b/src/main.odin
@@ -33,12 +33,12 @@ main :: proc() {
sizing_width=t.GROW)}
{t.tafl(
padding={8,8,8,8},
- child_gap=4,
+ child_gap=8,
color={.0, .0, .0, 0.4},
)
- button()
- button()
- button()
+ button("Yeet")
+ button("Test")
+ button("Render")
}
}
@@ -107,25 +107,32 @@ main :: proc() {
}
-button :: proc() {
- t.tafl(sizing_width=t.FIXED(140),
+button :: proc(text : string) {
+ t.tafl(sizing_width=t.FIXED(120),
sizing_height=t.FIXED(40),
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={.1,.1,.1, 1},
+ position_horizontal=.MIDDLE,
+ position_vertical=.MIDDLE,)
+ t.tafl(text=text)
}
-
Color_Scheme :: struct {
background : t.Color,
panel_blackground : t.Color,
+ panel_border : t.Color,
button_outline : t.Color,
}
colors : Color_Scheme = {
background = {.1, .1, .1, 1},
panel_blackground = {.2, .2, .2, 1},
+ panel_border = {.35, .35, .35, 1},
button_outline = {.1, .5, 1, 1},
+}
+
+panel :: proc() {
} \ No newline at end of file
diff --git a/src/tafl/tafl.odin b/src/tafl/tafl.odin
index 9faf7a4..474639d 100644
--- a/src/tafl/tafl.odin
+++ b/src/tafl/tafl.odin
@@ -1,8 +1,12 @@
package tafl
import "core:fmt"
+import "core:strconv"
+import "core:strings"
import rl "vendor:raylib"
+__DEFAULT_FONT_FILE :: #load("../../res/Inter_24pt-Medium.ttf")
+
tafl_elements : [4096]Tafl
tafl_elements_count : int
@@ -15,6 +19,9 @@ child_index_buffer_len : int
temp_child_buffer : [4096]int
temp_child_buffer_len : int // May be inferred by child count, and not be needed
+DEFAULT_FONT : rl.Font
+FONT_SIZE : int : 24
+
clear_layout :: proc() {
tafl_stack_depth = 0
tafl_elements_count = 0
@@ -22,7 +29,7 @@ clear_layout :: proc() {
temp_child_buffer_len = 0
}
-@(deferred_out=__tafl_close)
+@(deferred_out=tafl_close)
tafl :: proc(
/*width : int = 0,
height : int = 0,
@@ -30,19 +37,61 @@ tafl :: proc(
y : int = 0,*/
sizing_width : Sizing_Dimension = FIT,
sizing_height : Sizing_Dimension = FIT,
- position_horizontal : Position = .START,
+ position_horizontal : Position = .START,
position_vertical : Position = .START,
layout : Layout = .LEFT_TO_RIGHT,
padding : Sides = {0,0,0,0},
child_gap : int = 0,
color : Color = {0,0,0,0},
+ text : = "",
+ ) -> ^Tafl {
+
+ return tafl_open(
+ /*width ,
+ height,
+ x,
+ y,*/
+ sizing_width,
+ sizing_height,
+ position_horizontal,
+ position_vertical,
+ layout,
+ padding,
+ child_gap,
+ color,
+ text)
+}
+
+tafl_open :: proc(
+ /*width : int = 0,
+ height : int = 0,
+ x : int = 0,
+ 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,
+ color : Color = {0,0,0,0},
+ text : = "",
) -> ^Tafl{
+ sizing_height := sizing_height
+ sizing_width := sizing_width
+
parent_ptr : ^Tafl = nil
if tafl_stack_depth > 0 {
parent_ptr = &tafl_elements[tafl_stack[tafl_stack_depth-1]]
}
+ if text != "" {
+ measurement := rl.MeasureTextEx(DEFAULT_FONT, strings.clone_to_cstring(text), f32(FONT_SIZE), 0)
+ sizing_width = {.FIXED, int(measurement.x), int(measurement.x)}
+ sizing_height = {.FIXED, FONT_SIZE, FONT_SIZE}
+ }
+
tafl_elements[tafl_elements_count] = {
/*width = width,
height = height,
@@ -58,6 +107,8 @@ tafl :: proc(
color = color,
parent = parent_ptr,
+
+ text = text,
}
this_tafl : ^Tafl = &tafl_elements[tafl_elements_count]
@@ -85,7 +136,7 @@ tafl :: proc(
}
-__tafl_close :: proc(tafl : ^Tafl) {
+tafl_close :: proc(tafl : ^Tafl) {
total_child_gap := max(tafl.children.len - 1, 0) * tafl.child_gap
switch tafl.layout {
@@ -293,6 +344,9 @@ render :: proc() {
u8(tafl.color.a*255.0),}
//fmt.printf("%#v\n\n", tafl)
rl.DrawRectangleRec({f32(tafl.x), f32(tafl.y), f32(tafl.width), f32(tafl.height),}, color)
+ if(tafl.text != "") {
+ rl.DrawTextEx(DEFAULT_FONT, strings.clone_to_cstring(tafl.text, allocator=context.allocator), {f32(tafl.x), f32(tafl.y)}, f32(FONT_SIZE), 0, rl.WHITE)
+ }
}
rl.DrawFPS(5, 5)
@@ -324,6 +378,7 @@ start_window :: proc(width, height : i32, title : cstring, fps_target : int = 60
rl.SetTargetFPS(60)
rl.SetConfigFlags({.WINDOW_RESIZABLE})
rl.InitWindow(width, height, title)
+ DEFAULT_FONT = rl.LoadFontFromMemory(".ttf", raw_data(__DEFAULT_FONT_FILE), i32(len(__DEFAULT_FONT_FILE)), i32(FONT_SIZE), nil, 0)
}
window_should_close :: proc() -> bool {
@@ -389,6 +444,7 @@ Tafl :: struct {
padding : Sides,
child_gap : int,
color : Color,
+ text : string,
}
__child_iterator_index : int = 0 // TODO: NOT THIS
@@ -418,6 +474,9 @@ FIT : Sizing_Dimension : {.FIT, 0, max(type_of(Sizing_Dimension{}.max))}
FIXED :: proc(x: int) -> Sizing_Dimension {
return {.FIXED, x, x}
}
+/*FRACTIONAL :: proc(x, y: f64) -> Sizing_Dimension {
+ return {.FRACTIONAL, x, x}
+}*/
u8_clamp :: proc(input: f32) -> u8 {
mult := input*255