A MoonBit port of winit with a native macOS event loop and windowing backend.
Dependencies
moon add Milky2018/windowimport {
"Milky2018/window/core",
"Milky2018/window/macos",
}
struct App {
mut window : @macos.Window?
}
pub impl @macos.ApplicationHandler for App with can_create_surfaces(
self,
event_loop,
) {
let attrs =
@core.WindowAttributes::default()
.with_title("window demo")
let window = event_loop.create_window(attrs)
self.window = Some(window)
window.request_redraw()
}
pub impl @macos.ApplicationHandler for App with window_event(
self,
event_loop,
_id,
event,
) {
for compat_event in event.into_winit_events() {
match compat_event {
@core.WinitWindowEvent::CloseRequested => event_loop.exit()
@core.WinitWindowEvent::Resized(_) =>
match self.window {
Some(window) => window.request_redraw()
None => ()
}
@core.WinitWindowEvent::RedrawRequested => println("redraw requested")
_ => ()
}
}
}
fn main {
let event_loop = @macos.EventLoop::new()
event_loop.run_app({ window: None })
}///|
pub impl @macos.ApplicationHandler for App with window_event(
self,
event_loop,
_id,
event,
) {
match event {
@core.WindowEvent::PointerMoved(_, position, _, _) =>
println("pointer moved: \{position}")
@core.WindowEvent::DragEntered(paths, position) =>
println("drag entered at \{position}: \{paths}")
@core.WindowEvent::CloseRequested => event_loop.exit()
_ => ()
}
}moon run examples/window --target nativeA MoonBit port of winit with a native macOS event loop and windowing backend.
Dependencies