working on dynamic feature loading
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 7 Aug 2021 13:46:48 +0000 (08:46 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 7 Aug 2021 13:46:48 +0000 (08:46 -0500)
res/colors_light.json
src/app.onyx
src/build.onyx
src/config.onyx
src/debug_log.onyx
src/features/load_features.onyx [new file with mode: 0644]
src/features/wasm/feature.onyx [new file with mode: 0644]
src/features/wasm/wasm.onyx [new file with mode: 0644]
src/ui/menubar.onyx [new file with mode: 0644]
src/wasm.onyx

index e02a70b56aa040333ea9dd8ab3c62de02b6f9e60..7a6311776701e9d16b9762bde2fbe659109e7c65 100644 (file)
     "primary":       [ 0.051, 0.278, 0.631 ],
     "primary_light": [ 0.329, 0.451, 0.827 ],
     "primary_dark":  [ 0,     0.129, 0.443 ],
-    "primary_text":  [ 0,     0,     0     ],
+    "primary_text":  [ 1,     1,     1     ],
 
     "secondary":       [ 0,     0.376, 0.392 ],
     "secondary_light": [ 0.259, 0.557, 0.573 ],
     "secondary_dark":  [ 0,     0.212, 0.227 ],
-    "secondary_text":  [ 0,     0,     0     ]
+    "secondary_text":  [ 1,     1,     1     ]
 }
index 5219f7fd75f79990f6711e2c619f4f874f436c0c..1baad432ddc877abbe55e3e478914a87b88b6657 100644 (file)
@@ -22,7 +22,9 @@ background_tile_texture : gfx.Texture;
 
 on_file_load_callbacks : map.Map(u32, (file_event: ^events.Event) -> void);
 
