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)
|
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;
|
||||||
|
|
@ -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>
|
impl<A, B> image::Renderer for Renderer<A, B>
|
||||||
where
|
where
|
||||||
A: image::Renderer,
|
A: image::Renderer,
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,19 @@ impl Layer {
|
||||||
self.text.push(Item::Live(text));
|
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(
|
pub fn draw_text_group(
|
||||||
&mut self,
|
&mut self,
|
||||||
text: Vec<Text>,
|
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")]
|
#[cfg(feature = "geometry")]
|
||||||
impl graphics::geometry::Renderer for Renderer {
|
impl graphics::geometry::Renderer for Renderer {
|
||||||
type Geometry = Geometry;
|
type Geometry = Geometry;
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,19 @@ impl Layer {
|
||||||
self.pending_text.push(text);
|
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) {
|
pub fn draw_image(&mut self, image: Image, transformation: Transformation) {
|
||||||
match image {
|
match image {
|
||||||
Image::Raster {
|
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")]
|
#[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