Hello World!
Topics: logging, app, run
Lets get started with a simple message box. Source.
extern crate kas; use kas::widgets::{Button, column}; use kas::window::Window; fn main() -> kas::runner::Result<()> { let ui = column![ "Hello, world!", Button::label("&Close").with(|cx, _| cx.exit()) ]; let window = Window::new(ui, "Hello").escapable(); kas::runner::Runner::new(())?.with(window).run() }
cargo run --example hello
The UI
We use the column!
macro to construct our layout. This macro turns string literals into label widgets for us, ensuring that "Hello, world!" will appear on the screen.
For the button, we use a Button
widget. The button's action handler calls EventState::exit
to terminate the UI. (To close the window without terminating the UI, we would instead call cx.window_action(Action::CLOSE);
.)
The Window
We construct a Window
over the ui
and a title. We also call Window::escapable
to allow our window to be closed using the Escape key.
The Runner
Every UI needs a Runner
. In this example we simply construct a runner over data ()
, add a single window, and run. In later examples you will see how we can select a theme, use input data, multiple windows and tweak the configuration.
Finally, Runner::run
starts our UI. This method runs the event-loop internally, returning Ok(())
once all windows have closed successfully.