From 1f8fc5100c6908e19e40c25d5bdb353addfc50bc Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 3 Mar 2025 21:31:02 +0100 Subject: [PATCH] Support pre-view of palette --- src/Tools/tim_tool/src/gui/file_tab.rs | 11 ++++++++- src/Tools/tim_tool/src/main.rs | 4 +-- src/Tools/tim_tool/ui/app-window.slint | 2 ++ src/Tools/tim_tool/ui/tab/file-tab.slint | 31 ++++++++++++++++++------ 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/Tools/tim_tool/src/gui/file_tab.rs b/src/Tools/tim_tool/src/gui/file_tab.rs index 02b1c9c3..d8ee67fb 100644 --- a/src/Tools/tim_tool/src/gui/file_tab.rs +++ b/src/Tools/tim_tool/src/gui/file_tab.rs @@ -21,10 +21,19 @@ impl FileTab { main_window.set_file_tab_enable(false); } - pub fn update_new_load(&self, file_name: Option, image: Image) { + pub fn update_new_load(&self, file_name: Option, image: Image, palette: Option) { let main_window = self.main_window.borrow(); main_window.set_file_tab_image_data(image); + if let Some(palette) = palette { + main_window.set_file_tab_palette_data(palette); + main_window.set_file_tab_palette_visible(true); + } + + else { + main_window.set_file_tab_palette_visible(false); + } + if let Some(file_name) = file_name { main_window.set_file_tab_image_name(file_name.into()); } diff --git a/src/Tools/tim_tool/src/main.rs b/src/Tools/tim_tool/src/main.rs index aa2d1a58..ac432830 100644 --- a/src/Tools/tim_tool/src/main.rs +++ b/src/Tools/tim_tool/src/main.rs @@ -58,13 +58,13 @@ fn setup_file_tab(gui_elements_ref: Rc>, logic_ref: Rc VRAM_WIDTH as u32 || img_size.height > VRAM_HEIGHT as u32 { return Err(Error::from_text(format!("Image size ({}; {}) is to big for VRAM ({}, {})", img_size.width, img_size.height, VRAM_WIDTH, VRAM_HEIGHT))); } - file_tab.update_new_load(file_name, image); + file_tab.update_new_load(file_name, image, palette); } Ok(()) diff --git a/src/Tools/tim_tool/ui/app-window.slint b/src/Tools/tim_tool/ui/app-window.slint index a556f9dc..93f1149c 100644 --- a/src/Tools/tim_tool/ui/app-window.slint +++ b/src/Tools/tim_tool/ui/app-window.slint @@ -15,6 +15,8 @@ export component MainWindow inherits Window { // Convert Image values in-out property file_tab_browse_path <=> file_tab.conv_image_path; in-out property file_tab_image_data <=> file_tab.conv_image_data; + in-out property file_tab_palette_data <=> file_tab.conv_palette_data; + in-out property file_tab_palette_visible <=> file_tab.conv_palette_enable; in-out property file_tab_image_name <=> file_tab.conv_image_name; in-out property file_tab_enable <=> file_tab.conv_image_enable; callback file_tab_browse_convert_image <=> file_tab.conv_image_browse_clicked; diff --git a/src/Tools/tim_tool/ui/tab/file-tab.slint b/src/Tools/tim_tool/ui/tab/file-tab.slint index 91a57665..d3685932 100644 --- a/src/Tools/tim_tool/ui/tab/file-tab.slint +++ b/src/Tools/tim_tool/ui/tab/file-tab.slint @@ -14,9 +14,10 @@ component ProjectWidget inherits Rectangle { component ConvertImageWidget inherits Rectangle { in-out property image_path; in-out property image_data; - in-out property image_palette_data; + in-out property palette_data; in-out property image_name; in-out property enable_button: false; + in-out property palette_visible: false; callback browse_clicked(); callback add_clicked(); @@ -80,10 +81,11 @@ component ConvertImageWidget inherits Rectangle { background: #404040; border-color: #808080; border-width: 4px; - Image { + palette_image := Image { width: 256px; height: 256px; - source: root.image_palette_data; + source: root.palette_data; + visible: root.palette_visible; image-fit: contain; image-rendering: pixelated; } @@ -114,11 +116,22 @@ component ConvertImageWidget inherits Rectangle { } } } + + public function set_palette_image(image: image) { + palette_image.source = image; + palette_image.visible = true; + } + + public function clear_palette_image() { + palette_image.visible = false; + } } export component FileTab inherits Rectangle { in-out property conv_image_path; in-out property conv_image_data; + in-out property conv_palette_data; + in-out property conv_palette_enable; in-out property conv_image_name; in-out property conv_image_enable; in-out property state; @@ -155,11 +168,13 @@ export component FileTab inherits Rectangle { if root.state == State.Project : ProjectWidget { } if root.state == State.ConvertImage : ConvertImageWidget { - image_path <=> root.conv_image_path; - image_data <=> root.conv_image_data; - image_name <=> root.conv_image_name; - enable_button <=> root.conv_image_enable; - + image_path <=> root.conv_image_path; + image_data <=> root.conv_image_data; + palette_data <=> root.conv_palette_data; + palette_visible <=> root.conv_palette_enable; + image_name <=> root.conv_image_name; + enable_button <=> root.conv_image_enable; + browse_clicked => { root.conv_image_browse_clicked(); }