`WakeTaskQueue` becomes `TaskQueue`, which carries the update itself. Delivery and waking are then one act: the winit host sends it through the `EventLoopProxy` as a `DefaultEvent::Update`, so there is no channel beside the loop and nothing has to claim a redraw is needed in order to be looked at. `Window::request_redraw` is gone from this path; `event` applies the update and then asks the tree whether anything became dirty, which is the same question `window_event` already ended with -- now `schedule_redraw`, called from both. The loop's message type is `DefaultEvent<State>`, so `Proxy` becomes a wrapper that takes the application's own `Event` and requires it to be `Send`, since it now crosses to the task thread by that route. The harness supplies a channel-backed queue, which is what lets a test hold updates until it asks for them. Tests split by subject -- layout, pointer, scroll, tasks -- with the region helper in `tests/common`.
24 lines
620 B
Rust
24 lines
620 B
Rust
//! What a background task can change, and how it gets back to the ui.
|
|
|
|
use std::time::Duration;
|
|
|
|
use iris::harness::Harness;
|
|
use iris::prelude::*;
|
|
|
|
#[test]
|
|
fn a_task_update_reaches_the_tree() {
|
|
let mut h = Harness::new((400, 200));
|
|
let widget = rect(Color::RED).add(&mut h.rsc);
|
|
h.set_root(widget.task_on(CursorSense::click(), async move |mut ctx| {
|
|
ctx.update(move |_, rsc| widget(rsc).color = Color::BLUE);
|
|
}));
|
|
|
|
h.click((200, 100));
|
|
|
|
assert!(
|
|
h.await_update(Duration::from_secs(5)),
|
|
"the task sent no update"
|
|
);
|
|
assert_eq!(h.rsc[widget].color, Color::BLUE);
|
|
}
|