From 1f2b103df7e71499229ae3a3f11a2520c09e596f Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Mon, 4 Oct 2021 20:04:25 -0500 Subject: [PATCH] random additions --- core/container/iter.onyx | 56 +++++++++----------- modules/ui/components/scrollable_region.onyx | 6 +-- modules/ui/flow.onyx | 10 ++-- modules/ui/input.onyx | 2 +- 4 files changed, 34 insertions(+), 40 deletions(-) diff --git a/core/container/iter.onyx b/core/container/iter.onyx index 639aec9a..e3593d87 100644 --- a/core/container/iter.onyx +++ b/core/container/iter.onyx @@ -272,43 +272,37 @@ enumerate :: (it: Iterator($T), start_index: i32 = 0) -> Iterator(Enumeration_Va }; } -from_array :: #match { - (arr: [..] $T) -> Iterator(^T) { - return from_array((#type [] T).{ arr.data, arr.count }); - }, - - (arr: [] $T) -> Iterator(^T) { - Context :: struct (T: type_expr) { - data: ^T; - count: u32; - current: u32; - } - - c := make(#type Context(T)); - c.data = arr.data; - c.count = arr.count; - c.current = 0; +from_array :: (arr: [] $T) -> Iterator(^T) { + Context :: struct (T: type_expr) { + data: ^T; + count: u32; + current: u32; + } - next :: ($T: type_expr, use _: ^Context(T)) -> (^T, bool) { - if current < count { - defer current += 1; - return ^data[current], true; + c := make(#type Context(T)); + c.data = arr.data; + c.count = arr.count; + c.current = 0; - } else { - return null, false; - } - } + next :: ($T: type_expr, use _: ^Context(T)) -> (^T, bool) { + if current < count { + defer current += 1; + return ^data[current], true; - close :: (data: rawptr) { - cfree(data); + } else { + return null, false; } + } - return .{ - data = c, - next = #solidify next { T = T }, - close = close, - }; + close :: (data: rawptr) { + cfree(data); } + + return .{ + data = c, + next = #solidify next { T = T }, + close = close, + }; } fold :: (it: Iterator($T), initial_value: R, combine: (T, $R) -> R) -> R { diff --git a/modules/ui/components/scrollable_region.onyx b/modules/ui/components/scrollable_region.onyx index 9511e4bd..976e0305 100644 --- a/modules/ui/components/scrollable_region.onyx +++ b/modules/ui/components/scrollable_region.onyx @@ -14,9 +14,9 @@ scrollable_region_states : Map(UI_Id, Scrollable_Region_State); Scrollable_Region_Controls :: struct { minimum_y := 0.0f; - maximum_y := 10000.0f; // Senseless default + maximum_y := 340000000000000000000000000000000000000.0f; // Senseless default minimum_x := 0.0f; - maximum_x := 10000.0f; // Senseless default + maximum_x := 340000000000000000000000000000000000000.0f; // Senseless default } scrollable_region_start :: (use r: Rectangle, use src: Scrollable_Region_Controls = .{}, @@ -62,4 +62,4 @@ scrollable_region_start :: (use r: Rectangle, use src: Scrollable_Region_Control scrollable_region_stop :: () { gfx.pop_scissor(); gfx.pop_matrix(); -} \ No newline at end of file +} diff --git a/modules/ui/flow.onyx b/modules/ui/flow.onyx index 03558ba9..929ab27a 100644 --- a/modules/ui/flow.onyx +++ b/modules/ui/flow.onyx @@ -43,16 +43,16 @@ Flow :: struct { x0, y0 := Rectangle.top_left(r); x1, y1 := Rectangle.bottom_right(r); - return .{ x0=x0, x1=x1, y0=y0, y1=y0+top_height }, - .{ x0=x0, x1=x1, y0=y0+top_height+padding, y1=y1 }; + return .{ x0=x0, x1=x1, y0=y0, y1=math.max(y0, y0+top_height) }, + .{ x0=x0, x1=x1, y0=math.min(y1, y0+top_height+padding), y1=y1 }; }, (r: Rectangle, bottom_height: f32, padding := 0.0f) -> (top: Rectangle, bottom: Rectangle) { x0, y0 := Rectangle.top_left(r); x1, y1 := Rectangle.bottom_right(r); - return .{ x0=x0, x1=x1, y0=y0, y1=y1-bottom_height-padding }, - .{ x0=x0, x1=x1, y0=y1-bottom_height, y1=y1 }; + return .{ x0=x0, x1=x1, y0=y0, y1=math.max(y0, y1-bottom_height-padding) }, + .{ x0=x0, x1=x1, y0=math.min(y1,y1-bottom_height), y1=y1 }; } } @@ -63,4 +63,4 @@ Flow :: struct { return .{ x0=x0 + left, x1=x1 - right, y0=y0 + top, y1=y1 - bottom }; } -} \ No newline at end of file +} diff --git a/modules/ui/input.onyx b/modules/ui/input.onyx index b127b5b0..3d885871 100644 --- a/modules/ui/input.onyx +++ b/modules/ui/input.onyx @@ -163,4 +163,4 @@ is_key_just_down :: (keycode: u32) -> bool { is_key_up :: (keycode: u32) -> bool { s := keyboard_state.state[keycode]; return s == .Up || s == .Just_Up; -} \ No newline at end of file +} -- 2.25.1