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