aboutsummaryrefslogtreecommitdiff
path: root/src/ui_implementation.odin
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui_implementation.odin')
-rw-r--r--src/ui_implementation.odin130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/ui_implementation.odin b/src/ui_implementation.odin
new file mode 100644
index 0000000..4842a76
--- /dev/null
+++ b/src/ui_implementation.odin
@@ -0,0 +1,130 @@
+package main
+
+import "../lib/oui"
+import rl "vendor:raylib"
+
+
+
+BGCOLOR : rl.Color : {30, 30, 30, 255}
+PBGCOLOR : rl.Color : {40, 40, 40, 255}
+
+DAY_HEIGHT :: 35
+TIMELINE_START :: 175
+TIMELINE_END :: -85
+
+
+
+Item :: oui.Item
+Call :: oui.Call
+
+Data_Element :: enum int {
+ Panel,
+ Button,
+ Label,
+ Text_Input,
+ Timeblock,
+// ...
+}
+
+Data_Head :: struct {
+ subtype: Data_Element,
+}
+
+Data_Panel :: struct {
+ using _: Data_Head,
+ color: rl.Color,
+}
+
+Data_Button :: struct {
+ using _: Data_Head,
+ text: string,
+ selected: bool,
+}
+
+Data_Label :: struct {
+ using _: Data_Head,
+ text: string,
+ alignment: Text_Alignment,
+}
+
+button_callback :: proc(item: Item, event: Call) -> int {
+ data := cast(^Data_Button) oui.get_handle(item)
+
+ #partial switch event {
+ case .Cursor_Handle:
+ //return int(Cursor_Type.Hand)
+ }
+
+ return -1
+}
+
+panel :: proc(color : rl.Color = rl.RED) -> Item {
+ item := oui.item_make()
+
+ data := oui.alloc_typed(item, Data_Panel)
+ data.subtype = .Panel
+ data.color = color
+
+ return item
+}
+
+button :: proc(text: string, width: int, selected := false) -> Item {
+ item := oui.item_make()
+ oui.set_size(item, width, 35)
+ oui.set_callback(item, button_callback)
+
+ data := oui.alloc_typed(item, Data_Button)
+ data.subtype = .Button
+ data.text = text
+ data.selected = selected
+
+ return item
+}
+
+Text_Alignment :: enum int {
+ Left,
+ Right,
+}
+label :: proc(text: string, font: rl.Font, alignment: Text_Alignment = .Left) -> Item {
+ item := oui.item_make()
+
+ data := oui.alloc_typed(item, Data_Label)
+ data.subtype = .Label
+ data.text = text
+ data.alignment = alignment
+
+ return item
+}
+
+// recursive loop
+ui_draw_children :: proc(item: oui.Item) {
+ list := oui.children_sorted(item)
+ for kid in list {
+ ui_draw(kid)
+ }
+}
+
+ui_draw :: proc(item: oui.Item) {
+ head := cast(^Data_Head) oui.get_handle(item)
+ rect := oui.get_rect(item)
+
+ //fmt.println(rect, head, item)
+
+ if head == nil {
+ ui_draw_children(item)
+ return
+ }
+
+ #partial switch head.subtype {
+ //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)
+ case .Panel:
+ subtyped := cast(^Data_Panel) head
+ rl.DrawRectangle(i32(rect.l), i32(rect.t), i32(rect.r-rect.l), i32(rect.b-rect.t), subtyped.color)
+ ui_draw_children(item)
+ case .Label:
+
+ }
+} \ No newline at end of file