aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.odin53
-rw-r--r--src/ui_implementation.odin59
2 files changed, 75 insertions, 37 deletions
diff --git a/src/main.odin b/src/main.odin
index ac3f693..79b1a1e 100644
--- a/src/main.odin
+++ b/src/main.odin
@@ -13,6 +13,8 @@ font : rl.Font
big_font : rl.Font
small_font : rl.Font
+c0 : ^oui.Context
+
main :: proc() {
// TODO: Replace the dynamic array of Workday-pointers with
@@ -87,9 +89,10 @@ main :: proc() {
// oui stuff
- c0 := oui.context_create(1028, 1028 * 8)
+ c0 = new(oui.Context)
+ defer free(c0)
+ oui.context_init(c0, 1028, 1028 * 8)
defer oui.context_destroy(c0)
- oui.context_make_current(c0)
// Setting up the timelines
@@ -130,8 +133,8 @@ main :: proc() {
// bottom left of the screen.
mousePosition: = rl.GetMousePosition()
- oui.set_cursor(int(mousePosition.x), int(mousePosition.y))
- oui.set_button(.Left, rl.IsMouseButtonPressed(rl.MouseButton(0)))
+ oui.set_cursor(c0, int(mousePosition.x), int(mousePosition.y))
+ oui.set_button(c0, .Left, rl.IsMouseButtonPressed(rl.MouseButton(0)))
// DRAW
// ------------------------------------------
@@ -141,26 +144,42 @@ main :: proc() {
when true {
// hotloop
- oui.begin_layout()
+ oui.begin_layout(c0)
master_container := panel()
- oui.set_layout(master_container, .Absolute)
- oui.set_size(master_container, int(GetScreenWidth()), int(GetScreenHeight()))
+ master_container.id = oui.push_id(c0, "big_mr_boss_man")
+ master_container.layout = .Absolute
+ master_container.layout_size = {int(GetScreenWidth()), int(GetScreenHeight())}
- top_bar := panel(BGCOLOR)
- oui.set_cut(master_container, .Top)
- oui.set_height(top_bar, 30)
- oui.set_margin(top_bar, 6)
- oui.item_insert(master_container, top_bar)
+ {
+ top_bar := panel_line(master_container, BGCOLOR, 30)
+ top_bar.id = oui.push_id(c0, "small_boie")
+ defer oui.pop_id(c0)
+ top_bar.layout_margin = 6
date_label := label("Date", font, .Left)
oui.item_insert(top_bar, date_label)
+ }
+ {
bottom_bar := panel(PBGCOLOR)
- oui.set_cut(master_container, .Bottom)
- oui.set_height(bottom_bar, 50)
+ bottom_bar.id = oui.push_id(c0, "not_small_boie")
+ defer oui.pop_id(c0)
+ bottom_bar.layout_cut_children = .Left
+ master_container.layout_cut_children = .Bottom
+ bottom_bar.layout_size.y = 50
oui.item_insert(master_container, bottom_bar)
+ }
+
+ {
+ middle_section := panel(WBGCOLOR)
+ 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)
+ }
+
@@ -174,11 +193,11 @@ when true {
oui.item_insert(a_panel, a_button)*/
- oui.end_layout()
+ oui.end_layout(c0)
- ui_draw(0)
+ ui_draw(master_container)
// DRAW HERE OR BELOW
- oui.process()
+ oui.process(c0)
} else {
DrawTextEx(font, "Date", {20, 8}, font_size, 0, RAYWHITE);
diff --git a/src/ui_implementation.odin b/src/ui_implementation.odin
index 27bcc65..cf38cc3 100644
--- a/src/ui_implementation.odin
+++ b/src/ui_implementation.odin
@@ -8,6 +8,7 @@ import rl "vendor:raylib"
BGCOLOR : rl.Color : {30, 30, 30, 255}
+WBGCOLOR : rl.Color : {20, 25, 25, 255}
PBGCOLOR : rl.Color : {40, 40, 40, 255}
DAY_HEIGHT :: 35
@@ -51,8 +52,8 @@ Data_Label :: struct {
alignment: Text_Alignment,
}
-button_callback :: proc(item: Item, event: Call) -> int {
- data := cast(^Data_Button) oui.get_handle(item)
+button_callback :: proc(ctxt: ^oui.Context, item: ^Item, event: Call) -> int {
+ data := cast(^Data_Button) item.handle
#partial switch event {
case .Cursor_Handle:
@@ -62,22 +63,39 @@ button_callback :: proc(item: Item, event: Call) -> int {
return -1
}
-panel :: proc(color : rl.Color = rl.RED) -> Item {
- item := oui.item_make()
+panel :: proc(color : rl.Color = rl.RED) -> ^Item {
+ item := oui.item_make(c0)
- data := oui.alloc_typed(item, Data_Panel)
+ data := oui.alloc_typed(c0, item, Data_Panel)
data.subtype = .Panel
data.color = color
- return item
+ return item
+}
+
+panel_line :: proc(parent: ^Item, color : rl.Color, height: int = 40) -> (item: ^Item) {
+ item = oui.item_make(c0)
+ item.layout_cut_children = .Left
+ item.layout_size.y = height
+
+ old := parent.layout_cut_children
+ parent.layout_cut_children = .Top
+ oui.item_insert(parent, item)
+ parent.layout_cut_children = old
+
+ data := oui.alloc_typed(c0, item, Data_Panel)
+ data.subtype = .Panel
+ data.color = color
+
+ return
}
-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)
+button :: proc(text: string, width: int, selected := false) -> ^Item {
+ item := oui.item_make(c0)
+ item.layout_size = {width, 35}
+ item.callback = button_callback
- data := oui.alloc_typed(item, Data_Button)
+ data := oui.alloc_typed(c0, item, Data_Button)
data.subtype = .Button
data.text = text
data.selected = selected
@@ -91,10 +109,10 @@ Text_Alignment :: enum int {
Right,
Center,
}
-label :: proc(text: string, font: rl.Font, alignment: Text_Alignment = .Left) -> Item {
- item := oui.item_make()
+label :: proc(text: string, font: rl.Font, alignment: Text_Alignment = .Left) -> ^Item {
+ item := oui.item_make(c0)
- data := oui.alloc_typed(item, Data_Label)
+ data := oui.alloc_typed(c0, item, Data_Label)
data.subtype = .Label
data.text = strings.unsafe_string_to_cstring(text)
data.font = font
@@ -104,16 +122,17 @@ label :: proc(text: string, font: rl.Font, alignment: Text_Alignment = .Left) ->
}
// recursive loop
-ui_draw_children :: proc(item: oui.Item) {
- list := oui.children_sorted(item)
+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)
}
}
-ui_draw :: proc(item: oui.Item) {
- head := cast(^Data_Head) oui.get_handle(item)
- rect := oui.get_rect(item)
+ui_draw :: proc(item: ^oui.Item) {
+ head := cast(^Data_Head) item.handle
+ rect := item.bounds
//fmt.println(rect, head, item)
@@ -132,7 +151,7 @@ ui_draw :: proc(item: oui.Item) {
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) oui.get_handle(item)
+ data := cast(^Data_Label) item.handle
horizontal_position : f32