-analyzer_state : Wasm_Analyzer_State;
+Application_State :: struct {
+    _: i32;
+}
 
 init :: () {
     debug_init();
@@ -46,7 +48,36 @@ init :: () {
     gl.enable(gl.BLEND);
     gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
 
-    __initialize(^analyzer_state);
+    {
+        use type_info;
+
+        for type: type_table {
+            if type.kind != .Struct do continue;
+
+            ts := cast(^Type_Info_Struct) type;
+            if !string.starts_with(ts.name, "Feature_") do continue;
+
+            debug_log(.Info, "Found feature '{}'", string.advance(ts.name, 8));
+
+            for ^member: ts.members {
+                Hook_Function_Type :: #type (^Application_State) -> void;
+
+                if member.name == "setup" {
+                    assert(member.type == Hook_Function_Type, "setup has the wrong type.");
+                    assert(member.default != null, "setup has no default function.");
+
+                    (*(cast(^Hook_Function_Type) member.default))(null);
+                }
+
+                if member.name == "work" {
+                    assert(member.type == Hook_Function_Type, "work has the wrong type.");
+                    assert(member.default != null, "work has no default function.");
+
+                    (*(cast(^Hook_Function_Type) member.default))(null);
+                }
+            }
+        }
+    }
 
     load_background_tile_texture :: () {
         background_tile_texture = gfx.load_texture(32, 32, #file_contents "res/images/background_tile.data", gl.RGB, gl.RGB);
@@ -93,6 +124,8 @@ init :: () {
         config.Colors.secondary_dark  = decode_color(colors.root["secondary_dark"]);
         config.Colors.secondary_text  = decode_color(colors.root["secondary_text"]);
 
+        update_ui_colors();
+
         decode_color :: (v: ^json.Value) -> gfx.Color4 {
             return .{
                 r = ~~v[0]->as_float(),
@@ -219,7 +252,7 @@ handle_event :: (event: ^events.Event) {
                 }
 
                 if event.keyboard->get_name() == "Tab" {
-                    toggle_sidebar(^analyzer_state);
+                    // toggle_sidebar(^analyzer_state);
                     break;
                 }
 
@@ -255,7 +288,7 @@ handle_event :: (event: ^events.Event) {
             }
 
             // This transfers ownership of wasm_data to the analyzer_state
-            load_wasm_binary(^analyzer_state, wasm_data);
+            // load_wasm_binary(^analyzer_state, wasm_data);
         }
     }
 }
@@ -279,7 +312,7 @@ draw :: () {
 
     ui.workspace_end();
 
-    draw_sidebar(^analyzer_state);
+    // draw_sidebar(^analyzer_state);
 
     // Menu bar drawing
     {
@@ -287,7 +320,11 @@ draw :: () {
         defer gfx.pop_matrix();
         
         gfx.identity();
-        draw_menu_bar(^menu_bar);
+        ui.menubar(menu_bar, ^search_buffer, ~~ui.Menu_Bar_Option.[
+            .{ label = "File" },
+            .{ label = "Test" },
+        ]);
+        //draw_menu_bar(^menu_bar);
     }
 
     // Debug log drawing
@@ -353,3 +390,20 @@ draw :: () {
 }
 
 #private_file background_tile_texture : gfx.Texture;
+
+
+update_ui_colors :: () {
+    ui.default_text_theme.text_color = config.Colors.foreground;
+
+    ui.default_button_theme.text_color       = config.Colors.primary_text;
+    ui.default_button_theme.background_color = config.Colors.primary_dark;
+    ui.default_button_theme.hover_color      = config.Colors.primary;
+    ui.default_button_theme.click_color      = config.Colors.primary_light;
+    ui.default_button_theme.border_color     = config.Colors.primary;
+
+    ui.default_textbox_theme.text_color       = config.Colors.primary_text;
+    ui.default_textbox_theme.background_color = config.Colors.primary_dark;
+    ui.default_textbox_theme.hover_color      = config.Colors.primary;
+    ui.default_textbox_theme.click_color      = config.Colors.primary_light;
+    ui.default_textbox_theme.border_color     = config.Colors.primary;
+}
index 0ad8357abcf87ff2fcc8c0bc9ded6aa37ab3efdc..b39a09de888d0d6640230fd428051cbd4df5aedc 100644 (file)
     #load "src/main"
     
     #load "src/app"
-    #load "src/wasm"
+    // #load "src/wasm"
+    #load "src/features/load_features"
 
     #load "src/ui/window"
+    #load "src/ui/menubar"
     #load "src/debug_log"
 }
 
index 0d7e4100efc25cc68cf2ce964036a37527227137..1e642cbe86b1f28caa29146cd04800ff6258295e 100644 (file)
@@ -4,7 +4,7 @@ package config
 
 use package immediate_mode { Color4 }
 
-color_scheme_file :: "/res/colors_dark.json"
+color_scheme_file :: "/res/colors_light.json"
 
 Colors : struct {
     dark_background : Color4;
index 49bb74f99d950141fdd9b0779f988b700b475c79..7c1978c489fcab74e2e0e15c44e9e5bfc0adbaf5 100644 (file)
@@ -3,6 +3,7 @@ package debug
 use package core
 #private_file ui  :: package ui
 #private_file gfx :: package immediate_mode
+#private_file config :: package config
 
 init :: () {
     log_buffer.line_arena = alloc.arena.make(context.allocator, 4096);
@@ -63,15 +64,17 @@ draw_debug_log :: (r: ui.Rectangle, y_scroll: ^f32 = null, site := #callsite) {
     gfx.push_scissor(x, y - h, w, h);
     defer gfx.pop_scissor();
 
-    ui.draw_rect(r, color=.{0,0,0,0.8});
+    background_color := config.Colors.background;
+    background_color.a = 0.8;
+    ui.draw_rect(r, color=background_color);
 
-    scale :: 1f;
+    scale :: 0.75f;
     y_offset := line_spacing * scale + *y_scroll;
 
     while i := log_buffer.lines.count - 1; cast(i32) i >= 0 {
         defer i -= 1;
 
-        ui.draw_text_raw(log_buffer.lines[i], x, y - y_offset, color=.{ 0.2, 1.0, 0.2 }, font=1, size=scale);
+        ui.draw_text_raw(log_buffer.lines[i], x, y - y_offset, color=.{ 0.2, 0.7, 0.2 }, font=1, size=scale);
         y_offset += line_spacing * scale;
     }
 }
diff --git a/src/features/load_features.onyx b/src/features/load_features.onyx
new file mode 100644 (file)
index 0000000..6e111df
--- /dev/null
@@ -0,0 +1,4 @@
+
+// Add #load statements for the features
+
+#load "./wasm/feature"
\ No newline at end of file
diff --git a/src/features/wasm/feature.onyx b/src/features/wasm/feature.onyx
new file mode 100644 (file)
index 0000000..3fd0983
--- /dev/null
@@ -0,0 +1,7 @@
+package feature_wasm
+
+#load "./wasm"
+
+Feature_Wasm_Loader :: struct {
+    setup := setup;
+}
\ No newline at end of file
diff --git a/src/features/wasm/wasm.onyx b/src/features/wasm/wasm.onyx
new file mode 100644 (file)
index 0000000..7447238
--- /dev/null
@@ -0,0 +1,8 @@
+package feature_wasm
+
+use package app { Application_State }
+use package debug { debug_log }
+
+setup :: (use app: ^Application_State) {
+    debug_log(.Info, "Wasm Loader Loaded from {}", #file);
+}
\ No newline at end of file
diff --git a/src/ui/menubar.onyx b/src/ui/menubar.onyx
new file mode 100644 (file)
index 0000000..6417628
--- /dev/null
@@ -0,0 +1,37 @@
+// This is not a portable file. It is heavily tied to this project.
+
+package ui
+
+#private_file iter   :: package core.iter
+#private_file config :: package config
+use package core.string
+
+Menu_Bar_Option :: struct {
+    label   : str;
+    action  : () -> void = null_proc;
+    options : [] Menu_Bar_Option = .{ null, 0 };
+}
+
+menubar :: (r: Rectangle, @Temporary search_buffer: ^String_Buffer, options: [] Menu_Bar_Option, site := #callsite, increment := 0) {
+    menu_rect := r;
+    draw_rect(menu_rect, color=config.Colors.background);
+
+    menu_button_theme := default_button_theme;
+    menu_button_theme.border_width = 2;
+    menu_button_theme.font_size = .9;
+    menu_button_theme.font = 0;
+
+    menu_textbox_theme := default_textbox_theme;
+    menu_textbox_theme.border_width = 2;
+    menu_textbox_theme.font_size = .9;
+
+    button_rect : Rectangle;
+
+    for option: iter.enumerate(iter.from_array(options)) {
+        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);
+    }
+
+    _, search_rect := Flow.split_vertical(menu_rect, right_width=300);
+    textbox(search_rect, search_buffer, "Search", theme=^menu_textbox_theme);
+}
index e0932ead9065852eab2ba76a76ddfb85ea200cf5..dc0ad532b90d30a2ffbf805fe0cafa5727e97d67 100644 (file)
@@ -48,7 +48,7 @@ draw_sidebar :: (use state: ^Wasm_Analyzer_State, y_offset := 32.0f) {
     if sidebar_expansion <= 0.0f do return;
 
     window_width, window_height := gfx.get_window_size();
-    sidebar_window.position = .{    (sidebar_expansion - 1) * sidebar_window.size.x, y_offset };
+    sidebar_window.position = .{ (sidebar_expansion - 1) * sidebar_window.size.x, y_offset };
     sidebar_window.size.y   = ~~window_height - y_offset;
     sidebar_window.active_color = config.Colors.background;
     sidebar_window.background_color = config.Colors.dark_background;