summaryrefslogtreecommitdiffstats
path: root/core/src/renderer
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2023-05-11 16:45:08 +0200
committerLibravatar GitHub <noreply@github.com>2023-05-11 16:45:08 +0200
commit669f7cc74b2e7918e86a8197916f503f2d3d9b93 (patch)
treeacb365358235be6ce115b50db9404d890b6e77a6 /core/src/renderer
parentbc62013b6cde52174bf4c4286939cf170bfa7760 (diff)
parent63d3fc6996b848e10e77e6924bfebdf6ba82852e (diff)
downloadiced-669f7cc74b2e7918e86a8197916f503f2d3d9b93.tar.gz
iced-669f7cc74b2e7918e86a8197916f503f2d3d9b93.tar.bz2
iced-669f7cc74b2e7918e86a8197916f503f2d3d9b93.zip
Merge pull request #1830 from iced-rs/advanced-text
Advanced text
Diffstat (limited to 'core/src/renderer')
-rw-r--r--core/src/renderer/null.rs86
1 files changed, 86 insertions, 0 deletions
diff --git a/core/src/renderer/null.rs b/core/src/renderer/null.rs
new file mode 100644
index 00000000..f0cc952e
--- /dev/null
+++ b/core/src/renderer/null.rs
@@ -0,0 +1,86 @@
+use crate::renderer::{self, Renderer};
+use crate::text::{self, Text};
+use crate::{Background, Font, Point, Rectangle, Size, Vector};
+
+use std::borrow::Cow;
+
+/// A renderer that does nothing.
+///
+/// It can be useful if you are writing tests!
+#[derive(Debug, Clone, Copy, Default)]
+pub struct Null;
+
+impl Null {
+ /// Creates a new [`Null`] renderer.
+ pub fn new() -> Null {
+ Null
+ }
+}
+
+impl Renderer for Null {
+ type Theme = ();
+
+ fn with_layer(&mut self, _bounds: Rectangle, _f: impl FnOnce(&mut Self)) {}
+
+ fn with_translation(
+ &mut self,
+ _translation: Vector,
+ _f: impl FnOnce(&mut Self),
+ ) {
+ }
+
+ fn clear(&mut self) {}
+
+ fn fill_quad(
+ &mut self,
+ _quad: renderer::Quad,
+ _background: impl Into<Background>,
+ ) {
+ }
+}
+
+impl text::Renderer for Null {
+ type Font = Font;
+
+ const ICON_FONT: Font = Font::DEFAULT;
+ const CHECKMARK_ICON: char = '0';
+ const ARROW_DOWN_ICON: char = '0';
+
+ fn default_font(&self) -> Self::Font {
+ Font::default()
+ }
+
+ fn default_size(&self) -> f32 {
+ 16.0
+ }
+
+ fn load_font(&mut self, _font: Cow<'static, [u8]>) {}
+
+ fn measure(
+ &self,
+ _content: &str,
+ _size: f32,
+ _line_height: text::LineHeight,
+ _font: Font,
+ _bounds: Size,
+ _shaping: text::Shaping,
+ ) -> (f32, f32) {
+ (0.0, 20.0)
+ }
+
+ fn hit_test(
+ &self,
+ _contents: &str,
+ _size: f32,
+ _line_height: text::LineHeight,
+ _font: Self::Font,
+ _bounds: Size,
+ _shaping: text::Shaping,
+ _point: Point,
+ _nearest_only: bool,
+ ) -> Option<text::Hit> {
+ None
+ }
+
+ fn fill_text(&mut self, _text: Text<'_, Self::Font>) {}
+}