aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSan Jacobs2024-09-11 18:45:51 +0200
committerSan Jacobs2024-09-11 18:45:51 +0200
commitd4ea66aa3b6fd9ffedbf42ab21a4eb34bc91ccbe (patch)
tree0d785eea78284bf69f14af74b8ffe98c0b6c5244
parentcc71145744d1a0818cbfa93ebdcb3ce2d3671dda (diff)
downloadsatscalc-d4ea66aa3b6fd9ffedbf42ab21a4eb34bc91ccbe.tar.gz
satscalc-d4ea66aa3b6fd9ffedbf42ab21a4eb34bc91ccbe.tar.bz2
satscalc-d4ea66aa3b6fd9ffedbf42ab21a4eb34bc91ccbe.zip
Updated odin again, odin version dev-2024-09:9b06ea5bf should work now
-rw-r--r--lib/oui/oui.odin51
-rw-r--r--src/main.odin25
-rw-r--r--src/time.odin2
-rw-r--r--src/ui_implementation.odin7
4 files changed, 73 insertions, 12 deletions
diff --git a/lib/oui/oui.odin b/lib/oui/oui.odin
index 88bafa1..bde88f0 100644
--- a/lib/oui/oui.odin
+++ b/lib/oui/oui.odin
@@ -147,9 +147,14 @@ Layout :: enum {
Absolute,
Relative,
Fractional,
+ Range,
// Custom,
}
+Direction :: enum {
+ Horizontal,
+ Vertical,
+}
// MOUSE calls:
// Down / Up called 1 frame
// Hot_Up called when active was over hot
@@ -226,6 +231,10 @@ Item :: struct {
// persistent data per item - queryable after end_layout
anim: Animation,
+
+ range_start: f32, // Start position (0.0 to 1.0)
+ range_end: f32, // End position (0.0 to 1.0)
+ range_direction: Direction
}
Animation :: struct {
@@ -747,6 +756,13 @@ focus_redirect :: proc(ctx: ^Context, item: ^Item) {
ctx.focus_redirect_item = item.id
}
+set_range :: proc(item: ^Item, start, end: f32, direction: Direction) {
+ item.layout = .Range
+ item.range_start = clamp(start, 0, 1)
+ item.range_end = clamp(end, 0, 1)
+ item.range_direction = direction
+}
+
////////////////////////////////////////////////////////////////////////////////
// ITERATION
////////////////////////////////////////////////////////////////////////////////
@@ -877,6 +893,13 @@ activeness2 :: proc(item: ^Item) -> f32 #no_bounds_check {
// compute the size of an item
// optional HSIZED / VSIZED for custom sizes
compute_size :: proc(item: ^Item) #no_bounds_check {
+ if item.layout == .Range {
+ // Skip size computation for Range items
+ // Their size will be determined during the arrange phase
+ // based on their parent's size and their range values
+ return
+ }
+
item.bounds.r = item.layout_size.x
item.bounds.b = item.layout_size.y
@@ -939,6 +962,9 @@ arrange :: proc(item: ^Item, layout: ^RectI, gap: int) #no_bounds_check {
case .Fractional:
rect.sized(&item.bounds, item.layout_offset, item.layout_size)
+
+ case .Range:
+ range_layout(item, layout)
}
// layout children with this resultant rect for LAYOUT_CUT
@@ -960,6 +986,31 @@ item_root :: proc(ctx: ^Context) -> ^Item {
return &ctx.items[0]
}
+range_layout :: proc(item: ^Item, parent_bounds: ^RectI) {
+ parent_width := rect.widthi(parent_bounds^)
+ parent_height := rect.heighti(parent_bounds^)
+
+ if item.range_direction == .Horizontal {
+ start_x := parent_bounds.l + int(f32(parent_width) * item.range_start)
+ end_x := parent_bounds.l + int(f32(parent_width) * item.range_end)
+ item.bounds = {
+ l = start_x,
+ t = parent_bounds.t,
+ r = end_x - start_x, // width
+ b = parent_height,
+ }
+ } else {
+ start_y := parent_bounds.t + int(f32(parent_height) * item.range_start)
+ end_y := parent_bounds.t + int(f32(parent_height) * item.range_end)
+ item.bounds = {
+ l = parent_bounds.l,
+ t = start_y,
+ r = parent_width,
+ b = end_y - start_y, // height
+ }
+ }
+}
+
////////////////////////////////////////////////////////////////////////////////
// ID gen - same as microui
////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main.odin b/src/main.odin
index 21d081d..f0e174a 100644
--- a/src/main.odin
+++ b/src/main.odin
@@ -122,7 +122,7 @@ main :: proc() {
// Setting up the timelines
- for day, f in &workdays {
+ for &day, f in &workdays {
beginning: Moment = {0, 0, day.call.day, day.call.month, day.call.year}
fmt.println("\nNew day!")
@@ -280,9 +280,24 @@ when true {
line.layout_cut_children = .Fill
{
a_timeline := timeline(line, &day)
+
+ x_offset := int(f32(width) * day.fractions[0].start)
+ for &block, i in day.blocks {
+ // TODO: Why isn't this rendering??
+ block_ui := timeline_block(&block)
+ block_width := int(f32(width) * (day.fractions[i].end - day.fractions[i].start))
+ block_ui.layout_size.x = block_width
+ block_ui.layout_offset.x = x_offset
+ oui.item_insert(a_timeline, block_ui)
+ x_offset += block_width
+ //fmt.printf("%#v\n", block_ui)
+ }
- /*x_offset := i32(int(f32(width)*fracts.start) - int(f32(width)*FRACT_MIN))
- i32(rect.t),
+ oui.item_insert(line, a_timeline)
+
+ //x_offset := i32(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)*/
@@ -303,7 +318,7 @@ when true {
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 {
+ for offset, i in st.offsets[:st.field_count] {
line := panel_line(middle_section, theme.background, 25)
line.id = oui.push_id(c0, fmt.tprintf("sizings_line_%d", i))
@@ -333,7 +348,7 @@ when true {
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 {
+ for offset, i in st.offsets[:st.field_count] {
line := panel_line(middle_section, theme.background, 25)
line.layout_cut_gap = 10
diff --git a/src/time.odin b/src/time.odin
index 5ab879f..00891bf 100644
--- a/src/time.odin
+++ b/src/time.odin
@@ -155,7 +155,7 @@ new_workday :: proc(previous_wrap : Moment,
fmt.println(total_timeblocks)
- for &block, i in &blocks {
+ for &block, i in blocks {
if i >= total_timeblocks do break
//using Weekday
diff --git a/src/ui_implementation.odin b/src/ui_implementation.odin
index d351761..c175fb5 100644
--- a/src/ui_implementation.odin
+++ b/src/ui_implementation.odin
@@ -242,16 +242,11 @@ 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
+ item.layout = .Absolute
data := oui.alloc_typed(c0, item, Data_Timeline_Block)
data.subtype = .Timeline_Block