1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use crate::window_event_handler::WindowEventHandler;
use crate::SystemEvent;
use druid_shell::kurbo::Size;
use druid_shell::piet::Piet;
use druid_shell::{Region, WindowBuilder};

///
pub trait Application {
    ///
    fn handle_system_event(&mut self, system_event: &SystemEvent);

    ///
    fn paint(&mut self, piet: &mut Piet, region: &Region);

    ///
    fn resize(&mut self, size: Size);
}

///
pub fn run(mut application: Box<dyn Application>, title: impl Into<String>, size: Size) {
    // Create a druid shell application.
    let druid_shell_application = druid_shell::Application::new().unwrap();

    // Set the initial size.
    application.resize(size);

    // Create a window builder.
    let mut window_builder = WindowBuilder::new(druid_shell_application.clone());
    window_builder.set_handler(Box::new(WindowEventHandler::new(application)));
    window_builder.set_title(title);
    window_builder.set_size(size);

    // Create a window and show it.
    let window_handle = window_builder.build().unwrap();
    window_handle.show();

    druid_shell_application.run(None);
}