From cf1edd7ac97c94fdf4d1858795353f658bc5843e Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Wed, 15 Sep 2021 22:46:38 -0500 Subject: [PATCH] using blocked scoping; fixed infinite redraw offscreen --- site/js/js_events.js | 2 +- src/app/app.onyx | 94 +++++++++++++---------- src/app/colors.onyx | 16 ++-- src/app/debug_log.onyx | 21 +++-- src/app/window_management.onyx | 32 ++++---- src/app/window_switcher.onyx | 21 ++--- src/build.onyx | 2 +- src/config.onyx | 1 + src/features/hex_editor/feature.onyx | 2 +- src/features/hex_editor/hex_viewer.onyx | 77 +++++++++++++------ src/features/text_editor/text_editor.onyx | 14 ++-- src/features/wasm/wasm.onyx | 12 ++- src/main.onyx | 10 ++- src/ui/menubar.onyx | 11 ++- src/ui/window.onyx | 15 ++-- src/wasm.onyx | 16 ++-- 16 files changed, 210 insertions(+), 136 deletions(-) diff --git a/site/js/js_events.js b/site/js/js_events.js index fe0d0fb..2679c3e 100644 --- a/site/js/js_events.js +++ b/site/js/js_events.js @@ -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); } diff --git a/src/app/app.onyx b/src/app/app.onyx index b9c8c1d..928e8aa 100644 --- a/src/app/app.onyx +++ b/src/app/app.onyx @@ -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(); + } } diff --git a/src/app/colors.onyx b/src/app/colors.onyx index 86784bf..3e7d2e1 100644 --- a/src/app/colors.onyx +++ b/src/app/colors.onyx @@ -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 } diff --git a/src/app/debug_log.onyx b/src/app/debug_log.onyx index 72b1c81..a1b5ebc 100644 --- a/src/app/debug_log.onyx +++ b/src/app/debug_log.onyx @@ -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); diff --git a/src/app/window_management.onyx b/src/app/window_management.onyx index 273f512..2168f66 100644 --- a/src/app/window_management.onyx +++ b/src/app/window_management.onyx @@ -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 +} diff --git a/src/app/window_switcher.onyx b/src/app/window_switcher.onyx index e54e90b..a50ce0d 100644 --- a/src/app/window_switcher.onyx +++ b/src/app/window_switcher.onyx @@ -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; diff --git a/src/build.onyx b/src/build.onyx index a1c1150..96d302b 100644 --- a/src/build.onyx +++ b/src/build.onyx @@ -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" diff --git a/src/config.onyx b/src/config.onyx index cd3f1e0..7d9156b 100644 --- a/src/config.onyx +++ b/src/config.onyx @@ -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" diff --git a/src/features/hex_editor/feature.onyx b/src/features/hex_editor/feature.onyx index 6b8548e..d28262d 100644 --- a/src/features/hex_editor/feature.onyx +++ b/src/features/hex_editor/feature.onyx @@ -4,4 +4,4 @@ package feature.hex_viewer Feature_Hex_Viewer :: struct { setup := setup; -} \ No newline at end of file +} diff --git a/src/features/hex_editor/hex_viewer.onyx b/src/features/hex_editor/hex_viewer.onyx index 17cf620..62ced36 100644 --- a/src/features/hex_editor/hex_viewer.onyx +++ b/src/features/hex_editor/hex_viewer.onyx @@ -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 + }; +} diff --git a/src/features/text_editor/text_editor.onyx b/src/features/text_editor/text_editor.onyx index 8948eb8..5c3e48d 100644 --- a/src/features/text_editor/text_editor.onyx +++ b/src/features/text_editor/text_editor.onyx @@ -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 +} diff --git a/src/features/wasm/wasm.onyx b/src/features/wasm/wasm.onyx index cac42be..3e048ba 100644 --- a/src/features/wasm/wasm.onyx +++ b/src/features/wasm/wasm.onyx @@ -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 +} diff --git a/src/main.onyx b/src/main.onyx index 33ec77c..32b35e5 100644 --- a/src/main.onyx +++ b/src/main.onyx @@ -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(); diff --git a/src/ui/menubar.onyx b/src/ui/menubar.onyx index 6417628..c3fbcc9 100644 --- a/src/ui/menubar.onyx +++ b/src/ui/menubar.onyx @@ -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); } diff --git a/src/ui/window.onyx b/src/ui/window.onyx index b147c7a..2dc486d 100644 --- a/src/ui/window.onyx +++ b/src/ui/window.onyx @@ -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 +} diff --git a/src/wasm.onyx b/src/wasm.onyx index dc0ad53..a1db1f5 100644 --- a/src/wasm.onyx +++ b/src/wasm.onyx @@ -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); } } -- 2.25.1