random additions
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 5 Oct 2021 01:04:25 +0000 (20:04 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 5 Oct 2021 01:04:25 +0000 (20:04 -0500)
core/container/iter.onyx
modules/ui/components/scrollable_region.onyx
modules/ui/flow.onyx
modules/ui/input.onyx

index 639aec9a25c5e0ed740a732e1a3adf25f5ec9e60..e3593d879d4b4996eefa50bc903824f2aee3805d 100644 (file)
@@ -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 {
index 9511e4bdf31ca12b00725d8fcf3f45616855345c..976e030579253d065c876886f56fdc66ef6e1195 100644 (file)
@@ -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
+}
index 03558ba9100217a1783948d237b4a6c7ea44862c..929ab27a205da566e34ed7209b51afef8f9738bb 100644 (file)
@@ -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
+}
index b127b5b059d3983cd2ddad0c4c49dbed40190ff8..3d885871b1e156992aef0489b2d77630acdf2d35 100644 (file)
@@ -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
+}