Skip to content

Commit 93b298b

Browse files
committed
Fix tests
1 parent ab12980 commit 93b298b

5 files changed

Lines changed: 29 additions & 42 deletions

File tree

src/calculator.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,15 @@ fn key_button_with(label: &str, key: Key) -> Button<AccessLabel> {
142142
Normally, access keys are only active while holding <kbd>Alt</kbd>. To avoid this requirement we call [`with_alt_bypass`]. Further, we disable <kbd>Tab</kbd> key navigation with [`without_nav_focus`] and ensure that the window can be closed with the <kbd>Esc</kbd> key.
143143
```rust
144144
# extern crate kas;
145-
# use kas::{Widget, widgets::{label_any, Adapt}};
145+
# use kas::{Widget, widgets::{Label, Adapt}, window::Window};
146146
# #[derive(Debug)]
147147
# struct Calculator;
148148
# impl Calculator {
149149
# fn new() -> Self { Calculator }
150150
# fn handle(&mut self, _key: ()) {}
151151
# }
152152
# fn ui() -> impl Widget<Data = ()> {
153-
# let ui = label_any("");
153+
# let ui = Label::new_any("");
154154
Window::new(ui, "Calculator")
155155
.escapable()
156156
.with_alt_bypass()
@@ -166,7 +166,7 @@ We already saw column and row layouts. This time, we'll use [`grid!`] for layout
166166
# extern crate kas;
167167
# use kas::event::NamedKey;
168168
# use kas::prelude::*;
169-
# use kas::widgets::{AccessLabel, Button};
169+
# use kas::widgets::{AccessLabel, Button, grid};
170170
# type Key = kas::event::Key<kas::event::SmolStr>;
171171
# fn key_button(label: &str) -> Button<AccessLabel> {
172172
# let string = AccessString::from(label);

src/config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Previously we adjusted the font size before the UI was started:
3232
let theme = kas::theme::SimpleTheme::new();
3333
let mut app = kas::runner::Runner::with_theme(theme).build(())?;
3434
let _ = app.config_mut().font.set_size(24.0);
35+
# Ok(())
3536
# }
3637
```
3738

src/counter.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Our user interface should be a widget tree: lets use a [`row!`] of buttons and a
7878
```rust
7979
# extern crate kas;
8080
# use kas::prelude::*;
81-
# use kas::widgets::{format_value, Adapt, Button};
81+
# use kas::widgets::{Adapt, AdaptWidget, Button, column, format_value, row};
8282
# #[derive(Clone, Debug)]
8383
# struct Increment(i32);
8484
# fn counter() -> impl Widget<Data = ()> {
@@ -90,7 +90,7 @@ Our user interface should be a widget tree: lets use a [`row!`] of buttons and a
9090
format_value!("{}").align(AlignHints::CENTER),
9191
buttons.map_any(),
9292
];
93-
# let _ = tree;
93+
# tree.with_state(0)
9494
# }
9595
```
9696

src/custom-widget.md

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ There are two types of child widgets: hidden layout-generated children and expli
113113
The first of these is a [`Text`] widget, passed `&self.count` as input data. The second is a [`Row`] widget over [`Button`]s over [`AccessLabel`]s. Since we didn't specify a data mapping for this second widget, it is is passed the `Count` widget's input data (`()`).
114114

115115
Omitting `#[widget]` on a field which is a child widget is an error; sometimes the outer `#[widget]` attribute-macro will report the issue but not always. For example, if we omit the attribute on `buttons` and run, we get a backtrace like the following:
116-
```
116+
```ignore
117117
thread 'main' (413532) panicked at /path/to/kas/crates/kas-core/src/core/data.rs:123:13:
118118
WidgetStatus of #INVALID: require Configured, found New
119119
stack backtrace:
@@ -160,9 +160,8 @@ It is however required to define the associated type [`Widget::Data`]. Since it
160160
# #[derive(Clone, Debug)]
161161
# struct Increment(i32);
162162
# impl_scope! {
163-
# #[widget{
164-
# layout = "";
165-
# }]
163+
# #[widget]
164+
# #[layout("")]
166165
# struct Counter {
167166
# core: widget_core!(),
168167
# count: i32,
@@ -202,24 +201,11 @@ Don't worry about remembering each step; macro diagnostics should point you in t
202201
### Aside: the type of child widgets
203202

204203
Our `Counter` has two (explicit) child widgets, and we must specify the type of each:
205-
```rust
206-
# extern crate kas;
207-
# use kas::impl_scope;
208-
# use kas::widgets::{AccessLabel, Button, Row, Text};
209-
# impl_scope! {
210-
# #[widget{
211-
# Data = ();
212-
# layout = "";
213-
# }]
214-
# struct Counter {
215-
# core: widget_core!(),
204+
```rust,ignore
216205
#[widget(&self.count)]
217206
display: Text<i32, String>,
218207
#[widget]
219208
buttons: Row<[Button<AccessLabel>; 2]>,
220-
# count: i32,
221-
# }
222-
# }
223209
```
224210
There is no real issue in this case, but widget types can get significantly harder to write than `Row<[Button<AccessLabel>; 2]>`. Worse, some widget types are impossible to write (e.g. the result of [`row!`] or widget generics instantiated with a closure). So what can we do instead?
225211

src/sync-counter.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,38 +70,35 @@ fn main() -> kas::runner::Result<()> {
7070
In the previous example, our top-level `AppData` was `()` and our mutable state was stored in an [`Adapt`] widget. This time, we will store our counter in top-level `AppData`, in a custom type which includes a message handler:
7171
```rust
7272
# extern crate kas;
73-
# use kas::{messages::MessageStack, Action};
73+
# use kas::{runner::MessageStack, Action};
7474
# #[derive(Clone, Debug)]
7575
# struct Increment(i32);
7676

7777
#[derive(Clone, Copy, Debug)]
7878
struct Count(i32);
7979

80-
impl kas::app::AppData for Count {
81-
fn handle_messages(&mut self, messages: &mut MessageStack) -> Action {
80+
impl kas::runner::AppData for Count {
81+
fn handle_messages(&mut self, messages: &mut kas::runner::MessageStack) {
8282
if let Some(Increment(add)) = messages.try_pop() {
8383
self.0 += add;
84-
Action::UPDATE
85-
} else {
86-
Action::empty()
8784
}
8885
}
8986
}
9087
```
91-
[`AppData::handle_messages`] is more verbose than [`Adapt::on_message`], but does the same job. The method notifies when widgets must be updated by returning [`Action::UPDATE`].
88+
[`AppData::handle_messages`] is more verbose than [`Adapt::on_message`], but does the same job.
9289

9390
To integrate this into our example, we pass a `Count` object into [`kas::runner::Builder::build`] and adjust the prototype of `counter` to:
9491
```rust
9592
# extern crate kas;
96-
# use kas::{messages::MessageStack, Action};
93+
# use kas::{runner::MessageStack, Action};
9794
# #[derive(Clone, Copy, Debug)]
9895
# struct Count(i32);
99-
# impl kas::app::AppData for Count {
100-
# fn handle_messages(&mut self, messages: &mut MessageStack) -> Action { Action::empty() }
96+
# impl kas::runner::AppData for Count {
97+
# fn handle_messages(&mut self, messages: &mut kas::runner::MessageStack) {}
10198
# }
10299
fn counter() -> impl kas::Widget<Data = Count> {
103100
// ...
104-
# kas::widgets::label_any("")
101+
# kas::widgets::Label::new_any("")
105102
}
106103
```
107104

@@ -122,18 +119,19 @@ Note that our local data includes a *copy* of the top-level data `Count` (along
122119
We'll skip right over the widget declarations to the new [`Adapt`] node:
123120
```rust
124121
# extern crate kas;
125-
# use kas::widgets::{label_any, Adapt};
122+
# use kas::widgets::{Adapt, AdaptWidget, Label};
126123
# #[derive(Clone, Copy, Debug)]
127124
# struct Count(i32);
128125
# fn counter() -> impl kas::Widget<Data = Count> {
129126
# #[derive(Clone, Debug)]
130127
# struct SetValue(i32);
131-
# let ui = label_any("");
128+
# let ui = Label::new_any("");
132129
# let initial = (Count(0), 1);
133130
let ui = ui
134131
.with_state(initial)
135132
.on_update(|_, state, count| state.0 = *count)
136133
.on_message(|_, state, SetValue(v)| state.1 = v);
134+
# ui
137135
# }
138136
```
139137
The notable addition here is [`Adapt::on_update`], which takes a closure over the expected mutable reference to local `state` as well as *input* data `count` (i.e. the top-level data), allowing us to update local state with the latest top-level `count`.
@@ -147,16 +145,18 @@ Aside aside: could we not make [`Widget::Data`] into a Generic Associated Type (
147145
Constructing multiple windows under a UI runner is simple:
148146
```rust
149147
# extern crate kas;
150-
# use kas::{messages::MessageStack, Action, Window};
148+
# use kas::{runner::MessageStack, Action, window::Window};
151149
# #[derive(Clone, Copy, Debug)]
152150
# struct Count(i32);
153-
# impl kas::app::AppData for Count {
154-
# fn handle_messages(&mut self, messages: &mut MessageStack) -> Action { Action::empty() }
151+
# impl kas::runner::AppData for Count {
152+
# fn handle_messages(&mut self, messages: &mut kas::runner::MessageStack) {}
155153
# }
156-
# fn counter() -> impl kas::Widget<Data = Count> {
157-
# kas::widgets::label_any("")
154+
# fn counter(title: &str) -> Window<Count> {
155+
# Window::new(kas::widgets::Label::new_any(""), title)
158156
# }
159-
# fn main() -> kas::app::Result<()> {
157+
# fn main() -> kas::runner::Result<()> {
158+
# let count = Count(0);
159+
# let theme = kas_wgpu::ShadedTheme::new();
160160
let mut runner = kas::runner::Runner::with_theme(theme).build(count)?;
161161
let _ = runner.config_mut().font.set_size(24.0);
162162
runner

0 commit comments

Comments
 (0)