From 61ac9375b4a35878576ac2727c5210cd9fc51a92 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 26 Jul 2023 21:19:59 +0200 Subject: add gtk3 gui --- src/gui/state.rs | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'src/gui/state.rs') diff --git a/src/gui/state.rs b/src/gui/state.rs index 7b9542a..be41f86 100644 --- a/src/gui/state.rs +++ b/src/gui/state.rs @@ -1,27 +1,31 @@ use gtk::prelude::*; use std::collections::HashMap; -use std::rc::Rc; use std::sync::Mutex; +use crate::index::Index; +use std::rc::Rc; +use std::sync::Arc; pub trait View { fn name(&self) -> &str; fn set_vm(&mut self, vm : Rc); - fn make_current(&self) -> gtk::Box; + fn make_current(&self) -> Option; } #[derive(Default)] pub struct ViewManager { views : HashMap>>, - pub current : String, - pub window : Option + pub current : Mutex, + pub window : Option, + index : Arc> } impl ViewManager { pub fn new(window : gtk::ApplicationWindow) -> Self { Self { views : HashMap::new(), - current : String::new(), + current : Mutex::new(String::new()), window : Some(window), + index : Arc::new(Mutex::new(Index::default())) } } @@ -41,11 +45,31 @@ impl ViewManager { for child in window.children() { window.remove(&child) } - window.add(&b); - window.show_all() + { + *(self.current.lock().unwrap()) = name.to_string(); + } + if let Some(b) = b { + window.add(&b); + window.show_all(); + } else { + window.hide(); + } + } + + pub fn get_current_view(&self) -> String { + self.current.lock().unwrap().to_string() } pub fn get_window(&self) -> >k::ApplicationWindow { self.window.as_ref().unwrap() } + + pub fn get_index(&self) -> Arc> { + Arc::clone(&self.index) + } + + pub fn set_index(&self, index : Index) { + let mut idx = self.index.lock().unwrap(); + *idx = index; + } } -- cgit v1.2.3-70-g09d2