diff --git a/src/Tools/tim_tool/src/gui/main_tab.rs b/src/Tools/tim_tool/src/gui/main_tab.rs index 86980bee..61d5609e 100644 --- a/src/Tools/tim_tool/src/gui/main_tab.rs +++ b/src/Tools/tim_tool/src/gui/main_tab.rs @@ -24,18 +24,26 @@ impl MainTab { pub fn add_new_vram_file(&mut self, file_name: &String, image: slint::Image) { let vram_image = VRAMImage{ - img: image, - x: 0, - y: 0 + img: image, + x: 0, + y: 0, + is_palette: false, }; self.vram_file_list.push(slint::StandardListViewItem::from(file_name.as_str())); self.vram_image_list.push(vram_image); } - pub fn remove_vram_file(&mut self, idx: usize) { + pub fn remove_vram_file(&mut self, idx: usize) -> bool { + if let Some(element) = self.vram_image_list.iter().skip(idx).next() { + if element.is_palette { + return false; + } + } + self.vram_file_list.remove(idx); self.vram_image_list.remove(idx); + return true; } pub fn move_vram_image(&mut self, idx: usize, dx: i32, dy: i32) { diff --git a/src/Tools/tim_tool/src/gui/mod.rs b/src/Tools/tim_tool/src/gui/mod.rs index 5be11d69..438d75fd 100644 --- a/src/Tools/tim_tool/src/gui/mod.rs +++ b/src/Tools/tim_tool/src/gui/mod.rs @@ -16,7 +16,11 @@ pub const VRAM_HEIGHT:usize = 512; type MainWindowRef = Rc>; type GUIElementsRef = Rc>; -fn display_error(title: &str, text: &String) { +pub fn display_information(title: impl Into, text: impl Into) { + MessageDialog::new().set_title(title).set_level(rfd::MessageLevel::Info).set_description(text).show(); +} + +pub fn display_error(title: impl Into, text: impl Into) { MessageDialog::new().set_title(title).set_level(rfd::MessageLevel::Error).set_description(text).show(); } diff --git a/src/Tools/tim_tool/src/main.rs b/src/Tools/tim_tool/src/main.rs index 086a6cbf..f89dafd9 100644 --- a/src/Tools/tim_tool/src/main.rs +++ b/src/Tools/tim_tool/src/main.rs @@ -2,7 +2,7 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] mod gui; -use gui::{GUIElements, VRAM_WIDTH, VRAM_HEIGHT}; +use gui::{GUIElements, VRAM_WIDTH, VRAM_HEIGHT, display_information}; use rfd::FileDialog; use std::{cell::RefCell, rc::Rc}; use slint::SharedString; @@ -33,7 +33,9 @@ fn setup_main_tab(gui_elements_ref: Rc>) { gui_elements.main_tab.on_remove_file(gui_elements_ref.clone(), move |main_tab, _main_window, idx| { if idx >= 0 { - main_tab.remove_vram_file(idx as usize); + if !main_tab.remove_vram_file(idx as usize) { + display_information("Removing VRAM file", "Can not remove palette. Delete image instead"); + } } }); } diff --git a/src/Tools/tim_tool/ui/tab/main-tab.slint b/src/Tools/tim_tool/ui/tab/main-tab.slint index ae73d468..028b333e 100644 --- a/src/Tools/tim_tool/ui/tab/main-tab.slint +++ b/src/Tools/tim_tool/ui/tab/main-tab.slint @@ -2,9 +2,10 @@ import { VRAMArea } from "../vram-components.slint"; import { Button, ComboBox, GroupBox, StandardListView } from "std-widgets.slint"; struct VRAMImage { - img: image, - x: int, - y: int, + img: image, + x: int, + y: int, + is_palette: bool, } export component MainTab inherits Rectangle {