From b26890f76ea4cd730639b4dcfe966758f4c1040c Mon Sep 17 00:00:00 2001 From: pml68 Date: Sun, 25 May 2025 21:08:31 +0200 Subject: [PATCH 1/4] feat: add `fill_raw` method and `Raw` associated type for text::Renderer --- core/src/renderer/null.rs | 3 +++ core/src/text.rs | 6 ++++++ renderer/src/fallback.rs | 6 ++++++ tiny_skia/src/layer.rs | 11 ++++++++++- tiny_skia/src/lib.rs | 8 +++++++- wgpu/src/layer.rs | 11 ++++++++++- wgpu/src/lib.rs | 8 +++++++- 7 files changed, 49 insertions(+), 4 deletions(-) diff --git a/core/src/renderer/null.rs b/core/src/renderer/null.rs index 8c4b328a..34d1ffc1 100644 --- a/core/src/renderer/null.rs +++ b/core/src/renderer/null.rs @@ -41,6 +41,7 @@ impl text::Renderer for () { type Font = Font; type Paragraph = (); type Editor = (); + type Raw = (); const ICON_FONT: Font = Font::DEFAULT; const CHECKMARK_ICON: char = '0'; @@ -73,6 +74,8 @@ impl text::Renderer for () { ) { } + fn fill_raw(&mut self, _raw: Self::Raw) {} + fn fill_text( &mut self, _paragraph: Text, diff --git a/core/src/text.rs b/core/src/text.rs index eddc0532..e1a7b3a8 100644 --- a/core/src/text.rs +++ b/core/src/text.rs @@ -299,6 +299,9 @@ pub trait Renderer: crate::Renderer { /// The [`Editor`] of this [`Renderer`]. type Editor: Editor + 'static; + /// The [`Raw`] text of this [`Renderer`]. + type Raw: 'static; + /// The icon font of the backend. const ICON_FONT: Self::Font; @@ -343,6 +346,9 @@ pub trait Renderer: crate::Renderer { clip_bounds: Rectangle, ); + /// Draws the given [`Raw`] text. + fn fill_raw(&mut self, raw: Self::Raw); + /// Draws the given [`Text`] at the given position and with the given /// [`Color`]. fn fill_text( diff --git a/renderer/src/fallback.rs b/renderer/src/fallback.rs index 907fe9b6..fee0d462 100644 --- a/renderer/src/fallback.rs +++ b/renderer/src/fallback.rs @@ -88,11 +88,13 @@ where Font = A::Font, Paragraph = A::Paragraph, Editor = A::Editor, + Raw = A::Raw, >, { type Font = A::Font; type Paragraph = A::Paragraph; type Editor = A::Editor; + type Raw = A::Raw; const ICON_FONT: Self::Font = A::ICON_FONT; const CHECKMARK_ICON: char = A::CHECKMARK_ICON; @@ -135,6 +137,10 @@ where ); } + fn fill_raw(&mut self, raw: Self::Raw) { + delegate!(self, renderer, renderer.fill_raw(raw)); + } + fn fill_text( &mut self, text: core::Text, diff --git a/tiny_skia/src/layer.rs b/tiny_skia/src/layer.rs index 951f4b14..bc77680e 100644 --- a/tiny_skia/src/layer.rs +++ b/tiny_skia/src/layer.rs @@ -5,7 +5,7 @@ use crate::core::{ }; use crate::graphics::damage; use crate::graphics::layer; -use crate::graphics::text::{Editor, Paragraph, Text}; +use crate::graphics::text::{Editor, Paragraph, Raw, Text}; use crate::graphics::{self, Image}; use std::sync::Arc; @@ -70,6 +70,15 @@ impl Layer { self.text.push(Item::Live(editor)); } + pub fn draw_raw(&mut self, raw: Raw, transformation: Transformation) { + let raw = Text::Raw { + raw, + transformation, + }; + + self.text.push(Item::Live(raw)); + } + pub fn draw_text( &mut self, text: core::Text, diff --git a/tiny_skia/src/lib.rs b/tiny_skia/src/lib.rs index c0bd78af..9a190f27 100644 --- a/tiny_skia/src/lib.rs +++ b/tiny_skia/src/lib.rs @@ -35,7 +35,7 @@ use crate::core::{ use crate::engine::Engine; use crate::graphics::Viewport; use crate::graphics::compositor; -use crate::graphics::text::{Editor, Paragraph}; +use crate::graphics::text::{Editor, Paragraph, Raw}; /// A [`tiny-skia`] graphics renderer for [`iced`]. /// @@ -250,6 +250,7 @@ impl core::text::Renderer for Renderer { type Font = Font; type Paragraph = Paragraph; type Editor = Editor; + type Raw = Raw; const ICON_FONT: Font = Font::with_name("Iced-Icons"); const CHECKMARK_ICON: char = '\u{f00c}'; @@ -293,6 +294,11 @@ impl core::text::Renderer for Renderer { layer.draw_editor(editor, position, color, clip_bounds, transformation); } + fn fill_raw(&mut self, raw: Self::Raw) { + let (layer, transformation) = self.layers.current_mut(); + layer.draw_raw(raw, transformation); + } + fn fill_text( &mut self, text: core::Text, diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs index f7ee2a3a..2dc06a39 100644 --- a/wgpu/src/layer.rs +++ b/wgpu/src/layer.rs @@ -5,7 +5,7 @@ use crate::graphics; use crate::graphics::Mesh; use crate::graphics::color; use crate::graphics::layer; -use crate::graphics::text::{Editor, Paragraph}; +use crate::graphics::text::{Editor, Paragraph, Raw}; use crate::image::{self, Image}; use crate::primitive::{self, Primitive}; use crate::quad::{self, Quad}; @@ -101,6 +101,15 @@ impl Layer { self.pending_text.push(editor); } + pub fn draw_raw(&mut self, raw: Raw, transformation: Transformation) { + let raw = Text::Raw { + raw, + transformation, + }; + + self.pending_text.push(raw); + } + pub fn draw_text( &mut self, text: crate::core::Text, diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 1726beac..61908637 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -65,7 +65,7 @@ use crate::core::renderer; use crate::core::{ Background, Color, Font, Pixels, Point, Rectangle, Size, Transformation, }; -use crate::graphics::text::{Editor, Paragraph}; +use crate::graphics::text::{Editor, Paragraph, Raw}; use crate::graphics::{Shell, Viewport}; /// A [`wgpu`] graphics renderer for [`iced`]. @@ -717,6 +717,7 @@ impl core::text::Renderer for Renderer { type Font = Font; type Paragraph = Paragraph; type Editor = Editor; + type Raw = Raw; const ICON_FONT: Font = Font::with_name("Iced-Icons"); const CHECKMARK_ICON: char = '\u{f00c}'; @@ -760,6 +761,11 @@ impl core::text::Renderer for Renderer { layer.draw_editor(editor, position, color, clip_bounds, transformation); } + fn fill_raw(&mut self, raw: Self::Raw) { + let (layer, transformation) = self.layers.current_mut(); + layer.draw_raw(raw, transformation); + } + fn fill_text( &mut self, text: core::Text, From 4ea0db665fcaf415afa6db3125fbbc6816b8d49a Mon Sep 17 00:00:00 2001 From: pml68 Date: Sun, 25 May 2025 21:31:50 +0200 Subject: [PATCH 2/4] fix: doc comments --- core/src/text.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/text.rs b/core/src/text.rs index e1a7b3a8..b642c243 100644 --- a/core/src/text.rs +++ b/core/src/text.rs @@ -299,7 +299,7 @@ pub trait Renderer: crate::Renderer { /// The [`Editor`] of this [`Renderer`]. type Editor: Editor + 'static; - /// The [`Raw`] text of this [`Renderer`]. + /// The `Raw` text of this [`Renderer`]. type Raw: 'static; /// The icon font of the backend. @@ -346,7 +346,7 @@ pub trait Renderer: crate::Renderer { clip_bounds: Rectangle, ); - /// Draws the given [`Raw`] text. + /// Draws the given `Raw` text. fn fill_raw(&mut self, raw: Self::Raw); /// Draws the given [`Text`] at the given position and with the given From a0b409ed7e0b8bbe49059790426ddaba57db1e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 26 Nov 2025 00:41:05 +0100 Subject: [PATCH 3/4] Replace `Raw` in `core::text::Renderer` with a new `Renderer` trait --- core/src/renderer/null.rs | 3 --- core/src/text.rs | 6 ------ graphics/src/text.rs | 6 ++++++ renderer/src/fallback.rs | 17 +++++++++++------ tiny_skia/src/lib.rs | 15 ++++++++------- wgpu/src/lib.rs | 15 ++++++++------- 6 files changed, 33 insertions(+), 29 deletions(-) diff --git a/core/src/renderer/null.rs b/core/src/renderer/null.rs index 34d1ffc1..8c4b328a 100644 --- a/core/src/renderer/null.rs +++ b/core/src/renderer/null.rs @@ -41,7 +41,6 @@ impl text::Renderer for () { type Font = Font; type Paragraph = (); type Editor = (); - type Raw = (); const ICON_FONT: Font = Font::DEFAULT; const CHECKMARK_ICON: char = '0'; @@ -74,8 +73,6 @@ impl text::Renderer for () { ) { } - fn fill_raw(&mut self, _raw: Self::Raw) {} - fn fill_text( &mut self, _paragraph: Text, diff --git a/core/src/text.rs b/core/src/text.rs index b642c243..eddc0532 100644 --- a/core/src/text.rs +++ b/core/src/text.rs @@ -299,9 +299,6 @@ pub trait Renderer: crate::Renderer { /// The [`Editor`] of this [`Renderer`]. type Editor: Editor + 'static; - /// The `Raw` text of this [`Renderer`]. - type Raw: 'static; - /// The icon font of the backend. const ICON_FONT: Self::Font; @@ -346,9 +343,6 @@ pub trait Renderer: crate::Renderer { clip_bounds: Rectangle, ); - /// Draws the given `Raw` text. - fn fill_raw(&mut self, raw: Self::Raw); - /// Draws the given [`Text`] at the given position and with the given /// [`Color`]. fn fill_text( diff --git a/graphics/src/text.rs b/graphics/src/text.rs index 74ab6b84..35ff24fb 100644 --- a/graphics/src/text.rs +++ b/graphics/src/text.rs @@ -352,3 +352,9 @@ pub fn to_color(color: Color) -> cosmic_text::Color { cosmic_text::Color::rgba(r, g, b, a) } + +/// A text renderer coupled to `iced_graphics`. +pub trait Renderer { + /// Draws the given [`Raw`] text. + fn fill_raw(&mut self, raw: Raw); +} diff --git a/renderer/src/fallback.rs b/renderer/src/fallback.rs index fee0d462..61312bb0 100644 --- a/renderer/src/fallback.rs +++ b/renderer/src/fallback.rs @@ -8,6 +8,7 @@ use crate::core::{ }; use crate::graphics::compositor; use crate::graphics::mesh; +use crate::graphics::text; use crate::graphics::{self, Shell}; use std::borrow::Cow; @@ -88,13 +89,11 @@ where Font = A::Font, Paragraph = A::Paragraph, Editor = A::Editor, - Raw = A::Raw, >, { type Font = A::Font; type Paragraph = A::Paragraph; type Editor = A::Editor; - type Raw = A::Raw; const ICON_FONT: Self::Font = A::ICON_FONT; const CHECKMARK_ICON: char = A::CHECKMARK_ICON; @@ -137,10 +136,6 @@ where ); } - fn fill_raw(&mut self, raw: Self::Raw) { - delegate!(self, renderer, renderer.fill_raw(raw)); - } - fn fill_text( &mut self, text: core::Text, @@ -156,6 +151,16 @@ where } } +impl text::Renderer for Renderer +where + A: text::Renderer, + B: text::Renderer, +{ + fn fill_raw(&mut self, raw: text::Raw) { + delegate!(self, renderer, renderer.fill_raw(raw)); + } +} + impl image::Renderer for Renderer where A: image::Renderer, diff --git a/tiny_skia/src/lib.rs b/tiny_skia/src/lib.rs index 9a190f27..878c7a4e 100644 --- a/tiny_skia/src/lib.rs +++ b/tiny_skia/src/lib.rs @@ -35,7 +35,7 @@ use crate::core::{ use crate::engine::Engine; use crate::graphics::Viewport; use crate::graphics::compositor; -use crate::graphics::text::{Editor, Paragraph, Raw}; +use crate::graphics::text::{Editor, Paragraph}; /// A [`tiny-skia`] graphics renderer for [`iced`]. /// @@ -250,7 +250,6 @@ impl core::text::Renderer for Renderer { type Font = Font; type Paragraph = Paragraph; type Editor = Editor; - type Raw = Raw; const ICON_FONT: Font = Font::with_name("Iced-Icons"); const CHECKMARK_ICON: char = '\u{f00c}'; @@ -294,11 +293,6 @@ impl core::text::Renderer for Renderer { layer.draw_editor(editor, position, color, clip_bounds, transformation); } - fn fill_raw(&mut self, raw: Self::Raw) { - let (layer, transformation) = self.layers.current_mut(); - layer.draw_raw(raw, transformation); - } - fn fill_text( &mut self, text: core::Text, @@ -311,6 +305,13 @@ impl core::text::Renderer for Renderer { } } +impl graphics::text::Renderer for Renderer { + fn fill_raw(&mut self, raw: graphics::text::Raw) { + let (layer, transformation) = self.layers.current_mut(); + layer.draw_raw(raw, transformation); + } +} + #[cfg(feature = "geometry")] impl graphics::geometry::Renderer for Renderer { type Geometry = Geometry; diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 61908637..40ace65f 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -65,7 +65,7 @@ use crate::core::renderer; use crate::core::{ Background, Color, Font, Pixels, Point, Rectangle, Size, Transformation, }; -use crate::graphics::text::{Editor, Paragraph, Raw}; +use crate::graphics::text::{Editor, Paragraph}; use crate::graphics::{Shell, Viewport}; /// A [`wgpu`] graphics renderer for [`iced`]. @@ -717,7 +717,6 @@ impl core::text::Renderer for Renderer { type Font = Font; type Paragraph = Paragraph; type Editor = Editor; - type Raw = Raw; const ICON_FONT: Font = Font::with_name("Iced-Icons"); const CHECKMARK_ICON: char = '\u{f00c}'; @@ -761,11 +760,6 @@ impl core::text::Renderer for Renderer { layer.draw_editor(editor, position, color, clip_bounds, transformation); } - fn fill_raw(&mut self, raw: Self::Raw) { - let (layer, transformation) = self.layers.current_mut(); - layer.draw_raw(raw, transformation); - } - fn fill_text( &mut self, text: core::Text, @@ -778,6 +772,13 @@ impl core::text::Renderer for Renderer { } } +impl graphics::text::Renderer for Renderer { + fn fill_raw(&mut self, raw: graphics::text::Raw) { + let (layer, transformation) = self.layers.current_mut(); + layer.draw_raw(raw, transformation); + } +} + #[cfg(feature = "image")] impl core::image::Renderer for Renderer { type Handle = core::image::Handle; From 06f3472df5751f6b33d6d985275a40b969269de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 26 Nov 2025 00:45:07 +0100 Subject: [PATCH 4/4] Improve naming in `layer` modules --- tiny_skia/src/layer.rs | 24 ++++++++++++++---------- tiny_skia/src/lib.rs | 2 +- wgpu/src/layer.rs | 24 ++++++++++++++---------- wgpu/src/lib.rs | 2 +- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/tiny_skia/src/layer.rs b/tiny_skia/src/layer.rs index bc77680e..5f3979bf 100644 --- a/tiny_skia/src/layer.rs +++ b/tiny_skia/src/layer.rs @@ -5,7 +5,7 @@ use crate::core::{ }; use crate::graphics::damage; use crate::graphics::layer; -use crate::graphics::text::{Editor, Paragraph, Raw, Text}; +use crate::graphics::text::{Editor, Paragraph, Text}; use crate::graphics::{self, Image}; use std::sync::Arc; @@ -70,15 +70,6 @@ impl Layer { self.text.push(Item::Live(editor)); } - pub fn draw_raw(&mut self, raw: Raw, transformation: Transformation) { - let raw = Text::Raw { - raw, - transformation, - }; - - self.text.push(Item::Live(raw)); - } - pub fn draw_text( &mut self, text: core::Text, @@ -104,6 +95,19 @@ impl Layer { self.text.push(Item::Live(text)); } + pub fn draw_text_raw( + &mut self, + raw: graphics::text::Raw, + transformation: Transformation, + ) { + let raw = Text::Raw { + raw, + transformation, + }; + + self.text.push(Item::Live(raw)); + } + pub fn draw_text_group( &mut self, text: Vec, diff --git a/tiny_skia/src/lib.rs b/tiny_skia/src/lib.rs index 878c7a4e..5e219bd2 100644 --- a/tiny_skia/src/lib.rs +++ b/tiny_skia/src/lib.rs @@ -308,7 +308,7 @@ impl core::text::Renderer for Renderer { impl graphics::text::Renderer for Renderer { fn fill_raw(&mut self, raw: graphics::text::Raw) { let (layer, transformation) = self.layers.current_mut(); - layer.draw_raw(raw, transformation); + layer.draw_text_raw(raw, transformation); } } diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs index 2dc06a39..bb557edd 100644 --- a/wgpu/src/layer.rs +++ b/wgpu/src/layer.rs @@ -5,7 +5,7 @@ use crate::graphics; use crate::graphics::Mesh; use crate::graphics::color; use crate::graphics::layer; -use crate::graphics::text::{Editor, Paragraph, Raw}; +use crate::graphics::text::{Editor, Paragraph}; use crate::image::{self, Image}; use crate::primitive::{self, Primitive}; use crate::quad::{self, Quad}; @@ -101,15 +101,6 @@ impl Layer { self.pending_text.push(editor); } - pub fn draw_raw(&mut self, raw: Raw, transformation: Transformation) { - let raw = Text::Raw { - raw, - transformation, - }; - - self.pending_text.push(raw); - } - pub fn draw_text( &mut self, text: crate::core::Text, @@ -135,6 +126,19 @@ impl Layer { self.pending_text.push(text); } + pub fn draw_text_raw( + &mut self, + raw: graphics::text::Raw, + transformation: Transformation, + ) { + let raw = Text::Raw { + raw, + transformation, + }; + + self.pending_text.push(raw); + } + pub fn draw_image(&mut self, image: Image, transformation: Transformation) { match image { Image::Raster { diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 40ace65f..11e0f086 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -775,7 +775,7 @@ impl core::text::Renderer for Renderer { impl graphics::text::Renderer for Renderer { fn fill_raw(&mut self, raw: graphics::text::Raw) { let (layer, transformation) = self.layers.current_mut(); - layer.draw_raw(raw, transformation); + layer.draw_text_raw(raw, transformation); } }