cacao/examples/todos_list/add/mod.rs

43 lines
1.1 KiB
Rust
Raw Normal View History

//! Implements a window for adding a new Todo.
use cacao::appkit::window::{Window, WindowDelegate};
use cacao::view::ViewController;
use crate::storage::{dispatch_ui, Message};
mod view;
use view::AddNewTodoContentView;
pub struct AddNewTodoWindow {
2022-08-19 07:45:19 +10:00
pub content: ViewController<AddNewTodoContentView>
}
impl AddNewTodoWindow {
pub fn new() -> Self {
let content = ViewController::new(AddNewTodoContentView::default());
2022-07-11 01:15:29 +10:00
2022-07-16 00:14:02 +10:00
AddNewTodoWindow { content: content }
}
2022-07-11 01:15:29 +10:00
pub fn on_message(&self, message: Message) {
if let Some(delegate) = &self.content.view.delegate {
delegate.on_message(message);
}
}
}
impl WindowDelegate for AddNewTodoWindow {
const NAME: &'static str = "AddNewTodoWindow";
2022-07-11 01:15:29 +10:00
fn did_load(&mut self, window: Window) {
window.set_autosave_name("AddNewTodoWindow");
window.set_minimum_content_size(300, 100);
window.set_title("Add a New Task");
window.set_content_view_controller(&self.content);
}
2022-07-11 01:15:29 +10:00
fn cancel(&self) {
dispatch_ui(Message::CloseSheet);
}
}