topic/bg/project-gui #21
|
@ -1,12 +1,11 @@
|
|||
use crate::{gui::{MutexTIMManager, main_tab::MainTab, VRAM_HEIGHT, VRAM_WIDTH}, MainWindow};
|
||||
use crate::{gui::{main_tab::MainTab, MutexTIMManager, VRAM_HEIGHT, VRAM_WIDTH}, MainWindow};
|
||||
use super::FileTab;
|
||||
use rfd::FileDialog;
|
||||
use slint::SharedString;
|
||||
use tim_tool::logic::tim::types::Encoding;
|
||||
use tool_helper::Error;
|
||||
|
||||
|
||||
pub fn on_browse_file(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
pub(super) fn on_browse_file(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
return move |file_tab, main_window| -> Result<(), Error> {
|
||||
let file = FileDialog::new()
|
||||
.add_filter("PNG image (.png)", &["png"])
|
||||
|
@ -33,14 +32,14 @@ pub fn on_browse_file(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab,
|
|||
};
|
||||
}
|
||||
|
||||
pub fn on_update_palette_size(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &MainWindow, u32, u32) -> Result<(), Error> + 'static {
|
||||
pub(super) fn on_update_palette_size(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &MainWindow, u32, u32) -> Result<(), Error> + 'static {
|
||||
return move |file_tab, _main_window, width, height| -> Result<(), Error> {
|
||||
file_tab.update_palette(tim_manager.lock().expect("VRAM already locked").change_unadded_tim_palette_size(width, height)?);
|
||||
Ok(())
|
||||
};
|
||||
}
|
||||
|
||||
pub fn on_add_image(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &mut MainTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
pub(super) fn on_add_image(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &mut MainTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
return move |file_tab, main_tab, main_window| {
|
||||
let file_name = file_tab.get_file_name();
|
||||
let encoding = file_tab.get_encoding()?;
|
||||
|
@ -58,4 +57,28 @@ pub fn on_add_image(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &m
|
|||
main_window.invoke_change_to_main();
|
||||
Ok(())
|
||||
};
|
||||
}
|
||||
|
||||
pub(super) fn on_load_project_clicked() -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
move |_file_tab, _main_window| {
|
||||
Err(Error::not_implemented("on_load_project_clicked"))
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn on_save_project_clicked() -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
move |_file_tab, _main_window| {
|
||||
Err(Error::not_implemented("on_save_project_clicked"))
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn on_browse_open_project_clicked() -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
move |_file_tab, _main_window| {
|
||||
Err(Error::not_implemented("on_browse_open_project_clicked"))
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn on_browse_save_project_clicked() -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
move |_file_tab, _main_window| {
|
||||
Err(Error::not_implemented("on_browse_save_project_clicked"))
|
||||
}
|
||||
}
|
|
@ -50,6 +50,7 @@ impl FileTab {
|
|||
|
||||
let object = Rc::new(RefCell::new(FileTab{main_window: main_window.clone(), encoding_options}));
|
||||
|
||||
// Image conv functions
|
||||
let (cloned_object, cloned_main_window, mut function) = (object.clone(), main_window.clone(), callbacks::on_browse_file(tim_manager.clone()));
|
||||
main_window.borrow().on_file_tab_browse_convert_image(move || {
|
||||
if let Err(error) = function(&mut cloned_object.borrow_mut(), &cloned_main_window.borrow()) {
|
||||
|
@ -60,7 +61,7 @@ impl FileTab {
|
|||
let (cloned_object, cloned_main_window, mut function) = (object.clone(), main_window.clone(), callbacks::on_update_palette_size(tim_manager.clone()));
|
||||
main_window.borrow().on_file_tab_update_palette_size(move |width, height| {
|
||||
if let Err(error) = function(&mut cloned_object.borrow_mut(), &cloned_main_window.borrow(), width as u32, height as u32) {
|
||||
display_error("Loadind file failed", &error.to_string());
|
||||
display_error("Updating palette failed", &error.to_string());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -71,6 +72,35 @@ impl FileTab {
|
|||
}
|
||||
});
|
||||
|
||||
// Project functions
|
||||
let (cloned_object, cloned_main_window, mut function) = (object.clone(), main_window.clone(), callbacks::on_load_project_clicked());
|
||||
main_window.borrow().on_project_widget_load_project_clicked(move || {
|
||||
if let Err(error) = function(&mut cloned_object.borrow_mut(), &cloned_main_window.borrow()) {
|
||||
display_error("Loading project failed", &error.to_string());
|
||||
}
|
||||
});
|
||||
|
||||
let (cloned_object, cloned_main_window, mut function) = (object.clone(), main_window.clone(), callbacks::on_save_project_clicked());
|
||||
main_window.borrow().on_project_widget_save_project_clicked (move || {
|
||||
if let Err(error) = function(&mut cloned_object.borrow_mut(), &cloned_main_window.borrow()) {
|
||||
display_error("Saving project failed", &error.to_string());
|
||||
}
|
||||
});
|
||||
|
||||
let (cloned_object, cloned_main_window, mut function) = (object.clone(), main_window.clone(), callbacks::on_browse_open_project_clicked());
|
||||
main_window.borrow().on_project_widget_browse_open_project_clicked (move || {
|
||||
if let Err(error) = function(&mut cloned_object.borrow_mut(), &cloned_main_window.borrow()) {
|
||||
display_error("Browsing project failed", &error.to_string());
|
||||
}
|
||||
});
|
||||
|
||||
let (cloned_object, cloned_main_window, mut function) = (object.clone(), main_window.clone(), callbacks::on_browse_save_project_clicked());
|
||||
main_window.borrow().on_project_widget_browse_save_project_clicked(move || {
|
||||
if let Err(error) = function(&mut cloned_object.borrow_mut(), &cloned_main_window.borrow()) {
|
||||
display_error("Browsing save location failed", &error.to_string());
|
||||
}
|
||||
});
|
||||
|
||||
object
|
||||
}
|
||||
|
||||
|
|
|
@ -304,8 +304,6 @@ export component FileTab inherits Rectangle {
|
|||
callback conv-image_browse_clicked;
|
||||
callback conv-image_add_clicked;
|
||||
|
||||
|
||||
|
||||
x: 0px;
|
||||
y: 0px;
|
||||
|
||||
|
@ -350,7 +348,7 @@ export component FileTab inherits Rectangle {
|
|||
}
|
||||
|
||||
browse_save_project_clicked() => {
|
||||
root.project_widget-save_project_clicked();
|
||||
root.project_widget-browse_save_project_clicked();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue