Introduce RawText to Primitive in iced_graphics

This should allow users to directly render a
`cosmic_text::Buffer`.
This commit is contained in:
Héctor Ramón Jiménez 2023-12-05 02:19:17 +01:00
parent fc285d3e46
commit 603832e66c
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
8 changed files with 131 additions and 4 deletions

View file

@ -1,5 +1,6 @@
use crate::core::{Background, Color, Gradient, Rectangle, Vector};
use crate::graphics::backend;
use crate::graphics::text;
use crate::graphics::Viewport;
use crate::primitive::{self, Primitive};
@ -444,6 +445,35 @@ impl Backend {
clip_mask,
);
}
Primitive::RawText(text::Raw {
buffer,
position,
color,
clip_bounds: text_clip_bounds,
}) => {
let Some(buffer) = buffer.upgrade() else {
return;
};
let physical_bounds =
(*text_clip_bounds + translation) * scale_factor;
if !clip_bounds.intersects(&physical_bounds) {
return;
}
let clip_mask = (!physical_bounds.is_within(&clip_bounds))
.then_some(clip_mask as &_);
self.text_pipeline.draw_raw(
&buffer,
*position + translation,
*color,
scale_factor,
pixels,
clip_mask,
);
}
#[cfg(feature = "image")]
Primitive::Image {
handle,