Skip to main content

iced_core/renderer/
null.rs

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 ellipsis(&self) -> text::Ellipsis {
129        text::Ellipsis::default()
130    }
131
132    fn shaping(&self) -> text::Shaping {
133        text::Shaping::default()
134    }
135
136    fn grapheme_position(&self, _line: usize, _index: usize) -> Option<Point> {
137        None
138    }
139
140    fn bounds(&self) -> Size {
141        Size::ZERO
142    }
143
144    fn min_bounds(&self) -> Size {
145        Size::ZERO
146    }
147
148    fn hit_test(&self, _point: Point) -> Option<text::Hit> {
149        None
150    }
151
152    fn hit_span(&self, _point: Point) -> Option<usize> {
153        None
154    }
155
156    fn span_bounds(&self, _index: usize) -> Vec<Rectangle> {
157        vec![]
158    }
159}
160
161impl text::Editor for () {
162    type Font = Font;
163
164    fn with_text(_text: &str) -> Self {}
165
166    fn is_empty(&self) -> bool {
167        true
168    }
169
170    fn cursor(&self) -> text::editor::Cursor {
171        text::editor::Cursor {
172            position: text::editor::Position { line: 0, column: 0 },
173            selection: None,
174        }
175    }
176
177    fn selection(&self) -> text::editor::Selection {
178        text::editor::Selection::Caret(Point::ORIGIN)
179    }
180
181    fn copy(&self) -> Option<String> {
182        None
183    }
184
185    fn line(&self, _index: usize) -> Option<text::editor::Line<'_>> {
186        None
187    }
188
189    fn line_count(&self) -> usize {
190        0
191    }
192
193    fn perform(&mut self, _action: text::editor::Action) {}
194
195    fn move_to(&mut self, _cursor: text::editor::Cursor) {}
196
197    fn bounds(&self) -> Size {
198        Size::ZERO
199    }
200
201    fn hint_factor(&self) -> Option<f32> {
202        None
203    }
204
205    fn min_bounds(&self) -> Size {
206        Size::ZERO
207    }
208
209    fn update(
210        &mut self,
211        _new_bounds: Size,
212        _new_font: Self::Font,
213        _new_size: Pixels,
214        _new_line_height: text::LineHeight,
215        _new_wrapping: text::Wrapping,
216        _new_hint_factor: Option<f32>,
217        _new_highlighter: &mut impl text::Highlighter,
218    ) {
219    }
220
221    fn highlight<H: text::Highlighter>(
222        &mut self,
223        _font: Self::Font,
224        _highlighter: &mut H,
225        _format_highlight: impl Fn(&H::Highlight) -> text::highlighter::Format<Self::Font>,
226    ) {
227    }
228}
229
230impl image::Renderer for () {
231    type Handle = image::Handle;
232
233    fn load_image(&self, handle: &Self::Handle) -> Result<image::Allocation, image::Error> {
234        #[allow(unsafe_code)]
235        Ok(unsafe { image::allocate(handle, Size::new(100, 100)) })
236    }
237
238    fn measure_image(&self, _handle: &Self::Handle) -> Option<Size<u32>> {
239        Some(Size::new(100, 100))
240    }
241
242    fn draw_image(&mut self, _image: Image, _bounds: Rectangle, _clip_bounds: Rectangle) {}
243}
244
245impl svg::Renderer for () {
246    fn measure_svg(&self, _handle: &svg::Handle) -> Size<u32> {
247        Size::default()
248    }
249
250    fn draw_svg(&mut self, _svg: svg::Svg, _bounds: Rectangle, _clip_bounds: Rectangle) {}
251}
252
253impl renderer::Headless for () {
254    async fn new(
255        _default_font: Font,
256        _default_text_size: Pixels,
257        _backend: Option<&str>,
258    ) -> Option<Self>
259    where
260        Self: Sized,
261    {
262        Some(())
263    }
264
265    fn name(&self) -> String {
266        "null renderer".to_owned()
267    }
268
269    fn screenshot(
270        &mut self,
271        _size: Size<u32>,
272        _scale_factor: f32,
273        _background_color: Color,
274    ) -> Vec<u8> {
275        Vec::new()
276    }
277}