From 248c0c28aeceed52dcf300b29ec8e36116ac3375 Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Sun, 21 May 2023 17:03:24 +0200 Subject: Tweaks, optimizations, more UI --- src/main.odin | 55 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 20 deletions(-) (limited to 'src/main.odin') diff --git a/src/main.odin b/src/main.odin index 03b95cd..43a9d28 100644 --- a/src/main.odin +++ b/src/main.odin @@ -2,25 +2,44 @@ package main import "core:fmt" import "core:math" +import "core:slice" import "core:strings" import rl "vendor:raylib" main :: proc() { workdays: [dynamic]^Workday + resize(&workdays, 3) + + workday0: = new_workday({10, 22, 4, 5, 2023}, + {00, 08, 5, 5, 2023}, + {00, 22, 5, 5, 2023}, + {30, 21, 5, 5, 2023}) + workdays[0] = &workday0 + + workday1: = new_workday(workday0.wrap, + {00, 08, 7, 5, 2023}, + {30, 17, 7, 5, 2023}, + {30, 16, 7, 5, 2023}) + workdays[1] = &workday1 + + workday2: = new_workday(workday1.wrap, + {00, 12, 6, 5, 2023}, + {15, 17, 6, 5, 2023}, + {00, 17, 6, 5, 2023}) + workdays[2] = &workday2 + + slice.sort_by(workdays[:], lessWorkdayPtr) + + //call_text: cstring = "00:00" + call_text: = make([]byte, 6) + defer delete(call_text) + call_text[len(call_text)-1] = 0 + //wrap_text: cstring = "00:00" + wrap_text: = make([]byte, 6) + defer delete(wrap_text) + wrap_text[len(wrap_text)-1] = 0 - default_workday: = new_workday({10, 22, 4, 5, 2023}, - {00, 08, 5, 5, 2023}, - {00, 22, 6, 5, 2023}, - {30, 21, 5, 5, 2023}) - - append(&workdays, &default_workday) - append(&workdays, &default_workday) - append(&workdays, &default_workday) - append(&workdays, &default_workday) - - call_text: cstring = "noffin" - wrap_text: cstring = "noffin" total_sum: cstring = "3500 NOK + 26%" inc_soc: cstring = "4276 NOK" text_height: f32 @@ -89,17 +108,13 @@ main :: proc() { DAY_HEIGHT*i32(i+1)-4, width-170, DAY_HEIGHT-1, BLUE) } - // TODO: This is bad, figure out how to overwrite the existing memory instead - // of doing these horrible repeated allocations and deallocations - call_text = strings.clone_to_cstring(clockprint(day.call)) - defer delete(call_text) - wrap_text = strings.clone_to_cstring(clockprint(day.wrap)) - defer delete(wrap_text) + copy(call_text, clockprint(day.call)) + copy(wrap_text, clockprint(day.wrap)) text_height = math.round(f32(i+1)*DAY_HEIGHT+(DAY_HEIGHT-font_size)*0.25) - DrawTextEx(font, call_text, {20, text_height}, font_size, 0, RAYWHITE); - DrawTextEx(font, wrap_text, {f32(width)-70, text_height}, font_size, 0, RAYWHITE); + DrawTextEx(font, cstring(&call_text[0]), {20, text_height}, font_size, 0, RAYWHITE); + DrawTextEx(font, cstring(&wrap_text[0]), {f32(width)-70, text_height}, font_size, 0, RAYWHITE); if i == len(workdays)-1 { DrawTextEx(big_font, "+", {20, DAY_HEIGHT*f32(i+2)}, big_font_size, 0, RAYWHITE) -- cgit v1.2.1