aboutsummaryrefslogtreecommitdiff
path: root/lib/oui/oui.odin
diff options
context:
space:
mode:
authorSan Jacobs2024-09-11 18:45:51 +0200
committerSan Jacobs2024-09-11 18:45:51 +0200
commitd4ea66aa3b6fd9ffedbf42ab21a4eb34bc91ccbe (patch)
tree0d785eea78284bf69f14af74b8ffe98c0b6c5244 /lib/oui/oui.odin
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
Diffstat (limited to 'lib/oui/oui.odin')
-rw-r--r--lib/oui/oui.odin51
1 files changed, 51 insertions, 0 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
////////////////////////////////////////////////////////////////////////////////