package main import "../lib/oui" import "core:strings" import "core:fmt" 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 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: cstring, font: rl.Font, font_size: i32, alignment: Text_Alignment, } button_callback :: proc(ctxt: ^oui.Context, item: ^Item, event: Call) -> int { data := cast(^Data_Button) item.handle #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(c0) data := oui.alloc_typed(c0, item, Data_Panel) data.subtype = .Panel data.color = color 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(c0) item.layout_size = {width, 35} item.callback = button_callback data := oui.alloc_typed(c0, item, Data_Button) data.subtype = .Button data.text = text data.selected = selected return item } Text_Alignment :: enum int { // Techically called justification, but text_alignment is more self-explanatory. Left, Right, Center, } label :: proc(text: string, font: rl.Font, alignment: Text_Alignment = .Left) -> ^Item { item := oui.item_make(c0) data := oui.alloc_typed(c0, item, Data_Label) data.subtype = .Label data.text = strings.unsafe_string_to_cstring(text) data.font = font data.alignment = alignment return item } // 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) } } ui_draw :: proc(item: ^oui.Item) { head := cast(^Data_Head) item.handle rect := item.bounds //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: 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); } }