From fd262c11c3c0f627927ecc7fd5115899033018bb Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Sat, 14 Oct 2023 13:11:39 +0200 Subject: New OUI version --- src/ui_implementation.odin | 59 ++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 20 deletions(-) (limited to 'src/ui_implementation.odin') 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 -- cgit v1.2.1