added Scrollable_Region_Handle
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 5 Oct 2021 02:10:18 +0000 (21:10 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 5 Oct 2021 02:10:18 +0000 (21:10 -0500)
bin/onyx
modules/ui/components/scrollable_region.onyx
src/parser.c

index f789cd6c28477ea756bc71126690185e61e47aa5..befb0c2879efd09b865456bfd0f68cb9a852c151 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 976e030579253d065c876886f56fdc66ef6e1195..eca3fd89e28d1f72d116a27e39c8c8b478eb00a7 100644 (file)
@@ -19,8 +19,23 @@ Scrollable_Region_Controls :: struct {
     maximum_x := 340000000000000000000000000000000000000.0f; // Senseless default
 }
 
+Scrollable_Region_Handle :: struct {
+    rect: Rectangle;
+    state: ^Scrollable_Region_State;
+
+    get_visible_rectangle :: (use this: ^Scrollable_Region_Handle) -> Rectangle {
+        trans := ^state.transform;
+        x0 := (rect.x0 - trans.translation.x) / trans.scale.x;
+        y0 := (rect.y0 - trans.translation.y) / trans.scale.y;
+        x1 := (rect.x1 - trans.translation.x) / trans.scale.x;
+        y1 := (rect.y1 - trans.translation.y) / trans.scale.y;
+
+        return .{ x0, y0, x1, y1 };
+    }
+}
+
 scrollable_region_start :: (use r: Rectangle, use src: Scrollable_Region_Controls = .{},
-                            site := #callsite, state: ^Scrollable_Region_State = null) {
+                            site := #callsite, state: ^Scrollable_Region_State = null) -> Scrollable_Region_Handle {
     hash := get_site_hash(site, 0);
     x, y := Rectangle.top_left(r);
     width, height := Rectangle.dimensions(r);
@@ -57,6 +72,8 @@ scrollable_region_start :: (use r: Rectangle, use src: Scrollable_Region_Control
     gfx.push_scissor(x, y, width, height);
     gfx.push_matrix();
     gfx.apply_transform(state.transform);
+
+    return .{ r, state };
 }
 
 scrollable_region_stop :: () {
index cc4891ed53423963258bedef8ef1d9b1f4c0e68d..f3775b41d9e47ac2f67798f55bf4ca166f1a6101 100644 (file)
@@ -732,6 +732,29 @@ static AstTyped* parse_factor(OnyxParser* parser) {
 
                 parse_arguments(parser, ')', &call_node->args);
 
+//              This could be a cool feature where you can write:
+//
+//              foo(x, y) {
+//                  // ...
+//              }
+//
+//              which just desugars into
+//
+//              foo(x, y, #code {
+//                  // ...
+//              })
+//
+//                if (parser->curr->type == '{') {
+//                    AstCodeBlock* code_block = make_node(AstCodeBlock, Ast_Kind_Code_Block);
+//                    code_block->token = parser->curr;
+//                    code_block->type_node = builtin_code_type;
+//
+//                    code_block->code = (AstNode *) parse_block(parser, 1);
+//                    ((AstBlock *) code_block->code)->rules = Block_Rule_Code_Block;
+//
+//                    bh_arr_push(call_node->args.values, (AstTyped *) code_block);
+//                }
+
                 // Wrap expressions in AstArgument
                 bh_arr_each(AstTyped *, arg, call_node->args.values) {
                     if ((*arg) == NULL) continue;