From 0c4cc3f052608b2410bf71787b14c2149e14c72b Mon Sep 17 00:00:00 2001 From: San Jacobs Date: Mon, 5 Feb 2024 15:36:44 +0100 Subject: Adding custom layout stuff to OUI for the timeline display --- src/ui_implementation.odin | 69 +++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 32 deletions(-) (limited to 'src/ui_implementation.odin') diff --git a/src/ui_implementation.odin b/src/ui_implementation.odin index 71f0e94..3a2ddc0 100644 --- a/src/ui_implementation.odin +++ b/src/ui_implementation.odin @@ -71,6 +71,7 @@ Data_Element :: enum int { Text_Input, Timeblock, Timeline, + Timeline_Block, // ... } @@ -115,6 +116,10 @@ Data_Timeline :: struct { using _: Data_Head, day: ^Workday, } +Data_Timeline_Block :: struct { + using _: Data_Head, + timeblock: ^Timeblock, +} panel :: proc(color : rl.Color = rl.RED) -> ^Item { item := oui.item_make(c0) @@ -237,9 +242,23 @@ timeline :: proc(parent: ^Item, day: ^Workday) -> ^Item { data.subtype = .Timeline data.day = day + for block in &day.blocks { + oui.item_insert(item, timeline_block(&block)) + } + oui.item_insert(parent, item) return item } +timeline_block :: proc(timeblock: ^Timeblock) -> ^Item { + item := oui.item_make(c0) + item.layout = .Fractional + + data := oui.alloc_typed(c0, item, Data_Timeline_Block) + data.subtype = .Timeline_Block + data.timeblock = timeblock + + return item +} Text_Alignment :: enum int { // Techically called justification, but text_alignment is more self-explanatory. @@ -350,40 +369,26 @@ ui_draw :: proc(item: ^oui.Item) { rl.DrawTextEx(data.font, text, i2f(position), f32(data.font.baseSize), 0.0, theme.text); case .Timeline: - data := cast(^Data_Timeline) item.handle + rl.DrawRectangle(i32(rect.l), + i32(rect.t), + i32(rect.r - rect.l), + i32(rect.b - rect.t), + theme.background_bar) + case .Timeline_Block: + data := cast(^Data_Timeline_Block) item.handle - width := int(f32(rect.r - rect.l)/(FRACT_MAX - FRACT_MIN)) + color := theme.price_100 + value := data.timeblock.value - for fracts, i in data.day.fractions { - - color := theme.price_100 - value := data.day.blocks[i].value - - switch { - case value>2.1: - color = theme.price_300 - case value>1.6: - color = theme.price_200 - case value>1.1: - color = theme.price_150 - } - - - - rl.DrawRectangle(i32(rect.l + int(f32(width)*fracts.start) - int(f32(width)*FRACT_MIN)), - i32(rect.t), - i32(f32(width) * (fracts.end - fracts.start)+0.99), - i32(rect.b - rect.t), - color) - // Dark middle of blocks, glowing edge. Disabled for now. - /*rl.DrawRectangle(i32(rect.l + int(f32(width)*fracts.start) - int(f32(width)*FRACT_MIN) + 1), - i32(rect.t) + 1, - i32(f32(width+1) * (fracts.end - fracts.start)-1.01), - i32(rect.b - rect.t)-2, - {0,0,0,100})*/ - if i+1 == data.day.total_timeblocks { - break - } + switch { + case value>2.1: + color = theme.price_300 + case value>1.6: + color = theme.price_200 + case value>1.1: + color = theme.price_150 } + + rl.DrawRectangle(i32(rect.l), i32(rect.t), i32(rect.r-rect.l), i32(rect.b-rect.t), color) } } \ No newline at end of file -- cgit v1.2.1