aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSan Jacobs2023-10-13 12:00:49 +0200
committerSan Jacobs2023-10-13 12:00:49 +0200
commite77dec086f94da480af8c42bec6cac8e873a6931 (patch)
tree79aca74dfb34a00658c1d23af11822a4e26b4682
parent40687c8c5624dda5bd6b9c6b0e281fb079755040 (diff)
downloadsatscalc-e77dec086f94da480af8c42bec6cac8e873a6931.tar.gz
satscalc-e77dec086f94da480af8c42bec6cac8e873a6931.tar.bz2
satscalc-e77dec086f94da480af8c42bec6cac8e873a6931.zip
Progressed ability to write text using new oui system
-rw-r--r--src/main.odin16
-rw-r--r--src/ui_implementation.odin20
2 files changed, 27 insertions, 9 deletions
diff --git a/src/main.odin b/src/main.odin
index 25cdf22..96a56d5 100644
--- a/src/main.odin
+++ b/src/main.odin
@@ -7,6 +7,8 @@ import "core:slice"
import "core:strings"
import rl "vendor:raylib"
+UBUNTU_MONO := #load("../res/UbuntuMono-Regular.ttf")
+
main :: proc() {
// TODO: Replace the dynamic array of Workday-pointers with
@@ -68,6 +70,7 @@ main :: proc() {
// Loading fonts - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
font_size :: 18
+ //font: Font = LoadFontFromMemory("ttf", &UBUNTU_MONO, i32(len(UBUNTU_MONO)), font_size, nil, 0)
font: Font = LoadFontEx("res/UbuntuMono-Regular.ttf", font_size, nil, 0)
defer UnloadFont(font)
@@ -139,20 +142,21 @@ when true {
master_container := panel()
- oui.set_layout(master_container, .Absolute)
- oui.set_size(master_container, int(GetScreenWidth()), int(GetScreenHeight()))
+ oui.set_layout(master_container, .Absolute)
+ oui.set_size(master_container, int(GetScreenWidth()), int(GetScreenHeight()))
top_bar := panel(BGCOLOR)
oui.set_cut(master_container, .Top)
oui.set_height(top_bar, 30)
oui.item_insert(master_container, top_bar)
- date_label := label("Date", font)
+ date_label := label("Date abcg", big_font)
+ oui.item_insert(top_bar, date_label)
bottom_bar := panel(PBGCOLOR)
- oui.set_cut(master_container, .Bottom)
- oui.set_height(bottom_bar, 50)
- oui.item_insert(master_container, bottom_bar)
+ oui.set_cut(master_container, .Bottom)
+ oui.set_height(bottom_bar, 50)
+ oui.item_insert(master_container, bottom_bar)
diff --git a/src/ui_implementation.odin b/src/ui_implementation.odin
index 4842a76..7c5f9e3 100644
--- a/src/ui_implementation.odin
+++ b/src/ui_implementation.odin
@@ -1,6 +1,8 @@
package main
import "../lib/oui"
+import "core:strings"
+import "core:fmt"
import rl "vendor:raylib"
@@ -44,6 +46,8 @@ Data_Button :: struct {
Data_Label :: struct {
using _: Data_Head,
text: string,
+ font: rl.Font,
+ font_size: i32,
alignment: Text_Alignment,
}
@@ -84,6 +88,7 @@ button :: proc(text: string, width: int, selected := false) -> Item {
Text_Alignment :: enum int {
Left,
Right,
+ Center
}
label :: proc(text: string, font: rl.Font, alignment: Text_Alignment = .Left) -> Item {
item := oui.item_make()
@@ -91,6 +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.font_size = font.baseSize // This should not be necesssary
data.alignment = alignment
return item
@@ -121,10 +127,18 @@ ui_draw :: proc(item: oui.Item) {
case .Button:
rl.DrawRectangle(i32(rect.l), i32(rect.t), i32(rect.r-rect.l), i32(rect.b-rect.t), PBGCOLOR)
case .Panel:
- subtyped := cast(^Data_Panel) head
- rl.DrawRectangle(i32(rect.l), i32(rect.t), i32(rect.r-rect.l), i32(rect.b-rect.t), subtyped.color)
+ 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)
}
} \ No newline at end of file