Native MoonBit application and window host.
Dependencies
import {
"Nanaloveyuki/orby",
}
struct Example {
mut window : @orby.Window?
}
pub impl @orby.App for Example with fn started(self, app) {
self.window = Some(
try! app.create_window(@orby.WindowOptions::new(title="Orby example")),
)
}
pub impl @orby.App for Example with fn window_event(self, _app, _id, event) {
match event {
@orby.WindowEvent::CloseRequested =>
match self.window {
Some(window) => window.destroy()
None => ()
}
_ => ()
}
}
fn main raise {
let event_loop = @orby.EventLoop::new()
ignore(event_loop.run_app({ window: None }))
}import {
"Nanaloveyuki/orby",
}
struct Example {
mut window : @orby.Window?
}
pub impl @orby.App for Example with fn started(self, app) {
self.window = Some(
try! app.create_window(
@orby.WindowOptions::new(
title="Orby example",
size=@orby.Size::new(width=960, height=640),
),
),
)
}
pub impl @orby.App for Example with fn window_event(self, _app, _id, event) {
match event {
@orby.WindowEvent::CloseRequested =>
match self.window {
Some(window) => window.destroy()
None => ()
}
_ => ()
}
}
fn main raise {
let loop = @orby.EventLoop::new()
ignore(loop.run_app({ window: None }))
}pub impl @orby.App for Example with fn about_to_wait(self, app) {
if startup_work_failed() {
app.fail("initial runtime setup failed")
}
}
fn run_example() raise {
let loop = @orby.EventLoop::new()
let app = { window: None }
try ignore(loop.run_app(app)) catch {
@orby.AppError::StartupFailed(reason) => println("startup: \{reason}")
@orby.AppError::RuntimeFailed(reason) => println("runtime: \{reason}")
}
}pub(all) suberror InitError {
AlreadyActive
UnsupportedHost(String)
PlatformFailure(String)
} derive(Debug)fn[A : App] EventLoop::start_external_app(self : EventLoop, app : A) -> ExternalAppLoop[A] raise AppErrorpub struct ExternalAppLoop[A] {
// private fields
}fn[A : App] ExternalAppLoop::poll(self : ExternalAppLoop[A], timeout? : Int) -> ExternalPoll raise AppErrorfn[A] ExternalAppLoop::wakeup_callback_for_foreign_thread(self : ExternalAppLoop[A]) -> FuncRef[() -> Unit]pub(all) struct NativeKeyEvent {
code : Int
state : InputState
repeat : Bool
modifiers : Modifiers
} derive(Eq, Debug)fn NativeKeyEvent::new(code~ : Int, state~ : InputState, repeat? : Bool, modifiers? : Modifiers) -> NativeKeyEventpub(all) enum WindowEvent {
CloseRequested
Destroyed
Resized(Size)
ScaleFactorChanged(Double)
FocusChanged(Bool)
RedrawRequested
KeyInput(NativeKeyEvent)
TextInput(String)
PointerMoved(Position)
PointerEntered
PointerLeft
MouseInput(MouseButton, InputState, Modifiers)
MouseWheel(ScrollDelta, Modifiers)
} derive(Debug)fn WindowOptions::new(title? : String, size? : Size, visible? : Bool, resizable? : Bool) -> WindowOptionsNative MoonBit application and window host.
Dependencies