Skip to content

Commit 7046249

Browse files
committed
Update Hello
1 parent 0da4b2e commit 7046249

1 file changed

Lines changed: 24 additions & 59 deletions

File tree

src/hello.md

Lines changed: 24 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,79 +9,44 @@ Lets get started with a simple message box.
99

1010
```rust
1111
# extern crate kas;
12-
use kas::widgets::dialog::MessageBox;
12+
use kas::widgets::{Button, column};
13+
use kas::window::Window;
1314

14-
fn main() -> kas::app::Result<()> {
15-
env_logger::init();
15+
fn main() -> kas::runner::Result<()> {
16+
let ui = column![
17+
"Hello, world!",
18+
Button::label("&Close").with(|cx, _| cx.exit())
19+
];
20+
let window = Window::new(ui, "Hello").escapable();
1621

17-
let window = MessageBox::new("Message").into_window("Hello world");
18-
19-
kas::app::Default::new(())?.with(window).run()
22+
kas::runner::Runner::new(())?.with(window).run()
2023
}
2124
```
2225

2326
```sh
2427
cargo run --example hello
2528
```
2629

27-
## A window, a shell
30+
## The UI
2831

29-
Next, we construct a [`MessageBox`] widget, then wrap with a [`Window`]:
30-
```rust
31-
# extern crate kas;
32-
# use kas::widgets::dialog::MessageBox;
33-
let window = MessageBox::new("Message")
34-
.into_window("Hello world");
35-
# let _: kas::Window<()> = window;
36-
```
32+
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.
3733

38-
Finally, we construct a default app, add this window, and run:
39-
```rust
40-
# extern crate kas;
41-
# use kas::widgets::dialog::MessageBox;
42-
# fn main() -> kas::app::Result<()> {
43-
# let window = MessageBox::new("Message").into_window("Hello world");
44-
kas::app::Default::new(())?
45-
.with(window)
46-
.run()
47-
# }
48-
```
34+
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);`.)
4935

50-
[`kas::app::Default`] is just a parameterisation of [`kas::app::Application`] which selects a sensible graphics backend and theme.
36+
## The Window
5137

52-
If you wanted to select your own theme instead, you could do so as follows:
53-
```rust
54-
# extern crate kas;
55-
# use kas::widgets::dialog::MessageBox;
56-
# fn main() -> kas::app::Result<()> {
57-
# let window = MessageBox::new("Message").into_window("Hello world");
58-
let theme = kas::theme::SimpleTheme::new();
59-
kas::app::Default::with_theme(theme)
60-
.build(())?
61-
.with(window)
62-
.run()
63-
# }
64-
```
38+
We construct a [`Window`] over the `ui` and a title. We also call [`Window::escapable`] to allow our window to be closed using the <kbd>Escape</kbd> key.
6539

66-
Or, if you wanted to specify the graphics backend and theme:
67-
```rust
68-
# extern crate kas;
69-
# use kas::widgets::dialog::MessageBox;
70-
# fn main() -> kas::app::Result<()> {
71-
# let window = MessageBox::new("Message").into_window("Hello world");
72-
kas_wgpu::WgpuBuilder::new(())
73-
.with_theme(kas_wgpu::ShadedTheme::new())
74-
.build(())?
75-
.with(window)
76-
.run()
77-
# }
78-
```
40+
## The Runner
41+
42+
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.
7943

80-
Finally, [`Application::run`] starts our UI. This method runs the event-loop internally, returning `Ok(())` once all windows have closed successfully.
44+
Finally, [`Runner::run`] starts our UI. This method runs the event-loop internally, returning `Ok(())` once all windows have closed successfully.
8145

82-
[`MessageBox`]: https://docs.rs/kas/latest/kas/widgets/dialog/struct.MessageBox.html
46+
[`column!`]: https://docs.rs/kas/latest/kas/widgets/macro.column.html
47+
[`Button`]: https://docs.rs/kas/latest/kas/widgets/struct.Button.html
8348
[`Window`]: https://docs.rs/kas/latest/kas/struct.Window.html
84-
[`kas::app::Default`]: https://docs.rs/kas/latest/kas/app/type.Default.html
85-
[`kas::app::Application`]: https://docs.rs/kas/latest/kas/app/struct.Application.html
86-
[`Application::run`]: https://docs.rs/kas/latest/kas/app/struct.Application.html#method.run
87-
[`winit::event_loop::EventLoop::run`]: https://docs.rs/winit/latest/winit/event_loop/struct.EventLoop.html#method.run
49+
[`Window::escapable`]: https://docs.rs/kas/latest/kas/struct.Window.html#method.escapable
50+
[`EventState::exit`]: https://docs.rs/kas/latest/kas/event/struct.EventState.html#method.exit
51+
[`Runner`]: https://docs.rs/kas/latest/kas/runner/struct.Runner.html
52+
[`Runner::run`]: https://docs.rs/kas/latest/kas/runner/struct.Runner.html#method.run

0 commit comments

Comments
 (0)