2020-09-13 03:06:21 +10:00
|
|
|
use raw_window_handle::RawWindowHandle;
|
2020-05-26 04:04:48 +10:00
|
|
|
|
2020-05-26 08:28:38 +10:00
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
mod win;
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
pub use win::*;
|
2020-05-26 12:10:32 +10:00
|
|
|
|
2020-05-26 08:28:38 +10:00
|
|
|
#[cfg(target_os = "linux")]
|
2020-05-26 05:35:33 +10:00
|
|
|
mod x11;
|
2020-05-26 12:10:32 +10:00
|
|
|
#[cfg(target_os = "linux")]
|
2020-06-01 04:29:32 +10:00
|
|
|
pub use crate::x11::*;
|
2020-05-26 12:10:32 +10:00
|
|
|
|
2020-05-26 08:28:38 +10:00
|
|
|
#[cfg(target_os = "macos")]
|
2020-05-26 07:14:42 +10:00
|
|
|
mod macos;
|
2020-05-26 08:28:38 +10:00
|
|
|
#[cfg(target_os = "macos")]
|
2020-05-26 12:10:32 +10:00
|
|
|
pub use macos::*;
|
2020-05-26 07:14:42 +10:00
|
|
|
|
2020-09-04 02:38:22 +10:00
|
|
|
mod event;
|
2020-09-12 01:21:05 +10:00
|
|
|
mod keyboard;
|
|
|
|
mod mouse_cursor;
|
2020-10-16 05:17:03 +11:00
|
|
|
mod window_info;
|
2020-10-18 05:35:39 +11:00
|
|
|
mod window_open_options;
|
2020-09-04 02:38:22 +10:00
|
|
|
pub use event::*;
|
2020-09-12 01:21:05 +10:00
|
|
|
pub use keyboard::*;
|
|
|
|
pub use mouse_cursor::MouseCursor;
|
2020-10-16 05:17:03 +11:00
|
|
|
pub use window_info::WindowInfo;
|
2020-10-18 05:35:39 +11:00
|
|
|
pub use window_open_options::*;
|
2020-09-03 07:22:49 +10:00
|
|
|
|
2020-10-18 05:35:39 +11:00
|
|
|
#[derive(Debug)]
|
2020-05-26 04:04:48 +10:00
|
|
|
pub enum Parent {
|
|
|
|
None,
|
|
|
|
AsIfParented,
|
2020-09-13 03:06:21 +10:00
|
|
|
WithParent(RawWindowHandle),
|
2020-05-26 04:04:48 +10:00
|
|
|
}
|
|
|
|
|
2020-09-12 02:18:39 +10:00
|
|
|
unsafe impl Send for Parent {}
|
|
|
|
|
2020-10-16 05:17:03 +11:00
|
|
|
pub struct WindowHandle {
|
|
|
|
thread: std::thread::JoinHandle<()>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl WindowHandle {
|
|
|
|
pub fn app_run_blocking(self) {
|
|
|
|
let _ = self.thread.join();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-18 06:01:03 +11:00
|
|
|
#[derive(Debug, Copy, Clone, PartialEq)]
|
|
|
|
pub struct Point<T> {
|
|
|
|
pub x: T,
|
|
|
|
pub y: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Point<T> {
|
|
|
|
pub fn new(x: T, y: T) -> Self {
|
|
|
|
Self { x, y }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Point<f64>> for Point<i32> {
|
|
|
|
fn from(p: Point<f64>) -> Point<i32> {
|
|
|
|
Point::new(p.x.round() as i32, p.y.round() as i32)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq)]
|
|
|
|
pub struct Size {
|
|
|
|
pub width: u32,
|
|
|
|
pub height: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Size {
|
|
|
|
pub fn new(width: u32, height: u32) -> Self {
|
|
|
|
Self { width, height }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-16 05:17:03 +11:00
|
|
|
type WindowOpenResult = Result<WindowInfo, ()>;
|
|
|
|
|
2020-09-08 12:36:54 +10:00
|
|
|
pub trait WindowHandler {
|
|
|
|
type Message;
|
2020-09-04 02:38:22 +10:00
|
|
|
|
2020-09-07 17:37:16 +10:00
|
|
|
fn build(window: &mut Window) -> Self;
|
2020-09-06 08:29:36 +10:00
|
|
|
|
2020-09-12 00:49:55 +10:00
|
|
|
fn on_frame(&mut self);
|
2020-09-07 17:37:16 +10:00
|
|
|
fn on_event(&mut self, window: &mut Window, event: Event);
|
2020-09-08 12:36:54 +10:00
|
|
|
fn on_message(&mut self, window: &mut Window, message: Self::Message);
|
2020-09-06 06:22:23 +10:00
|
|
|
}
|