aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.odin2
-rw-r--r--src/ui_implementation.odin23
2 files changed, 17 insertions, 8 deletions
diff --git a/src/main.odin b/src/main.odin
index 1ae20c6..e06639f 100644
--- a/src/main.odin
+++ b/src/main.odin
@@ -152,7 +152,7 @@ when true {
oui.set_height(top_bar, 30)
oui.item_insert(master_container, top_bar)
- date_label := label("Date abcg", font)
+ date_label := label("Date", font)
oui.item_insert(top_bar, date_label)
bottom_bar := panel(PBGCOLOR)
diff --git a/src/ui_implementation.odin b/src/ui_implementation.odin
index 5aa294c..4706728 100644
--- a/src/ui_implementation.odin
+++ b/src/ui_implementation.odin
@@ -45,7 +45,7 @@ Data_Button :: struct {
Data_Label :: struct {
using _: Data_Head,
- text: string,
+ text: cstring,
font: rl.Font,
font_size: i32,
alignment: Text_Alignment,
@@ -86,6 +86,7 @@ button :: proc(text: string, width: int, selected := false) -> Item {
}
Text_Alignment :: enum int {
+ // Techically called justification, but text_alignment is more self-explanatory.
Left,
Right,
Center,
@@ -95,7 +96,7 @@ label :: proc(text: string, font: rl.Font, alignment: Text_Alignment = .Left) ->
data := oui.alloc_typed(item, Data_Label)
data.subtype = .Label
- data.text = text
+ data.text = strings.unsafe_string_to_cstring(text)
data.font = font
data.alignment = alignment
@@ -132,10 +133,18 @@ ui_draw :: proc(item: oui.Item) {
ui_draw_children(item)
case .Label:
data := cast(^Data_Label) oui.get_handle(item)
-
- rl.DrawTextEx(data.font, strings.unsafe_string_to_cstring(data.text), { 0, 0 }, f32(data.font.baseSize), 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)
+
+ 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+50) }, f32(data.font.baseSize), 0.0, rl.RAYWHITE);
}
} \ No newline at end of file