1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
package main
import "../lib/oui"
import "core:strings"
import "core:fmt"
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,
font: rl.Font,
font_size: i32,
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,
Center
}
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.font_size = font.baseSize // This should not be necesssary
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:
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) oui.get_handle(item)
// For some reason, data.font.baseSize == 0 here. It doesn't outside of this function. Dunno why.
font_height := f32(data.font_size)
rl.DrawTextEx(data.font, strings.unsafe_string_to_cstring(data.text), { 0, 0 }, font_height, 0.0, rl.RAYWHITE);
//rl.DrawTextEx(rl.GetFontDefault(), strings.unsafe_string_to_cstring(data.text), { 0, 0 }, 40, 0, rl.WHITE);
//rl.DrawFPS(0, 0)
//fmt.println(font_height)
}
}
|