Replace Raw in core::text::Renderer with a new Renderer trait
This commit is contained in:
parent
4ea0db665f
commit
a0b409ed7e
6 changed files with 33 additions and 29 deletions
|
|
@ -41,7 +41,6 @@ impl text::Renderer for () {
|
||||||
type Font = Font;
|
type Font = Font;
|
||||||
type Paragraph = ();
|
type Paragraph = ();
|
||||||
type Editor = ();
|
type Editor = ();
|
||||||
type Raw = ();
|
|
||||||
|
|
||||||
const ICON_FONT: Font = Font::DEFAULT;
|
const ICON_FONT: Font = Font::DEFAULT;
|
||||||
const CHECKMARK_ICON: char = '0';
|
const CHECKMARK_ICON: char = '0';
|
||||||
|
|
@ -74,8 +73,6 @@ impl text::Renderer for () {
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fill_raw(&mut self, _raw: Self::Raw) {}
|
|
||||||
|
|
||||||
fn fill_text(
|
fn fill_text(
|
||||||
&mut self,
|
&mut self,
|
||||||
_paragraph: Text,
|
_paragraph: Text,
|
||||||
|
|
|
||||||
|
|
@ -299,9 +299,6 @@ pub trait Renderer: crate::Renderer {
|
||||||
/// The [`Editor`] of this [`Renderer`].
|
/// The [`Editor`] of this [`Renderer`].
|
||||||
type Editor: Editor<Font = Self::Font> + 'static;
|
type Editor: Editor<Font = Self::Font> + 'static;
|
||||||
|
|
||||||
/// The `Raw` text of this [`Renderer`].
|
|
||||||
type Raw: 'static;
|
|
||||||
|
|
||||||
/// The icon font of the backend.
|
/// The icon font of the backend.
|
||||||
const ICON_FONT: Self::Font;
|
const ICON_FONT: Self::Font;
|
||||||
|
|
||||||
|
|
@ -346,9 +343,6 @@ pub trait Renderer: crate::Renderer {
|
||||||
clip_bounds: Rectangle,
|
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
|
/// Draws the given [`Text`] at the given position and with the given
|
||||||
/// [`Color`].
|
/// [`Color`].
|
||||||
fn fill_text(
|
fn fill_text(
|
||||||
|
|
|
||||||
|
|
@ -352,3 +352,9 @@ pub fn to_color(color: Color) -> cosmic_text::Color {
|
||||||
|
|
||||||
cosmic_text::Color::rgba(r, g, b, a)
|
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);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use crate::core::{
|
||||||
};
|
};
|
||||||
use crate::graphics::compositor;
|
use crate::graphics::compositor;
|
||||||
use crate::graphics::mesh;
|
use crate::graphics::mesh;
|
||||||
|
use crate::graphics::text;
|
||||||
use crate::graphics::{self, Shell};
|
use crate::graphics::{self, Shell};
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
@ -88,13 +89,11 @@ where
|
||||||
Font = A::Font,
|
Font = A::Font,
|
||||||
Paragraph = A::Paragraph,
|
Paragraph = A::Paragraph,
|
||||||
Editor = A::Editor,
|
Editor = A::Editor,
|
||||||
Raw = A::Raw,
|
|
||||||
>,
|
>,
|
||||||
{
|
{
|
||||||
type Font = A::Font;
|
type Font = A::Font;
|
||||||
type Paragraph = A::Paragraph;
|
type Paragraph = A::Paragraph;
|
||||||
type Editor = A::Editor;
|
type Editor = A::Editor;
|
||||||
type Raw = A::Raw;
|
|
||||||
|
|
||||||
const ICON_FONT: Self::Font = A::ICON_FONT;
|
const ICON_FONT: Self::Font = A::ICON_FONT;
|
||||||
const CHECKMARK_ICON: char = A::CHECKMARK_ICON;
|
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(
|
fn fill_text(
|
||||||
&mut self,
|
&mut self,
|
||||||
text: core::Text<String, Self::Font>,
|
text: core::Text<String, Self::Font>,
|
||||||
|
|
@ -156,6 +151,16 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<A, B> text::Renderer for Renderer<A, B>
|
||||||
|
where
|
||||||
|
A: text::Renderer,
|
||||||
|
B: text::Renderer,
|
||||||
|
{
|
||||||
|
fn fill_raw(&mut self, raw: text::Raw) {
|
||||||
|
delegate!(self, renderer, renderer.fill_raw(raw));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<A, B> image::Renderer for Renderer<A, B>
|
impl<A, B> image::Renderer for Renderer<A, B>
|
||||||
where
|
where
|
||||||
A: image::Renderer,
|
A: image::Renderer,
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ use crate::core::{
|
||||||
use crate::engine::Engine;
|
use crate::engine::Engine;
|
||||||
use crate::graphics::Viewport;
|
use crate::graphics::Viewport;
|
||||||
use crate::graphics::compositor;
|
use crate::graphics::compositor;
|
||||||
use crate::graphics::text::{Editor, Paragraph, Raw};
|
use crate::graphics::text::{Editor, Paragraph};
|
||||||
|
|
||||||
/// A [`tiny-skia`] graphics renderer for [`iced`].
|
/// A [`tiny-skia`] graphics renderer for [`iced`].
|
||||||
///
|
///
|
||||||
|
|
@ -250,7 +250,6 @@ impl core::text::Renderer for Renderer {
|
||||||
type Font = Font;
|
type Font = Font;
|
||||||
type Paragraph = Paragraph;
|
type Paragraph = Paragraph;
|
||||||
type Editor = Editor;
|
type Editor = Editor;
|
||||||
type Raw = Raw;
|
|
||||||
|
|
||||||
const ICON_FONT: Font = Font::with_name("Iced-Icons");
|
const ICON_FONT: Font = Font::with_name("Iced-Icons");
|
||||||
const CHECKMARK_ICON: char = '\u{f00c}';
|
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);
|
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(
|
fn fill_text(
|
||||||
&mut self,
|
&mut self,
|
||||||
text: core::Text,
|
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")]
|
#[cfg(feature = "geometry")]
|
||||||
impl graphics::geometry::Renderer for Renderer {
|
impl graphics::geometry::Renderer for Renderer {
|
||||||
type Geometry = Geometry;
|
type Geometry = Geometry;
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ use crate::core::renderer;
|
||||||
use crate::core::{
|
use crate::core::{
|
||||||
Background, Color, Font, Pixels, Point, Rectangle, Size, Transformation,
|
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};
|
use crate::graphics::{Shell, Viewport};
|
||||||
|
|
||||||
/// A [`wgpu`] graphics renderer for [`iced`].
|
/// A [`wgpu`] graphics renderer for [`iced`].
|
||||||
|
|
@ -717,7 +717,6 @@ impl core::text::Renderer for Renderer {
|
||||||
type Font = Font;
|
type Font = Font;
|
||||||
type Paragraph = Paragraph;
|
type Paragraph = Paragraph;
|
||||||
type Editor = Editor;
|
type Editor = Editor;
|
||||||
type Raw = Raw;
|
|
||||||
|
|
||||||
const ICON_FONT: Font = Font::with_name("Iced-Icons");
|
const ICON_FONT: Font = Font::with_name("Iced-Icons");
|
||||||
const CHECKMARK_ICON: char = '\u{f00c}';
|
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);
|
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(
|
fn fill_text(
|
||||||
&mut self,
|
&mut self,
|
||||||
text: core::Text,
|
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")]
|
#[cfg(feature = "image")]
|
||||||
impl core::image::Renderer for Renderer {
|
impl core::image::Renderer for Renderer {
|
||||||
type Handle = core::image::Handle;
|
type Handle = core::image::Handle;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue