gnui 0.0.1-alpha.2

A GUI library to design apps for GNOME and beyond
Documentation
use winit::{
    event::{WindowEvent},
    event_loop::EventLoop,
    window::Window
};
use winit::application::ApplicationHandler;
use winit::event_loop::{ActiveEventLoop, ControlFlow};
use winit::window::WindowId;

#[derive(Debug)]
pub struct Application {
    title: Option<Box<str>>,
    application_id: Option<Box<str>>,
    window: Option<Box<dyn Window>>
}

pub fn application() -> Application {
    Application {
        title: None,
        application_id: None,
        window: None,
    }
}

impl Application {
    /// Sets the [`window::titl`] of the [`Application`].
    pub fn title(mut self, title: Box<str>) -> Self {
        self.title = Some(title);
        self
    }

    /// Sets the [`window`] of the [`Application`].
    pub fn application_id(mut self, id: Box<str>) -> Self {
        self.application_id = Some(id);
        self
    }

    /// Runs the [`window`] of the [`Application`].
    pub fn run(self) -> Result<(), winit::error::EventLoopError> {
        let event_loop = EventLoop::new()?;
        event_loop.set_control_flow(ControlFlow::Wait);
        event_loop.run_app(self)
    }
}

impl ApplicationHandler for Application {
    fn resumed(&mut self, event_loop: &dyn ActiveEventLoop) {
        todo!()
    }

    fn can_create_surfaces(&mut self, event_loop: &dyn ActiveEventLoop) {
        todo!()
    }

    fn window_event(&mut self, event_loop: &dyn ActiveEventLoop, window_id: WindowId, event: WindowEvent) {
        match event {
            WindowEvent::CloseRequested => {
                println!("The close button was pressed; stopping");
                event_loop.exit();
            },
            WindowEvent::RedrawRequested => {
                // Redraw the application.
                //
                // It's preferable for applications that do not render continuously to render in
                // this event rather than in AboutToWait, since rendering in here allows
                // the program to gracefully handle redraws requested by the OS.

                // Draw.

                // Queue a RedrawRequested event.
                //
                // You only need to call this if you've determined that you need to redraw in
                // applications which do not always need to. Applications that redraw continuously
                // can render here instead.
                self.window.as_ref().unwrap().request_redraw();
            }
            _ => (),
        }
    }
}