Clean up references
This commit is contained in:
parent
c114745a8e
commit
a4fe26f112
|
@ -1,12 +1,10 @@
|
||||||
use crate::{gui::{main_tab::MainTab, VRAM_HEIGHT, VRAM_WIDTH},MainWindow};
|
use crate::{gui::{gui_elements::MutexTIMManager, main_tab::MainTab, VRAM_HEIGHT, VRAM_WIDTH}, MainWindow};
|
||||||
use super::FileTab;
|
use super::FileTab;
|
||||||
use rfd::FileDialog;
|
use rfd::FileDialog;
|
||||||
use slint::SharedString;
|
use slint::SharedString;
|
||||||
use std::{rc::Rc, sync::Mutex};
|
use tim_tool::logic::tim::types::Encoding;
|
||||||
use tim_tool::logic::{tim::types::Encoding, TIMManager};
|
|
||||||
use tool_helper::Error;
|
use tool_helper::Error;
|
||||||
|
|
||||||
pub type MutexTIMManager = Rc<Mutex<TIMManager>>;
|
|
||||||
|
|
||||||
pub fn on_browse_file(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
pub fn on_browse_file(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||||
return move |file_tab, main_window| -> Result<(), Error> {
|
return move |file_tab, main_window| -> Result<(), Error> {
|
||||||
|
|
|
@ -1,16 +1,12 @@
|
||||||
mod callbacks;
|
mod callbacks;
|
||||||
|
|
||||||
use crate::MainWindow;
|
use crate::gui::gui_elements::MutexTIMManager;
|
||||||
use super::main_tab::SharedMainTab;
|
use super::{main_tab::SharedMainTab, MainWindowRef, display_error};
|
||||||
use super::{GUIElements, GUIElementsRef, MainWindowRef, display_error};
|
|
||||||
use slint::{Image, SharedString};
|
use slint::{Image, SharedString};
|
||||||
use std::cell::RefCell;
|
use std::{cell::RefCell, rc::Rc};
|
||||||
use std::rc::Rc;
|
|
||||||
use tim_tool::logic::tim::types::Encoding;
|
use tim_tool::logic::tim::types::Encoding;
|
||||||
use tool_helper::Error;
|
use tool_helper::Error;
|
||||||
|
|
||||||
pub use callbacks::MutexTIMManager;
|
|
||||||
|
|
||||||
pub struct FileTab {
|
pub struct FileTab {
|
||||||
main_window: MainWindowRef,
|
main_window: MainWindowRef,
|
||||||
encoding_options: Rc<slint::VecModel<SharedString>>
|
encoding_options: Rc<slint::VecModel<SharedString>>
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
use super::create_vram_bg;
|
use super::create_vram_bg;
|
||||||
|
|
||||||
use super::main_tab::SharedMainTab;
|
use super::main_tab::SharedMainTab;
|
||||||
use super::MainWindowRef;
|
use super::MainWindowRef;
|
||||||
use super::{file_tab::{FileTab, SharedFileTab, MutexTIMManager}, main_tab::MainTab};
|
use super::{file_tab::{FileTab, SharedFileTab}, main_tab::MainTab};
|
||||||
|
use std::{rc::Rc, sync::Mutex};
|
||||||
|
use tim_tool::logic::TIMManager;
|
||||||
|
|
||||||
|
pub type MutexTIMManager = Rc<Mutex<TIMManager>>;
|
||||||
|
|
||||||
pub struct GUIElements {
|
pub struct GUIElements {
|
||||||
pub file_tab: SharedFileTab,
|
_file_tab: SharedFileTab,
|
||||||
pub main_tab: SharedMainTab,
|
_main_tab: SharedMainTab,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GUIElements {
|
impl GUIElements {
|
||||||
pub fn new(main_window: MainWindowRef, tim_manager: MutexTIMManager) -> Result<GUIElements, slint::PlatformError> {
|
pub fn new(main_window: MainWindowRef, tim_manager: MutexTIMManager) -> Result<GUIElements, slint::PlatformError> {
|
||||||
main_window.borrow().set_main_tab_vram_bg(GUIElements::create_bg()?);
|
main_window.borrow().set_main_tab_vram_bg(GUIElements::create_bg()?);
|
||||||
|
|
||||||
let main_tab = MainTab::new(main_window.clone(), tim_manager.clone());
|
let _main_tab = MainTab::new(main_window.clone(), tim_manager.clone());
|
||||||
let file_tab = FileTab::new(main_window.clone(), main_tab.clone(), tim_manager);
|
let _file_tab = FileTab::new(main_window.clone(), _main_tab.clone(), tim_manager);
|
||||||
|
|
||||||
Ok(GUIElements{file_tab, main_tab})
|
Ok(GUIElements{_file_tab, _main_tab})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_bg() -> Result<slint::Image, slint::PlatformError> {
|
fn create_bg() -> Result<slint::Image, slint::PlatformError> {
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
use crate::{gui::{VRAM_HEIGHT, VRAM_WIDTH}, MainWindow, display_information};
|
use crate::{gui::gui_elements::MutexTIMManager, MainWindow, display_information};
|
||||||
use super::MainTab;
|
use super::MainTab;
|
||||||
use std::{rc::Rc, sync::Mutex};
|
|
||||||
use tim_tool::logic::{tim::types::Encoding, TIMManager};
|
|
||||||
|
|
||||||
pub type MutexTIMManager = Rc<Mutex<TIMManager>>;
|
|
||||||
|
|
||||||
pub fn on_move_vram_image() -> impl FnMut(&mut MainTab, &MainWindow, i32, i32, i32) + 'static {
|
pub fn on_move_vram_image() -> impl FnMut(&mut MainTab, &MainWindow, i32, i32, i32) + 'static {
|
||||||
return move |main_tab, _main_window, idx, dx, dy| {
|
return move |main_tab, _main_window, idx, dx, dy| {
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
mod callbacks;
|
mod callbacks;
|
||||||
|
|
||||||
use crate::{gui::{VRAM_HEIGHT, VRAM_WIDTH}, MainWindow, VRAMImage};
|
use crate::{gui::{gui_elements::MutexTIMManager, VRAM_HEIGHT, VRAM_WIDTH}, VRAMImage};
|
||||||
use super::{GUIElementsRef, MainWindowRef};
|
use super::MainWindowRef;
|
||||||
|
|
||||||
use slint::{Model, SharedString};
|
use slint::{Model, SharedString};
|
||||||
use tim_tool::logic::tim::types::Encoding;
|
|
||||||
use std::{cell::RefCell, ops::RangeInclusive, rc::Rc, sync::{Arc, Mutex}};
|
use std::{cell::RefCell, ops::RangeInclusive, rc::Rc, sync::{Arc, Mutex}};
|
||||||
|
use tim_tool::logic::tim::types::Encoding;
|
||||||
|
|
||||||
struct VRAM {
|
struct VRAM {
|
||||||
count: usize,
|
count: usize,
|
||||||
|
@ -32,14 +31,13 @@ impl VRAM {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MainTab {
|
pub struct MainTab {
|
||||||
main_window: MainWindowRef,
|
vram: Arc<Mutex<VRAM>>,
|
||||||
vram: Arc<Mutex<VRAM>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type SharedMainTab = Rc<RefCell<MainTab>>;
|
pub type SharedMainTab = Rc<RefCell<MainTab>>;
|
||||||
|
|
||||||
impl MainTab {
|
impl MainTab {
|
||||||
pub fn new(main_window: MainWindowRef, tim_manager: callbacks::MutexTIMManager) -> SharedMainTab {
|
pub fn new(main_window: MainWindowRef, tim_manager: MutexTIMManager) -> SharedMainTab {
|
||||||
let vram_file_list:Vec<slint::StandardListViewItem> = main_window.borrow().get_main_tab_vram_file_list().iter().collect();
|
let vram_file_list:Vec<slint::StandardListViewItem> = main_window.borrow().get_main_tab_vram_file_list().iter().collect();
|
||||||
let vram_file_list = Rc::new(slint::VecModel::from(vram_file_list));
|
let vram_file_list = Rc::new(slint::VecModel::from(vram_file_list));
|
||||||
let vram_image_list = Rc::new(slint::VecModel::from(Vec::<VRAMImage>::new()));
|
let vram_image_list = Rc::new(slint::VecModel::from(Vec::<VRAMImage>::new()));
|
||||||
|
@ -47,7 +45,7 @@ impl MainTab {
|
||||||
main_window.borrow().set_main_tab_vram_file_list(vram_file_list.clone().into());
|
main_window.borrow().set_main_tab_vram_file_list(vram_file_list.clone().into());
|
||||||
main_window.borrow().set_main_tab_vram_images(vram_image_list.clone().into());
|
main_window.borrow().set_main_tab_vram_images(vram_image_list.clone().into());
|
||||||
|
|
||||||
let object = SharedMainTab::new(MainTab{main_window: main_window.clone(), vram: Arc::new(Mutex::new(VRAM{count: 0, file_list: vram_file_list, image_list: vram_image_list}))}.into());
|
let object = SharedMainTab::new(MainTab{vram: Arc::new(Mutex::new(VRAM{count: 0, file_list: vram_file_list, image_list: vram_image_list}))}.into());
|
||||||
|
|
||||||
let (cloned_object, cloned_main_window, mut function) = (object.clone(), main_window.clone(), callbacks::on_move_vram_image());
|
let (cloned_object, cloned_main_window, mut function) = (object.clone(), main_window.clone(), callbacks::on_move_vram_image());
|
||||||
main_window.borrow().on_move_vram_image(move |idx, dx, dy| {
|
main_window.borrow().on_move_vram_image(move |idx, dx, dy| {
|
||||||
|
|
|
@ -14,7 +14,6 @@ pub const VRAM_WIDTH:usize = 1024;
|
||||||
pub const VRAM_HEIGHT:usize = 512;
|
pub const VRAM_HEIGHT:usize = 512;
|
||||||
|
|
||||||
type MainWindowRef = Rc<RefCell<MainWindow>>;
|
type MainWindowRef = Rc<RefCell<MainWindow>>;
|
||||||
type GUIElementsRef = Rc<RefCell<GUIElements>>;
|
|
||||||
|
|
||||||
pub fn display_information(title: impl Into<String>, text: impl Into<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();
|
MessageDialog::new().set_title(title).set_level(rfd::MessageLevel::Info).set_description(text).show();
|
||||||
|
|
|
@ -2,30 +2,28 @@
|
||||||
#![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, display_information};
|
use gui::{GUIElements, display_information};
|
||||||
use rfd::FileDialog;
|
|
||||||
use std::{cell::RefCell, rc::Rc, sync::Mutex};
|
use std::{cell::RefCell, rc::Rc, sync::Mutex};
|
||||||
use slint::SharedString;
|
use slint::SharedString;
|
||||||
use tim_tool::logic::{tim::types::Encoding, TIMManager};
|
use tim_tool::logic::TIMManager;
|
||||||
use tool_helper::Error;
|
|
||||||
|
|
||||||
slint::include_modules!();
|
slint::include_modules!();
|
||||||
|
|
||||||
struct Application {
|
struct Application {
|
||||||
main_window: Rc<RefCell<MainWindow>>,
|
main_window: Rc<RefCell<MainWindow>>,
|
||||||
gui_elements: Rc<RefCell<GUIElements>>,
|
_gui_elements: Rc<RefCell<GUIElements>>,
|
||||||
tim_manager: Rc<Mutex<TIMManager>>,
|
_tim_manager: Rc<Mutex<TIMManager>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Application {
|
impl Application {
|
||||||
fn new() -> Result<Application, slint::PlatformError> {
|
fn new() -> Result<Application, slint::PlatformError> {
|
||||||
let main_window = Rc::new(RefCell::new(MainWindow::new()?));
|
let main_window = Rc::new(RefCell::new(MainWindow::new()?));
|
||||||
let tim_manager = Rc::new(Mutex::new(TIMManager::new()));
|
let _tim_manager = Rc::new(Mutex::new(TIMManager::new()));
|
||||||
|
|
||||||
Ok(Application{
|
Ok(Application{
|
||||||
main_window: main_window.clone(),
|
main_window: main_window.clone(),
|
||||||
gui_elements: Rc::new(RefCell::new(GUIElements::new(main_window.clone(), tim_manager.clone())?)),
|
_gui_elements: Rc::new(RefCell::new(GUIElements::new(main_window.clone(), _tim_manager.clone())?)),
|
||||||
tim_manager: tim_manager,
|
_tim_manager,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue