From: Brendan Hansen Date: Tue, 5 Oct 2021 02:10:18 +0000 (-0500) Subject: added Scrollable_Region_Handle X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=d5c643adc83e9575cd4705a173737a81c02acc3d;p=onyx.git added Scrollable_Region_Handle --- diff --git a/bin/onyx b/bin/onyx index f789cd6c..befb0c28 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/modules/ui/components/scrollable_region.onyx b/modules/ui/components/scrollable_region.onyx index 976e0305..eca3fd89 100644 --- a/modules/ui/components/scrollable_region.onyx +++ b/modules/ui/components/scrollable_region.onyx @@ -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 :: () { diff --git a/src/parser.c b/src/parser.c index cc4891ed..f3775b41 100644 --- a/src/parser.c +++ b/src/parser.c @@ -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;