feat: add fill_raw method and Raw associated type for text::Renderer

This commit is contained in:
pml68 2025-05-25 21:08:31 +02:00 committed by Héctor Ramón Jiménez
parent 6bbe189809
commit b26890f76e
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
7 changed files with 49 additions and 4 deletions

View file

@ -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,

View file

@ -299,6 +299,9 @@ pub trait Renderer: crate::Renderer {
/// The [`Editor`] of this [`Renderer`].
type Editor: Editor<Font = Self::Font> + '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(

View file

@ -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<String, Self::Font>,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,