Turn on and off button
This commit is contained in:
parent
d9facb8d61
commit
5a4760b272
|
@ -11,15 +11,27 @@ impl FileTab {
|
|||
FileTab{main_window}
|
||||
}
|
||||
|
||||
pub fn clear_load(&self) {
|
||||
let main_window = self.main_window.borrow();
|
||||
|
||||
main_window.set_file_tab_browse_path("".into());
|
||||
main_window.set_file_tab_image_data(Image::default());
|
||||
main_window.set_file_tab_image_name("".into());
|
||||
main_window.set_file_tab_enable(false);
|
||||
}
|
||||
|
||||
pub fn update_new_load(&self, file_name: Option<String>, image: Image) {
|
||||
self.main_window.borrow().set_file_tab_image_data(image);
|
||||
let main_window = self.main_window.borrow();
|
||||
|
||||
main_window.set_file_tab_image_data(image);
|
||||
if let Some(file_name) = file_name {
|
||||
self.main_window.borrow().set_file_tab_image_name(file_name.into());
|
||||
main_window.set_file_tab_image_name(file_name.into());
|
||||
}
|
||||
|
||||
else {
|
||||
self.main_window.borrow().set_file_tab_image_name("".into());
|
||||
main_window.set_file_tab_image_name("".into());
|
||||
}
|
||||
main_window.set_file_tab_enable(true);
|
||||
}
|
||||
|
||||
pub fn on_browse_file(&self, gui_elements: GUIElementsRef, mut function: impl FnMut(&mut GUIElements, &MainWindow) + 'static) {
|
||||
|
@ -30,4 +42,13 @@ impl FileTab {
|
|||
function(&mut gui_cloned.borrow_mut(), &main_window_cloned.borrow());
|
||||
});
|
||||
}
|
||||
|
||||
pub fn on_add_image(&self, gui_elements: GUIElementsRef, mut function: impl FnMut(&mut GUIElements, &MainWindow) + 'static) {
|
||||
let main_window_cloned = self.main_window.clone();
|
||||
let gui_cloned = gui_elements.clone();
|
||||
|
||||
self.main_window.borrow().on_file_tab_add_convert_image(move || {
|
||||
function(&mut gui_cloned.borrow_mut(), &main_window_cloned.borrow());
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1 +1 @@
|
|||
pub mod tim_tool;
|
||||
pub mod logic;
|
|
@ -0,0 +1,12 @@
|
|||
pub mod tim;
|
||||
use tim::TIMInfo;
|
||||
|
||||
pub struct Logic {
|
||||
pub unadded_tim: TIMInfo,
|
||||
}
|
||||
|
||||
impl Logic {
|
||||
pub fn new() -> Logic {
|
||||
Logic{unadded_tim: TIMInfo{}}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
use std::path::PathBuf;
|
||||
use tool_helper::Error;
|
||||
|
||||
pub struct TIMInfo {}
|
||||
|
||||
pub fn load_image(path: PathBuf) -> Result<(slint::Image, TIMInfo), Error> {
|
||||
Ok((slint::Image::load_from_path(&path).or_else(|_| {Err(Error::from_str("Failed loading image"))})?, TIMInfo{}))
|
||||
}
|
|
@ -6,16 +6,18 @@ use gui::{GUIElements, VRAM_WIDTH, VRAM_HEIGHT};
|
|||
use rfd::{FileDialog, MessageDialog};
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
use slint::SharedString;
|
||||
use tim_tool::tim_tool::load_image;
|
||||
use tim_tool::logic::{tim::load_image, Logic};
|
||||
|
||||
slint::include_modules!();
|
||||
|
||||
|
||||
fn main() -> Result<(), slint::PlatformError> {
|
||||
let logic_ref = Rc::new(RefCell::new(Logic::new()));
|
||||
let main_window_ref = Rc::new(RefCell::new(MainWindow::new()?));
|
||||
let gui_elements_ref = Rc::new(RefCell::new(GUIElements::new(main_window_ref.clone())?));
|
||||
|
||||
setup_main_tab(gui_elements_ref.clone());
|
||||
setup_file_tab(gui_elements_ref.clone());
|
||||
setup_file_tab(gui_elements_ref.clone(), logic_ref);
|
||||
|
||||
let main_window = main_window_ref.borrow();
|
||||
main_window.run()
|
||||
|
@ -35,7 +37,7 @@ fn setup_main_tab(gui_elements_ref: Rc<RefCell<GUIElements>>) {
|
|||
});
|
||||
}
|
||||
|
||||
fn setup_file_tab(gui_elements_ref: Rc<RefCell<GUIElements>>) {
|
||||
fn setup_file_tab(gui_elements_ref: Rc<RefCell<GUIElements>>, logic_ref: Rc<RefCell<Logic>>) {
|
||||
let gui_elements = gui_elements_ref.borrow();
|
||||
|
||||
gui_elements.file_tab.on_browse_file(gui_elements_ref.clone(), move |gui_elements, main_window| {
|
||||
|
@ -52,11 +54,14 @@ fn setup_file_tab(gui_elements_ref: Rc<RefCell<GUIElements>>) {
|
|||
if let Some(file_path) = file.to_str() {
|
||||
main_window.set_file_tab_browse_path(SharedString::from(file_path));
|
||||
}
|
||||
|
||||
|
||||
let file_tab = &gui_elements.file_tab;
|
||||
let file_name = if let Some(name) = file.file_name() {Some(name.to_string_lossy().to_string())} else {None};
|
||||
let (image, _info) = match load_image(file) {
|
||||
|
||||
let (image, info) = match load_image(file) {
|
||||
Ok((image, info)) => (image, info),
|
||||
Err(error) => {
|
||||
file_tab.clear_load();
|
||||
show_error_message(error.to_string());
|
||||
return;
|
||||
}
|
||||
|
@ -64,14 +69,20 @@ fn setup_file_tab(gui_elements_ref: Rc<RefCell<GUIElements>>) {
|
|||
|
||||
let img_size = image.size();
|
||||
if img_size.width > VRAM_WIDTH as u32 || img_size.height > VRAM_HEIGHT as u32 {
|
||||
file_tab.clear_load();
|
||||
show_error_message(format!("Image size ({}; {}) is to big for VRAM ({}, {})", img_size.width, img_size.height, VRAM_WIDTH, VRAM_HEIGHT));
|
||||
return;
|
||||
}
|
||||
|
||||
let file_tab = &mut gui_elements.file_tab;
|
||||
logic_ref.borrow_mut().unadded_tim = info;
|
||||
file_tab.update_new_load(file_name, image);
|
||||
|
||||
//main_window.invoke_change_to_main();
|
||||
}
|
||||
});
|
||||
|
||||
gui_elements.file_tab.on_add_image(gui_elements_ref.clone(), move |gui_elements, _main_window| {
|
||||
let file_tab = &gui_elements.file_tab;
|
||||
file_tab.clear_load();
|
||||
});
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
use std::path::PathBuf;
|
||||
use tool_helper::Error;
|
||||
|
||||
pub struct TIMImage {}
|
||||
|
||||
pub fn load_image(path: PathBuf) -> Result<(slint::Image, TIMImage), Error> {
|
||||
Ok((slint::Image::load_from_path(&path).or_else(|_| {Err(Error::from_str("Failed loading image"))})?, TIMImage{}))
|
||||
}
|
|
@ -16,7 +16,9 @@ export component MainWindow inherits Window {
|
|||
in-out property file_tab_browse_path <=> file_tab.conv_image_path;
|
||||
in-out property file_tab_image_data <=> file_tab.conv_image_data;
|
||||
in-out property file_tab_image_name <=> file_tab.conv_image_name;
|
||||
in-out property file_tab_enable <=> file_tab.conv_image_enable;
|
||||
callback file_tab_browse_convert_image <=> file_tab.conv_image_browse_clicked;
|
||||
callback file_tab_add_convert_image <=> file_tab.conv_image_add_clicked;
|
||||
|
||||
title: "TIM Tool 0.1.0";
|
||||
width: tab_widget.width;
|
||||
|
|
|
@ -15,8 +15,10 @@ component ConvertImageWidget inherits Rectangle {
|
|||
in-out property <string> image_path;
|
||||
in-out property <image> image_data;
|
||||
in-out property <string> image_name;
|
||||
in-out property <bool> enable_button: false;
|
||||
|
||||
callback browse_clicked();
|
||||
callback add_clicked();
|
||||
|
||||
background: #D0D0D0;
|
||||
|
||||
|
@ -82,7 +84,8 @@ component ConvertImageWidget inherits Rectangle {
|
|||
padding: 4px;
|
||||
Button {
|
||||
text: "Add Image";
|
||||
enabled: false;
|
||||
enabled: root.enable_button;
|
||||
clicked => {root.add_clicked();}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,8 +97,10 @@ export component FileTab inherits Rectangle {
|
|||
in-out property <string> conv_image_path;
|
||||
in-out property <image> conv_image_data;
|
||||
in-out property <string> conv_image_name;
|
||||
in-out property <bool> conv_image_enable;
|
||||
in-out property <State> state;
|
||||
callback conv_image_browse_clicked;
|
||||
callback conv_image_add_clicked;
|
||||
|
||||
x: 0px;
|
||||
y: 0px;
|
||||
|
@ -130,9 +135,15 @@ export component FileTab inherits Rectangle {
|
|||
image_path <=> root.conv_image_path;
|
||||
image_data <=> root.conv_image_data;
|
||||
image_name <=> root.conv_image_name;
|
||||
enable_button <=> root.conv_image_enable;
|
||||
|
||||
browse_clicked => {
|
||||
root.conv_image_browse_clicked();
|
||||
}
|
||||
|
||||
add_clicked => {
|
||||
root.conv_image_add_clicked();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue