From 10dab4c2b34ed4748db50f4f6bc80e53d43f2767 Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 17 Feb 2025 10:29:40 +0100 Subject: [PATCH] Handle palette in GUI --- src/Tools/tim_tool/src/gui/main_tab.rs | 43 +++++++++++++++++++------- src/Tools/tim_tool/src/main.rs | 2 +- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/Tools/tim_tool/src/gui/main_tab.rs b/src/Tools/tim_tool/src/gui/main_tab.rs index 13bacb9e..7ede86cf 100644 --- a/src/Tools/tim_tool/src/gui/main_tab.rs +++ b/src/Tools/tim_tool/src/gui/main_tab.rs @@ -28,31 +28,52 @@ impl MainTab { pub fn add_new_vram_file(&mut self, file_name: &String, image: slint::Image, image_palette: Option) { let vram_data = self.vram.lock().expect("VRAM already locked"); - let add_new_image = |file_name: &String, image: slint::Image| { + let add_new_image = |file_name: &String, image: slint::Image, palette_count: i32, is_palette: bool| { let vram_image = VRAMImage{ img: image, x: 0, y: 0, - palette_count: 0, - is_palette: false, + palette_count, + is_palette, }; vram_data.file_list.push(slint::StandardListViewItem::from(file_name.as_str())); vram_data.image_list.push(vram_image); }; - add_new_image(file_name, image); + + add_new_image(file_name, image, if image_palette.is_some() {1} else {0}, false); + if let Some(image_palette) = image_palette { + let file_name = file_name.clone() + " (Palette)"; + add_new_image(&file_name, image_palette, 0, true); + } } pub fn remove_vram_file(&mut self, idx: usize) -> bool { let vram_data = self.vram.lock().expect("VRAM already locked"); - if let Some(element) = vram_data.image_list.iter().skip(idx).next() { - if element.is_palette { - return false; - } - } + let remove_image = |idx: usize| { + vram_data.file_list.remove(idx); + vram_data.image_list.remove(idx); + }; - vram_data.file_list.remove(idx); - vram_data.image_list.remove(idx); + let extras = { + if let Some(element) = vram_data.image_list.iter().skip(idx).next() { + if element.is_palette { + return false; + } + + else { + element.palette_count as usize + } + } + + else { + 0 + } + }; + + for _ in idx..=idx+extras { + remove_image(idx); + } return true; } diff --git a/src/Tools/tim_tool/src/main.rs b/src/Tools/tim_tool/src/main.rs index 3506d5a5..aa2d1a58 100644 --- a/src/Tools/tim_tool/src/main.rs +++ b/src/Tools/tim_tool/src/main.rs @@ -58,7 +58,7 @@ fn setup_file_tab(gui_elements_ref: Rc>, logic_ref: Rc VRAM_WIDTH as u32 || img_size.height > VRAM_HEIGHT as u32 {