From 287219f80ab5c5d0cfb2c26f6de7e73c7c473fbc Mon Sep 17 00:00:00 2001 From: luboslenco Date: Sat, 20 Jul 2024 22:14:26 +0200 Subject: [PATCH] minits fixes --- base/Sources/context.ts | 12 ++++--- base/Sources/tab_browser.ts | 2 +- base/Sources/ui_files.ts | 67 ++++++++++++++++++++----------------- 3 files changed, 46 insertions(+), 35 deletions(-) diff --git a/base/Sources/context.ts b/base/Sources/context.ts index 7cc8fc96..ed71fb82 100644 --- a/base/Sources/context.ts +++ b/base/Sources/context.ts @@ -769,11 +769,13 @@ function context_in_paint_area(): bool { } function context_in_layers(): bool { - return zui_hovered_tab_name() == tr("Layers"); + let tab: string = zui_hovered_tab_name(); + return tab == tr("Layers"); } function context_in_materials(): bool { - return zui_hovered_tab_name() == tr("Materials"); + let tab: string = zui_hovered_tab_name(); + return tab == tr("Materials"); } ///if (is_paint || is_sculpt) @@ -791,11 +793,13 @@ function context_in_nodes(): bool { } function context_in_swatches(): bool { - return zui_hovered_tab_name() == tr("Swatches"); + let tab: string = zui_hovered_tab_name(); + return tab == tr("Swatches"); } function context_in_browser(): bool { - return zui_hovered_tab_name() == tr("Browser"); + let tab: string = zui_hovered_tab_name(); + return tab == tr("Browser"); } function context_get_area_type(): area_type_t { diff --git a/base/Sources/tab_browser.ts b/base/Sources/tab_browser.ts index 802d4e21..631836c7 100644 --- a/base/Sources/tab_browser.ts +++ b/base/Sources/tab_browser.ts @@ -29,7 +29,7 @@ function tab_browser_draw(htab: zui_handle_t) { } zui_begin_sticky(); - let step: i32 = (1 - bookmarks_w / ui._w); + let step: f32 = (1.0 - bookmarks_w / ui._w); if (tab_browser_hsearch.text != "") { let row: f32[] = [bookmarks_w / ui._w, step * 0.73, step * 0.07, step * 0.17, step * 0.03]; zui_row(row); diff --git a/base/Sources/ui_files.ts b/base/Sources/ui_files.ts index d552650b..4fb761fd 100644 --- a/base/Sources/ui_files.ts +++ b/base/Sources/ui_files.ts @@ -65,8 +65,6 @@ function ui_files_release_keys() { let _ui_files_file_browser_handle: zui_handle_t; let _ui_files_file_browser_f: string; -let _ui_files_file_browser_shandle: string; -let _ui_files_file_browser_w: i32; function ui_files_file_browser(ui: zui_t, handle: zui_handle_t, folders_only: bool = false, drag_files: bool = false, search: string = "", refresh: bool = false, context_menu: (s: string)=>void = null): string { @@ -311,27 +309,12 @@ function ui_files_file_browser(ui: zui_t, handle: zui_handle_t, folders_only: bo map_set(ui_files_icon_map, shandle, empty); let image: image_t = data_get_image(shandle); - _ui_files_file_browser_shandle = shandle; - _ui_files_file_browser_w = w; - - app_notify_on_init(function (image: image_t) { - if (base_pipe_copy_rgb == null) { - base_make_pipe_copy_rgb(); - } - let w: i32 = _ui_files_file_browser_w; - let sw: i32 = image.width > image.height ? w : math_floor(1.0 * image.width / image.height * w); - let sh: i32 = image.width > image.height ? math_floor(1.0 * image.height / image.width * w) : w; - let icon: image_t = image_create_render_target(sw, sh); - g2_begin(icon); - g2_clear(0xffffffff); - g2_set_pipeline(base_pipe_copy_rgb); - g2_draw_scaled_image(image, 0, 0, sw, sh); - g2_set_pipeline(null); - g2_end(); - map_set(ui_files_icon_map, _ui_files_file_browser_shandle, icon); - ui_base_hwnds[tab_area_t.STATUS].redraws = 3; - data_delete_image(_ui_files_file_browser_shandle); // The big image is not needed anymore - }, image); + let args: ui_files_make_icon_t = { + image: image, + shandle: shandle, + w: w + }; + app_notify_on_init(ui_files_make_icon, args); } if (icon != null) { if (i == ui_files_selected) { @@ -379,17 +362,15 @@ function ui_files_file_browser(ui: zui_t, handle: zui_handle_t, folders_only: bo if (f == "..") { // Up handle.text = substring(handle.text, 0, string_last_index_of(handle.text, path_sep)); // Drive root - let text: string = handle.text; - if (text.length == 2 && char_at(text, 1) == ":") { - text += path_sep; + if (handle.text.length == 2 && char_at(handle.text, 1) == ":") { + handle.text += path_sep; } } else { - let text: string = handle.text; - if (char_at(text, text.length - 1) != path_sep) { - text += path_sep; + if (char_at(handle.text, handle.text.length - 1) != path_sep) { + handle.text += path_sep; } - text += f; + handle.text += f; } ui_files_selected = -1; } @@ -437,3 +418,29 @@ function ui_files_file_browser(ui: zui_t, handle: zui_handle_t, folders_only: bo return handle.text; } + +function ui_files_make_icon (args: ui_files_make_icon_t) { + if (base_pipe_copy_rgb == null) { + base_make_pipe_copy_rgb(); + } + let w: i32 = args.w; + let image: image_t = args.image; + let sw: i32 = image.width > image.height ? w : math_floor(1.0 * image.width / image.height * w); + let sh: i32 = image.width > image.height ? math_floor(1.0 * image.height / image.width * w) : w; + let icon: image_t = image_create_render_target(sw, sh); + g2_begin(icon); + g2_clear(0xffffffff); + g2_set_pipeline(base_pipe_copy_rgb); + g2_draw_scaled_image(image, 0, 0, sw, sh); + g2_set_pipeline(null); + g2_end(); + map_set(ui_files_icon_map, args.shandle, icon); + ui_base_hwnds[tab_area_t.STATUS].redraws = 3; + data_delete_image(args.shandle); // The big image is not needed anymore +} + +type ui_files_make_icon_t = { + image: image_t; + shandle: string; + w: i32; +};