2020-03-20 14:07:44 +11:00
|
|
|
//! This example showcases setting up a basic application and window delegate.
|
|
|
|
//! Window Delegate's give you lifecycle methods that you can respond to.
|
|
|
|
|
2021-08-08 15:31:48 +10:00
|
|
|
use cacao::appkit::menu::{Menu, MenuItem};
|
|
|
|
use cacao::appkit::window::{Window, WindowConfig, WindowDelegate};
|
2022-07-16 00:14:02 +10:00
|
|
|
use cacao::appkit::{App, AppDelegate};
|
2020-03-20 14:07:44 +11:00
|
|
|
|
|
|
|
struct BasicApp {
|
2022-08-27 00:40:31 +10:00
|
|
|
window: Window<MyWindow>
|
2020-03-20 14:07:44 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
impl AppDelegate for BasicApp {
|
|
|
|
fn did_finish_launching(&self) {
|
2021-08-08 15:31:48 +10:00
|
|
|
App::set_menu(vec![
|
2022-08-27 00:40:31 +10:00
|
|
|
Menu::new("", vec![
|
|
|
|
MenuItem::Services,
|
|
|
|
MenuItem::Separator,
|
|
|
|
MenuItem::Hide,
|
|
|
|
MenuItem::HideOthers,
|
|
|
|
MenuItem::ShowAll,
|
|
|
|
MenuItem::Separator,
|
|
|
|
MenuItem::Quit,
|
|
|
|
]),
|
2022-07-16 00:14:02 +10:00
|
|
|
Menu::new("File", vec![MenuItem::CloseWindow]),
|
|
|
|
Menu::new("View", vec![MenuItem::EnterFullScreen]),
|
2022-08-27 00:40:31 +10:00
|
|
|
Menu::new("Window", vec![
|
|
|
|
MenuItem::Minimize,
|
|
|
|
MenuItem::Zoom,
|
|
|
|
MenuItem::Separator,
|
|
|
|
MenuItem::new("Bring All to Front"),
|
|
|
|
]),
|
2021-08-08 15:31:48 +10:00
|
|
|
]);
|
|
|
|
|
2021-02-08 15:51:40 +11:00
|
|
|
App::activate();
|
2022-07-11 01:15:29 +10:00
|
|
|
|
2020-03-20 14:07:44 +11:00
|
|
|
self.window.show();
|
|
|
|
}
|
2021-08-08 15:31:48 +10:00
|
|
|
|
|
|
|
fn should_terminate_after_last_window_closed(&self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
2020-03-20 14:07:44 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
struct MyWindow;
|
|
|
|
|
|
|
|
impl WindowDelegate for MyWindow {
|
2021-02-08 15:51:40 +11:00
|
|
|
const NAME: &'static str = "MyWindow";
|
|
|
|
|
|
|
|
fn did_load(&mut self, window: Window) {
|
2020-03-20 14:07:44 +11:00
|
|
|
window.set_minimum_content_size(400., 400.);
|
|
|
|
window.set_title("A Basic Window!?");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn will_close(&self) {
|
|
|
|
println!("Closing now!");
|
|
|
|
}
|
2020-03-27 11:31:42 +11:00
|
|
|
|
|
|
|
fn will_move(&self) {
|
|
|
|
println!("Will move...");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn did_move(&self) {
|
|
|
|
println!("Did move...");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn will_resize(&self, width: f64, height: f64) -> (f64, f64) {
|
|
|
|
println!("Resizing to: {} {}", width, height);
|
|
|
|
(width, height)
|
|
|
|
}
|
2020-03-20 14:07:44 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2022-08-27 00:40:31 +10:00
|
|
|
App::new("com.test.window-delegate", BasicApp {
|
|
|
|
window: Window::with(WindowConfig::default(), MyWindow::default())
|
|
|
|
})
|
2022-07-16 00:14:02 +10:00
|
|
|
.run();
|
2020-03-20 14:07:44 +11:00
|
|
|
}
|