aboutsummaryrefslogtreecommitdiff
path: root/src/ui_implementation.odin
diff options
context:
space:
mode:
authorSan Jacobs2024-02-05 15:36:44 +0100
committerSan Jacobs2024-02-05 15:36:44 +0100
commit0c4cc3f052608b2410bf71787b14c2149e14c72b (patch)
tree048ebb29c2045b6f08b2bb5d10d070d733f29021 /src/ui_implementation.odin
parent5f685eaabf4c57606c3b86791a33d5cdce46ec67 (diff)
downloadsatscalc-0c4cc3f052608b2410bf71787b14c2149e14c72b.tar.gz
satscalc-0c4cc3f052608b2410bf71787b14c2149e14c72b.tar.bz2
satscalc-0c4cc3f052608b2410bf71787b14c2149e14c72b.zip
Adding custom layout stuff to OUI for the timeline display
Diffstat (limited to 'src/ui_implementation.odin')
-rw-r--r--src/ui_implementation.odin69
1 files changed, 37 insertions, 32 deletions
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