Clear existing elements

This commit is contained in:
Jaby 2025-04-01 16:28:27 +02:00
parent bab01bbd86
commit 47b5de2d6a
5 changed files with 35 additions and 7 deletions

View File

@ -69,9 +69,11 @@ pub(super) fn on_load_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
} }
}; };
for job in new_project.jobs { let mut tim_manager = tim_manager.lock().expect("VRAM already locked");
let mut tim_manager = tim_manager.lock().expect("VRAM already locked"); clear_all_vram_images(main_tab, &mut tim_manager);
main_window.invoke_clear_file_tab_current_selected_file();
for job in new_project.jobs {
let (_, _) = tim_manager.load_unadded_tim(&job.file_path)?; let (_, _) = tim_manager.load_unadded_tim(&job.file_path)?;
let (pal_width, pal_height) = job.palette_rect.size.into(); let (pal_width, pal_height) = job.palette_rect.size.into();
@ -208,6 +210,11 @@ fn add_unadded_tim(main_tab: &mut MainTab, tim_manager: &mut TIMManager, unadded
Ok(()) Ok(())
} }
fn clear_all_vram_images(main_tab: &mut MainTab, tim_manager: &mut TIMManager) {
tim_manager.clear();
main_tab.clear();
}
fn create_project_file_dialog() -> FileDialog { fn create_project_file_dialog() -> FileDialog {
FileDialog::new() FileDialog::new()
.add_filter("TIM project file (.tim_project)", &["tim_project"]) .add_filter("TIM project file (.tim_project)", &["tim_project"])

View File

@ -72,6 +72,15 @@ impl MainTab {
object object
} }
pub fn clear(&mut self) {
let mut vram_data = self.vram.lock().expect("VRAM already locked");
let count = vram_data.count;
for _ in 0..count {
vram_data.pop();
}
}
pub fn add_new_vram_file(&mut self, file_name: &String, full_image: slint::Image, texture: NewVRAMImageInfo, image_palette: Option<NewVRAMImageInfo>) -> usize { pub fn add_new_vram_file(&mut self, file_name: &String, full_image: slint::Image, texture: NewVRAMImageInfo, image_palette: Option<NewVRAMImageInfo>) -> usize {
let mut vram_data = self.vram.lock().expect("VRAM already locked"); let mut vram_data = self.vram.lock().expect("VRAM already locked");
let mut add_new_image = |file_name: &String, full_image: slint::Image, vram_image: NewVRAMImageInfo, palette_count: i32, is_palette: bool| { let mut add_new_image = |file_name: &String, full_image: slint::Image, vram_image: NewVRAMImageInfo, palette_count: i32, is_palette: bool| {

View File

@ -13,6 +13,10 @@ impl TIMManager {
TIMManager{added_tims: Default::default(), unadded_tim: None} TIMManager{added_tims: Default::default(), unadded_tim: None}
} }
pub fn clear(&mut self) {
self.added_tims.clear();
}
pub fn remove_added_tim(&mut self, range: RangeInclusive<usize>) { pub fn remove_added_tim(&mut self, range: RangeInclusive<usize>) {
let idx = *range.start(); let idx = *range.start();
for _ in range { for _ in range {

View File

@ -80,4 +80,8 @@ export component MainWindow inherits Window {
public function change_to_main() { public function change_to_main() {
tab_widget.current-index = 1; tab_widget.current-index = 1;
} }
public function clear_file_tab-current_selected_file() {
main_tab.clear_current_selection();
}
} }

View File

@ -179,10 +179,7 @@ export component MainTab inherits Rectangle {
text: "Remove file"; text: "Remove file";
clicked => { clicked => {
root.remove_file_clicked(vram_files_list.current_item); root.remove_file_clicked(vram_files_list.current_item);
vram_files_list.current-item = -1; root.clear_current_selection();
cur_sel_x.text = 0;
cur_sel_y.text = 0;
cur_sel_img.visible = false;
} }
} }
} }
@ -285,4 +282,11 @@ export component MainTab inherits Rectangle {
function get_border_width() -> int { function get_border_width() -> int {
return 4; return 4;
} }
public function clear_current_selection() {
vram_files_list.current-item = -1;
cur_sel_x.text = 0;
cur_sel_y.text = 0;
cur_sel_img.visible = false;
}
} }