Fix default selection

This commit is contained in:
Jaby 2025-03-06 22:02:30 +01:00
parent 8ead2a205d
commit 72b97ad7d3
2 changed files with 14 additions and 9 deletions

View File

@ -15,10 +15,11 @@ 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 mut selected_str = Self::EIGHT_BIT_NAME;
let has_4bit = width%4 == 0;
let has_8bit = width%2 == 0;
@ -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(())
}

View File

@ -95,7 +95,6 @@ component ConvertImageWidget inherits Rectangle {
ComboBox {
model: root.encoding_options;
enabled: root.enable_view;
current-value: root.encoding_options[0];
selected(current-value) => {
root.selected_encoding = current-value;