cacao/examples/todos_list/preferences/mod.rs

69 lines
1.9 KiB
Rust
Raw Normal View History

//! Implements a stock-ish Preferences window.
use cacao::appkit::toolbar::Toolbar;
2022-07-16 00:14:02 +10:00
use cacao::appkit::window::{Window, WindowDelegate};
use cacao::view::ViewController;
use crate::storage::Message;
mod toolbar;
use toolbar::PreferencesToolbar;
mod general;
use general::GeneralPreferencesContentView;
mod advanced;
use advanced::AdvancedPreferencesContentView;
mod toggle_option_view;
pub struct PreferencesWindow {
pub toolbar: Toolbar<PreferencesToolbar>,
pub general: ViewController<GeneralPreferencesContentView>,
pub advanced: ViewController<AdvancedPreferencesContentView>,
2022-08-27 00:40:31 +10:00
window: Option<Window>
}
impl PreferencesWindow {
pub fn new() -> Self {
PreferencesWindow {
toolbar: Toolbar::new("PreferencesToolbar", PreferencesToolbar::default()),
general: ViewController::new(GeneralPreferencesContentView::default()),
advanced: ViewController::new(AdvancedPreferencesContentView::default()),
2022-08-27 00:40:31 +10:00
window: None
}
}
2022-07-11 01:15:29 +10:00
pub fn on_message(&self, message: Message) {
let window = self.window.as_ref().unwrap();
match message {
Message::SwitchPreferencesToGeneralPane => {
window.set_title("General");
window.set_content_view_controller(&self.general);
},
Message::SwitchPreferencesToAdvancedPane => {
window.set_title("Advanced");
window.set_content_view_controller(&self.advanced);
},
2022-08-27 00:40:31 +10:00
_ => {}
}
}
}
impl WindowDelegate for PreferencesWindow {
const NAME: &'static str = "PreferencesWindow";
2022-07-11 01:15:29 +10:00
fn did_load(&mut self, window: Window) {
window.set_autosave_name("TodosPreferencesWindow");
window.set_movable_by_background(true);
window.set_toolbar(&self.toolbar);
2022-07-11 01:15:29 +10:00
self.window = Some(window);
self.on_message(Message::SwitchPreferencesToGeneralPane);
}
}