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: renderer::Scale) {}
29
30    fn scale(&self) -> Option<renderer::Scale> {
31        None
32    }
33
34    fn reset(&mut self, _new_bounds: Rectangle) {}
35
36    fn settings(&self) -> renderer::Settings {
37        renderer::Settings::default()
38    }
39}
40
41impl text::Renderer for () {
42    type Font = Font;
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 default_font(&self) -> Self::Font {
56        Font::default()
57    }
58
59    fn default_size(&self) -> Pixels {
60        Pixels(16.0)
61    }
62
63    fn fill_paragraph(
64        &mut self,
65        _paragraph: &Self::Paragraph,
66        _position: Point,
67        _color: Color,
68        _clip_bounds: Rectangle,
69    ) {
70    }
71
72    fn fill_editor(
73        &mut self,
74        _editor: &Self::Editor,
75        _position: Point,
76        _color: Color,
77        _clip_bounds: Rectangle,
78    ) {
79    }
80
81    fn fill_text(
82        &mut self,
83        _paragraph: Text,
84        _position: Point,
85        _color: Color,
86        _clip_bounds: Rectangle,
87    ) {
88    }
89}
90
91impl text::Paragraph for () {
92    type Font = Font;
93
94    fn with_text(_text: Text<&str>) -> Self {}
95
96    fn with_spans<Link>(_text: Text<&[text::Span<'_, Link, Self::Font>], Self::Font>) -> Self {}
97
98    fn resize(&mut self, _new_bounds: Size) {}
99
100    fn compare(&self, _text: Text<()>) -> text::Difference {
101        text::Difference::None
102    }
103
104    fn hint_factor(&self) -> Option<f32> {
105        None
106    }
107
108    fn size(&self) -> Pixels {
109        Pixels(16.0)
110    }
111
112    fn font(&self) -> Font {
113        Font::DEFAULT
114    }
115
116    fn line_height(&self) -> text::LineHeight {
117        text::LineHeight::default()
118    }
119
120    fn align_x(&self) -> text::Alignment {
121        text::Alignment::Default
122    }
123
124    fn align_y(&self) -> alignment::Vertical {
125        alignment::Vertical::Top
126    }
127
128    fn wrapping(&self) -> text::Wrapping {
129        text::Wrapping::default()
130    }
131
132    fn ellipsis(&self) -> text::Ellipsis {
133        text::Ellipsis::default()
134    }
135
136    fn shaping(&self) -> text::Shaping {
137        text::Shaping::default()
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::Position { line: 0, index: 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_alignment: text::Alignment,
217        _new_hint_factor: Option<f32>,
218        _new_highlighter: &mut impl text::Highlighter,
219    ) {
220    }
221
222    fn overwrite(&mut self, _new_text: &str) {}
223
224    fn highlight<H: text::Highlighter>(
225        &mut self,
226        _font: Self::Font,
227        _highlighter: &mut H,
228        _format_highlight: impl Fn(&H::Highlight) -> text::highlighter::Format<Self::Font>,
229    ) {
230    }
231
232    fn text_size(&self) -> Pixels {
233        Pixels(0.0)
234    }
235
236    fn line_height(&self) -> text::LineHeight {
237        text::LineHeight::default()
238    }
239
240    fn font(&self) -> Self::Font {
241        Self::Font::default()
242    }
243}
244
245impl image::Renderer for () {
246    type Handle = image::Handle;
247
248    fn load_image(&self, handle: &Self::Handle) -> Result<image::Allocation, image::Error> {
249        #[allow(unsafe_code)]
250        Ok(unsafe { image::allocate(handle, Size::new(100, 100)) })
251    }
252
253    fn measure_image(&self, _handle: &Self::Handle) -> Option<Size<u32>> {
254        Some(Size::new(100, 100))
255    }
256
257    fn draw_image(&mut self, _image: Image, _bounds: Rectangle, _clip_bounds: Rectangle) {}
258}
259
260impl svg::Renderer for () {
261    fn measure_svg(&self, _handle: &svg::Handle) -> Size<u32> {
262        Size::default()
263    }
264
265    fn draw_svg(&mut self, _svg: svg::Svg, _bounds: Rectangle, _clip_bounds: Rectangle) {}
266}
267
268impl renderer::Headless for () {
269    async fn new(_settings: renderer::Settings, _backend: Option<&str>) -> Option<Self>
270    where
271        Self: Sized,
272    {
273        Some(())
274    }
275
276    fn name(&self) -> String {
277        "null renderer".to_owned()
278    }
279
280    fn screenshot(
281        &mut self,
282        _size: Size<u32>,
283        _scale_factor: f32,
284        _background_color: Color,
285    ) -> Vec<u8> {
286        Vec::new()
287    }
288}