random cleanup; fixed ui layering bug
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 9 Aug 2021 10:39:36 +0000 (05:39 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 9 Aug 2021 10:39:36 +0000 (05:39 -0500)
bin/onyx
modules/immediate_mode/immediate_renderer.onyx
modules/ui/components/scrollable_region.onyx
modules/ui/components/workspace.onyx
modules/ui/ui.onyx
src/onyxastnodes.c
src/onyxchecker.c
src/onyxwasm.c
tests/aoc-2020/day17.onyx
tests/aoc-2020/day25.onyx
tests/aoc-2020/day3.onyx

index 27fc96e3b4c91a13a61076a871222134c81c0895..1e5eadc5611997a53af92b5029278488f0f152c8 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 4f7e3ccadf67c83f27dc5e45da0593e7c9ec9b62..4cb38fde9dd28b5c6c1171f5d5c86cd0f1c79369 100644 (file)
@@ -515,3 +515,10 @@ push_matrix :: () do global_renderer->push_matrix();
 pop_matrix  :: () do global_renderer->pop_matrix();
 identity    :: () do global_renderer->identity();
 apply_transform :: (transform: Transform) do global_renderer->apply_transform(transform);
+
+
+
+save_matrix :: #code {
+    (package immediate_mode).push_matrix();
+    defer (package immediate_mode).pop_matrix();
+}
\ No newline at end of file
index 41ff29ec23c341e548f7269be51dd0bb02c51183..edd9082b57b064e10453a21b88038501e22da9c9 100644 (file)
@@ -21,13 +21,11 @@ scrollable_region_start :: (use r: Rectangle, x_scroll: ^f32, y_scroll: ^f32, si
     state := map.get(^scrollable_region_states, hash);
 
     mx, my := get_mouse_position();
-    contained := false;
     if Rectangle.contains(r, mx, my) {
-        // if hot_item == 0 do set_hot_item(hash);
-        contained = true;
+        set_hot_item(hash);
     }
 
-    if contained { // is_hot_item(hash) {
+    if is_hot_item(hash) {
         speed :: 30.0f; @ThemeConfiguration
 
         if is_key_down(38)  do state.transform.translation.y += speed;
index 64558d2f865749fc98971e7425e93a9b6b374208..900952d89d9f75c8602f7891605f7993779a8c67 100644 (file)
@@ -24,7 +24,7 @@ workspace_start :: (use r: Rectangle, site := #callsite) {
 
     mx, my := get_mouse_position();
     if Rectangle.contains(r, mx, my) {
-        if hot_item == 0 do set_hot_item(hash);
+        set_hot_item(hash);
     }
 
     if is_hot_item(hash) {
index 92e06f09b5fc956d59bcd152676a1c431289b4d8..3a6c4084ba1090b0a02667dfbbb6697c3c1b0fbd 100644 (file)
@@ -29,6 +29,7 @@ init_ui :: () {
 
 // This function should be called at the end of drawing a frame, after all of the UI elements
 // had a chance to interact with the hardware events.
+
 end_frame :: () {
     mouse_state.left_button_just_up    = false;
     mouse_state.left_button_just_down  = false;
@@ -47,7 +48,9 @@ end_frame :: () {
     keyboard_state.keys_down_this_frame = 0;
     keyboard_state.keys_up_this_frame = 0;
 
+    hot_item_depth_needed = hot_item_depth;
     if !hot_item_was_set do set_hot_item(0);
+    hot_item_depth = 0;
     hot_item_was_set = false;
 
     for ^s: keyboard_state.state {
@@ -61,13 +64,26 @@ set_active_item :: (id: UI_Id) -> bool {
     return true;
 }
 
-set_hot_item :: (id: UI_Id) -> bool {
+#private_file hot_item_depth := 0;
+#private_file hot_item_depth_needed := 0;
+
+set_hot_item :: (id: UI_Id, force := false) -> bool {
     if active_item != 0 do return false;
 
-    hot_item_was_set = true;
+    if force {
+        hot_item_was_set = true;
+        hot_item = id;
+        return true;
+    }
 
-    hot_item = id;
-    return true;
+    hot_item_depth += 1;
+    if hot_item_depth >= hot_item_depth_needed {
+        hot_item_was_set = true;
+        hot_item = id;
+        return true;
+    } else {
+        return false;
+    }
 }
 
 is_active_item :: (id: UI_Id) -> bool {
index 9944f63a1e1791375249f9da5000349e0fd49fce..5aef4393e340d55d8f119596078cb1bb98b46dfe 100644 (file)
@@ -58,7 +58,7 @@ static const char* ast_node_names[] = {
     "ARRAY ACCESS",
     "SLICE",
     "FIELD ACCESS",
-    "UNARY FIELD ACCESS"
+    "UNARY FIELD ACCESS",
     "PIPE",
     "METHOD_CALL",
     "RANGE",
@@ -257,8 +257,6 @@ AstTyped* ast_reduce_unaryop(bh_allocator a, AstUnaryOp* unop) {
     AstNumLit* operand = (AstNumLit *) ast_reduce(a, unop->expr);
     unop->expr = (AstTyped *) operand;
 
-    // while (operand->kind == Ast_Kind_Alias) operand = (AstNumLit *) ((AstAlias *) operand)->alias;
-
     if (operand->kind != Ast_Kind_NumLit) {
         return (AstTyped *) unop;
     }
@@ -278,6 +276,72 @@ AstTyped* ast_reduce_unaryop(bh_allocator a, AstUnaryOp* unop) {
         }
         case Unary_Op_Bitwise_Not: REDUCE_UNOP_INT(~);
 
+        case Unary_Op_Cast: {
+            #if 0
+            Type* from = operand->type;
+            Type* to   = unop->type;
+
+            if (from->kind == Type_Kind_Enum) from = from->Enum.backing;
+            if (to->kind == Type_Kind_Enum) to = to->Enum.backing;
+
+            if (from->kind != Type_Kind_Pointer && from->kind != Type_Kind_Basic) return (AstTyped *) unop;
+            if (to->kind != Type_Kind_Pointer && to->kind != Type_Kind_Basic) return (AstTyped *) unop;
+
+            b32 from_is_int=0, to_is_int=0;
+            i32 from_size,     to_size;
+
+            from_size   = type_size_of(from);
+            to_size     = type_size_of(to);
+
+            if (from->kind == Type_Kind_Basic) from_is_int = (from->flags & (Basic_Flag_Integer | Basic_Flag_Pointer)) != 0;
+            if (to->kind   == Type_Kind_Basic) to_is_int   = (to->flags   & (Basic_Flag_Integer | Basic_Flag_Pointer)) != 0;
+
+            if (from->kind == Type_Kind_Pointer) from_is_int = 1;
+            if (to->kind   == Type_Kind_Pointer) to_is_int = 1;
+
+            if (from_is_int == to_is_int && from_size == to_size) {
+                // If they are already equal, nothing to do
+                return (AstTyped *) res;
+            }
+
+            if (from_is_int && !to_is_int) {
+                if (from_size == to_size) {
+                    if (from_size == 4) {
+                        res->value.f = (f32) operand->value.i;
+                    }
+                    else if (from_size == 8) {
+                        res->value.d = (f64) operand->value.l;
+                    }
+                } else {
+                    if (from_size == 4) {
+                        res->value.d = (f64) operand->value.i;
+                    }
+                    else if (from_size == 8) {
+                        res->value.f = (f32) operand->value.l;
+                    }
+                }
+            } else {
+                if (from_size == to_size) {
+                    if (from_size == 4) {
+                        res->value.i = (i32) operand->value.f;
+                    }
+                    else if (from_size == 8) {
+                        res->value.l = (i64) operand->value.d;
+                    }
+                } else {
+                    if (from_size == 4) {
+                        res->value.l = (i64) operand->value.f;
+                    }
+                    else if (from_size == 8) {
+                        res->value.i = (i32) operand->value.d;
+                    }
+                }
+            }
+            break;
+
+            #endif
+        }
+
         default: return (AstTyped *) unop;
     }
 
index ca848767626c464b369f5b99d90f303d8bb8a570..3cac3da85e9ffe37c44d16c12c1c4be724239070 100644 (file)
@@ -1733,6 +1733,7 @@ CheckStatus check_insert_directive(AstDirectiveInsert** pinsert) {
     assert(code_block->kind == Ast_Kind_Code_Block);
 
     AstNode* cloned_block = ast_clone(context.ast_alloc, code_block->code);
+    cloned_block->next = insert->next;
 
     if (cloned_block->kind == Ast_Kind_Block) {
         AstNode* next = insert->next;
index e2e63bc947c074fd26e2ed234a123e1153231713..0bc1cb45bb08916c0e0de36023bff7c24f612bb2 100644 (file)
@@ -3212,15 +3212,17 @@ static b32 emit_raw_data_(OnyxWasmModule* mod, ptr data, AstTyped* node) {
 
         Type* sl_type = sl->type;
         // ROBUSTNESS: Handle cases for slices and dynamic arrays
-        if (sl_type->kind != Type_Kind_Struct) {
+        if (sl_type->kind != Type_Kind_Struct && sl_type->kind != Type_Kind_Slice && sl_type->kind != Type_Kind_DynArray) {
             retval = 0;
             break;
         }
 
-        i32 i = 0;
-        bh_arr_each(AstTyped *, expr, sl->args.values) {
-            retval &= emit_raw_data_(mod, bh_pointer_add(data, sl_type->Struct.memarr[i]->offset), *expr);
-            i++;
+        i32 mem_count = type_structlike_mem_count(sl_type);
+        StructMember smem;
+
+        fori (i, 0, mem_count) {
+            type_lookup_member_by_idx(sl_type, i, &smem);
+            retval &= emit_raw_data_(mod, bh_pointer_add(data, smem.offset), sl->args.values[i]);
         }
 
         break;
index 6c6825f2bca02f5b40c836e318b09bf35d233097..19c29ab9a0926ce136cd927e2cf11b3d7bc88d80 100644 (file)
@@ -41,7 +41,7 @@ main :: (args: [] cstr) {
 
     file := reader.make(contents);
 
-    cubes := map.make(CubePos, CubeState, .{}, 1021);
+    cubes := map.make(CubePos, CubeState, .{}, 2047);
     defer map.free(^cubes);
 
     z := 0;
index 7806bede2e09f96ecb3e70fa9739fb8405846ba5..443a1cb8fef145ddf09403c777c1a2cfb20f6f76 100644 (file)
@@ -20,8 +20,7 @@ power_mod :: (base: u32, exp: u32, mod: u32) -> u32 {
 }
 
 dlp_bsgs :: (n: u32, a: u32, b: u32) -> u32 {
-    use package core.intrinsics.wasm { ceil_f64, sqrt_f64 }
-    m := cast(u32) ceil_f64(sqrt_f64(~~n));
+    m := cast(u32) math.ceil(math.sqrt(cast(f64) n));
 
     t := map.make(u32, u32, default=0, hash_count=m/2);
     defer map.free(^t);
@@ -36,8 +35,8 @@ dlp_bsgs :: (n: u32, a: u32, b: u32) -> u32 {
 
     tmp = ~~b;
     for i: 0 .. m {
-        if map.has(^t, cast(u32) tmp) {
-            v := map.get(^t, cast(u32) tmp);
+        if map.has(^t, ~~tmp) {
+            v := map.get(^t, ~~tmp);
             return i * m + v; 
         }
 
index f494fe659d0fb4598eb3da60722457d496462afd..ad082a60f69e0ab16ceafee949ae77022199cf56 100644 (file)
@@ -34,12 +34,13 @@ main :: (args: [] cstr) {
         for ch: line do array.push(^forest, ch);
     }
 
-    lis : [5] LineInterp;
-    lis[0] = .{ 0, 0, 1, 1 };
-    lis[1] = .{ 0, 0, 3, 1 };
-    lis[2] = .{ 0, 0, 5, 1 };
-    lis[3] = .{ 0, 0, 7, 1 };
-    lis[4] = .{ 0, 0, 1, 2 };
+    lis := LineInterp.[
+        .{ 0, 0, 1, 1 },
+        .{ 0, 0, 3, 1 },
+        .{ 0, 0, 5, 1 },
+        .{ 0, 0, 7, 1 },
+        .{ 0, 0, 1, 2 },
+    ];
 
     tree_prod: u64 = 1;