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",
}
supported_targets = "native"
options("is-main": true)///|
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 : @macos.Window? = Some(event_loop.try_create_window(attrs)) catch {
err => {
println("error creating window: \{err}")
event_loop.exit()
None
}
}
self.window = window
}
///|
pub impl @macos.ApplicationHandler for App with window_event(
self,
event_loop,
_id,
event,
) {
match event {
CloseRequested => event_loop.exit()
SurfaceResized(_) =>
match self.window {
Some(window) => window.request_redraw()
None => ()
}
RedrawRequested => println("redraw requested")
_ => ()
}
}
///|
fn main {
let event_loop = @macos.EventLoop::EventLoop()
event_loop.run_app({ window: None })
}let raw = try! window.window_handle().as_raw()
match raw {
@windowing.RawWindowHandle::AppKit(handle) => {
let ns_view = handle.ns_view()
// Create the renderer surface from ns_view.
}
_ => abort("renderer does not support this window backend")
}///|
pub impl @macos.ApplicationHandler for App with window_event(
self,
event_loop,
_id,
event,
) {
match event {
PointerMoved(_, position, _, _) =>
println("pointer moved: \{position}")
DragEntered(paths, position) =>
println("drag entered at \{position}: \{paths}")
CloseRequested => event_loop.exit()
_ => ()
}
}moon run modules/window/examples/window --target nativescripts/check_ci.shRUN_EXAMPLE_TRANSCRIPTS=1 scripts/check_ci.shA MoonBit port of winit with a native macOS event loop and windowing backend.
Dependencies