Merge pull request #2958 from pml68/feat/fill-raw
Add `fill_raw` method and `Raw` associated type to text Renderer
This commit is contained in:
commit
c99f4d08f0
6 changed files with 57 additions and 0 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -150,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>
|
||||
where
|
||||
A: image::Renderer,
|
||||
|
|
|
|||
|
|
@ -95,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<Text>,
|
||||
|
|
|
|||
|
|
@ -305,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_text_raw(raw, transformation);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "geometry")]
|
||||
impl graphics::geometry::Renderer for Renderer {
|
||||
type Geometry = Geometry;
|
||||
|
|
|
|||
|
|
@ -126,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 {
|
||||
|
|
|
|||
|
|
@ -772,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_text_raw(raw, transformation);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "image")]
|
||||
impl core::image::Renderer for Renderer {
|
||||
type Handle = core::image::Handle;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue