From a7c2d13bcca784350d851b665b8a19697e113b34 Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Thu, 17 Aug 2023 01:48:00 +0200 Subject: Screw everything, we do oui now --- src/main.odin | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 125 insertions(+), 2 deletions(-) (limited to 'src/main.odin') diff --git a/src/main.odin b/src/main.odin index bcbaeec..17517c7 100644 --- a/src/main.odin +++ b/src/main.odin @@ -1,4 +1,5 @@ package main +import "../lib/oui" import "core:fmt" import "core:math" @@ -78,6 +79,11 @@ main :: proc() { big_font: Font = LoadFontEx("res/UbuntuMono-Regular.ttf", big_font_size, nil, 0) defer UnloadFont(big_font) + // oui stuff + + c0 := oui.context_create(1028, 1028 * 8) + defer oui.context_destroy(c0) + oui.context_make_current(c0) // Setting up the timelines @@ -116,13 +122,42 @@ main :: proc() { // clicking will put a white border around the timeblock, // and display information about the block in the // bottom left of the screen. - + + mousePosition: = rl.GetMousePosition() + oui.set_cursor(int(mousePosition.x), int(mousePosition.y)) + oui.set_button(.Left, rl.IsMouseButtonPressed(rl.MouseButton(0))) // DRAW // ------------------------------------------ BeginDrawing() ClearBackground(BGCOLOR) + + // hotloop + oui.begin_layout() + + a_panel := panel() + oui.set_layout(a_panel, .Absolute) + oui.set_size(a_panel, 200, 200) + oui.set_offset(a_panel, 20, 20) + + a_button := button("Testerino", 50) + if oui.latest_clicked() { + fmt.println("CLICKO BOIO") + } + oui.set_cut(a_panel, .Left) + oui.set_height(a_button, 50) + oui.set_offset(a_button, 20, 20) + + oui.item_insert(a_panel, a_button) + + oui.end_layout() + + ui_draw(0) + // DRAW HERE OR BELOW + oui.process() + + /* DrawTextEx(font, "Date", {20, 8}, font_size, 0, RAYWHITE); DrawTextEx(font, "Calltime", {105, 8}, font_size, 0, RAYWHITE); DrawTextEx(font, "Wraptime", {f32(width)-83, 8}, font_size, 0, RAYWHITE); @@ -176,7 +211,7 @@ main :: proc() { DrawTextEx(small_font, total_sum, {f32(width)-120, f32(height)-43}, small_font_size, 0, RAYWHITE); DrawTextEx(big_font, inc_soc, {f32(width)-120, f32(height)-29}, big_font_size, 0, RAYWHITE); - + */ EndDrawing() } } @@ -187,3 +222,91 @@ 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, + Text_Input, + Timeblock, +// ... +} + +Data_Head :: struct { + subtype: Data_Element, +} + +Data_Panel :: struct { + using _: Data_Head, +} + +Data_Button :: struct { + using _: Data_Head, + text: string, + selected: bool, +} + +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() -> Item { + item := oui.item_make() + + data := oui.alloc_typed(item, Data_Panel) + data.subtype = .Panel + + 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 +} + +// 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: + rl.DrawRectangle(i32(rect.l), i32(rect.t), i32(rect.r-rect.l), i32(rect.b-rect.t), rl.RED) + ui_draw_children(item) + } +} \ No newline at end of file -- cgit v1.2.1 From 408c473839fcc8bdb0f7ac843031507ae99e33f0 Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Thu, 17 Aug 2023 02:35:08 +0200 Subject: Made it easier to switch back to old unfinished UI for reference --- src/main.odin | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/main.odin') diff --git a/src/main.odin b/src/main.odin index 17517c7..1657c0f 100644 --- a/src/main.odin +++ b/src/main.odin @@ -133,6 +133,7 @@ main :: proc() { ClearBackground(BGCOLOR) +when true { // hotloop oui.begin_layout() @@ -157,7 +158,7 @@ main :: proc() { // DRAW HERE OR BELOW oui.process() - /* +} else { DrawTextEx(font, "Date", {20, 8}, font_size, 0, RAYWHITE); DrawTextEx(font, "Calltime", {105, 8}, font_size, 0, RAYWHITE); DrawTextEx(font, "Wraptime", {f32(width)-83, 8}, font_size, 0, RAYWHITE); @@ -211,7 +212,7 @@ main :: proc() { DrawTextEx(small_font, total_sum, {f32(width)-120, f32(height)-43}, small_font_size, 0, RAYWHITE); DrawTextEx(big_font, inc_soc, {f32(width)-120, f32(height)-29}, big_font_size, 0, RAYWHITE); - */ +} EndDrawing() } } -- cgit v1.2.1 From 40687c8c5624dda5bd6b9c6b0e281fb079755040 Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Sat, 26 Aug 2023 12:57:44 +0200 Subject: WIP OUI stuff --- src/main.odin | 120 ++++++++++------------------------------------------------ 1 file changed, 20 insertions(+), 100 deletions(-) (limited to 'src/main.odin') diff --git a/src/main.odin b/src/main.odin index 1657c0f..25cdf22 100644 --- a/src/main.odin +++ b/src/main.odin @@ -137,12 +137,26 @@ when true { // hotloop oui.begin_layout() - a_panel := panel() - oui.set_layout(a_panel, .Absolute) - oui.set_size(a_panel, 200, 200) - oui.set_offset(a_panel, 20, 20) - a_button := button("Testerino", 50) + master_container := panel() + 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) + + bottom_bar := panel(PBGCOLOR) + oui.set_cut(master_container, .Bottom) + oui.set_height(bottom_bar, 50) + oui.item_insert(master_container, bottom_bar) + + + +/* a_button := button("Testerino", 50) if oui.latest_clicked() { fmt.println("CLICKO BOIO") } @@ -150,7 +164,7 @@ when true { oui.set_height(a_button, 50) oui.set_offset(a_button, 20, 20) - oui.item_insert(a_panel, a_button) + oui.item_insert(a_panel, a_button)*/ oui.end_layout() @@ -217,97 +231,3 @@ when true { } } -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, - Text_Input, - Timeblock, -// ... -} - -Data_Head :: struct { - subtype: Data_Element, -} - -Data_Panel :: struct { - using _: Data_Head, -} - -Data_Button :: struct { - using _: Data_Head, - text: string, - selected: bool, -} - -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() -> Item { - item := oui.item_make() - - data := oui.alloc_typed(item, Data_Panel) - data.subtype = .Panel - - 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 -} - -// 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: - rl.DrawRectangle(i32(rect.l), i32(rect.t), i32(rect.r-rect.l), i32(rect.b-rect.t), rl.RED) - ui_draw_children(item) - } -} \ No newline at end of file -- cgit v1.2.1 From e77dec086f94da480af8c42bec6cac8e873a6931 Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Fri, 13 Oct 2023 12:00:49 +0200 Subject: Progressed ability to write text using new oui system --- src/main.odin | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/main.odin') 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) -- cgit v1.2.1 From a8ae49ea33b9575597012cb5b3927583184c4c73 Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Fri, 13 Oct 2023 18:47:06 +0200 Subject: Fonts are now embedded in the program --- src/main.odin | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/main.odin') diff --git a/src/main.odin b/src/main.odin index 96a56d5..1ae20c6 100644 --- a/src/main.odin +++ b/src/main.odin @@ -70,16 +70,18 @@ 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) + font: Font = LoadFontFromMemory(".ttf", raw_data(UBUNTU_MONO), i32(len(UBUNTU_MONO)), font_size, nil, 0) + //font: Font = LoadFontEx("res/UbuntuMono-Regular.ttf", font_size, nil, 0) defer UnloadFont(font) small_font_size :: 14 - small_font: Font = LoadFontEx("res/UbuntuMono-Regular.ttf", small_font_size, nil, 0) + small_font: Font = LoadFontFromMemory(".ttf", raw_data(UBUNTU_MONO), i32(len(UBUNTU_MONO)), small_font_size, nil, 0) + //small_font: Font = LoadFontEx("res/UbuntuMono-Regular.ttf", small_font_size, nil, 0) defer UnloadFont(small_font) big_font_size :: 24 - big_font: Font = LoadFontEx("res/UbuntuMono-Regular.ttf", big_font_size, nil, 0) + big_font: Font = LoadFontFromMemory(".ttf", raw_data(UBUNTU_MONO), i32(len(UBUNTU_MONO)), big_font_size, nil, 0) + //big_font: Font = LoadFontEx("res/UbuntuMono-Regular.ttf", big_font_size, nil, 0) defer UnloadFont(big_font) // oui stuff @@ -150,7 +152,7 @@ when true { oui.set_height(top_bar, 30) oui.item_insert(master_container, top_bar) - date_label := label("Date abcg", big_font) + date_label := label("Date abcg", font) oui.item_insert(top_bar, date_label) bottom_bar := panel(PBGCOLOR) @@ -234,4 +236,3 @@ when true { EndDrawing() } } - -- cgit v1.2.1 From 1197fa1b73bb60dd7bbc67d046e5f8172c3dcfab Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Fri, 13 Oct 2023 19:11:55 +0200 Subject: Added text justification setting --- src/main.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main.odin') 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) -- cgit v1.2.1 From 56b701ded16bad6f4599be61263c1574d5297288 Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Sat, 14 Oct 2023 12:14:02 +0200 Subject: Fonts are now in the global scope --- src/main.odin | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/main.odin') diff --git a/src/main.odin b/src/main.odin index e06639f..9689598 100644 --- a/src/main.odin +++ b/src/main.odin @@ -9,6 +9,10 @@ import rl "vendor:raylib" UBUNTU_MONO := #load("../res/UbuntuMono-Regular.ttf") +font : rl.Font +big_font : rl.Font +small_font : rl.Font + main :: proc() { // TODO: Replace the dynamic array of Workday-pointers with @@ -70,18 +74,15 @@ main :: proc() { // Loading fonts - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - font_size :: 18 - font: Font = LoadFontFromMemory(".ttf", raw_data(UBUNTU_MONO), i32(len(UBUNTU_MONO)), font_size, nil, 0) - //font: Font = LoadFontEx("res/UbuntuMono-Regular.ttf", font_size, nil, 0) + font = LoadFontFromMemory(".ttf", raw_data(UBUNTU_MONO), i32(len(UBUNTU_MONO)), font_size, nil, 0) defer UnloadFont(font) small_font_size :: 14 - small_font: Font = LoadFontFromMemory(".ttf", raw_data(UBUNTU_MONO), i32(len(UBUNTU_MONO)), small_font_size, nil, 0) - //small_font: Font = LoadFontEx("res/UbuntuMono-Regular.ttf", small_font_size, nil, 0) + small_font = LoadFontFromMemory(".ttf", raw_data(UBUNTU_MONO), i32(len(UBUNTU_MONO)), small_font_size, nil, 0) defer UnloadFont(small_font) big_font_size :: 24 - big_font: Font = LoadFontFromMemory(".ttf", raw_data(UBUNTU_MONO), i32(len(UBUNTU_MONO)), big_font_size, nil, 0) - //big_font: Font = LoadFontEx("res/UbuntuMono-Regular.ttf", big_font_size, nil, 0) + big_font = LoadFontFromMemory(".ttf", raw_data(UBUNTU_MONO), i32(len(UBUNTU_MONO)), big_font_size, nil, 0) defer UnloadFont(big_font) // oui stuff -- cgit v1.2.1 From d6cb7ac37d86d0c4ee03982813b94275fd62016a Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Sat, 14 Oct 2023 12:18:23 +0200 Subject: Added cute padding to text --- src/main.odin | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/main.odin') diff --git a/src/main.odin b/src/main.odin index 9689598..ac3f693 100644 --- a/src/main.odin +++ b/src/main.odin @@ -151,9 +151,10 @@ when true { top_bar := panel(BGCOLOR) oui.set_cut(master_container, .Top) oui.set_height(top_bar, 30) + oui.set_margin(top_bar, 6) oui.item_insert(master_container, top_bar) - date_label := label("Date", font) + date_label := label("Date", font, .Left) oui.item_insert(top_bar, date_label) bottom_bar := panel(PBGCOLOR) -- cgit v1.2.1 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/main.odin | 53 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 17 deletions(-) (limited to 'src/main.odin') diff --git a/src/main.odin b/src/main.odin index ac3f693..79b1a1e 100644 --- a/src/main.odin +++ b/src/main.odin @@ -13,6 +13,8 @@ font : rl.Font big_font : rl.Font small_font : rl.Font +c0 : ^oui.Context + main :: proc() { // TODO: Replace the dynamic array of Workday-pointers with @@ -87,9 +89,10 @@ main :: proc() { // oui stuff - c0 := oui.context_create(1028, 1028 * 8) + c0 = new(oui.Context) + defer free(c0) + oui.context_init(c0, 1028, 1028 * 8) defer oui.context_destroy(c0) - oui.context_make_current(c0) // Setting up the timelines @@ -130,8 +133,8 @@ main :: proc() { // bottom left of the screen. mousePosition: = rl.GetMousePosition() - oui.set_cursor(int(mousePosition.x), int(mousePosition.y)) - oui.set_button(.Left, rl.IsMouseButtonPressed(rl.MouseButton(0))) + oui.set_cursor(c0, int(mousePosition.x), int(mousePosition.y)) + oui.set_button(c0, .Left, rl.IsMouseButtonPressed(rl.MouseButton(0))) // DRAW // ------------------------------------------ @@ -141,26 +144,42 @@ main :: proc() { when true { // hotloop - oui.begin_layout() + oui.begin_layout(c0) master_container := panel() - oui.set_layout(master_container, .Absolute) - oui.set_size(master_container, int(GetScreenWidth()), int(GetScreenHeight())) + master_container.id = oui.push_id(c0, "big_mr_boss_man") + master_container.layout = .Absolute + master_container.layout_size = {int(GetScreenWidth()), int(GetScreenHeight())} - top_bar := panel(BGCOLOR) - oui.set_cut(master_container, .Top) - oui.set_height(top_bar, 30) - oui.set_margin(top_bar, 6) - oui.item_insert(master_container, top_bar) + { + top_bar := panel_line(master_container, BGCOLOR, 30) + top_bar.id = oui.push_id(c0, "small_boie") + defer oui.pop_id(c0) + top_bar.layout_margin = 6 date_label := label("Date", font, .Left) oui.item_insert(top_bar, date_label) + } + { bottom_bar := panel(PBGCOLOR) - oui.set_cut(master_container, .Bottom) - oui.set_height(bottom_bar, 50) + bottom_bar.id = oui.push_id(c0, "not_small_boie") + defer oui.pop_id(c0) + bottom_bar.layout_cut_children = .Left + master_container.layout_cut_children = .Bottom + bottom_bar.layout_size.y = 50 oui.item_insert(master_container, bottom_bar) + } + + { + middle_section := panel(WBGCOLOR) + middle_section.id = oui.push_id(c0, "middle_section") + defer oui.pop_id(c0) + master_container.layout_cut_children = .Fill + oui.item_insert(master_container, middle_section) + } + @@ -174,11 +193,11 @@ when true { oui.item_insert(a_panel, a_button)*/ - oui.end_layout() + oui.end_layout(c0) - ui_draw(0) + ui_draw(master_container) // DRAW HERE OR BELOW - oui.process() + oui.process(c0) } else { DrawTextEx(font, "Date", {20, 8}, font_size, 0, RAYWHITE); -- cgit v1.2.1 From fca6955979f4791acb016ef5da86fed1013b524e Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Sat, 14 Oct 2023 14:03:07 +0200 Subject: There are themes! There is button with text! There is increased comfy! --- src/main.odin | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/main.odin') diff --git a/src/main.odin b/src/main.odin index 79b1a1e..fcb425d 100644 --- a/src/main.odin +++ b/src/main.odin @@ -111,6 +111,8 @@ main :: proc() { for !WindowShouldClose() { // MAIN LOOP ---- MAIN LOOP ---- MAIN LOOP ---- MAIN LOOP + free_all(context.temp_allocator) + if IsWindowResized() { height = GetScreenHeight() width = GetScreenWidth() @@ -140,7 +142,7 @@ main :: proc() { // ------------------------------------------ BeginDrawing() - ClearBackground(BGCOLOR) + ClearBackground(rl.RED) when true { // hotloop @@ -153,7 +155,7 @@ when true { master_container.layout_size = {int(GetScreenWidth()), int(GetScreenHeight())} { - top_bar := panel_line(master_container, BGCOLOR, 30) + top_bar := panel_line(master_container, theme.background_top, 30) top_bar.id = oui.push_id(c0, "small_boie") defer oui.pop_id(c0) top_bar.layout_margin = 6 @@ -161,9 +163,9 @@ when true { date_label := label("Date", font, .Left) oui.item_insert(top_bar, date_label) } - + { - bottom_bar := panel(PBGCOLOR) + bottom_bar := panel(theme.background_bottom) bottom_bar.id = oui.push_id(c0, "not_small_boie") defer oui.pop_id(c0) bottom_bar.layout_cut_children = .Left @@ -173,11 +175,21 @@ when true { } { - middle_section := panel(WBGCOLOR) + middle_section := panel(theme.background) middle_section.id = oui.push_id(c0, "middle_section") defer oui.pop_id(c0) master_container.layout_cut_children = .Fill oui.item_insert(master_container, middle_section) + + { + line := panel_line(middle_section, theme.background, 40) + line.id = oui.push_id(c0, "a_line") + defer oui.pop_id(c0) + { + a_button := button("Testor", 100) + oui.item_insert(line, a_button) + } + } } -- cgit v1.2.1 From 44d408583ab8811f2b89d8fcb9e21b98f1409b7d Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Sat, 14 Oct 2023 16:19:16 +0200 Subject: There is a theme editor now??? --- src/main.odin | 65 +++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 29 deletions(-) (limited to 'src/main.odin') diff --git a/src/main.odin b/src/main.odin index fcb425d..bed835a 100644 --- a/src/main.odin +++ b/src/main.odin @@ -4,6 +4,7 @@ import "../lib/oui" import "core:fmt" import "core:math" import "core:slice" +import "core:runtime" import "core:strings" import rl "vendor:raylib" @@ -136,7 +137,8 @@ main :: proc() { mousePosition: = rl.GetMousePosition() oui.set_cursor(c0, int(mousePosition.x), int(mousePosition.y)) - oui.set_button(c0, .Left, rl.IsMouseButtonPressed(rl.MouseButton(0))) + if rl.IsMouseButtonPressed(rl.MouseButton(0)) do oui.set_button(c0, .Left, true) + if rl.IsMouseButtonReleased(rl.MouseButton(0)) do oui.set_button(c0, .Left, false) // DRAW // ------------------------------------------ @@ -150,22 +152,24 @@ when true { master_container := panel() - master_container.id = oui.push_id(c0, "big_mr_boss_man") + master_container.id = oui.push_id(c0, "big_mr_boss_man") // Make ID for master thing just because. + // Does not need to be freed because master. master_container.layout = .Absolute master_container.layout_size = {int(GetScreenWidth()), int(GetScreenHeight())} { - top_bar := panel_line(master_container, theme.background_top, 30) - top_bar.id = oui.push_id(c0, "small_boie") - defer oui.pop_id(c0) + top_bar := panel_line(master_container, theme.background_bar, 30) + top_bar.id = oui.push_id(c0, "small_boie") // Make ID for anything that will have children. + defer oui.pop_id(c0) // These need to be pop'ed before the next item at the same level in the hierachy. top_bar.layout_margin = 6 - date_label := label("Date", font, .Left) - oui.item_insert(top_bar, date_label) + oui.item_insert(top_bar, label("Date", font, .Left)) + oui.item_insert(top_bar, label("Calltime", font, .Left)) + oui.item_insert(top_bar, label("Lunch", font, .Left)) } { - bottom_bar := panel(theme.background_bottom) + bottom_bar := panel(theme.background_bar) bottom_bar.id = oui.push_id(c0, "not_small_boie") defer oui.pop_id(c0) bottom_bar.layout_cut_children = .Left @@ -178,32 +182,35 @@ when true { middle_section := panel(theme.background) middle_section.id = oui.push_id(c0, "middle_section") defer oui.pop_id(c0) + middle_section.layout_margin = 10 // Spacing from edges + middle_section.layout_cut_gap = 5 // Spacing between children master_container.layout_cut_children = .Fill oui.item_insert(master_container, middle_section) - { - line := panel_line(middle_section, theme.background, 40) - line.id = oui.push_id(c0, "a_line") + // To loop over the members of a struct you need to do this goofy shit: + info := runtime.type_info_base(type_info_of(Theme)) + st := info.variant.(runtime.Type_Info_Struct) + root := uintptr(&theme) + for offset, i in st.offsets { + + line := panel_line(middle_section, theme.background, 25) + line.layout_cut_gap = 10 + line.id = oui.push_id(c0, fmt.tprintf("line_%d", i)) defer oui.pop_id(c0) - { - a_button := button("Testor", 100) - oui.item_insert(line, a_button) - } + + oui.item_insert(line, label(st.names[i], font, )) + + // To then access the member of the struct you're looping over + // you need to do this shit: + // v------------------------v + color_sliders(line, cast(^Color) (root+offset)) } - } - - - -/* a_button := button("Testerino", 50) - if oui.latest_clicked() { - fmt.println("CLICKO BOIO") + output_theme_button := button("output theme", 100) + oui.item_insert(middle_section, output_theme_button) + if oui.is_clicked(c0, output_theme_button) do fmt.printf("%#v", theme) } - oui.set_cut(a_panel, .Left) - oui.set_height(a_button, 50) - oui.set_offset(a_button, 20, 20) - - oui.item_insert(a_panel, a_button)*/ + oui.end_layout(c0) @@ -227,7 +234,7 @@ when true { // (At least, given how lunch breaks are currently implemented, // as holes in the workday) - DrawRectangle(10, DAY_HEIGHT*i32(i+1)-4, width-20, DAY_HEIGHT-1, PBGCOLOR) + DrawRectangle(10, DAY_HEIGHT*i32(i+1)-4, width-20, DAY_HEIGHT-1, theme.background_top) for block, j in day.blocks { if j == day.total_timeblocks do break block_color: = GREEN @@ -261,7 +268,7 @@ when true { } } - DrawRectangle(0, height-50, width+10, 60, PBGCOLOR) + DrawRectangle(0, height-50, width+10, 60, theme.background_top) DrawTextEx(small_font, total_sum, {f32(width)-120, f32(height)-43}, small_font_size, 0, RAYWHITE); DrawTextEx(big_font, inc_soc, {f32(width)-120, f32(height)-29}, big_font_size, 0, RAYWHITE); -- cgit v1.2.1 From a437a92bb39894beb91d6c4308d04852bc0d5eac Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Sat, 14 Oct 2023 17:05:01 +0200 Subject: Advancements on theme and layout --- src/main.odin | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'src/main.odin') diff --git a/src/main.odin b/src/main.odin index bed835a..e0a4507 100644 --- a/src/main.odin +++ b/src/main.odin @@ -159,23 +159,36 @@ when true { { top_bar := panel_line(master_container, theme.background_bar, 30) - top_bar.id = oui.push_id(c0, "small_boie") // Make ID for anything that will have children. + top_bar.id = oui.push_id(c0, "top_bar") // Make ID for anything that will have children. defer oui.pop_id(c0) // These need to be pop'ed before the next item at the same level in the hierachy. top_bar.layout_margin = 6 - oui.item_insert(top_bar, label("Date", font, .Left)) - oui.item_insert(top_bar, label("Calltime", font, .Left)) - oui.item_insert(top_bar, label("Lunch", font, .Left)) + oui.item_insert(top_bar, label("Date", font, 100, .Center)) + oui.item_insert(top_bar, label("Calltime", font, 100, .Center)) + oui.item_insert(top_bar, label("Lunch", font, 100, .Center)) } { bottom_bar := panel(theme.background_bar) - bottom_bar.id = oui.push_id(c0, "not_small_boie") + bottom_bar.id = oui.push_id(c0, "bottom_bar") defer oui.pop_id(c0) bottom_bar.layout_cut_children = .Left master_container.layout_cut_children = .Bottom bottom_bar.layout_size.y = 50 + bottom_bar.layout_margin = 10 // Spacing from edges oui.item_insert(master_container, bottom_bar) + + pre_sos_price := label("120 000 kr", big_font, 0, .Right) + bottom_bar.layout_cut_children = .Right + oui.item_insert(bottom_bar, pre_sos_price) + + post_sos_price := label("160 000 kr", small_font, 300, .Right) + bottom_bar.layout_cut_children = .Right + oui.item_insert(bottom_bar, post_sos_price) + + price_reason := label("Reason for price of highlighted timeblock", font, 300,) + bottom_bar.layout_cut_children = .Left + oui.item_insert(bottom_bar, price_reason) } { @@ -234,17 +247,17 @@ when true { // (At least, given how lunch breaks are currently implemented, // as holes in the workday) - DrawRectangle(10, DAY_HEIGHT*i32(i+1)-4, width-20, DAY_HEIGHT-1, theme.background_top) + DrawRectangle(10, DAY_HEIGHT*i32(i+1)-4, width-20, DAY_HEIGHT-1, theme.background_bar) for block, j in day.blocks { if j == day.total_timeblocks do break - block_color: = GREEN + block_color: = theme.price_100 switch { case block.value > 2.1: - block_color = PURPLE + block_color = theme.price_300 case block.value > 1.6: - block_color = RED + block_color = theme.price_200 case block.value > 1.1: - block_color = ORANGE + block_color = theme.price_150 } DrawRectangle(TIMELINE_START+i32(math.round(day.fractions[j].start*f32(width+TIMELINE_END-TIMELINE_START))), @@ -268,7 +281,7 @@ when true { } } - DrawRectangle(0, height-50, width+10, 60, theme.background_top) + DrawRectangle(0, height-50, width+10, 60, theme.background_bar) DrawTextEx(small_font, total_sum, {f32(width)-120, f32(height)-43}, small_font_size, 0, RAYWHITE); DrawTextEx(big_font, inc_soc, {f32(width)-120, f32(height)-29}, big_font_size, 0, RAYWHITE); -- cgit v1.2.1 From 2e3a7e10756954dc5a99d617a1c0eef327d3adbb Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Sun, 15 Oct 2023 14:37:29 +0200 Subject: Normalized timelines and editor for spacing and sizing --- src/main.odin | 195 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 140 insertions(+), 55 deletions(-) (limited to 'src/main.odin') diff --git a/src/main.odin b/src/main.odin index e0a4507..5f6449b 100644 --- a/src/main.odin +++ b/src/main.odin @@ -14,6 +14,9 @@ font : rl.Font big_font : rl.Font small_font : rl.Font +FRACT_MIN : f32 = 0.0 +FRACT_MAX : f32 = 1.0 + c0 : ^oui.Context main :: proc() { @@ -59,9 +62,8 @@ main :: proc() { defer delete(date_text) wrap_text[len(wrap_text)-1] = 0 - total_sum: cstring = "3500 NOK + 26%" - inc_soc: cstring = "4276 NOK" - text_height: f32 + total_sum: cstring = "3500 NOK + 26%" // Only here for legacy UI + inc_soc: cstring = "4276 NOK" // Only here for legacy UI using rl @@ -76,17 +78,13 @@ main :: proc() { SetWindowMinSize(width, height) // Loading fonts - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - font_size :: 18 - font = LoadFontFromMemory(".ttf", raw_data(UBUNTU_MONO), i32(len(UBUNTU_MONO)), font_size, nil, 0) - defer UnloadFont(font) - small_font_size :: 14 - small_font = LoadFontFromMemory(".ttf", raw_data(UBUNTU_MONO), i32(len(UBUNTU_MONO)), small_font_size, nil, 0) - defer UnloadFont(small_font) - - big_font_size :: 24 - big_font = LoadFontFromMemory(".ttf", raw_data(UBUNTU_MONO), i32(len(UBUNTU_MONO)), big_font_size, nil, 0) + small_font = LoadFontFromMemory(".ttf", raw_data(UBUNTU_MONO), i32(len(UBUNTU_MONO)), 14, nil, 0) + font = LoadFontFromMemory(".ttf", raw_data(UBUNTU_MONO), i32(len(UBUNTU_MONO)), 18, nil, 0) + big_font = LoadFontFromMemory(".ttf", raw_data(UBUNTU_MONO), i32(len(UBUNTU_MONO)), 24, nil, 0) defer UnloadFont(big_font) + defer UnloadFont(font) + defer UnloadFont(small_font) // oui stuff @@ -155,17 +153,24 @@ when true { master_container.id = oui.push_id(c0, "big_mr_boss_man") // Make ID for master thing just because. // Does not need to be freed because master. master_container.layout = .Absolute + master_container.sort_children = true master_container.layout_size = {int(GetScreenWidth()), int(GetScreenHeight())} { top_bar := panel_line(master_container, theme.background_bar, 30) top_bar.id = oui.push_id(c0, "top_bar") // Make ID for anything that will have children. - defer oui.pop_id(c0) // These need to be pop'ed before the next item at the same level in the hierachy. - top_bar.layout_margin = 6 + defer oui.pop_id(c0) // They must be pop'ed before the next equal-in-hiarchy item + top_bar.layout_margin = 10 + + oui.item_insert(top_bar, label("Date", font, sizings.date, .Center)) + oui.item_insert(top_bar, label("Calltimes", font, sizings.call, .Center)) - oui.item_insert(top_bar, label("Date", font, 100, .Center)) - oui.item_insert(top_bar, label("Calltime", font, 100, .Center)) - oui.item_insert(top_bar, label("Lunch", font, 100, .Center)) + top_bar.layout_cut_children = .Right + oui.item_insert(top_bar, label("Price", font, sizings.price, .Center)) + oui.item_insert(top_bar, label("Wrap", font, sizings.wrap, .Center)) + + top_bar.layout_cut_children = .Fill + oui.item_insert(top_bar, label("Timeline", font, 0, .Center)) } { @@ -174,21 +179,29 @@ when true { defer oui.pop_id(c0) bottom_bar.layout_cut_children = .Left master_container.layout_cut_children = .Bottom + bottom_bar.z_index = 10 // Makes this render over/after the middle section bottom_bar.layout_size.y = 50 bottom_bar.layout_margin = 10 // Spacing from edges + bottom_bar.layout_cut_gap = 5 // Spacing between children oui.item_insert(master_container, bottom_bar) - - pre_sos_price := label("120 000 kr", big_font, 0, .Right) - bottom_bar.layout_cut_children = .Right - oui.item_insert(bottom_bar, pre_sos_price) - - post_sos_price := label("160 000 kr", small_font, 300, .Right) - bottom_bar.layout_cut_children = .Right - oui.item_insert(bottom_bar, post_sos_price) price_reason := label("Reason for price of highlighted timeblock", font, 300,) bottom_bar.layout_cut_children = .Left oui.item_insert(bottom_bar, price_reason) + + totals := panel(theme.background_bar) + totals.layout_cut_children = .Top + totals.layout_size.x = 50 + bottom_bar.layout_cut_children = .Right + oui.item_insert(bottom_bar, totals) + + pre_sos_price := label("120 000 kr", small_font, 0, .Right) + pre_sos_price.layout_size.y = 11 + oui.item_insert(totals, pre_sos_price) + + post_sos_price := label("160 000 kr", big_font, 300, .Right) + post_sos_price.layout_size.y = 27 + oui.item_insert(totals, post_sos_price) } { @@ -196,45 +209,117 @@ when true { middle_section.id = oui.push_id(c0, "middle_section") defer oui.pop_id(c0) middle_section.layout_margin = 10 // Spacing from edges - middle_section.layout_cut_gap = 5 // Spacing between children + middle_section.layout_cut_gap = sizings.inter_timeline // Spacing between children master_container.layout_cut_children = .Fill oui.item_insert(master_container, middle_section) - // To loop over the members of a struct you need to do this goofy shit: - info := runtime.type_info_base(type_info_of(Theme)) - st := info.variant.(runtime.Type_Info_Struct) - root := uintptr(&theme) - for offset, i in st.offsets { + + // - - - - WORKDAYS - - - - + + FRACT_MAX = workdays[0].fractions[0].start + FRACT_MIN = FRACT_MAX // TODO: Optimize this. It doesn't need to re-calculated every frame + + for day, i in workdays { + + for fract, i in day.fractions { + if fract.start < FRACT_MIN do FRACT_MIN = fract.start + if fract.end > FRACT_MAX do FRACT_MAX = fract.end + if i+1 == day.total_timeblocks do break + } + + line := panel_line(middle_section, theme.background) + line.layout_cut_children = .Left + line.layout_cut_gap = 0 + line.layout_margin = 0 + line.layout_size.y = sizings.timeline + oui.item_insert(line, label(dayprint(day.call), font, sizings.date, .Center)) + oui.item_insert(line, label(clockprint(day.call), font, sizings.call, .Center)) + + line.layout_cut_children = .Right + oui.item_insert(line, label("3500 kr", font, sizings.price, .Center)) + oui.item_insert(line, label(clockprint(day.wrap), font, sizings.wrap, .Center)) + + line.layout_cut_children = .Fill + timeline(line, day) + } + new_workday := button("+", 100) + middle_section.layout_cut_children = .Top + oui.item_insert(middle_section, new_workday) + if oui.is_clicked(c0, new_workday) do fmt.println("NEW WORKDAY!") + + + + // - - - - SIZINGS EDITOR - - - - + { + oui.item_insert(middle_section, label("Sizings Editor", big_font, 100, .Center)) - line := panel_line(middle_section, theme.background, 25) - line.layout_cut_gap = 10 - line.id = oui.push_id(c0, fmt.tprintf("line_%d", i)) - defer oui.pop_id(c0) + // To loop over the members of a struct you need to do this goofy shit: + info := runtime.type_info_base(type_info_of(Sizings)) + st := info.variant.(runtime.Type_Info_Struct) + root := uintptr(&sizings) + for offset, i in st.offsets { - oui.item_insert(line, label(st.names[i], font, )) + line := panel_line(middle_section, theme.background, 25) + line.id = oui.push_id(c0, fmt.tprintf("sizings_line_%d", i)) + defer oui.pop_id(c0) + + oui.item_insert(line, label(st.names[i], font, )) + + // To then access the member of the struct you're looping over + // you need to do this shit: + // v----------------------v + current_value := cast(^int) (root+offset) + + oui.item_insert(line, slider_int(fmt.tprintf("sizings-%d", i), fmt.tprintf("%d", current_value^), 300, current_value, 0, 200)) + } + output_button := button("output sizings", 100) + middle_section.layout_cut_children = .Top + oui.item_insert(middle_section, output_button) + if oui.is_clicked(c0, output_button) do fmt.printf("%#v", sizings) + } + + + // - - - - THEME EDITOR - - - - + { + oui.item_insert(middle_section, label("Theme Editor", big_font, 100, .Center)) + + // To loop over the members of a struct you need to do this goofy shit: + info := runtime.type_info_base(type_info_of(Theme)) + st := info.variant.(runtime.Type_Info_Struct) + root := uintptr(&theme) + for offset, i in st.offsets { - // To then access the member of the struct you're looping over - // you need to do this shit: - // v------------------------v - color_sliders(line, cast(^Color) (root+offset)) + line := panel_line(middle_section, theme.background, 25) + line.layout_cut_gap = 10 + line.id = oui.push_id(c0, fmt.tprintf("line_%d", i)) + defer oui.pop_id(c0) + + oui.item_insert(line, label(st.names[i], font, )) + + // To then access the member of the struct you're looping over + // you need to do this shit: + // v------------------------v + color_sliders(line, cast(^Color) (root+offset)) + } + output_theme_button := button("output theme", 100) + middle_section.layout_cut_children = .Top + oui.item_insert(middle_section, output_theme_button) + if oui.is_clicked(c0, output_theme_button) do fmt.printf("%#v", theme) } - output_theme_button := button("output theme", 100) - oui.item_insert(middle_section, output_theme_button) - if oui.is_clicked(c0, output_theme_button) do fmt.printf("%#v", theme) } - + oui.end_layout(c0) - + ui_draw(master_container) - // DRAW HERE OR BELOW + oui.process(c0) } else { - DrawTextEx(font, "Date", {20, 8}, font_size, 0, RAYWHITE); - DrawTextEx(font, "Calltime", {105, 8}, font_size, 0, RAYWHITE); - DrawTextEx(font, "Wraptime", {f32(width)-83, 8}, font_size, 0, RAYWHITE); + DrawTextEx(font, "Date", {20, 8}, f32(font.baseSize), 0, RAYWHITE); + DrawTextEx(font, "Calltime", {105, 8}, f32(font.baseSize), 0, RAYWHITE); + DrawTextEx(font, "Wraptime", {f32(width)-83, 8}, f32(font.baseSize), 0, RAYWHITE); for day, i in workdays { @@ -271,20 +356,20 @@ when true { copy(wrap_text, clockprint(day.wrap)) copy(date_text, toString(day.call)) - text_height = math.round(f32(i+1)*DAY_HEIGHT+(DAY_HEIGHT-font_size)*0.25) + text_height := math.round(f32(i+1)*DAY_HEIGHT+(DAY_HEIGHT-f32(font.baseSize))*0.25) - DrawTextEx(font, cstring(&date_text[0]), {20, text_height}, font_size, 0, RAYWHITE); - DrawTextEx(font, cstring(&wrap_text[0]), {f32(width)-70, text_height}, font_size, 0, RAYWHITE); + DrawTextEx(font, cstring(&date_text[0]), {20, text_height}, f32(font.baseSize), 0, RAYWHITE); + DrawTextEx(font, cstring(&wrap_text[0]), {f32(width)-70, text_height}, f32(font.baseSize), 0, RAYWHITE); if i == len(workdays)-1 { - DrawTextEx(big_font, "+", {20, DAY_HEIGHT*f32(i+2)}, big_font_size, 0, RAYWHITE) + DrawTextEx(big_font, "+", {20, DAY_HEIGHT*f32(i+2)}, f32(big_font.baseSize), 0, RAYWHITE) } } DrawRectangle(0, height-50, width+10, 60, theme.background_bar) - DrawTextEx(small_font, total_sum, {f32(width)-120, f32(height)-43}, small_font_size, 0, RAYWHITE); - DrawTextEx(big_font, inc_soc, {f32(width)-120, f32(height)-29}, big_font_size, 0, RAYWHITE); + DrawTextEx(small_font, total_sum, {f32(width)-120, f32(height)-43}, f32(small_font.baseSize), 0, RAYWHITE); + DrawTextEx(big_font, inc_soc, {f32(width)-120, f32(height)-29}, f32(big_font.baseSize), 0, RAYWHITE); } EndDrawing() } -- cgit v1.2.1