diff --git a/src/Tools/tim_tool/src/gui/file_tab.rs b/src/Tools/tim_tool/src/gui/file_tab.rs index df6461da..9c7635f9 100644 --- a/src/Tools/tim_tool/src/gui/file_tab.rs +++ b/src/Tools/tim_tool/src/gui/file_tab.rs @@ -15,12 +15,13 @@ impl FileTab { const EIGHT_BIT_NAME:&str = "8 bit"; const FULL_COLOR_NAME:&str = "Full color"; - fn update_encoding_options(&self, width: u32, height: u32, has_palette: bool) -> Result<(), Error> { + fn update_encoding_options(&self, width: u32, height: u32, has_palette: bool) -> Result<&str, Error> { self.encoding_options.clear(); if has_palette { - let has_4bit = width%4 == 0; - let has_8bit = width%2 == 0; + let mut selected_str = Self::EIGHT_BIT_NAME; + let has_4bit = width%4 == 0; + let has_8bit = width%2 == 0; if !has_4bit && !has_8bit { return Err(Error::from_text(format!("Image width must be multiple of 2 and or 4 ({}/{})", width, height))); @@ -28,17 +29,18 @@ impl FileTab { if has_4bit { self.encoding_options.push(SharedString::from(format!("{} ({}/{})", Self::FOUR_BIT_NAME, width/4, height))); + selected_str = Self::FOUR_BIT_NAME; } if has_8bit { self.encoding_options.push(SharedString::from(format!("{} ({}/{})", Self::EIGHT_BIT_NAME, width/2, height))); } - Ok(()) + Ok(selected_str) } else { self.encoding_options.push(SharedString::from(format!("{} ({}/{})", Self::FULL_COLOR_NAME, width, height))); - Ok(()) + Ok(Self::FULL_COLOR_NAME) } } @@ -55,7 +57,11 @@ impl FileTab { self.encoding_options.clear(); main_window.set_file_tab_browse_path("".into()); main_window.set_file_tab_image_data(Image::default()); + main_window.set_file_tab_image_width(0); + main_window.set_file_tab_image_height(0); main_window.set_file_tab_palette_data(Image::default()); + main_window.set_file_tab_palette_width(0); + main_window.set_file_tab_palette_height(0); main_window.set_file_tab_image_name("".into()); main_window.set_file_tab_enable(false); } @@ -79,7 +85,7 @@ impl FileTab { main_window.set_file_tab_image_name("".into()); } - self.update_encoding_options(image_size.width, image_size.height, has_palette)?; + main_window.set_file_tab_selected_encoding(SharedString::from(self.update_encoding_options(image_size.width, image_size.height, has_palette)?)); main_window.set_file_tab_enable(true); Ok(()) } diff --git a/src/Tools/tim_tool/ui/tab/file-tab.slint b/src/Tools/tim_tool/ui/tab/file-tab.slint index 2c2c7442..a9a9e078 100644 --- a/src/Tools/tim_tool/ui/tab/file-tab.slint +++ b/src/Tools/tim_tool/ui/tab/file-tab.slint @@ -93,9 +93,8 @@ component ConvertImageWidget inherits Rectangle { VerticalLayout { alignment: center; ComboBox { - model: root.encoding_options; - enabled: root.enable_view; - current-value: root.encoding_options[0]; + model: root.encoding_options; + enabled: root.enable_view; selected(current-value) => { root.selected_encoding = current-value;