aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.odin22
-rw-r--r--src/ui_implementation.odin71
2 files changed, 68 insertions, 25 deletions
diff --git a/src/main.odin b/src/main.odin
index 79b1a1e..fcb425d 100644
--- a/src/main.odin
+++ b/src/main.odin
@@ -111,6 +111,8 @@ main :: proc() {
for !WindowShouldClose() { // MAIN LOOP ---- MAIN LOOP ---- MAIN LOOP ---- MAIN LOOP
+ free_all(context.temp_allocator)
+
if IsWindowResized() {
height = GetScreenHeight()
width = GetScreenWidth()
@@ -140,7 +142,7 @@ main :: proc() {
// ------------------------------------------
BeginDrawing()
- ClearBackground(BGCOLOR)
+ ClearBackground(rl.RED)
when true {
// hotloop
@@ -153,7 +155,7 @@ when true {
master_container.layout_size = {int(GetScreenWidth()), int(GetScreenHeight())}
{
- top_bar := panel_line(master_container, BGCOLOR, 30)
+ top_bar := panel_line(master_container, theme.background_top, 30)
top_bar.id = oui.push_id(c0, "small_boie")
defer oui.pop_id(c0)
top_bar.layout_margin = 6
@@ -161,9 +163,9 @@ when true {
date_label := label("Date", font, .Left)
oui.item_insert(top_bar, date_label)
}
-
+
{
- bottom_bar := panel(PBGCOLOR)
+ bottom_bar := panel(theme.background_bottom)
bottom_bar.id = oui.push_id(c0, "not_small_boie")
defer oui.pop_id(c0)
bottom_bar.layout_cut_children = .Left
@@ -173,11 +175,21 @@ when true {
}
{
- middle_section := panel(WBGCOLOR)
+ middle_section := panel(theme.background)
middle_section.id = oui.push_id(c0, "middle_section")
defer oui.pop_id(c0)
master_container.layout_cut_children = .Fill
oui.item_insert(master_container, middle_section)
+
+ {
+ line := panel_line(middle_section, theme.background, 40)
+ line.id = oui.push_id(c0, "a_line")
+ defer oui.pop_id(c0)
+ {
+ a_button := button("Testor", 100)
+ oui.item_insert(line, a_button)
+ }
+ }
}
diff --git a/src/ui_implementation.odin b/src/ui_implementation.odin
index cf38cc3..3e9b913 100644
--- a/src/ui_implementation.odin
+++ b/src/ui_implementation.odin
@@ -6,10 +6,21 @@ import "core:fmt"
import rl "vendor:raylib"
+Theme :: struct {
+ background: rl.Color,
+ background_top: rl.Color,
+ background_bottom: rl.Color,
+ button: rl.Color,
+ text: rl.Color,
+}
-BGCOLOR : rl.Color : {30, 30, 30, 255}
-WBGCOLOR : rl.Color : {20, 25, 25, 255}
-PBGCOLOR : rl.Color : {40, 40, 40, 255}
+theme : Theme = {
+ background = {20, 25, 25, 255},
+ background_top = {30, 35, 35, 255},
+ background_bottom = {40, 40, 40, 255},
+ button = {80, 80, 80, 255},
+ text = rl.RAYWHITE,
+}
DAY_HEIGHT :: 35
TIMELINE_START :: 175
@@ -46,7 +57,7 @@ Data_Button :: struct {
Data_Label :: struct {
using _: Data_Head,
- text: cstring,
+ text: string,
font: rl.Font,
font_size: i32,
alignment: Text_Alignment,
@@ -114,17 +125,39 @@ label :: proc(text: string, font: rl.Font, alignment: Text_Alignment = .Left) ->
data := oui.alloc_typed(c0, item, Data_Label)
data.subtype = .Label
- data.text = strings.unsafe_string_to_cstring(text)
+ data.text = text
data.font = font
data.alignment = alignment
return item
}
+calculate_text_alignment :: proc(text: cstring, font: rl.Font, alignment: Text_Alignment, rect: oui.RectI) -> (output: [2]int) {
+
+ measurement := rl.MeasureTextEx(font, text, f32(font.baseSize), 0.0)
+
+ switch alignment {
+ case .Left:
+ output.x = rect.l
+ case .Right:
+ output.x = rect.r - int(measurement.x)
+ case .Center:
+ output.x = (rect.l+(rect.r-rect.l)/2) - int(measurement.x/2)
+ }
+
+ output.y = (rect.t+(rect.b-rect.t)/2) - int(measurement.y/2)
+
+ return
+}
+i2f :: proc "contextless" (input: [2]int) -> rl.Vector2 {
+ return { f32(input.x), f32(input.y) }
+}
+f2i :: proc "contextless" (input: [2]f32) -> [2]int {
+ return { int(input.x), int(input.y) }
+}
// recursive loop
ui_draw_children :: proc(item: ^oui.Item) {
list := oui.children_list(c0, item)
- if len(list)>0 do fmt.println(list[len(list)-1])
for kid in list {
ui_draw(kid)
}
@@ -145,25 +178,23 @@ ui_draw :: proc(item: ^oui.Item) {
//case .Panel_Root:
// ... render any type of item
case .Button:
- rl.DrawRectangle(i32(rect.l), i32(rect.t), i32(rect.r-rect.l), i32(rect.b-rect.t), PBGCOLOR)
+ data := cast(^Data_Button) item.handle
+ rl.DrawRectangle(i32(rect.l), i32(rect.t), i32(rect.r-rect.l), i32(rect.b-rect.t), theme.button)
+
+ text := strings.clone_to_cstring(data.text, context.temp_allocator)
+ position := calculate_text_alignment(text, font, .Center, rect)
+
+ rl.DrawTextEx(font, text, i2f(position), f32(font.baseSize), 0.0, theme.text);
+
case .Panel:
data := cast(^Data_Panel) head
rl.DrawRectangle(i32(rect.l), i32(rect.t), i32(rect.r-rect.l), i32(rect.b-rect.t), data.color)
ui_draw_children(item)
case .Label:
data := cast(^Data_Label) item.handle
-
- horizontal_position : f32
-
- switch data.alignment {
- case .Left:
- horizontal_position = f32(rect.l)
- case .Right:
- horizontal_position = f32(rect.l) - rl.MeasureTextEx(data.font, data.text, f32(data.font.baseSize), 0.0).x
- case .Center:
- horizontal_position = f32(rect.l) - f32(int((rl.MeasureTextEx(data.font, data.text, f32(data.font.baseSize), 0.0).x)/2))
- }
-
- rl.DrawTextEx(data.font, data.text, { horizontal_position, f32(rect.t) }, f32(data.font.baseSize), 0.0, rl.RAYWHITE);
+ text := strings.clone_to_cstring(data.text, context.temp_allocator)
+ position := calculate_text_alignment(text, data.font, data.alignment, rect)
+
+ rl.DrawTextEx(data.font, text, i2f(position), f32(data.font.baseSize), 0.0, theme.text);
}
} \ No newline at end of file