1use sui_animation::{Easing, Transition};
2use sui_core::{
3 Event, Point, Rect, SafeAreaInsets, SemanticsNode, SemanticsRole, Size, Vector, WakeEvent,
4};
5use sui_layout::{
6 Alignment, Axis, Constraints, GridItem, GridLayout, GridPlacement, GridStyle, GridTrack,
7 Padding, grid_layout,
8};
9use sui_runtime::{
10 ArrangeCtx, EventCtx, LayerOptions, MeasureCtx, PaintBoundaryMode, PaintCtx, SemanticsCtx,
11 SingleChild, Widget, WidgetChildren, WidgetPodMutVisitor, WidgetPodVisitor,
12};
13use sui_scene::{LayerCompositionMode, LayerProperties};
14
15#[derive(Debug, Clone, Copy, PartialEq)]
16pub struct GridCell {
17 pub placement: GridPlacement,
18 pub horizontal_alignment: Alignment,
19 pub vertical_alignment: Alignment,
20}
21
22impl GridCell {
23 pub const fn new(row: usize, column: usize) -> Self {
24 Self {
25 placement: GridPlacement::new(row, column),
26 horizontal_alignment: Alignment::Stretch,
27 vertical_alignment: Alignment::Stretch,
28 }
29 }
30
31 pub const fn span(mut self, rows: usize, columns: usize) -> Self {
32 self.placement = self.placement.span(rows, columns);
33 self
34 }
35
36 pub const fn align(mut self, horizontal: Alignment, vertical: Alignment) -> Self {
37 self.horizontal_alignment = horizontal;
38 self.vertical_alignment = vertical;
39 self
40 }
41}
42
43pub struct Grid {
46 style: GridStyle,
47 cells: Vec<GridCell>,
48 children: WidgetChildren,
49 layout: GridLayout,
50 name: Option<String>,
51}
52
53impl Grid {
54 pub fn new(columns: impl IntoIterator<Item = GridTrack>) -> Self {
55 Self {
56 style: GridStyle::new(columns),
57 cells: Vec::new(),
58 children: WidgetChildren::new(),
59 layout: grid_layout(&GridStyle::default(), &[], Constraints::default()),
60 name: None,
61 }
62 }
63
64 pub fn name(mut self, name: impl Into<String>) -> Self {
65 self.name = Some(name.into());
66 self
67 }
68
69 pub fn rows(mut self, rows: impl IntoIterator<Item = GridTrack>) -> Self {
70 self.style = self.style.rows(rows);
71 self
72 }
73
74 pub fn gap(mut self, gap: f32) -> Self {
75 self.style = self.style.gap(gap);
76 self
77 }
78
79 pub fn column_gap(mut self, gap: f32) -> Self {
80 self.style = self.style.column_gap(gap);
81 self
82 }
83
84 pub fn row_gap(mut self, gap: f32) -> Self {
85 self.style = self.style.row_gap(gap);
86 self
87 }
88
89 pub fn with_child<W>(mut self, child: W) -> Self
90 where
91 W: Widget + 'static,
92 {
93 let columns = self.style.columns.len().max(1);
94 let index = self.children.len();
95 self.children.push(child);
96 self.cells
97 .push(GridCell::new(index / columns, index % columns));
98 self
99 }
100
101 pub fn with_cell<W>(mut self, cell: GridCell, child: W) -> Self
102 where
103 W: Widget + 'static,
104 {
105 self.children.push(child);
106 self.cells.push(cell);
107 self
108 }
109
110 pub fn push<W>(&mut self, child: W)
111 where
112 W: Widget + 'static,
113 {
114 let columns = self.style.columns.len().max(1);
115 let index = self.children.len();
116 self.children.push(child);
117 self.cells
118 .push(GridCell::new(index / columns, index % columns));
119 }
120
121 pub fn push_cell<W>(&mut self, cell: GridCell, child: W)
122 where
123 W: Widget + 'static,
124 {
125 self.children.push(child);
126 self.cells.push(cell);
127 }
128
129 pub fn layout(&self) -> &GridLayout {
130 &self.layout
131 }
132
133 fn layout_items(&self, natural_sizes: &[Size], minimum_widths: &[f32]) -> Vec<GridItem> {
134 self.cells
135 .iter()
136 .zip(natural_sizes)
137 .zip(minimum_widths)
138 .map(|((cell, natural_size), minimum_width)| {
139 GridItem::new(cell.placement, *natural_size)
140 .minimum_size(Size::new(*minimum_width, natural_size.height))
141 .align(cell.horizontal_alignment, cell.vertical_alignment)
142 })
143 .collect()
144 }
145}
146
147impl Widget for Grid {
148 fn measure(&mut self, ctx: &mut MeasureCtx, constraints: Constraints) -> Size {
149 let mut natural_sizes = Vec::with_capacity(self.children.len());
150 let mut minimum_widths = Vec::with_capacity(self.children.len());
151 for child in self.children.as_mut_slice() {
152 let natural = child.measure(ctx, Constraints::UNBOUNDED);
153 let intrinsic = child.intrinsic_size(ctx, Axis::Horizontal, natural.height);
154 natural_sizes.push(natural);
155 minimum_widths.push(intrinsic.minimum);
156 }
157
158 let provisional = grid_layout(
159 &self.style,
160 &self.layout_items(&natural_sizes, &minimum_widths),
161 constraints,
162 );
163 for (index, child) in self.children.as_mut_slice().iter_mut().enumerate() {
164 let cell = provisional
165 .items
166 .get(index)
167 .map(|item| item.cell)
168 .unwrap_or(Rect::ZERO);
169 natural_sizes[index] = child.measure(
170 ctx,
171 Constraints::new(Size::ZERO, Size::new(cell.width(), f32::INFINITY)),
172 );
173 }
174 self.layout = grid_layout(
175 &self.style,
176 &self.layout_items(&natural_sizes, &minimum_widths),
177 constraints,
178 );
179 self.layout.size
180 }
181
182 fn arrange(&mut self, ctx: &mut ArrangeCtx, bounds: Rect) {
183 let translation = bounds.origin.to_vector();
184 for (index, item) in self.layout.items.iter().enumerate() {
185 self.children
186 .arrange_child(index, ctx, item.rect.translate(translation));
187 }
188 }
189
190 fn paint(&self, ctx: &mut PaintCtx) {
191 self.children.paint(ctx);
192 }
193
194 fn semantics(&self, ctx: &mut SemanticsCtx) {
195 if let Some(name) = &self.name {
196 let mut node = SemanticsNode::new(
197 ctx.widget_id(),
198 SemanticsRole::GenericContainer,
199 ctx.bounds(),
200 );
201 node.name = Some(name.clone());
202 ctx.push(node);
203 }
204 self.children.semantics(ctx);
205 }
206
207 fn visit_children(&self, visitor: &mut dyn WidgetPodVisitor) {
208 self.children.visit_children(visitor);
209 }
210
211 fn visit_children_mut(&mut self, visitor: &mut dyn WidgetPodMutVisitor) {
212 self.children.visit_children_mut(visitor);
213 }
214}
215
216#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
217pub enum AspectRatioFit {
218 #[default]
219 Contain,
220 Cover,
221}
222
223pub struct AspectRatio {
226 ratio: f32,
227 fit: AspectRatioFit,
228 alignment: (Alignment, Alignment),
229 child: SingleChild,
230}
231
232impl AspectRatio {
233 pub fn new<W>(ratio: f32, child: W) -> Self
234 where
235 W: Widget + 'static,
236 {
237 Self {
238 ratio: normalize_ratio(ratio),
239 fit: AspectRatioFit::Contain,
240 alignment: (Alignment::Center, Alignment::Center),
241 child: SingleChild::new(child),
242 }
243 }
244
245 pub fn fit(mut self, fit: AspectRatioFit) -> Self {
246 self.fit = fit;
247 self
248 }
249
250 pub fn align(mut self, horizontal: Alignment, vertical: Alignment) -> Self {
251 self.alignment = (horizontal, vertical);
252 self
253 }
254
255 pub fn ratio(mut self, ratio: f32) -> Self {
256 self.ratio = normalize_ratio(ratio);
257 self
258 }
259
260 fn child_rect(&self, bounds: Rect) -> Rect {
261 let size = aspect_size(bounds.size, self.ratio, self.fit);
262 let x = aligned_start(self.alignment.0, bounds.x(), bounds.width(), size.width);
263 let y = aligned_start(self.alignment.1, bounds.y(), bounds.height(), size.height);
264 Rect::new(x, y, size.width, size.height)
265 }
266}
267
268impl Widget for AspectRatio {
269 fn measure(&mut self, ctx: &mut MeasureCtx, constraints: Constraints) -> Size {
270 let natural = self.child.measure(ctx, constraints.loosen());
271 let desired = if natural.width > 0.0 || natural.height > 0.0 {
272 aspect_size(natural, self.ratio, AspectRatioFit::Contain)
273 } else {
274 Size::ZERO
275 };
276 constraints.clamp(desired)
277 }
278
279 fn arrange(&mut self, ctx: &mut ArrangeCtx, bounds: Rect) {
280 self.child.arrange(ctx, self.child_rect(bounds));
281 }
282
283 fn paint(&self, ctx: &mut PaintCtx) {
284 if self.fit == AspectRatioFit::Cover {
285 ctx.push_clip_rect(ctx.bounds());
286 self.child.paint(ctx);
287 ctx.pop_clip();
288 } else {
289 self.child.paint(ctx);
290 }
291 }
292
293 fn semantics(&self, ctx: &mut SemanticsCtx) {
294 self.child.semantics(ctx);
295 }
296
297 fn visit_children(&self, visitor: &mut dyn WidgetPodVisitor) {
298 self.child.visit_children(visitor);
299 }
300
301 fn visit_children_mut(&mut self, visitor: &mut dyn WidgetPodMutVisitor) {
302 self.child.visit_children_mut(visitor);
303 }
304}
305
306fn normalize_ratio(ratio: f32) -> f32 {
307 if ratio.is_finite() {
308 ratio.max(0.01)
309 } else {
310 1.0
311 }
312}
313
314fn aspect_size(available: Size, ratio: f32, fit: AspectRatioFit) -> Size {
315 let width = available.width.max(0.0);
316 let height = available.height.max(0.0);
317 if width == 0.0 || height == 0.0 {
318 return if width > 0.0 {
319 Size::new(width, width / ratio)
320 } else if height > 0.0 {
321 Size::new(height * ratio, height)
322 } else {
323 Size::ZERO
324 };
325 }
326 let available_ratio = width / height;
327 let use_width = match fit {
328 AspectRatioFit::Contain => available_ratio <= ratio,
329 AspectRatioFit::Cover => available_ratio >= ratio,
330 };
331 if use_width {
332 Size::new(width, width / ratio)
333 } else {
334 Size::new(height * ratio, height)
335 }
336}
337
338#[derive(Debug, Clone, Copy, PartialEq, Eq)]
340pub struct SafeAreaEdges(u8);
341
342impl SafeAreaEdges {
343 pub const NONE: Self = Self(0);
344 pub const LEFT: Self = Self(1 << 0);
345 pub const TOP: Self = Self(1 << 1);
346 pub const RIGHT: Self = Self(1 << 2);
347 pub const BOTTOM: Self = Self(1 << 3);
348 pub const HORIZONTAL: Self = Self(Self::LEFT.0 | Self::RIGHT.0);
349 pub const VERTICAL: Self = Self(Self::TOP.0 | Self::BOTTOM.0);
350 pub const ALL: Self = Self(Self::HORIZONTAL.0 | Self::VERTICAL.0);
351
352 pub const fn union(self, other: Self) -> Self {
353 Self(self.0 | other.0)
354 }
355
356 pub const fn contains(self, edge: Self) -> bool {
357 self.0 & edge.0 == edge.0
358 }
359}
360
361impl Default for SafeAreaEdges {
362 fn default() -> Self {
363 Self::ALL
364 }
365}
366
367pub struct SafeArea {
372 edges: SafeAreaEdges,
373 minimum: SafeAreaInsets,
374 child: SingleChild,
375}
376
377impl SafeArea {
378 pub fn new<W>(child: W) -> Self
379 where
380 W: Widget + 'static,
381 {
382 Self {
383 edges: SafeAreaEdges::ALL,
384 minimum: SafeAreaInsets::ZERO,
385 child: SingleChild::new(child),
386 }
387 }
388
389 pub fn edges(mut self, edges: SafeAreaEdges) -> Self {
390 self.edges = edges;
391 self
392 }
393
394 pub fn minimum(mut self, minimum: SafeAreaInsets) -> Self {
397 self.minimum = minimum.normalized();
398 self
399 }
400
401 fn resolved_insets(&self, platform: SafeAreaInsets) -> Padding {
402 let platform = platform.normalized();
403 Padding {
404 left: if self.edges.contains(SafeAreaEdges::LEFT) {
405 platform.left.max(self.minimum.left)
406 } else {
407 0.0
408 },
409 top: if self.edges.contains(SafeAreaEdges::TOP) {
410 platform.top.max(self.minimum.top)
411 } else {
412 0.0
413 },
414 right: if self.edges.contains(SafeAreaEdges::RIGHT) {
415 platform.right.max(self.minimum.right)
416 } else {
417 0.0
418 },
419 bottom: if self.edges.contains(SafeAreaEdges::BOTTOM) {
420 platform.bottom.max(self.minimum.bottom)
421 } else {
422 0.0
423 },
424 }
425 }
426}
427
428impl Widget for SafeArea {
429 fn measure(&mut self, ctx: &mut MeasureCtx, constraints: Constraints) -> Size {
430 let insets = self.resolved_insets(ctx.dpi().safe_area);
431 let child_size = self.child.measure(
432 ctx,
433 Constraints::new(insets.inset(constraints.min), insets.inset(constraints.max)),
434 );
435 constraints.clamp(Size::new(
436 child_size.width + insets.left + insets.right,
437 child_size.height + insets.top + insets.bottom,
438 ))
439 }
440
441 fn arrange(&mut self, ctx: &mut ArrangeCtx, bounds: Rect) {
442 let insets = self.resolved_insets(ctx.dpi().safe_area);
443 self.child.arrange(
444 ctx,
445 Rect::from_origin_size(
446 bounds.origin + insets.offset().to_vector(),
447 insets.inset(bounds.size),
448 ),
449 );
450 }
451
452 fn paint(&self, ctx: &mut PaintCtx) {
453 self.child.paint(ctx);
454 }
455
456 fn semantics(&self, ctx: &mut SemanticsCtx) {
457 self.child.semantics(ctx);
458 }
459
460 fn visit_children(&self, visitor: &mut dyn WidgetPodVisitor) {
461 self.child.visit_children(visitor);
462 }
463
464 fn visit_children_mut(&mut self, visitor: &mut dyn WidgetPodMutVisitor) {
465 self.child.visit_children_mut(visitor);
466 }
467}
468
469pub struct LayoutTransition {
475 child: SingleChild,
476 duration: f64,
477 easing: Easing,
478 destination: Option<Point>,
479 translation: Vector,
480 transition: Option<Transition<Vector>>,
481}
482
483impl LayoutTransition {
484 pub fn new<W>(child: W) -> Self
485 where
486 W: Widget + 'static,
487 {
488 Self {
489 child: SingleChild::new(child),
490 duration: 0.18,
491 easing: Easing::EaseOut,
492 destination: None,
493 translation: Vector::ZERO,
494 transition: None,
495 }
496 }
497
498 pub fn duration(mut self, duration: f64) -> Self {
499 self.duration = duration.max(0.0);
500 self
501 }
502
503 pub fn easing(mut self, easing: Easing) -> Self {
504 self.easing = easing;
505 self
506 }
507
508 fn sample(&self, time: f64) -> Vector {
509 self.transition
510 .map(|transition| transition.sample(time))
511 .unwrap_or(self.translation)
512 }
513}
514
515impl Widget for LayoutTransition {
516 fn event(&mut self, ctx: &mut EventCtx, event: &Event) {
517 let Event::Wake(WakeEvent::AnimationFrame { time, .. }) = event else {
518 return;
519 };
520 let Some(transition) = self.transition else {
521 return;
522 };
523
524 self.translation = transition.sample(*time);
525 if transition.is_complete(*time) {
526 self.translation = Vector::ZERO;
527 self.transition = None;
528 } else {
529 ctx.request_animation_frame();
530 }
531 ctx.request_transform();
532 ctx.set_handled();
533 }
534
535 fn measure(&mut self, ctx: &mut MeasureCtx, constraints: Constraints) -> Size {
536 self.child.measure(ctx, constraints)
537 }
538
539 fn arrange(&mut self, ctx: &mut ArrangeCtx, bounds: Rect) {
540 if let Some(previous_destination) = self.destination
541 && previous_destination != bounds.origin
542 {
543 let visual_origin = previous_destination + self.sample(ctx.current_time());
544 self.translation = visual_origin - bounds.origin;
545 if self.duration <= f64::EPSILON || self.translation == Vector::ZERO {
546 self.translation = Vector::ZERO;
547 self.transition = None;
548 } else {
549 self.transition = Some(Transition::new(
550 self.translation,
551 Vector::ZERO,
552 ctx.current_time(),
553 self.duration,
554 self.easing,
555 ));
556 ctx.request_animation_frame();
557 ctx.request_transform();
558 }
559 }
560 self.destination = Some(bounds.origin);
561 self.child.arrange(ctx, bounds);
562 }
563
564 fn paint(&self, ctx: &mut PaintCtx) {
565 self.child.paint(ctx);
566 }
567
568 fn layer_options(&self) -> LayerOptions {
569 LayerOptions {
570 paint_boundary: PaintBoundaryMode::Explicit,
571 composition_mode: LayerCompositionMode::Normal,
572 }
573 }
574
575 fn layer_properties(&self) -> LayerProperties {
576 LayerProperties::default().with_translation(self.translation)
577 }
578
579 fn semantics(&self, ctx: &mut SemanticsCtx) {
580 self.child.semantics(ctx);
581 }
582
583 fn visit_children(&self, visitor: &mut dyn WidgetPodVisitor) {
584 self.child.visit_children(visitor);
585 }
586
587 fn visit_children_mut(&mut self, visitor: &mut dyn WidgetPodMutVisitor) {
588 self.child.visit_children_mut(visitor);
589 }
590}
591
592fn aligned_start(alignment: Alignment, start: f32, available: f32, child: f32) -> f32 {
593 match alignment {
594 Alignment::Start | Alignment::Stretch => start,
595 Alignment::Center => start + (available - child) * 0.5,
596 Alignment::End => start + available - child,
597 }
598}
599
600#[cfg(test)]
601mod tests {
602 use super::*;
603 use sui_core::{Color, DpiInfo, WindowEvent, WindowId};
604 use sui_reactive::Signal;
605 use sui_runtime::{Application, WidgetPod, WindowBuilder};
606
607 struct Fixed(Size);
608
609 impl Widget for Fixed {
610 fn measure(&mut self, _ctx: &mut MeasureCtx, constraints: Constraints) -> Size {
611 constraints.clamp(self.0)
612 }
613
614 fn paint(&self, ctx: &mut PaintCtx) {
615 ctx.fill_bounds(Color::WHITE);
616 }
617
618 fn intrinsic_size(
619 &mut self,
620 _ctx: &mut MeasureCtx,
621 axis: Axis,
622 _available_cross: f32,
623 ) -> sui_layout::IntrinsicSize {
624 let natural = match axis {
625 Axis::Horizontal => self.0.width,
626 Axis::Vertical => self.0.height,
627 };
628 sui_layout::IntrinsicSize::new(0.0, natural)
629 }
630 }
631
632 #[test]
633 fn grid_wraps_children_against_resolved_fraction_tracks() {
634 let root = Grid::new([GridTrack::Fixed(80.0), GridTrack::Fraction(1.0)])
635 .gap(8.0)
636 .with_child(Fixed(Size::new(80.0, 20.0)))
637 .with_child(Fixed(Size::new(220.0, 30.0)));
638 let mut runtime = Application::new()
639 .window(WindowBuilder::new().root(root))
640 .build()
641 .unwrap();
642 let window = runtime.window_ids()[0];
643 runtime
644 .handle_event(
645 window,
646 sui_core::Event::Window(sui_core::WindowEvent::Resized(Size::new(240.0, 80.0))),
647 )
648 .unwrap();
649 let output = runtime.render(window).unwrap();
650 let graph = runtime.widget_graph(window).unwrap();
651 assert_eq!(output.frame.viewport, Size::new(240.0, 80.0));
652 assert_eq!(graph.nodes[1].bounds.width(), 80.0);
653 assert_eq!(graph.nodes[2].bounds.x(), 88.0);
654 assert_eq!(graph.nodes[2].bounds.width(), 152.0);
655 }
656
657 #[test]
658 fn aspect_ratio_contains_child_inside_tight_bounds() {
659 let mut pod = WidgetPod::new(AspectRatio::new(16.0 / 9.0, Fixed(Size::new(10.0, 10.0))));
660 let mut measure = sui_runtime::MeasureCtx::with_layout(
661 WindowId::new(1),
662 pod.id(),
663 Rect::ZERO,
664 sui_layout::LayoutContext::new(
665 DpiInfo::default(),
666 std::sync::Arc::new(sui_text::TextSystem::new()),
667 std::sync::Arc::new(sui_text::FontRegistry::new()),
668 std::sync::Arc::new(sui_scene::ImageRegistry::new()),
669 ),
670 );
671 assert_eq!(
672 pod.measure(&mut measure, Constraints::tight(Size::new(160.0, 120.0))),
673 Size::new(160.0, 120.0)
674 );
675 }
676
677 #[test]
678 fn safe_area_tracks_window_insets_and_selected_edges() {
679 let root = SafeArea::new(Fixed(Size::new(20.0, 20.0)))
680 .edges(SafeAreaEdges::LEFT.union(SafeAreaEdges::TOP));
681 let mut runtime = Application::new()
682 .window(WindowBuilder::new().root(root))
683 .build()
684 .unwrap();
685 let window = runtime.window_ids()[0];
686 runtime
687 .handle_event(
688 window,
689 Event::Window(WindowEvent::SafeAreaChanged(SafeAreaInsets::new(
690 10.0, 12.0, 14.0, 16.0,
691 ))),
692 )
693 .unwrap();
694 runtime
695 .handle_event(
696 window,
697 Event::Window(WindowEvent::Resized(Size::new(100.0, 80.0))),
698 )
699 .unwrap();
700 runtime.render(window).unwrap();
701
702 let graph = runtime.widget_graph(window).unwrap();
703 assert_eq!(graph.nodes[1].bounds, Rect::new(10.0, 12.0, 90.0, 68.0));
704 }
705
706 struct MovingHost {
707 moved: Signal<bool>,
708 child: SingleChild,
709 }
710
711 impl Widget for MovingHost {
712 fn measure(&mut self, ctx: &mut MeasureCtx, constraints: Constraints) -> Size {
713 let _ = self
714 .child
715 .measure(ctx, Constraints::tight(Size::new(20.0, 20.0)));
716 constraints.clamp(Size::new(100.0, 20.0))
717 }
718
719 fn arrange(&mut self, ctx: &mut ArrangeCtx, bounds: Rect) {
720 let x = if ctx.observe(&self.moved) { 60.0 } else { 0.0 };
721 self.child
722 .arrange(ctx, Rect::new(bounds.x() + x, bounds.y(), 20.0, 20.0));
723 }
724
725 fn paint(&self, ctx: &mut PaintCtx) {
726 self.child.paint(ctx);
727 }
728
729 fn visit_children(&self, visitor: &mut dyn WidgetPodVisitor) {
730 self.child.visit_children(visitor);
731 }
732
733 fn visit_children_mut(&mut self, visitor: &mut dyn WidgetPodMutVisitor) {
734 self.child.visit_children_mut(visitor);
735 }
736 }
737
738 #[test]
739 fn layout_transition_schedules_compositor_animation_after_rearrange() {
740 let moved = Signal::new(false);
741 let root = MovingHost {
742 moved: moved.clone(),
743 child: SingleChild::new(LayoutTransition::new(Fixed(Size::new(20.0, 20.0)))),
744 };
745 let mut runtime = Application::new()
746 .window(WindowBuilder::new().root(root))
747 .build()
748 .unwrap();
749 let window = runtime.window_ids()[0];
750 runtime
751 .handle_event(
752 window,
753 Event::Window(WindowEvent::Resized(Size::new(100.0, 20.0))),
754 )
755 .unwrap();
756 runtime.render(window).unwrap();
757
758 moved.set(true);
759 runtime.render(window).unwrap();
760 let graph = runtime.widget_graph(window).unwrap();
761 assert_eq!(graph.nodes[1].bounds.x(), 60.0);
762 assert_eq!(runtime.next_wakeup_time(window).unwrap(), Some(0.0));
763
764 runtime.tick(0.2);
765 for (ready_window, event) in runtime.drain_ready_events() {
766 runtime.handle_event(ready_window, event).unwrap();
767 }
768 runtime.render(window).unwrap();
769 assert_eq!(runtime.next_wakeup_time(window).unwrap(), None);
770 }
771}