1#![forbid(unsafe_code)]
13
14use std::cell::{Cell, RefCell};
15use std::collections::BTreeMap;
16use std::rc::Rc;
17
18use mgui_core::frame::{run_frame, FrameHost};
19use mgui_core::{
20 ElementId, FramePaint, KeyCode, KeyModifiers, Point, PointerData, Rect, SemanticsData, Size, WidgetEvent,
21};
22use mgui_core::{ElementTree, WidgetNode};
23use mgui_shell::{Clock, ImeEvent, ManualClock, ShellEvent, ShellMetrics, ShellWindowId, WindowShell};
24use mgui_software::{RgbaImage, SoftwareRenderer};
25
26pub struct HeadlessShell {
28 tree: ElementTree,
29 renderer: Rc<RefCell<SoftwareRenderer>>,
30 clock: Rc<ManualClock>,
31 metrics: ShellMetrics,
32 frame: Option<FramePaint>,
33 image: Option<RgbaImage>,
34 title: RefCell<String>,
35 ime_allowed: Cell<bool>,
36 ime_cursor_area: Cell<Option<Rect>>,
37}
38
39impl HeadlessShell {
40 pub fn new(width: f32, height: f32) -> Self {
41 Self::with_metrics(ShellMetrics::new(Size::new(width, height), 1.0))
42 }
43
44 pub fn with_metrics(metrics: ShellMetrics) -> Self {
45 Self::with_shared(metrics, Rc::new(ManualClock::new(0)), Rc::new(RefCell::new(SoftwareRenderer::new())))
46 }
47
48 pub(crate) fn with_shared(
50 metrics: ShellMetrics,
51 clock: Rc<ManualClock>,
52 renderer: Rc<RefCell<SoftwareRenderer>>,
53 ) -> Self {
54 let mut tree = ElementTree::new();
55 tree.set_text_measurer(Some(|text, size_px, max_width| {
56 use mgui_text::text::{measure_text_width, text_visual_height};
57 (measure_text_width(text, size_px), text_visual_height(text, size_px, max_width))
58 }));
59 tree.set_viewport_size(metrics.logical_size);
60
61 Self {
62 tree,
63 renderer,
64 clock,
65 metrics,
66 frame: None,
67 image: None,
68 title: RefCell::new(String::new()),
69 ime_allowed: Cell::new(false),
70 ime_cursor_area: Cell::new(None),
71 }
72 }
73
74 pub fn metrics(&self) -> ShellMetrics {
75 self.metrics
76 }
77
78 pub fn now_ms(&self) -> u64 {
79 self.clock.now_ms()
80 }
81
82 pub fn advance(&self, delta_ms: u64) -> u64 {
84 self.clock.advance(delta_ms)
85 }
86
87 pub fn set_time(&self, now_ms: u64) {
88 self.clock.set(now_ms);
89 }
90
91 pub fn resize(&mut self, logical_size: Size, scale_factor: f32) {
92 self.metrics = ShellMetrics::new(logical_size, scale_factor);
93 self.tree.set_viewport_size(self.metrics.logical_size);
94 self.tree.mark_all_layers_dirty();
95 }
96
97 pub fn mount(&mut self, root: WidgetNode) {
98 self.tree.set_viewport_size(self.metrics.logical_size);
99 self.tree.mount(root);
100 }
101
102 pub fn update(&mut self, root: WidgetNode) {
103 self.tree.set_viewport_size(self.metrics.logical_size);
104 self.tree.update(root);
105 }
106
107 pub fn dispatch_event(&mut self, event: &WidgetEvent) {
109 let pos = event_position(event).unwrap_or(Point::ZERO);
110 self.tree.dispatch_event(event, pos);
111 }
112
113 pub fn dispatch_event_at(&mut self, event: &WidgetEvent, position: Point) {
115 self.tree.dispatch_event(event, position);
116 }
117
118 pub fn click(&mut self, position: Point) {
119 self.dispatch_event(&WidgetEvent::PointerDown(PointerData::at(position)));
120 self.dispatch_event(&WidgetEvent::PointerUp(PointerData::at(position)));
121 }
122
123 pub fn key_down(&mut self, key: KeyCode) {
124 self.tree.dispatch_key_event(&WidgetEvent::KeyDown(key, KeyModifiers::none()));
125 }
126
127 pub fn key_down_with(&mut self, key: KeyCode, mods: KeyModifiers) {
128 self.tree.dispatch_key_event(&WidgetEvent::KeyDown(key, mods));
129 }
130
131 pub fn key_up(&mut self, key: KeyCode) {
132 self.tree.dispatch_key_event(&WidgetEvent::KeyUp(key, KeyModifiers::none()));
133 }
134
135 pub fn type_text(&mut self, text: &str) {
136 for ch in text.chars() {
137 self.key_down(KeyCode::Char(ch));
138 self.key_up(KeyCode::Char(ch));
139 }
140 }
141
142 pub fn ime_commit(&mut self, text: impl Into<String>) {
143 self.dispatch_event(&WidgetEvent::ImeCommit(text.into()));
144 }
145
146 pub fn dispatch_shell_event(&mut self, event: &ShellEvent) {
148 let now = self.now_ms();
149 match event {
150 ShellEvent::CursorMoved { position } => {
151 self.dispatch_event(&WidgetEvent::PointerMove(PointerData::new(*position, now)));
152 }
153 ShellEvent::MouseInput { position, button, pressed, modifiers } => {
154 let data = PointerData::with_button(*position, now, *button).with_modifiers(*modifiers);
155 let event = if *pressed { WidgetEvent::PointerDown(data) } else { WidgetEvent::PointerUp(data) };
156 self.dispatch_event(&event);
157 }
158 ShellEvent::Wheel { position, delta, .. } => {
159 self.dispatch_event_at(&WidgetEvent::Scroll(delta.x, delta.y), *position);
160 }
161 ShellEvent::ModifiersChanged(_) => {}
162 ShellEvent::Keyboard { key, pressed, modifiers, .. } => {
163 let event = if *pressed {
164 WidgetEvent::KeyDown(*key, *modifiers)
165 } else {
166 WidgetEvent::KeyUp(*key, *modifiers)
167 };
168 self.tree.dispatch_key_event(&event);
169 }
170 ShellEvent::CursorLeft => self.tree.pointer_leave_window(),
171 ShellEvent::Focused(false) => {
172 self.tree.pointer_leave_window();
173 self.tree.clear_focus();
174 }
175 ShellEvent::Focused(true) => {}
176 ShellEvent::FileHovered(_)
177 | ShellEvent::FileHoverCancelled
178 | ShellEvent::FileDropped(_)
179 | ShellEvent::ThemeChanged(_) => {}
180 ShellEvent::Ime(ime) => {
181 let event = match ime {
182 ImeEvent::Enabled => WidgetEvent::ImeEnabled,
183 ImeEvent::Disabled => WidgetEvent::ImeDisabled,
184 ImeEvent::Preedit(text, cursor) => WidgetEvent::ImePreedit(text.clone(), *cursor),
185 ImeEvent::Commit(text) => WidgetEvent::ImeCommit(text.clone()),
186 };
187 self.tree.dispatch_key_event(&event);
188 }
189 }
190 }
191
192 pub fn frame(&mut self) -> &RgbaImage {
194 let now = self.clock.now_ms();
195 let viewport = self.metrics.logical_size;
196 let (frame, _stats) = run_frame(self, viewport, now, true);
197 let mut image = self.image.take().unwrap_or(RgbaImage { width: 0, height: 0, data: Vec::new() });
199 self.renderer.borrow_mut().render_into(
200 &frame,
201 self.metrics.logical_size,
202 self.metrics.scale_factor,
203 &mut image,
204 );
205 self.frame = Some(frame);
206 self.image = Some(image);
207 self.image.as_ref().expect("image set above")
208 }
209
210 pub fn frame_paint(&self) -> Option<&FramePaint> {
212 self.frame.as_ref()
213 }
214
215 pub fn image(&self) -> Option<&RgbaImage> {
216 self.image.as_ref()
217 }
218
219 pub fn pixel(&self, x: u32, y: u32) -> Option<[u8; 4]> {
220 self.image.as_ref()?.try_pixel(x, y)
221 }
222
223 pub fn tree(&self) -> &ElementTree {
224 &self.tree
225 }
226
227 pub fn tree_mut(&mut self) -> &mut ElementTree {
228 &mut self.tree
229 }
230
231 pub fn overlay_count(&self) -> usize {
232 self.tree.overlay_count()
233 }
234
235 pub fn element_bounds(&self, id: ElementId) -> Option<mgui_core::Rect> {
236 self.tree.element_bounds(id)
237 }
238
239 pub fn a11y_snapshot(&self) -> Vec<(ElementId, SemanticsData)> {
241 self.tree.build_accessibility_tree()
242 }
243
244 pub fn title(&self) -> String {
245 self.title.borrow().clone()
246 }
247
248 pub fn ime_allowed(&self) -> bool {
249 self.ime_allowed.get()
250 }
251
252 pub fn ime_cursor_area(&self) -> Option<Rect> {
253 self.ime_cursor_area.get()
254 }
255}
256
257impl FrameHost for HeadlessShell {
258 fn tree_mut(&mut self) -> &mut ElementTree {
259 &mut self.tree
260 }
261}
262
263impl WindowShell for HeadlessShell {
264 fn metrics(&self) -> ShellMetrics {
265 self.metrics
266 }
267
268 fn request_redraw(&self) {}
269
270 fn set_title(&self, title: &str) {
271 *self.title.borrow_mut() = title.to_string();
272 }
273
274 fn set_visible(&self, _visible: bool) {}
275
276 fn set_ime_allowed(&self, allowed: bool) {
277 self.ime_allowed.set(allowed);
278 }
279
280 fn set_ime_cursor_area(&self, rect: Rect) {
281 self.ime_cursor_area.set(Some(rect));
282 }
283}
284
285fn event_position(event: &WidgetEvent) -> Option<Point> {
286 match event {
287 WidgetEvent::PointerDown(data) | WidgetEvent::PointerUp(data) | WidgetEvent::PointerMove(data) => {
288 Some(data.position)
289 }
290 _ => None,
291 }
292}
293
294pub struct HeadlessHost {
299 clock: Rc<ManualClock>,
300 renderer: Rc<RefCell<SoftwareRenderer>>,
301 windows: BTreeMap<ShellWindowId, HeadlessShell>,
302 next_id: u64,
303 focused: Option<ShellWindowId>,
304}
305
306impl Default for HeadlessHost {
307 fn default() -> Self {
308 Self::new()
309 }
310}
311
312impl HeadlessHost {
313 pub fn new() -> Self {
314 Self {
315 clock: Rc::new(ManualClock::new(0)),
316 renderer: Rc::new(RefCell::new(SoftwareRenderer::new())),
317 windows: BTreeMap::new(),
318 next_id: 0,
319 focused: None,
320 }
321 }
322
323 pub fn create_window(&mut self, metrics: ShellMetrics) -> ShellWindowId {
324 let id = ShellWindowId(self.next_id);
325 self.next_id += 1;
326 let shell = HeadlessShell::with_shared(metrics, Rc::clone(&self.clock), Rc::clone(&self.renderer));
327 self.windows.insert(id, shell);
328 if self.focused.is_none() {
329 self.focused = Some(id);
330 }
331 id
332 }
333
334 pub fn close_window(&mut self, id: ShellWindowId) -> bool {
336 let removed = self.windows.remove(&id).is_some();
337 if removed && self.focused == Some(id) {
338 self.focused = self.windows.keys().next().copied();
339 if let Some(next) = self.focused {
340 if let Some(shell) = self.windows.get_mut(&next) {
341 shell.dispatch_shell_event(&ShellEvent::Focused(true));
342 }
343 }
344 }
345 removed
346 }
347
348 pub fn window(&self, id: ShellWindowId) -> Option<&HeadlessShell> {
349 self.windows.get(&id)
350 }
351
352 pub fn window_mut(&mut self, id: ShellWindowId) -> Option<&mut HeadlessShell> {
353 self.windows.get_mut(&id)
354 }
355
356 pub fn ids(&self) -> impl Iterator<Item = ShellWindowId> + '_ {
357 self.windows.keys().copied()
358 }
359
360 pub fn window_count(&self) -> usize {
361 self.windows.len()
362 }
363
364 pub fn focused(&self) -> Option<ShellWindowId> {
365 self.focused
366 }
367
368 pub fn set_focused(&mut self, id: ShellWindowId) -> bool {
369 if !self.windows.contains_key(&id) {
370 return false;
371 }
372 if self.focused == Some(id) {
373 return true;
374 }
375 if let Some(previous) = self.focused.take() {
376 if let Some(shell) = self.windows.get_mut(&previous) {
377 shell.dispatch_shell_event(&ShellEvent::Focused(false));
378 }
379 }
380 self.focused = Some(id);
381 if let Some(shell) = self.windows.get_mut(&id) {
382 shell.dispatch_shell_event(&ShellEvent::Focused(true));
383 }
384 true
385 }
386
387 pub fn now_ms(&self) -> u64 {
388 self.clock.now_ms()
389 }
390
391 pub fn advance(&self, delta_ms: u64) -> u64 {
392 self.clock.advance(delta_ms)
393 }
394
395 pub fn set_time(&self, now_ms: u64) {
396 self.clock.set(now_ms);
397 }
398
399 pub fn frame_all(&mut self) -> usize {
401 for shell in self.windows.values_mut() {
402 shell.frame();
403 }
404 self.windows.len()
405 }
406}
407
408#[cfg(test)]
409mod tests {
410 use super::*;
411 use std::cell::Cell;
412 use std::rc::Rc;
413
414 use mgui_components::{ButtonWidget, DropdownOption, DropdownWidget, TextFieldWidget};
415 use mgui_core::{Color, Point, RRectWidget, SemanticsRole, Signal, Size, StackWidget};
416
417 #[test]
418 fn renders_rrect_to_rgba() {
419 let mut shell = HeadlessShell::new(200.0, 100.0);
420 shell.mount(WidgetNode::new(
421 StackWidget::new()
422 .push(Point::ZERO, RRectWidget::new(Size::new(200.0, 100.0), Color::from_rgb8(255, 0, 0), 0.0)),
423 ));
424 let image = shell.frame();
425 assert_eq!((image.width, image.height), (200, 100));
426 assert_eq!(shell.pixel(100, 50), Some([255, 0, 0, 255]));
427 }
428
429 #[test]
430 fn frame_reuses_output_buffer_and_resizes() {
431 let mut shell = HeadlessShell::new(200.0, 100.0);
432 shell.mount(WidgetNode::new(
433 StackWidget::new()
434 .push(Point::ZERO, RRectWidget::new(Size::new(200.0, 100.0), Color::from_rgb8(255, 0, 0), 0.0)),
435 ));
436 assert_eq!(shell.frame().pixel(100, 50), [255, 0, 0, 255]);
437
438 shell.update(WidgetNode::new(
440 StackWidget::new()
441 .push(Point::ZERO, RRectWidget::new(Size::new(200.0, 100.0), Color::from_rgb8(0, 0, 255), 0.0)),
442 ));
443 assert_eq!(shell.frame().pixel(100, 50), [0, 0, 255, 255]);
444
445 shell.resize(Size::new(120.0, 80.0), 1.0);
447 let image = shell.frame();
448 assert_eq!((image.width, image.height), (120, 80));
449 assert_eq!(shell.pixel(60, 40), Some([0, 0, 255, 255]));
450 }
451
452 #[test]
453 fn click_button_triggers_callback_and_exposes_semantics() {
454 let clicks = Rc::new(Cell::new(0));
455 let cb = Rc::clone(&clicks);
456 let button = ButtonWidget::new(Size::new(120.0, 40.0)).with_text("Run", 14.0).on_press(move || {
457 cb.set(cb.get() + 1);
458 });
459
460 let mut shell = HeadlessShell::new(200.0, 100.0);
461 shell.mount(WidgetNode::new(button));
462 shell.click(Point::new(60.0, 20.0));
463 shell.frame();
464
465 assert_eq!(clicks.get(), 1, "PointerDown/Up 应触发 Button on_press");
466 let snapshot = shell.a11y_snapshot();
467 assert!(snapshot.iter().any(|(_, data)| data.role == SemanticsRole::Button), "语义快照应包含 Button 节点");
468 }
469
470 #[test]
471 fn clock_is_manual_and_frame_uses_it() {
472 let mut shell = HeadlessShell::new(100.0, 100.0);
473 assert_eq!(shell.now_ms(), 0);
474 assert_eq!(shell.advance(16), 16);
475 shell.set_time(500);
476 assert_eq!(shell.now_ms(), 500);
477 shell.mount(WidgetNode::new(RRectWidget::new(Size::new(100.0, 100.0), Color::WHITE, 0.0)));
478 shell.frame();
479 assert_eq!(shell.pixel(50, 50), Some([255, 255, 255, 255]));
480 }
481
482 #[test]
483 fn shell_event_pipeline_clicks_button() {
484 let clicks = Rc::new(Cell::new(0));
485 let cb = Rc::clone(&clicks);
486 let button = ButtonWidget::new(Size::new(120.0, 40.0)).with_text("Run", 14.0).on_press(move || {
487 cb.set(cb.get() + 1);
488 });
489 let mut shell = HeadlessShell::new(200.0, 100.0);
490 shell.mount(WidgetNode::new(button));
491 shell.dispatch_shell_event(&ShellEvent::CursorMoved { position: Point::new(60.0, 20.0) });
492 for pressed in [true, false] {
493 shell.dispatch_shell_event(&ShellEvent::MouseInput {
494 position: Point::new(60.0, 20.0),
495 button: mgui_core::MouseButton::Left,
496 pressed,
497 modifiers: KeyModifiers::none(),
498 });
499 }
500 shell.frame();
501 assert_eq!(clicks.get(), 1);
502 }
503
504 #[test]
505 fn multi_window_renders_independently_with_shared_clock() {
506 let mut host = HeadlessHost::new();
507 let a = host.create_window(ShellMetrics::new(Size::new(80.0, 60.0), 1.0));
508 let b = host.create_window(ShellMetrics::new(Size::new(80.0, 60.0), 1.0));
509 host.window_mut(a).unwrap().mount(WidgetNode::new(RRectWidget::new(
510 Size::new(80.0, 60.0),
511 Color::from_rgb8(255, 0, 0),
512 0.0,
513 )));
514 host.window_mut(b).unwrap().mount(WidgetNode::new(RRectWidget::new(
515 Size::new(80.0, 60.0),
516 Color::from_rgb8(0, 0, 255),
517 0.0,
518 )));
519
520 assert_eq!(host.frame_all(), 2);
521 assert_eq!(host.window(a).unwrap().pixel(10, 10), Some([255, 0, 0, 255]));
522 assert_eq!(host.window(b).unwrap().pixel(10, 10), Some([0, 0, 255, 255]));
523
524 assert_eq!(host.advance(16), 16);
525 assert_eq!(host.window(a).unwrap().now_ms(), 16, "共享时钟");
526 assert_eq!(host.window(b).unwrap().now_ms(), 16, "共享时钟");
527 assert_eq!(host.focused(), Some(a), "首个窗口自动获得焦点");
528 }
529
530 #[test]
531 fn cross_window_focus_and_ime_are_isolated() {
532 let text_a = Signal::new(String::new());
533 let text_b = Signal::new(String::new());
534 let ta = text_a.clone();
535 let tb = text_b.clone();
536 let field_a = TextFieldWidget::new(200.0, 34.0).on_change(move |v| ta.set(v.to_string()));
537 let field_b = TextFieldWidget::new(200.0, 34.0).on_change(move |v| tb.set(v.to_string()));
538
539 let mut host = HeadlessHost::new();
540 let wa = host.create_window(ShellMetrics::new(Size::new(240.0, 80.0), 1.0));
541 let wb = host.create_window(ShellMetrics::new(Size::new(240.0, 80.0), 1.0));
542 host.window_mut(wa).unwrap().mount(WidgetNode::new(field_a));
543 host.window_mut(wb).unwrap().mount(WidgetNode::new(field_b));
544
545 assert!(host.set_focused(wa));
546 host.window_mut(wa).unwrap().click(Point::new(20.0, 16.0));
547 assert!(host.window(wa).unwrap().tree().focused_element().is_some());
548 host.window_mut(wa).unwrap().ime_commit("你");
549 assert_eq!(text_a.peek(), "你");
550 assert_eq!(text_b.peek(), "", "IME 不得串窗口");
551
552 assert!(host.set_focused(wb));
553 assert!(host.window(wa).unwrap().tree().focused_element().is_none(), "切换窗口焦点应清空旧窗口焦点");
554 host.window_mut(wb).unwrap().click(Point::new(20.0, 16.0));
555 host.window_mut(wb).unwrap().ime_commit("好");
556 assert_eq!(text_b.peek(), "好");
557 assert_eq!(text_a.peek(), "你", "旧窗口文本不得被新窗口 IME 修改");
558 }
559
560 #[test]
561 fn cross_window_overlays_are_isolated() {
562 fn dropdown() -> DropdownWidget {
563 DropdownWidget::new(
564 vec![DropdownOption::new("a", "Apple"), DropdownOption::new("b", "Banana")],
565 vec![],
566 false,
567 false,
568 Signal::new(Vec::new()),
569 )
570 }
571
572 let mut host = HeadlessHost::new();
573 let wa = host.create_window(ShellMetrics::new(Size::new(240.0, 160.0), 1.0));
574 let wb = host.create_window(ShellMetrics::new(Size::new(240.0, 160.0), 1.0));
575 host.window_mut(wa).unwrap().mount(WidgetNode::new(dropdown()));
576 host.window_mut(wb).unwrap().mount(WidgetNode::new(dropdown()));
577 host.window_mut(wa).unwrap().frame();
578 host.window_mut(wb).unwrap().frame();
579
580 host.window_mut(wa).unwrap().click(Point::new(20.0, 16.0));
581 host.window_mut(wa).unwrap().frame();
582 assert_eq!(host.window(wa).unwrap().overlay_count(), 1);
583 assert_eq!(host.window(wb).unwrap().overlay_count(), 0, "A 的浮层不得出现在 B");
584
585 host.window_mut(wb).unwrap().click(Point::new(20.0, 16.0));
586 host.window_mut(wb).unwrap().frame();
587 assert_eq!(host.window(wa).unwrap().overlay_count(), 1);
588 assert_eq!(host.window(wb).unwrap().overlay_count(), 1);
589
590 host.window_mut(wa).unwrap().key_down(KeyCode::Escape);
591 host.window_mut(wa).unwrap().frame();
592 assert_eq!(host.window(wa).unwrap().overlay_count(), 0);
593 assert_eq!(host.window(wb).unwrap().overlay_count(), 1, "关闭 A 的浮层不得影响 B");
594 }
595
596 #[test]
597 fn input_and_close_are_per_window() {
598 let clicks_a = Rc::new(Cell::new(0));
599 let clicks_b = Rc::new(Cell::new(0));
600 let ca = Rc::clone(&clicks_a);
601 let cb = Rc::clone(&clicks_b);
602 let a = ButtonWidget::new(Size::new(60.0, 30.0)).on_press(move || ca.set(ca.get() + 1));
603 let b = ButtonWidget::new(Size::new(60.0, 30.0)).on_press(move || cb.set(cb.get() + 1));
604
605 let mut host = HeadlessHost::new();
606 let wa = host.create_window(ShellMetrics::new(Size::new(100.0, 100.0), 1.0));
607 let wb = host.create_window(ShellMetrics::new(Size::new(100.0, 100.0), 1.0));
608 host.window_mut(wa).unwrap().mount(WidgetNode::new(a));
609 host.window_mut(wb).unwrap().mount(WidgetNode::new(b));
610
611 host.window_mut(wa).unwrap().click(Point::new(20.0, 15.0));
612 host.frame_all();
613 assert_eq!(clicks_a.get(), 1);
614 assert_eq!(clicks_b.get(), 0, "输入不得串窗口");
615
616 assert!(host.set_focused(wb));
617 assert!(host.close_window(wb));
618 assert_eq!(host.window_count(), 1);
619 assert_eq!(host.focused(), Some(wa), "关闭后焦点回落到剩余窗口");
620 assert_eq!(host.frame_all(), 1);
621 assert!(host.window(wa).unwrap().image().is_some(), "剩余窗口仍可渲染");
622
623 assert!(host.close_window(wa));
624 assert_eq!(host.focused(), None);
625 assert_eq!(host.frame_all(), 0);
626 }
627
628 #[test]
629 fn implements_window_shell_contract() {
630 let shell = HeadlessShell::new(320.0, 240.0);
631 let win: &dyn WindowShell = &shell;
632 win.set_title("headless");
633 win.set_ime_allowed(true);
634 win.set_ime_cursor_area(Rect::new(10.0, 20.0, 0.0, 22.0));
635 assert_eq!(shell.title(), "headless");
636 assert!(shell.ime_allowed());
637 assert_eq!(shell.ime_cursor_area(), Some(Rect::new(10.0, 20.0, 0.0, 22.0)));
638 assert_eq!(win.metrics().logical_size, Size::new(320.0, 240.0));
639 }
640}