using blocked scoping; fixed infinite redraw offscreen
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 16 Sep 2021 03:46:38 +0000 (22:46 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 16 Sep 2021 03:46:38 +0000 (22:46 -0500)
16 files changed:
site/js/js_events.js
src/app/app.onyx
src/app/colors.onyx
src/app/debug_log.onyx
src/app/window_management.onyx
src/app/window_switcher.onyx
src/build.onyx
src/config.onyx
src/features/hex_editor/feature.onyx
src/features/hex_editor/hex_viewer.onyx
src/features/text_editor/text_editor.onyx
src/features/wasm/wasm.onyx
src/main.onyx
src/ui/menubar.onyx
src/ui/window.onyx
src/wasm.onyx

index fe0d0fb779691acfa4ec475f6371aa575254cdf1..2679c3e29ece6a9b0bed75f75eaff45256e07303 100644 (file)
@@ -171,7 +171,7 @@ window.ONYX_MODULES.push({
 
         WASM_U8.set(u8_data, bufferptr);
 
-        if (namelen >= file_data.name.length) {
+        if (nameptr != 0 && namelen <= file_data.name.length) {
             var name_data = new TextEncoder().encode(file_data.name);
             WASM_U8.set(name_data, nameptr);
         }
index b9c8c1dbf7001b7cbef5689874c8c783e2dd3ff9..928e8aad4924dc98282178022d41cbfcdfc6f38e 100644 (file)
@@ -2,19 +2,21 @@ package app
 
 use package core
 
-#private_file events :: package js_events
-#private_file gl     :: package gl
-#private_file gfx    :: package immediate_mode
-#private_file ui     :: package ui
-#private_file config :: package config
-#private_file wasm   :: package wasm_utils
-#private_file debug  :: package debug
+#private_file {
+    events :: package js_events
+    gl     :: package gl
+    gfx    :: package immediate_mode
+    ui     :: package ui
+    config :: package config
+    wasm   :: package wasm_utils
+    debug  :: package debug
+}
 
 use package debug { init as debug_init, debug_log, draw_debug_log }
 use package core.intrinsics.onyx { __initialize }
 
 @Relocate search_buffer: string.String_Buffer;
-on_file_load_callbacks : map.Map(u32, (file_event: ^events.Event) -> void);
+on_file_load_callbacks : Map(u32, (file_event: ^events.Event) -> void);
 
 @Relocate
 Tool :: struct {
@@ -34,7 +36,7 @@ Application_State :: struct {
     file := Active_File.{};
 
     windows_store  : alloc.pool.PoolAllocator(Application_Window);
-    windows_map    : map.Map(str, ^Application_Window);
+    windows_map    : Map(str, ^Application_Window);
     windows_sorted : [..] ^Application_Window;
 
     window_switcher_state : Window_Switcher_State;
@@ -85,17 +87,17 @@ init :: () {
     gl.enable(gl.BLEND);
     gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
 
-    array.push(^registered_tools, .{
+    registered_tools << Tool.{
         id   = "load_file_info",
         name = "File Info",
         open = () {
-            open_window("load_file_info", "Loaded file info", .{ 0, 0 }, (_: rawptr, win: ^Application_Window) {
+            open_window("load_file_info", "Loaded file info", .{ 0, 0 }, (_, win) => {
                 if state.has_active_file {
                     buffer: [512] u8;
-                    name_text := conv.str_format("File name: {}", ~~buffer, state.file.name);
+                    name_text := conv.str_format(buffer, "File name: {}", state.file.name);
                     ui.draw_text(.{ 0, 0, 300, 200 }, name_text);
 
-                    size_text := conv.str_format("File size: {} bytes", ~~buffer, state.file.data.count);
+                    size_text := conv.str_format(buffer, "File size: {} bytes", state.file.data.count);
                     ui.draw_text(.{ 0, 32, 300, 200 }, size_text);
 
                 } else {
@@ -106,7 +108,7 @@ init :: () {
             move_window_to_top("load_file_info");
             focus_window("load_file_info");
         }
-    });
+    };
 
     // Dynamically load things in the binary
     {
@@ -182,12 +184,12 @@ init :: () {
             fnt_file_id : u32;
             tex_file_id : u32;
 
-            fnt_file_size := cast(u32) 0;
-            tex_file_size := cast(u32) 0;
+            fnt_file_size := 0;
+            tex_file_size := 0;
         }
         #persist fonts_loading : [..] Loading_Font;
 
-        font_file_loaded :: (ev: ^events.Event) {
+        font_file_loaded :: (ev) => {
             lf: ^Loading_Font = null;
 
             for ^entry: fonts_loading {
@@ -201,8 +203,8 @@ init :: () {
                 fnt_data := memory.make_slice(u8, lf.fnt_file_size);
                 tex_data := memory.make_slice(u8, lf.tex_file_size);
                 defer {
-                    cfree(fnt_data.data); 
-                    cfree(tex_data.data); 
+                    cfree(fnt_data.data);
+                    cfree(tex_data.data);
                 }
 
                 @ErrorHandling
@@ -313,7 +315,8 @@ handle_event :: (event: ^events.Event) {
 needs_redraw :: () -> bool {
     return ui.has_active_animation()
         || debug.debug_log_transitioning()
-        || state.window_switcher_state->is_animating();
+        || state.window_switcher_state->is_animating()
+        || state.workspace_state.transform_transition > 0;
 }
 
 update :: (dt: f32) {
@@ -325,7 +328,7 @@ draw :: () {
     gl.clearColor(bg_color.r, bg_color.g, bg_color.b, bg_color.a);
     gl.clear(gl.COLOR_BUFFER_BIT);
 
-    ui.set_cursor(ui.Cursors.Default);
+    #if #defined(ui.set_cursor) { ui.set_cursor(ui.Cursors.Default); }
 
     window_width, window_height := gfx.get_window_size();
     window_rectangle := ui.Rectangle.{ 0, 0, ~~window_width, ~~window_height };
@@ -376,10 +379,10 @@ draw :: () {
 
     // Menu bar drawing
     {
-        #insert gfx.save_matrix;
-        
+        gfx.save_matrix();
+
         gfx.identity();
-        ui.menubar(menu_bar, ^search_buffer, ~~ui.Menu_Bar_Option.[
+        ui.menubar(menu_bar, ^search_buffer, ui.Menu_Bar_Option.[
             .{ label = "File" },
             .{ label = "Test" },
         ]);
@@ -390,17 +393,24 @@ draw :: () {
 
     gfx.flush();
     ui.end_frame();
+
+    #if config.DEBUG {
+        if needs_redraw() {
+            gfx.rect(.{~~(window_width-16),0}, .{16,16}, .{1,0,0});
+            gfx.flush();
+        }
+    }
 }
 
-open_tool_opener :: () {
+open_tool_opener :: macro () {
     mouse_pos := gfx.transform_point(^state.workspace_state.transform, .{ ui.mouse_state.x_, ui.mouse_state.y_ });
 
     close_window("tool_opener");
     open_window("tool_opener", "Tool Opener", .{ mouse_pos.x, mouse_pos.y }, init_size=.{ 200, 400 },
-        draw=(_: rawptr, win: ^Application_Window) {
+        draw=(_, win) => {
         window_rect := ui.Rectangle.{ 0, 0, win.window_state.size.x, win.window_state.size.y };
 
-        ui.scrollable_region_start(window_rect, maximum_y=~~(registered_tools.count - 1) * 40.0f);
+        ui.scrollable_region_start(window_rect, .{ maximum_y=~~(registered_tools.count - 1) * 40.0f });
         defer ui.scrollable_region_stop();
 
         button_rect : ui.Rectangle;
@@ -420,20 +430,24 @@ open_tool_opener :: () {
     });
 }
 
-#private_file background_tile_texture : gfx.Texture;
-#private_file draw_background_lines :: (width: f32, height: f32, line_color := gfx.Color4.{0.2, 0.2, 0.2}, line_spacing := 32.0f) {
-    gl :: package gl
+@Relocate // This should be moved to somewhere else when the code base.
+#private_file {
+    background_tile_texture : gfx.Texture;
+
+    draw_background_lines :: (width: f32, height: f32, line_color := gfx.Color4.{0.2, 0.2, 0.2}, line_spacing := 32.0f) {
+        gl :: package gl
 
-    #insert gfx.save_matrix;
+        gfx.save_matrix();
 
-    trans := gfx.global_renderer->get_transform();
-    sx    := trans.scale.x * line_spacing;
-    sy    := trans.scale.y * line_spacing;
-    tx    := -trans.translation.x / sx;
-    ty    := -trans.translation.y / sy;
+        trans := gfx.global_renderer->get_transform();
+        sx    := trans.scale.x * line_spacing;
+        sy    := trans.scale.y * line_spacing;
+        tx    := -trans.translation.x / sx;
+        ty    := -trans.translation.y / sy;
 
-    gfx.identity();
-    gfx.set_texture(^background_tile_texture);
-    gfx.textured_rect(.{ 0, 0 }, .{ width, height }, .{ tx, ty }, .{ width / sx, height / sy }, color=line_color); 
-    gfx.set_texture(); 
+        gfx.identity();
+        gfx.set_texture(^background_tile_texture);
+        gfx.textured_rect(.{ 0, 0 }, .{ width, height }, .{ tx, ty }, .{ width / sx, height / sy }, color=line_color); 
+        gfx.set_texture(); 
+    }
 }
index 86784bfde6d2e37d94d264f64434e9a8b8b4814e..3e7d2e1a4e6f4bb798b98f478b795e9ad7cc8d7c 100644 (file)
@@ -2,13 +2,15 @@ package app
 
 use package core
 
-#private_file events :: package js_events
-#private_file gl     :: package gl
-#private_file gfx    :: package immediate_mode
-#private_file ui     :: package ui
-#private_file config :: package config
-#private_file wasm   :: package wasm_utils
-#private_file debug  :: package debug
+#private_file {
+    events :: package js_events
+    gl     :: package gl
+    gfx    :: package immediate_mode
+    ui     :: package ui
+    config :: package config
+    wasm   :: package wasm_utils
+    debug  :: package debug
+}
 
 use package debug { init as debug_init, debug_log, draw_debug_log }
 use package core.intrinsics.onyx { __initialize }
index 72b1c819ff21576cb390830fa4d17f0dd6346e84..a1b5ebc73b6b0036473fb29e9aefcbc38b50a422 100644 (file)
@@ -1,13 +1,18 @@
 package debug
 
 use package core
-#private_file ui  :: package ui
-#private_file gfx :: package immediate_mode
-#private_file config :: package config
 
-#private y_scroll := 0.0f;
-#private debug_log_y_offset := 0.0f;
-#private debug_log_y_offset_target := 0.0f;
+#private_file {
+    ui  :: package ui
+    gfx :: package immediate_mode
+    config :: package config
+}
+
+#private {
+    y_scroll := 0.0f;
+    debug_log_y_offset := 0.0f;
+    debug_log_y_offset_target := 0.0f;
+}
 
 init :: () {
     log_buffer.line_arena = alloc.arena.make(context.allocator, 4096);
@@ -48,7 +53,7 @@ debug_log :: (severity: Severity, format: str, args: ..any) {
     if severity < minimum_severity do return;
 
     buffer1: [4096] u8;
-    s := conv.str_format_va(format, ~~buffer1, ~~args);
+    s := conv.str_format_va(buffer1, format, args);
     lines := string.split(s, #char "\n", context.temp_allocator);
 
     line_alloc := alloc.arena.make_allocator(^log_buffer.line_arena);
@@ -56,7 +61,7 @@ debug_log :: (severity: Severity, format: str, args: ..any) {
         if l.count == 0 do continue;
 
         buffer2: [4096] u8;
-        s = conv.str_format("[{}] {}\n", ~~buffer2, severity, l);
+        s = conv.str_format(buffer2, "[{}] {}\n", severity, l);
         line := string.alloc_copy(s, line_alloc);
 
         array.push(^log_buffer.lines, line);
index 273f5129d93e636533669bf38252e8b929a1788d..2168f6605234430c91616de1f6c221c830963e6c 100644 (file)
@@ -2,22 +2,25 @@ package app
 
 use package core
 
-#private_file events :: package js_events
-#private_file gl     :: package gl
-#private_file gfx    :: package immediate_mode
-#private_file ui     :: package ui
-#private_file config :: package config
-#private_file wasm   :: package wasm_utils
-#private_file debug  :: package debug
+#private_file {
+    events :: package js_events
+    gl     :: package gl
+    gfx    :: package immediate_mode
+    ui     :: package ui
+    config :: package config
+    wasm   :: package wasm_utils
+    debug  :: package debug
+}
 
 use package debug { init as debug_init, debug_log, draw_debug_log }
 use package core.intrinsics.onyx { __initialize }
 
 open_window :: (id: str,
-                    title: str,
-                    init_position: gfx.Vector2,
-                    draw: (rawptr, ^Application_Window) -> void,
-                    init_size := gfx.Vector2.{ 600, 600 }) {
+                title: str,
+                init_position: gfx.Vector2,
+                draw: (rawptr, ^Application_Window) -> void,
+                init_size := gfx.Vector2.{ 600, 600 },
+                draw_data := null) {
 
     if map.has(^state.windows_map, id) {
         debug_log(.Warning, "Window with id '{}' is already registered.", id);
@@ -39,6 +42,7 @@ open_window :: (id: str,
     win.window_state.title = title;
 
     win.draw = draw;
+    win.draw_data = draw_data;
 
     map.put(^state.windows_map, id, win);
     array.push(^state.windows_sorted, win);
@@ -52,10 +56,10 @@ move_window_to_top :: (id: str) {
 
     win := map.get(^state.windows_map, id);
 
-    index := array.find(^state.windows_sorted, win);
+    index := array.find(state.windows_sorted, win);
     assert(index >= 0, "Window not found.");
 
-    array.transplant(^state.windows_sorted, index, state.windows_sorted.count - 1);
+    array.transplant(state.windows_sorted, index, state.windows_sorted.count - 1);
 }
 
 focus_window :: (id: str) {
@@ -103,4 +107,4 @@ close_window :: (id: str) {
 
 window_is_open :: (id: str) -> bool {
     return map.has(^state.windows_map, id);
-}
\ No newline at end of file
+}
index e54e90be6a6bd2c1347c266029b152ee76cc96c0..a50ce0d3287f5c068775c4e417438be31a494e10 100644 (file)
@@ -1,12 +1,15 @@
 package app
 
-#private_file ui  :: package ui
-#private_file gfx :: package immediate_mode
-#private_file config :: package config
-#private_file math :: package core.math
-#private_file string :: package core.string
-#private_file memory :: package core.memory
-use package core.intrinsics.onyx { __initialize }
+#private_file {
+    ui  :: package ui
+    gfx :: package immediate_mode
+    config :: package config
+    math :: package core.math
+    string :: package core.string
+    memory :: package core.memory
+
+    use package core.intrinsics.onyx { __initialize }
+}
 
 Window_Switcher_State :: struct {
     visibility := 0.0f;
@@ -21,7 +24,7 @@ Window_Switcher_State :: struct {
     x_scroll := 0.0f;
     y_scroll := 0.0f;
 
-    selected_index: i32 = 0;
+    selected_index := 0;
 
     init :: (use state: ^Window_Switcher_State) {
         __initialize(state);
@@ -54,7 +57,7 @@ Window_Switcher_State :: struct {
         ui.move_towards(^visibility, visibility_target, 0.08f);
         if visibility == 0.0f do return;
 
-        #insert gfx.save_matrix;
+        gfx.save_matrix();
         gfx.identity();
 
         quater_width  := ui.Rectangle.width(window_rectangle) / 4;
index a1c11506b7e71f47b962f506e26e8ba54a3113de..96d302be9005643a55bb3e0e8c6c1d03af969e46 100644 (file)
@@ -11,7 +11,7 @@
     #load "modules/ui/module"
     #load "modules/js_events/module"
     #load "modules/bmfont/module"
-    
+
     #load "src/ui/window"
     #load "src/ui/menubar"
     #load "src/ui/cursor"
index cd3f1e0ccbcf26f4dbe0a18f4fb37f457f0f1434..7d9156b52bcc0a664354fede18761631fdca6acb 100644 (file)
@@ -4,6 +4,7 @@ package config
 
 use package immediate_mode { Color4 }
 
+DEBUG :: true
 ONLY_REDRAW_ON_EVENTS :: true
 
 light_color_scheme_file :: "/res/colors_light.json"
index 6b8548ea1df437b9f3c5c9d4616e598b68c58d52..d28262d9cf415dfc321731685c278ada71cb82be 100644 (file)
@@ -4,4 +4,4 @@ package feature.hex_viewer
 
 Feature_Hex_Viewer :: struct {
     setup := setup;
-}
\ No newline at end of file
+}
index 17cf6207c7691148006509135de35700224b51ef..62ced36a025c383da3aa1b106fb66b4f77784f86 100644 (file)
@@ -1,8 +1,10 @@
 package feature.hex_viewer
 
-#private_file app :: package app
-#private_file ui :: package ui
-#private_file config :: package config
+#private_file {
+    app :: package app
+    ui :: package ui
+    config :: package config
+}
 
 use package core
 use package debug { debug_log }
@@ -12,12 +14,15 @@ window_name :: "Hex Viewer"
 
 Hex_Viewer_State :: struct {
     scrollable_region := ui.Scrollable_Region_State.{};
+
+    highlighted_line   : i32 = -1; // -1 is uninitialized
+    highlighted_column : i32 = -1;
 }
 
 // Should this be global? Or should each viewer window get their own?
-#private viewer_state := Hex_Viewer_State.{};
+#private global_viewer_state := Hex_Viewer_State.{};
 
-window_draw :: (_: rawptr, win: ^app.Application_Window) {
+window_draw :: (use viewer_state: ^Hex_Viewer_State, win: ^app.Application_Window) {
     orig_r: ui.Rectangle = .{ 0, 0, win.window_state.size.x, win.window_state.size.y };
     r := orig_r;
 
@@ -27,6 +32,7 @@ window_draw :: (_: rawptr, win: ^app.Application_Window) {
 
     ui.use_font(text_theme.font);
     em_height := ui.get_text_height("M", text_theme.font_size) / 2;
+    line_height := em_height * 2;
 
     win.window_state.max_size.x = (10 + 1 + 3 * 16 + 2 + 16) * em_height;
     win.window_state.background_color = config.Colors.dark_background;
@@ -36,19 +42,46 @@ window_draw :: (_: rawptr, win: ^app.Application_Window) {
         return;
     }
 
+    mx, my    := ui.get_mouse_position();
     file_data := app.state.file.data;
 
     {
         // This is a hack to get the region to be "scrollable" without actually applying any of the scrolling effects
-        ui.scrollable_region_start(r, maximum_y=em_height*~~(file_data.count / 8 - 1), state=^viewer_state.scrollable_region);
+        ui.scrollable_region_start(r, .{ maximum_y=em_height*~~(file_data.count / 8 - 1) }, state=^scrollable_region);
         ui.scrollable_region_stop();
     }
 
+
     line_data: [128] u8;
-    line := string.buffer_make(~~line_data);
+    line := string.buffer_make(line_data);
+
+    first_line: i32 = ~~math.floor(-scrollable_region.transform.translation.y / line_height);
+    line_count: i32 = ~~math.ceil(win.window_state.size.y / em_height);
 
-    first_line: i32 = ~~math.floor(-viewer_state.scrollable_region.transform.translation.y / (2*em_height));
-    line_count: i32 = ~~math.ceil(win.window_state.size.y / (em_height));
+    highlighted_column = -1;
+    highlighted_line = ~~math.floor(my / line_height) if ui.Rectangle.contains(r, mx, my) else -1;
+    if highlighted_line >= 0 {
+        if mx >= 10 * em_height && mx <= em_height * (9 + 3 * 16 - 0.0625f) {
+            highlighted_column = ~~math.floor((mx - 9 * em_height) / (3 * em_height));
+        }
+
+        if mx >= em_height * (9 + 3 * 16 + 2) && mx <= em_height * (9 + 3 * 16 + 2 + 16) {
+            highlighted_column = ~~math.floor((mx - (9 + 3 * 16 + 2) * em_height) / em_height);
+        }
+    }
+
+    if highlighted_line >= 0 && highlighted_line <= line_count {
+        hy := ~~highlighted_line * line_height;
+        ui.draw_rect(.{ 0, hy, r.x1, hy + line_height }, color=config.Colors.background);
+
+        if highlighted_column >= 0 {
+            cx := em_height * ~~(10 + highlighted_column * 3);
+            ui.draw_rect(.{ cx, hy, cx + em_height * 2, hy + line_height }, color=config.Colors.secondary);
+
+            cx = em_height * ~~(59 + highlighted_column);
+            ui.draw_rect(.{ cx, hy, cx + em_height, hy + line_height }, color=config.Colors.secondary);
+        }
+    }
 
     visible_lines := first_line .. (first_line + line_count);
 
@@ -56,7 +89,7 @@ window_draw :: (_: rawptr, win: ^app.Application_Window) {
         if i * 16 >= file_data.count do break;
 
         offset_data: [16] u8;
-        output := conv.str_format("{w8b16} ", ~~offset_data, i * 16);
+        output := conv.str_format(offset_data, "{w8b16} ", i * 16);
         ui.draw_text(r, output, theme=^text_theme);
         r = ui.Flow.padding(r, top=32);
     }
@@ -73,7 +106,7 @@ window_draw :: (_: rawptr, win: ^app.Application_Window) {
             if index >= file_data.count do break;
 
             ch_data: [8] u8;
-            output := conv.str_format("{w2b16} ", ~~ch_data, cast(u32) file_data[index]);
+            output := conv.str_format(ch_data, "{w2b16} ", cast(u32) file_data[index]);
             string.buffer_append(^line, output);
         }
 
@@ -81,7 +114,7 @@ window_draw :: (_: rawptr, win: ^app.Application_Window) {
         r = ui.Flow.padding(r, top=32);
     }
 
-    r = ui.Flow.padding(orig_r, left=3*em_height*16 + 10*em_height + 32);
+    r = ui.Flow.padding(orig_r, left=3*em_height*16 + 10*em_height + em_height);
 
     for i: visible_lines {
         if i * 16 >= file_data.count do break;
@@ -98,7 +131,7 @@ window_draw :: (_: rawptr, win: ^app.Application_Window) {
             if char >= 32 && char <= 126 do data[0] = char;
             else                         do data[0] = #char ".";
 
-            string.buffer_append(^line, ~~data);
+            string.buffer_append(^line, data);
         }
 
         ui.draw_text(r, string.buffer_to_str(^line), theme=^text_theme);
@@ -107,25 +140,25 @@ window_draw :: (_: rawptr, win: ^app.Application_Window) {
 }
 
 open_window :: () {
-    app.open_window(window_id, window_name, .{ 0, 0 }, window_draw, .{ 1300, 650 });
+    app.open_window(window_id, window_name, .{ 0, 0 }, window_draw, .{ 1300, 650 }, draw_data=^global_viewer_state);
     app.move_window_to_top(window_id);
     app.focus_window(window_id);
 
-/*
-    app.open_window("dummy", "DUMMY TESTING", .{ 0, 0 }, (_: rawptr, _: ^app.Application_Window) {
+    app.open_window("dummy", "DUMMY TESTING", .{ 0, 0 }, (_, win) => {
         buffer: [1024] u8;
-        s := conv.str_format("{p}", ~~buffer, viewer_state);
-        ui.draw_text(.{0,0,0,0}, s);
+        s := conv.str_format(buffer, "{p*}", ^global_viewer_state);
+        theme := ui.default_text_theme;
+        theme.font = config.Fonts.FiraCode.index;
+        ui.draw_text(.{0,0,0,0}, s, theme=^theme);
     });
-*/
 }
 
 setup :: () {
     debug_log(.Debug, "Initializing hex viewer...", 0);
 
-    array.push(^app.registered_tools, .{
+    app.registered_tools << app.Tool.{
         id   = window_id,
         name = window_name,
         open = open_window,
-    });
-}
\ No newline at end of file
+    };
+}
index 8948eb891cf1cca35df815cb77d944edfe6fe138..5c3e48da74182282760e8188facad1e734426076 100644 (file)
@@ -1,8 +1,10 @@
 package feature.text_editor
 
-#private_file app :: package app
-#private_file ui  :: package ui
-#private_file config :: package config
+#private_file {
+    app :: package app
+    ui  :: package ui
+    config :: package config
+}
 
 use package core
 use package debug { debug_log }
@@ -11,12 +13,12 @@ window_id :: "text_editor"
 window_name :: "Text Editor"
 
 open_text_editor :: () {
-    app.open_window(window_id, window_name, .{ 0, 0 }, (_: rawptr, win: ^app.Application_Window) {
+    app.open_window(window_id, window_name, .{ 0, 0 }, (_, win) => {
         if !app.state.has_active_file do return;
 
         ui.scrollable_region_start(.{ 0, 0, win.window_state.size.x, win.window_state.size.y });
         defer ui.scrollable_region_stop();
-        
+
         text_theme := ui.default_text_theme;
         text_theme.font = config.Fonts.FiraCode.index;
         ui.draw_text(.{ 0, 0, 200, 200 }, app.state.file.data, theme=^text_theme);
@@ -34,4 +36,4 @@ setup :: () {
         name = window_name,
         open = open_text_editor,
     });
-}
\ No newline at end of file
+}
index cac42be62c1ca6030a36ebdcf0b2e9f68d9ebf8e..3e048bab260d5f8ec7f750d33ff53ade5bbb05ad 100644 (file)
@@ -1,8 +1,14 @@
 package feature.wasm
 
-use package app { Application_State }
-use package debug { debug_log }
+#private_file {
+    app    :: package app
+    ui     :: package ui
+    config :: package config
+
+    use package core
+    use package debug { debug_log }
+}
 
 setup :: () {
     debug_log(.Info, "Wasm Loader Loaded from {}", #file);
-}
\ No newline at end of file
+}
index 33ec77c5bde795130b8c00c4972fcbf97d594735..32b35e52984e67f1409816da2e5b05ffae50b2a4 100644 (file)
@@ -1,8 +1,10 @@
 
-#private_file events :: package js_events
-#private_file config :: package config
-#private_file app    :: package app
-#private_file ui     :: package ui
+#private_file {
+    events :: package js_events
+    config :: package config
+    app    :: package app
+    ui     :: package ui
+}
 
 main :: (args: [] cstr) {
     app.init();
index 641762866927ce6b7eb081fe66f5fd8cbc17878e..c3fbcc951b7528d3f17799c2ecdc947b9488d02d 100644 (file)
@@ -2,9 +2,12 @@
 
 package ui
 
-#private_file iter   :: package core.iter
-#private_file config :: package config
-use package core.string
+#private_file {
+    iter   :: package core.iter
+    config :: package config
+
+    use package core.string
+}
 
 Menu_Bar_Option :: struct {
     label   : str;
@@ -27,7 +30,7 @@ menubar :: (r: Rectangle, @Temporary search_buffer: ^String_Buffer, options: []
 
     button_rect : Rectangle;
 
-    for option: iter.enumerate(iter.from_array(options)) {
+    for option: options |> iter.from_array() |> iter.enumerate() {
         button_rect, menu_rect = Flow.split_vertical(menu_rect, left_width=100);
         button(button_rect, option.value.label, theme=^menu_button_theme, increment=option.index);
     }
index b147c7a488182135f25a3ff220f96e758df6993f..2dc486db2af85dd8658de84093a5cc034d008fe8 100644 (file)
@@ -1,5 +1,8 @@
 package ui
-#private_file map :: package core.map
+
+#private_file {
+    map :: package core.map
+}
 
 // This will be stored by the end user's library.
 Window_State :: struct {
@@ -35,7 +38,7 @@ Window_State :: struct {
 window_start :: (use state: ^Window_State, site := #callsite, increment := 0) -> bool {
 
     hash := get_site_hash(site, increment);
-    animation_state := map.get(^animation_states, hash);
+    animation_state := get_animation(hash);
 
     mx, my := get_mouse_position();
     if state->get_rectangle() |> Rectangle.contains(mx, my) {
@@ -104,12 +107,6 @@ window_start :: (use state: ^Window_State, site := #callsite, increment := 0) ->
         state.should_close = true;
     }
 
-    if animation_state.click_time > 0 || animation_state.hover_time > 0 {
-        map.put(^animation_states, hash, animation_state);
-    } else {
-        map.delete(^animation_states, hash);
-    }
-
     gfx.push_matrix();
     gfx.push_scissor(x, y, w, h);
     gfx.apply_transform(.{ translation = .{ x, y }, scale = .{ 1, 1 } });
@@ -120,4 +117,4 @@ window_start :: (use state: ^Window_State, site := #callsite, increment := 0) ->
 window_end :: () {
     gfx.pop_scissor();
     gfx.pop_matrix();
-}
\ No newline at end of file
+}
index dc0ad532b90d30a2ffbf805fe0cafa5727e97d67..a1db1f588682c1fdab8a19b37056b22211159398 100644 (file)
@@ -2,10 +2,12 @@ package app
 
 use package core
 
-#private_file ui     :: package ui
-#private_file gfx    :: package immediate_mode
-#private_file config :: package config
-#private_file wasm   :: package wasm_utils
+#private_file {
+    ui     :: package ui
+    gfx    :: package immediate_mode
+    config :: package config
+    wasm   :: package wasm_utils
+}
 
 use package core.intrinsics.onyx { __initialize }
 
@@ -26,7 +28,7 @@ Wasm_Analyzer_State :: struct {
     wasm_binary   : wasm.WasmBinary;
     wasm_sections : wasm.WasmSections;
 
-    window_states : map.Map(u32, ui.Window_State);
+    window_states : Map(u32, ui.Window_State);
 
     sidebar_expansion_target := 0.0f;
 }
@@ -83,12 +85,12 @@ draw_sidebar :: (use state: ^Wasm_Analyzer_State, y_offset := 32.0f) {
     button_rect : ui.Rectangle;
 
     text_rect, sidebar_rectangle = ui.Flow.split_horizontal(sidebar_rectangle, top_height=50);
-    s := conv.str_format("Function count: {}\n", ~~text_buffer, wasm_sections.code_section.count);
+    s := conv.str_format(text_buffer, "Function count: {}\n", wasm_sections.code_section.count);
     ui.draw_text(text_rect, s);
 
     for i: wasm_sections.code_section.count {
         button_rect, sidebar_rectangle = ui.Flow.split_horizontal(sidebar_rectangle, top_height=40);
-        ui.button(button_rect, conv.str_format("Function {}", ~~text_buffer, i), increment=i);
+        ui.button(button_rect, conv.str_format(text_buffer, "Function {}", i), increment=i);
     }
 }