Add palette flag that prevents deleting

This commit is contained in:
Jaby 2025-02-16 15:49:25 +01:00
parent ac6a46134e
commit 6ddca9e79f
4 changed files with 25 additions and 10 deletions

View File

@ -24,18 +24,26 @@ impl MainTab {
pub fn add_new_vram_file(&mut self, file_name: &String, image: slint::Image) { pub fn add_new_vram_file(&mut self, file_name: &String, image: slint::Image) {
let vram_image = VRAMImage{ let vram_image = VRAMImage{
img: image, img: image,
x: 0, x: 0,
y: 0 y: 0,
is_palette: false,
}; };
self.vram_file_list.push(slint::StandardListViewItem::from(file_name.as_str())); self.vram_file_list.push(slint::StandardListViewItem::from(file_name.as_str()));
self.vram_image_list.push(vram_image); 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_file_list.remove(idx);
self.vram_image_list.remove(idx); self.vram_image_list.remove(idx);
return true;
} }
pub fn move_vram_image(&mut self, idx: usize, dx: i32, dy: i32) { pub fn move_vram_image(&mut self, idx: usize, dx: i32, dy: i32) {

View File

@ -16,7 +16,11 @@ pub const VRAM_HEIGHT:usize = 512;
type MainWindowRef = Rc<RefCell<MainWindow>>; type MainWindowRef = Rc<RefCell<MainWindow>>;
type GUIElementsRef = Rc<RefCell<GUIElements>>; type GUIElementsRef = Rc<RefCell<GUIElements>>;
fn display_error(title: &str, text: &String) { pub fn display_information(title: impl Into<String>, text: impl Into<String>) {
MessageDialog::new().set_title(title).set_level(rfd::MessageLevel::Info).set_description(text).show();
}
pub fn display_error(title: impl Into<String>, text: impl Into<String>) {
MessageDialog::new().set_title(title).set_level(rfd::MessageLevel::Error).set_description(text).show(); MessageDialog::new().set_title(title).set_level(rfd::MessageLevel::Error).set_description(text).show();
} }

View File

@ -2,7 +2,7 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
mod gui; mod gui;
use gui::{GUIElements, VRAM_WIDTH, VRAM_HEIGHT}; use gui::{GUIElements, VRAM_WIDTH, VRAM_HEIGHT, display_information};
use rfd::FileDialog; use rfd::FileDialog;
use std::{cell::RefCell, rc::Rc}; use std::{cell::RefCell, rc::Rc};
use slint::SharedString; use slint::SharedString;
@ -33,7 +33,9 @@ fn setup_main_tab(gui_elements_ref: Rc<RefCell<GUIElements>>) {
gui_elements.main_tab.on_remove_file(gui_elements_ref.clone(), move |main_tab, _main_window, idx| { gui_elements.main_tab.on_remove_file(gui_elements_ref.clone(), move |main_tab, _main_window, idx| {
if idx >= 0 { 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");
}
} }
}); });
} }

View File

@ -2,9 +2,10 @@ import { VRAMArea } from "../vram-components.slint";
import { Button, ComboBox, GroupBox, StandardListView } from "std-widgets.slint"; import { Button, ComboBox, GroupBox, StandardListView } from "std-widgets.slint";
struct VRAMImage { struct VRAMImage {
img: image, img: image,
x: int, x: int,
y: int, y: int,
is_palette: bool,
} }
export component MainTab inherits Rectangle { export component MainTab inherits Rectangle {