maycoon_core/vgi/
dummy.rs

1use crate::vgi::kurbo::{
2    Affine, Circle, CircleSegment, CubicBez, Ellipse, QuadBez, Rect, RoundedRect, Stroke, Triangle,
3};
4use crate::vgi::{FontData, Scene, VectorGraphicsInterface};
5use nalgebra::Vector2;
6use peniko::{Brush, Color, ImageBrush};
7use std::any::Any;
8use std::convert::Infallible;
9use std::fmt::Debug;
10use std::sync::Arc;
11use winit::event_loop::ActiveEventLoop;
12use winit::window::Window;
13
14/// A dummy graphics backend that does nothing.
15///
16/// Useful for testing.
17#[derive(Debug)]
18pub struct DummyGraphics;
19
20impl VectorGraphicsInterface for DummyGraphics {
21    type Error = Infallible;
22    type Scene = DummyScene;
23    type Config = ();
24
25    fn new(_: Self::Config) -> Result<Self, Self::Error>
26    where
27        Self: Sized,
28    {
29        Ok(Self)
30    }
31
32    fn init(
33        &mut self,
34        _window: Arc<Window>,
35        _event_loop: &ActiveEventLoop,
36    ) -> Result<(), Self::Error> {
37        Ok(())
38    }
39
40    fn render(
41        &mut self,
42        _window: Arc<Window>,
43        _event_loop: &ActiveEventLoop,
44        _scene: &Self::Scene,
45        _bg_color: Color,
46    ) -> Result<(), Self::Error> {
47        Ok(())
48    }
49
50    fn resize(
51        &mut self,
52        _window: Arc<Window>,
53        _event_loop: &ActiveEventLoop,
54        _size: Vector2<u32>,
55    ) -> Result<(), Self::Error> {
56        Ok(())
57    }
58
59    fn uninit(
60        &mut self,
61        _window: Arc<Window>,
62        _event_loop: &ActiveEventLoop,
63    ) -> Result<(), Self::Error> {
64        Ok(())
65    }
66
67    fn destroy(
68        &mut self,
69        _window: Arc<Window>,
70        _event_loop: &ActiveEventLoop,
71    ) -> Result<(), Self::Error> {
72        Ok(())
73    }
74}
75
76/// A dummy scene that does nothing.
77///
78/// Useful for testing.
79pub struct DummyScene;
80
81impl Scene for DummyScene {
82    fn new() -> Self
83    where
84        Self: Sized,
85    {
86        unimplemented!("This is a dummy scene")
87    }
88
89    fn as_any(&self) -> &dyn Any {
90        self
91    }
92
93    fn as_any_mut(&mut self) -> &mut dyn Any {
94        self
95    }
96
97    fn dyn_clone(&self) -> Box<dyn Scene> {
98        Box::new(DummyScene)
99    }
100
101    fn reset(&mut self) {}
102
103    fn append(&mut self, _other: &dyn Scene, _transform: Option<Affine>) {}
104
105    fn draw_rect(
106        &mut self,
107        _brush: &Brush,
108        _transform: Option<Affine>,
109        _stroke: Option<&Stroke>,
110        _rect: &Rect,
111    ) {
112    }
113
114    fn draw_rounded_rect(
115        &mut self,
116        _brush: &Brush,
117        _transform: Option<Affine>,
118        _stroke: Option<&Stroke>,
119        _rect: &RoundedRect,
120    ) {
121    }
122
123    fn draw_circle(
124        &mut self,
125        _brush: &Brush,
126        _transform: Option<Affine>,
127        _stroke: Option<&Stroke>,
128        _circle: &Circle,
129    ) {
130    }
131
132    fn draw_circle_segment(
133        &mut self,
134        _brush: &Brush,
135        _transform: Option<Affine>,
136        _stroke: Option<&Stroke>,
137        _circle_segment: &CircleSegment,
138    ) {
139    }
140
141    fn draw_ellipse(
142        &mut self,
143        _brush: &Brush,
144        _transform: Option<Affine>,
145        _stroke: Option<&Stroke>,
146        _ellipse: &Ellipse,
147    ) {
148    }
149
150    fn draw_cubic_bezier(
151        &mut self,
152        _brush: &Brush,
153        _transform: Option<Affine>,
154        _stroke: Option<&Stroke>,
155        _cubic_bez: &CubicBez,
156    ) {
157    }
158
159    fn draw_quadratic_bezier(
160        &mut self,
161        _brush: &Brush,
162        _transform: Option<Affine>,
163        _stroke: Option<&Stroke>,
164        _quad_bez: &QuadBez,
165    ) {
166    }
167
168    fn draw_triangle(
169        &mut self,
170        _brush: &Brush,
171        _transform: Option<Affine>,
172        _stroke: Option<&Stroke>,
173        _triangle: &Triangle,
174    ) {
175    }
176
177    fn draw_image(
178        &mut self,
179        _img: &ImageBrush,
180        _transform: Option<Affine>,
181        _position: Vector2<f32>,
182    ) {
183    }
184
185    fn draw_text(
186        &mut self,
187        _brush: &Brush,
188        _transform: Option<Affine>,
189        _position: Vector2<f32>,
190        _text: &str,
191        _hinting: bool,
192        _font: &FontData,
193        _size: f32,
194        _line_gap: f32,
195        _max_width: f32,
196    ) {
197    }
198
199    #[cfg(feature = "svg")]
200    fn draw_svg(&mut self, _svg: &usvg::Tree, _transform: Option<Affine>) {}
201}