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.
|
|
|
|
|
2020-03-30 16:33:51 +11:00
|
|
|
use cacao::macos::app::{App, AppDelegate};
|
|
|
|
use cacao::macos::window::{Window, WindowConfig, WindowDelegate};
|
2020-03-20 14:07:44 +11:00
|
|
|
|
|
|
|
struct BasicApp {
|
|
|
|
window: Window<MyWindow>
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AppDelegate for BasicApp {
|
|
|
|
fn did_finish_launching(&self) {
|
|
|
|
self.window.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
struct MyWindow;
|
|
|
|
|
|
|
|
impl WindowDelegate for MyWindow {
|
2020-03-30 16:33:51 +11:00
|
|
|
fn did_load(&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() {
|
|
|
|
App::new("com.test.window-delegate", BasicApp {
|
|
|
|
window: Window::with(WindowConfig::default(), MyWindow::default())
|
|
|
|
}).run();
|
|
|
|
}
|