use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use crate::event::WindowEvent;
#[cfg_attr(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
), path = "unix/mod.rs")]
#[cfg_attr(target_os = "macos", path = "macos/mod.rs")]
#[cfg_attr(target_os = "windows", path = "windows/mod.rs")]
mod os;
use os::event_source::EventSourceImpl;
use os::window::EditorWindowImpl;
trait EditorWindowBackend: raw_window_handle::HasRawWindowHandle {
fn build(parent: *mut std::os::raw::c_void, size_xy: (i32, i32)) -> Self;
}
trait EventSourceBackend {
fn new(window: &EditorWindowImpl, size_xy: (i32, i32)) -> Self;
fn poll_event(&self) -> Option<WindowEvent>;
}
pub fn setup(
parent: *mut std::os::raw::c_void,
size_xy: (i32, i32),
) -> (EditorWindow, EventSource) {
let window = EditorWindowImpl::build(parent, size_xy);
let event_source = EventSourceImpl::new(&window, size_xy);
(EditorWindow(window), EventSource(event_source))
}
pub struct EditorWindow(EditorWindowImpl);
unsafe impl HasRawWindowHandle for EditorWindow {
fn raw_window_handle(&self) -> RawWindowHandle {
self.0.raw_window_handle()
}
}
pub struct EventSource(EventSourceImpl);
impl EventSource {
pub fn poll_event(&self) -> Option<WindowEvent> {
self.0.poll_event()
}
}