1use crate::alignment;
2use crate::image::{self, Image};
3use crate::renderer::{self, Renderer};
4use crate::svg;
5use crate::text::{self, Text};
6use crate::{Background, Color, Font, Pixels, Point, Rectangle, Size, Transformation};
7
8impl Renderer for () {
9 fn start_layer(&mut self, _bounds: Rectangle) {}
10
11 fn end_layer(&mut self) {}
12
13 fn start_transformation(&mut self, _transformation: Transformation) {}
14
15 fn end_transformation(&mut self) {}
16
17 fn fill_quad(&mut self, _quad: renderer::Quad, _background: impl Into<Background>) {}
18
19 fn allocate_image(
20 &mut self,
21 handle: &image::Handle,
22 callback: impl FnOnce(Result<image::Allocation, image::Error>) + Send + 'static,
23 ) {
24 #[allow(unsafe_code)]
25 callback(Ok(unsafe { image::allocate(handle, Size::new(100, 100)) }));
26 }
27
28 fn hint(&mut self, _scale_factor: f32) {}
29
30 fn scale_factor(&self) -> Option<f32> {
31 None
32 }
33
34 fn reset(&mut self, _new_bounds: Rectangle) {}
35}
36
37impl text::Renderer for () {
38 type Font = Font;
39 type Paragraph = ();
40 type Editor = ();
41
42 const ICON_FONT: Font = Font::DEFAULT;
43 const CHECKMARK_ICON: char = '0';
44 const ARROW_DOWN_ICON: char = '0';
45 const SCROLL_UP_ICON: char = '0';
46 const SCROLL_DOWN_ICON: char = '0';
47 const SCROLL_LEFT_ICON: char = '0';
48 const SCROLL_RIGHT_ICON: char = '0';
49 const ICED_LOGO: char = '0';
50
51 fn default_font(&self) -> Self::Font {
52 Font::default()
53 }
54
55 fn default_size(&self) -> Pixels {
56 Pixels(16.0)
57 }
58
59 fn fill_paragraph(
60 &mut self,
61 _paragraph: &Self::Paragraph,
62 _position: Point,
63 _color: Color,
64 _clip_bounds: Rectangle,
65 ) {
66 }
67
68 fn fill_editor(
69 &mut self,
70 _editor: &Self::Editor,
71 _position: Point,
72 _color: Color,
73 _clip_bounds: Rectangle,
74 ) {
75 }
76
77 fn fill_text(
78 &mut self,
79 _paragraph: Text,
80 _position: Point,
81 _color: Color,
82 _clip_bounds: Rectangle,
83 ) {
84 }
85}
86
87impl text::Paragraph for () {
88 type Font = Font;
89
90 fn with_text(_text: Text<&str>) -> Self {}
91
92 fn with_spans<Link>(_text: Text<&[text::Span<'_, Link, Self::Font>], Self::Font>) -> Self {}
93
94 fn resize(&mut self, _new_bounds: Size) {}
95
96 fn compare(&self, _text: Text<()>) -> text::Difference {
97 text::Difference::None
98 }
99
100 fn hint_factor(&self) -> Option<f32> {
101 None
102 }
103
104 fn size(&self) -> Pixels {
105 Pixels(16.0)
106 }
107
108 fn font(&self) -> Font {
109 Font::DEFAULT
110 }
111
112 fn line_height(&self) -> text::LineHeight {
113 text::LineHeight::default()
114 }
115
116 fn align_x(&self) -> text::Alignment {
117 text::Alignment::Default
118 }
119
120 fn align_y(&self) -> alignment::Vertical {
121 alignment::Vertical::Top
122 }
123
124 fn wrapping(&self) -> text::Wrapping {
125 text::Wrapping::default()
126 }
127
128 fn shaping(&self) -> text::Shaping {
129 text::Shaping::default()
130 }
131
132 fn grapheme_position(&self, _line: usize, _index: usize) -> Option<Point> {
133 None
134 }
135
136 fn bounds(&self) -> Size {
137 Size::ZERO
138 }
139
140 fn min_bounds(&self) -> Size {
141 Size::ZERO
142 }
143
144 fn hit_test(&self, _point: Point) -> Option<text::Hit> {
145 None
146 }
147
148 fn hit_span(&self, _point: Point) -> Option<usize> {
149 None
150 }
151
152 fn span_bounds(&self, _index: usize) -> Vec<Rectangle> {
153 vec![]
154 }
155}
156
157impl text::Editor for () {
158 type Font = Font;
159
160 fn with_text(_text: &str) -> Self {}
161
162 fn is_empty(&self) -> bool {
163 true
164 }
165
166 fn cursor(&self) -> text::editor::Cursor {
167 text::editor::Cursor {
168 position: text::editor::Position { line: 0, column: 0 },
169 selection: None,
170 }
171 }
172
173 fn selection(&self) -> text::editor::Selection {
174 text::editor::Selection::Caret(Point::ORIGIN)
175 }
176
177 fn copy(&self) -> Option<String> {
178 None
179 }
180
181 fn line(&self, _index: usize) -> Option<text::editor::Line<'_>> {
182 None
183 }
184
185 fn line_count(&self) -> usize {
186 0
187 }
188
189 fn perform(&mut self, _action: text::editor::Action) {}
190
191 fn move_to(&mut self, _cursor: text::editor::Cursor) {}
192
193 fn bounds(&self) -> Size {
194 Size::ZERO
195 }
196
197 fn hint_factor(&self) -> Option<f32> {
198 None
199 }
200
201 fn min_bounds(&self) -> Size {
202 Size::ZERO
203 }
204
205 fn update(
206 &mut self,
207 _new_bounds: Size,
208 _new_font: Self::Font,
209 _new_size: Pixels,
210 _new_line_height: text::LineHeight,
211 _new_wrapping: text::Wrapping,
212 _new_hint_factor: Option<f32>,
213 _new_highlighter: &mut impl text::Highlighter,
214 ) {
215 }
216
217 fn highlight<H: text::Highlighter>(
218 &mut self,
219 _font: Self::Font,
220 _highlighter: &mut H,
221 _format_highlight: impl Fn(&H::Highlight) -> text::highlighter::Format<Self::Font>,
222 ) {
223 }
224}
225
226impl image::Renderer for () {
227 type Handle = image::Handle;
228
229 fn load_image(&self, handle: &Self::Handle) -> Result<image::Allocation, image::Error> {
230 #[allow(unsafe_code)]
231 Ok(unsafe { image::allocate(handle, Size::new(100, 100)) })
232 }
233
234 fn measure_image(&self, _handle: &Self::Handle) -> Option<Size<u32>> {
235 Some(Size::new(100, 100))
236 }
237
238 fn draw_image(&mut self, _image: Image, _bounds: Rectangle, _clip_bounds: Rectangle) {}
239}
240
241impl svg::Renderer for () {
242 fn measure_svg(&self, _handle: &svg::Handle) -> Size<u32> {
243 Size::default()
244 }
245
246 fn draw_svg(&mut self, _svg: svg::Svg, _bounds: Rectangle, _clip_bounds: Rectangle) {}
247}
248
249impl renderer::Headless for () {
250 async fn new(
251 _default_font: Font,
252 _default_text_size: Pixels,
253 _backend: Option<&str>,
254 ) -> Option<Self>
255 where
256 Self: Sized,
257 {
258 Some(())
259 }
260
261 fn name(&self) -> String {
262 "null renderer".to_owned()
263 }
264
265 fn screenshot(
266 &mut self,
267 _size: Size<u32>,
268 _scale_factor: f32,
269 _background_color: Color,
270 ) -> Vec<u8> {
271 Vec::new()
272 }
273}