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