suzy/platform/
stub.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use crate::widget::{
6    WidgetChildReceiver, WidgetContent, WidgetGraphicReceiver, WidgetInit,
7};
8
9use super::{Event, SimpleEventLoopState};
10
11macro_rules! stub {
12    () => {
13        unimplemented!("StubPlatform used at runtime")
14    };
15}
16
17/// The stub platform is used as a placeholder when no other platforms are
18/// enabled.  All its methods will panic.
19#[derive(Default)]
20pub struct StubPlatform;
21
22/// The stub platform is used as a placeholder when no other platforms are
23/// enabled.  All its methods will panic.
24#[derive(Default)]
25pub struct StubWindow;
26
27/// The stub platform is used as a placeholder when no other platforms are
28/// enabled.  All its methods will panic.
29#[derive(Default)]
30pub struct StubRenderPlatform;
31
32/// The stub platform is used as a placeholder when no other platforms are
33/// enabled.  All its methods will panic.
34#[derive(Default)]
35pub struct StubDrawParams;
36
37/// The stub platform is used as a placeholder when no other platforms are
38/// enabled.  All its methods will panic.
39#[derive(Default)]
40pub struct StubButtonContent;
41
42/// The stub platform is used as a placeholder when no other platforms are
43/// enabled.  All its methods will panic.
44#[cfg(feature = "platform_opengl")]
45#[derive(Default)]
46pub struct StubOpenglPlatform;
47
48impl crate::platform::RenderPlatform for StubRenderPlatform {
49    type Context = ();
50    type DrawParams = StubDrawParams;
51
52    type DefaultButtonContent = StubButtonContent;
53}
54
55impl crate::graphics::DrawParams<()> for StubDrawParams {
56    fn apply_all(&mut self, _ctx: &mut ()) {
57        stub!()
58    }
59    fn apply_change(_c: &Self, _n: &mut Self, _ctx: &mut ()) {
60        stub!()
61    }
62}
63
64impl crate::platform::Platform for StubPlatform {
65    type State = SimpleEventLoopState;
66    type Window = StubWindow;
67    type Renderer = StubRenderPlatform;
68
69    fn new() -> Self {
70        stub!()
71    }
72
73    fn create_window(
74        &mut self,
75        _settings: crate::window::WindowBuilder,
76    ) -> Result<Self::Window, String> {
77        stub!()
78    }
79
80    fn run<F>(self, _event_handler: F) -> !
81    where
82        F: 'static + FnMut(&mut Self::State, Event),
83    {
84        stub!()
85    }
86}
87
88#[cfg(feature = "platform_opengl")]
89impl crate::platform::Platform for StubOpenglPlatform {
90    type State = SimpleEventLoopState;
91    type Window = StubWindow;
92    type Renderer = super::opengl::OpenGlRenderPlatform;
93
94    fn new() -> Self {
95        stub!()
96    }
97
98    fn create_window(
99        &mut self,
100        _settings: crate::window::WindowBuilder,
101    ) -> Result<Self::Window, String> {
102        stub!()
103    }
104
105    fn run<F>(self, _event_handler: F) -> !
106    where
107        F: 'static + FnMut(&mut Self::State, Event),
108    {
109        stub!()
110    }
111}
112
113impl crate::window::WindowSettings for StubWindow {
114    fn size(&self) -> (f32, f32) {
115        stub!()
116    }
117    fn set_size(&mut self, _size: (f32, f32)) {
118        stub!()
119    }
120    fn title(&self) -> &str {
121        stub!()
122    }
123    fn set_title(&mut self, _title: String) {
124        stub!()
125    }
126    fn fullscreen(&self) -> bool {
127        stub!()
128    }
129    fn set_fullscreen(&mut self, _fullscreen: bool) {
130        stub!()
131    }
132    fn background_color(&self) -> crate::graphics::Color {
133        stub!()
134    }
135    fn set_background_color(&mut self, _color: crate::graphics::Color) {
136        stub!()
137    }
138}
139
140impl crate::window::Window<StubRenderPlatform> for StubWindow {
141    fn pixels_per_dp(&self) -> f32 {
142        stub!()
143    }
144
145    fn normalize_pointer_event(
146        &self,
147        _event: &mut crate::pointer::PointerEventData,
148    ) {
149        stub!()
150    }
151
152    fn recalculate_viewport(&mut self) {
153        stub!()
154    }
155
156    fn flip(&mut self) {
157        stub!()
158    }
159
160    fn prepare_draw(
161        &mut self,
162        _first_pass: bool,
163    ) -> crate::graphics::DrawContext<StubRenderPlatform> {
164        stub!()
165    }
166
167    fn take_screenshot(&self) -> Box<[u8]> {
168        stub!()
169    }
170}
171
172#[cfg(feature = "platform_opengl")]
173impl crate::window::Window<super::opengl::OpenGlRenderPlatform>
174    for StubWindow
175{
176    fn pixels_per_dp(&self) -> f32 {
177        stub!()
178    }
179
180    fn normalize_pointer_event(
181        &self,
182        _event: &mut crate::pointer::PointerEventData,
183    ) {
184        stub!()
185    }
186
187    fn recalculate_viewport(&mut self) {
188        stub!()
189    }
190
191    fn flip(&mut self) {
192        stub!()
193    }
194
195    fn prepare_draw(
196        &mut self,
197        _first_pass: bool,
198    ) -> crate::graphics::DrawContext<super::opengl::OpenGlRenderPlatform>
199    {
200        stub!()
201    }
202
203    fn take_screenshot(&self) -> Box<[u8]> {
204        stub!()
205    }
206}
207
208impl crate::widgets::TextContent for StubButtonContent {
209    fn set_text(&mut self, _text: &str) {
210        stub!()
211    }
212}
213
214impl<P: super::RenderPlatform> WidgetContent<P> for StubButtonContent {
215    fn init(_init: impl WidgetInit<Self, P>) {
216        stub!()
217    }
218
219    fn children(&mut self, _receiver: impl WidgetChildReceiver<P>) {
220        stub!()
221    }
222
223    fn graphics(&mut self, _receiver: impl WidgetGraphicReceiver<P>) {
224        stub!()
225    }
226}
227
228impl crate::selectable::Selectable for StubButtonContent {
229    fn selection_changed(
230        &mut self,
231        _state: crate::selectable::SelectionState,
232    ) {
233        stub!()
234    }
235}