From 3a0d34c0240f4421737a6a08761f99d6f8140d02 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 4 Mar 2023 05:37:11 +0100 Subject: Create `iced_widget` subcrate and re-organize the whole codebase --- core/src/renderer/null.rs | 82 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 core/src/renderer/null.rs (limited to 'core/src/renderer') diff --git a/core/src/renderer/null.rs b/core/src/renderer/null.rs new file mode 100644 index 00000000..d93338ae --- /dev/null +++ b/core/src/renderer/null.rs @@ -0,0 +1,82 @@ +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, + ) { + } +} + +impl text::Renderer for Null { + type Font = Font; + + const ICON_FONT: Font = Font::SansSerif; + const CHECKMARK_ICON: char = '0'; + const ARROW_DOWN_ICON: char = '0'; + + fn default_font(&self) -> Self::Font { + Font::SansSerif + } + + fn default_size(&self) -> f32 { + 16.0 + } + + fn load_font(&mut self, _font: Cow<'static, [u8]>) {} + + fn measure( + &self, + _content: &str, + _size: f32, + _font: Font, + _bounds: Size, + ) -> (f32, f32) { + (0.0, 20.0) + } + + fn hit_test( + &self, + _contents: &str, + _size: f32, + _font: Self::Font, + _bounds: Size, + _point: Point, + _nearest_only: bool, + ) -> Option { + None + } + + fn fill_text(&mut self, _text: Text<'_, Self::Font>) {} +} -- cgit From 707de9d788dc3c49d4ac57a19afac1bb938b78d9 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 30 Mar 2023 00:56:00 +0200 Subject: Introduce support for `Font` attributes --- core/src/renderer/null.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core/src/renderer') diff --git a/core/src/renderer/null.rs b/core/src/renderer/null.rs index d93338ae..88c58825 100644 --- a/core/src/renderer/null.rs +++ b/core/src/renderer/null.rs @@ -42,12 +42,12 @@ impl Renderer for Null { impl text::Renderer for Null { type Font = Font; - const ICON_FONT: Font = Font::SansSerif; + const ICON_FONT: Font = Font::DEFAULT; const CHECKMARK_ICON: char = '0'; const ARROW_DOWN_ICON: char = '0'; fn default_font(&self) -> Self::Font { - Font::SansSerif + Font::default() } fn default_size(&self) -> f32 { -- cgit From 33b5a900197e2798a393d6d9a0834039666eddbb Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 19 Apr 2023 01:19:56 +0200 Subject: Make basic text shaping the default shaping strategy --- core/src/renderer/null.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'core/src/renderer') diff --git a/core/src/renderer/null.rs b/core/src/renderer/null.rs index 88c58825..f62a4338 100644 --- a/core/src/renderer/null.rs +++ b/core/src/renderer/null.rs @@ -62,6 +62,7 @@ impl text::Renderer for Null { _size: f32, _font: Font, _bounds: Size, + _needs_shaping: bool, ) -> (f32, f32) { (0.0, 20.0) } @@ -74,6 +75,7 @@ impl text::Renderer for Null { _bounds: Size, _point: Point, _nearest_only: bool, + _advanced_shape: bool, ) -> Option { None } -- cgit From 4bd290afe7d81d9aaf7467b3ce91491f6600261a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 19 Apr 2023 02:00:45 +0200 Subject: Introduce `text::Shaping` enum and replace magic boolean --- core/src/renderer/null.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core/src/renderer') diff --git a/core/src/renderer/null.rs b/core/src/renderer/null.rs index f62a4338..22afb058 100644 --- a/core/src/renderer/null.rs +++ b/core/src/renderer/null.rs @@ -62,7 +62,7 @@ impl text::Renderer for Null { _size: f32, _font: Font, _bounds: Size, - _needs_shaping: bool, + _shaping: text::Shaping, ) -> (f32, f32) { (0.0, 20.0) } @@ -73,9 +73,9 @@ impl text::Renderer for Null { _size: f32, _font: Self::Font, _bounds: Size, + _shaping: text::Shaping, _point: Point, _nearest_only: bool, - _advanced_shape: bool, ) -> Option { None } -- cgit From 9499a8f9e6f9971dedfae563cb133232aa3cebc2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 4 May 2023 13:00:16 +0200 Subject: Support configurable `LineHeight` in text widgets --- core/src/renderer/null.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'core/src/renderer') diff --git a/core/src/renderer/null.rs b/core/src/renderer/null.rs index 22afb058..f0cc952e 100644 --- a/core/src/renderer/null.rs +++ b/core/src/renderer/null.rs @@ -60,6 +60,7 @@ impl text::Renderer for Null { &self, _content: &str, _size: f32, + _line_height: text::LineHeight, _font: Font, _bounds: Size, _shaping: text::Shaping, @@ -71,6 +72,7 @@ impl text::Renderer for Null { &self, _contents: &str, _size: f32, + _line_height: text::LineHeight, _font: Self::Font, _bounds: Size, _shaping: text::Shaping, -- cgit