1use std::{rc::Rc, sync::Arc};
2
3use parking_lot::Mutex;
4
5use crate::{
6 px, Pixels, PlatformAtlas, PlatformDisplay, PlatformWindow, Point, Scene, Size,
7 WindowAppearance, WindowBounds, WindowOptions,
8};
9
10#[derive(Default)]
11struct Handlers {
12 active_status_change: Vec<Box<dyn FnMut(bool)>>,
13 input: Vec<Box<dyn FnMut(crate::InputEvent) -> bool>>,
14 moved: Vec<Box<dyn FnMut()>>,
15 resize: Vec<Box<dyn FnMut(Size<Pixels>, f32)>>,
16}
17
18pub struct TestWindow {
19 bounds: WindowBounds,
20 current_scene: Mutex<Option<Scene>>,
21 display: Rc<dyn PlatformDisplay>,
22
23 handlers: Mutex<Handlers>,
24 sprite_atlas: Arc<dyn PlatformAtlas>,
25}
26impl TestWindow {
27 pub fn new(options: WindowOptions, display: Rc<dyn PlatformDisplay>) -> Self {
28 Self {
29 bounds: options.bounds,
30 current_scene: Default::default(),
31 display,
32
33 sprite_atlas: Arc::new(TestAtlas),
34 handlers: Default::default(),
35 }
36 }
37}
38
39impl PlatformWindow for TestWindow {
40 fn bounds(&self) -> WindowBounds {
41 self.bounds
42 }
43
44 fn content_size(&self) -> Size<Pixels> {
45 let bounds = match self.bounds {
46 WindowBounds::Fixed(bounds) => bounds,
47 WindowBounds::Maximized | WindowBounds::Fullscreen => self.display().bounds(),
48 };
49 bounds.size.map(|p| px(p.0))
50 }
51
52 fn scale_factor(&self) -> f32 {
53 2.0
54 }
55
56 fn titlebar_height(&self) -> Pixels {
57 todo!()
58 }
59
60 fn appearance(&self) -> WindowAppearance {
61 todo!()
62 }
63
64 fn display(&self) -> std::rc::Rc<dyn crate::PlatformDisplay> {
65 self.display.clone()
66 }
67
68 fn mouse_position(&self) -> Point<Pixels> {
69 Point::zero()
70 }
71
72 fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
73 todo!()
74 }
75
76 fn set_input_handler(&mut self, _input_handler: Box<dyn crate::PlatformInputHandler>) {
77 todo!()
78 }
79
80 fn prompt(
81 &self,
82 _level: crate::PromptLevel,
83 _msg: &str,
84 _answers: &[&str],
85 ) -> futures::channel::oneshot::Receiver<usize> {
86 todo!()
87 }
88
89 fn activate(&self) {
90 todo!()
91 }
92
93 fn set_title(&mut self, _title: &str) {
94 todo!()
95 }
96
97 fn set_edited(&mut self, _edited: bool) {
98 todo!()
99 }
100
101 fn show_character_palette(&self) {
102 todo!()
103 }
104
105 fn minimize(&self) {
106 todo!()
107 }
108
109 fn zoom(&self) {
110 todo!()
111 }
112
113 fn toggle_full_screen(&self) {
114 todo!()
115 }
116
117 fn on_input(&self, callback: Box<dyn FnMut(crate::InputEvent) -> bool>) {
118 self.handlers.lock().input.push(callback)
119 }
120
121 fn on_active_status_change(&self, callback: Box<dyn FnMut(bool)>) {
122 self.handlers.lock().active_status_change.push(callback)
123 }
124
125 fn on_resize(&self, callback: Box<dyn FnMut(Size<Pixels>, f32)>) {
126 self.handlers.lock().resize.push(callback)
127 }
128
129 fn on_fullscreen(&self, _callback: Box<dyn FnMut(bool)>) {
130 todo!()
131 }
132
133 fn on_moved(&self, callback: Box<dyn FnMut()>) {
134 self.handlers.lock().moved.push(callback)
135 }
136
137 fn on_should_close(&self, _callback: Box<dyn FnMut() -> bool>) {
138 todo!()
139 }
140
141 fn on_close(&self, _callback: Box<dyn FnOnce()>) {
142 todo!()
143 }
144
145 fn on_appearance_changed(&self, _callback: Box<dyn FnMut()>) {
146 todo!()
147 }
148
149 fn is_topmost_for_position(&self, _position: crate::Point<Pixels>) -> bool {
150 todo!()
151 }
152
153 fn draw(&self, scene: crate::Scene) {
154 self.current_scene.lock().replace(scene);
155 }
156
157 fn sprite_atlas(&self) -> std::sync::Arc<dyn crate::PlatformAtlas> {
158 self.sprite_atlas.clone()
159 }
160}
161
162pub struct TestAtlas;
163
164impl PlatformAtlas for TestAtlas {
165 fn get_or_insert_with<'a>(
166 &self,
167 _key: &crate::AtlasKey,
168 _build: &mut dyn FnMut() -> anyhow::Result<(
169 Size<crate::DevicePixels>,
170 std::borrow::Cow<'a, [u8]>,
171 )>,
172 ) -> anyhow::Result<crate::AtlasTile> {
173 todo!()
174 }
175
176 fn clear(&self) {
177 todo!()
178 }
179}