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,12 +15,13 @@ impl FileTab {
const EIGHT_BIT_NAME:&str = "8 bit"; const EIGHT_BIT_NAME:&str = "8 bit";
const FULL_COLOR_NAME:&str = "Full color"; 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(); self.encoding_options.clear();
if has_palette { if has_palette {
let has_4bit = width%4 == 0; let mut selected_str = Self::EIGHT_BIT_NAME;
let has_8bit = width%2 == 0; let has_4bit = width%4 == 0;
let has_8bit = width%2 == 0;
if !has_4bit && !has_8bit { if !has_4bit && !has_8bit {
return Err(Error::from_text(format!("Image width must be multiple of 2 and or 4 ({}/{})", width, height))); 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 { if has_4bit {
self.encoding_options.push(SharedString::from(format!("{} ({}/{})", Self::FOUR_BIT_NAME, width/4, height))); self.encoding_options.push(SharedString::from(format!("{} ({}/{})", Self::FOUR_BIT_NAME, width/4, height)));
selected_str = Self::FOUR_BIT_NAME;
} }
if has_8bit { if has_8bit {
self.encoding_options.push(SharedString::from(format!("{} ({}/{})", Self::EIGHT_BIT_NAME, width/2, height))); self.encoding_options.push(SharedString::from(format!("{} ({}/{})", Self::EIGHT_BIT_NAME, width/2, height)));
} }
Ok(()) Ok(selected_str)
} }
else { else {
self.encoding_options.push(SharedString::from(format!("{} ({}/{})", Self::FULL_COLOR_NAME, width, height))); 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(); self.encoding_options.clear();
main_window.set_file_tab_browse_path("".into()); main_window.set_file_tab_browse_path("".into());
main_window.set_file_tab_image_data(Image::default()); 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_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_image_name("".into());
main_window.set_file_tab_enable(false); main_window.set_file_tab_enable(false);
} }
@ -79,7 +85,7 @@ impl FileTab {
main_window.set_file_tab_image_name("".into()); 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); main_window.set_file_tab_enable(true);
Ok(()) Ok(())
} }

View File

@ -93,9 +93,8 @@ component ConvertImageWidget inherits Rectangle {
VerticalLayout { VerticalLayout {
alignment: center; alignment: center;
ComboBox { ComboBox {
model: root.encoding_options; model: root.encoding_options;
enabled: root.enable_view; enabled: root.enable_view;
current-value: root.encoding_options[0];
selected(current-value) => { selected(current-value) => {
root.selected_encoding = current-value; root.selected_encoding = current-value;