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 +++++++++++++++++++++++++++++++++++-------------------- src/time.odin | 30 ++++++++++++++++++------------ 2 files changed, 53 insertions(+), 32 deletions(-) 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) diff --git a/src/time.odin b/src/time.odin index 2161239..700bed7 100644 --- a/src/time.odin +++ b/src/time.odin @@ -161,18 +161,18 @@ new_workday :: proc(previous_wrap : Moment, // Holidays! - if (block.start.day==1) && (block.start.month==1) do upvalue(&block, 2, "New year") - if (block.start.day==1) && (block.start.month==5) do upvalue(&block, 2, "1st of May") - if (block.start.day==17) && (block.start.month==5) do upvalue(&block, 2, "17th of May") - if (block.start.day==25 || block.start.day==26) && block.start.month==12 do upvalue(&block, 2, "Christmas") + if (block.start.day==1) && (block.start.month==1) { upvalue(&block, 2, "New year"); continue} + if (block.start.day==1) && (block.start.month==5) { upvalue(&block, 2, "1st of May"); continue} + if (block.start.day==17) && (block.start.month==5) { upvalue(&block, 2, "17th of May"); continue} + if (block.start.day==25 || block.start.day==26) && block.start.month==12 { upvalue(&block, 2, "Christmas"); continue} easter: Moment = gaussEaster(block.start.year) - if (block.start.day == sub(easter, {0,0,3}).day) && block.start.month == sub(easter, {0,0,3}).month do upvalue(&block, 2, "Maundy Thursday") - if (block.start.day == sub(easter, {0,0,2}).day) && block.start.month == sub(easter, {0,0,2}).month do upvalue(&block, 2, "Good Friday") - if (block.start.day == easter.day) && (block.start.month == easter.month) do upvalue(&block, 2, "Easter") - if (block.start.day == add(easter, {0,0,1}).day) && (block.start.month == add(easter, {0,0,1}).month) do upvalue(&block, 2, "Easter") - if (block.start.day == add(easter, {0,0,39}).day) && (block.start.month == add(easter, {0,0,39}).month) do upvalue(&block, 2, "Feast of the Ascension") - if (block.start.day == add(easter, {0,0,49}).day) && (block.start.month == add(easter, {0,0,49}).month) do upvalue(&block, 2, "Pentecost") - if (block.start.day == add(easter, {0,0,50}).day) && (block.start.month == add(easter, {0,0,50}).month) do upvalue(&block, 2, "Pentecost Monday") + if (block.start.day == sub(easter, {0,0,3}).day) && block.start.month == sub(easter, {0,0,3}).month { upvalue(&block, 2, "Maundy Thursday"); continue} + if (block.start.day == sub(easter, {0,0,2}).day) && block.start.month == sub(easter, {0,0,2}).month { upvalue(&block, 2, "Good Friday"); continue} + if (block.start.day == easter.day) && (block.start.month == easter.month) { upvalue(&block, 2, "Easter"); continue} + if (block.start.day == add(easter, {0,0,1}).day) && (block.start.month == add(easter, {0,0,1}).month) { upvalue(&block, 2, "Easter"); continue} + if (block.start.day == add(easter, {0,0,39}).day) && (block.start.month == add(easter, {0,0,39}).month) { upvalue(&block, 2, "Feast of the Ascension"); continue} + if (block.start.day == add(easter, {0,0,49}).day) && (block.start.month == add(easter, {0,0,49}).month) { upvalue(&block, 2, "Pentecost"); continue} + if (block.start.day == add(easter, {0,0,50}).day) && (block.start.month == add(easter, {0,0,50}).month) { upvalue(&block, 2, "Pentecost Monday"); continue} } for each_block, i in blocks { @@ -413,7 +413,13 @@ lessTimeblock :: proc(block_a: Timeblock, block_b: Timeblock) -> bool { if block_a.start == {0, 0, 0, 0, 0} do return false return bool(sortable(block_a.start) < sortable(block_b.start)) } -less :: proc{lessMoment, lessDelta, lessTimeblock} +lessWorkday :: proc(day_a: Workday, day_b: Workday) -> bool { + return bool(sortable(day_a.call) < sortable(day_b.call)) +} +lessWorkdayPtr :: proc(day_a: ^Workday, day_b: ^Workday) -> bool { + return bool(sortable(day_a.call) < sortable(day_b.call)) +} +less :: proc{lessMoment, lessDelta, lessTimeblock, lessWorkday} lessEqMoment :: proc(moment_a: Moment, moment_b: Moment) -> bool { return moment_a==moment_b || less(moment_a, moment_b) -- cgit v1.2.1