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