aboutsummaryrefslogtreecommitdiff
path: root/src/ui_implementation.odin
diff options
context:
space:
mode:
authorSan Jacobs2023-10-14 14:03:07 +0200
committerSan Jacobs2023-10-14 14:03:07 +0200
commitfca6955979f4791acb016ef5da86fed1013b524e (patch)
tree860d3d70b9fa0ae404833c536097976b2b847329 /src/ui_implementation.odin
parentfd262c11c3c0f627927ecc7fd5115899033018bb (diff)
downloadsatscalc-fca6955979f4791acb016ef5da86fed1013b524e.tar.gz
satscalc-fca6955979f4791acb016ef5da86fed1013b524e.tar.bz2
satscalc-fca6955979f4791acb016ef5da86fed1013b524e.zip
There are themes! There is button with text! There is increased comfy!
Diffstat (limited to 'src/ui_implementation.odin')
-rw-r--r--src/ui_implementation.odin71
1 files changed, 51 insertions, 20 deletions
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