use gtk::prelude::*; use std::collections::HashMap; use std::rc::Rc; use std::sync::Mutex; pub trait View { fn name(&self) -> &str; fn set_vm(&mut self, vm : Rc); fn make_current(&self) -> gtk::Box; } #[derive(Default)] pub struct ViewManager { views : HashMap>>, pub current : String, pub window : Option } impl ViewManager { pub fn new(window : gtk::ApplicationWindow) -> Self { Self { views : HashMap::new(), current : String::new(), window : Some(window), } } pub fn empty() -> Self { Self { .. Default::default() } } pub fn add_view(&mut self, view : Rc>) { self.views.insert(view.lock().unwrap().name().to_string(), view.clone()); } pub fn set_current_view(&self, name : &str) { let b = self.views.get(name).expect("unkown view").lock().unwrap().make_current(); let window = self.window.as_ref().unwrap(); for child in window.children() { window.remove(&child) } window.add(&b); window.show_all() } pub fn get_window(&self) -> >k::ApplicationWindow { self.window.as_ref().unwrap() } }