Merge pull request #2158 from iced-rs/feature/raw-text-primitive
Introduce `RawText` to `Primitive` in `iced_graphics`
This commit is contained in:
commit
a5ae442819
8 changed files with 131 additions and 4 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::core::alignment;
|
||||
use crate::core::text::{LineHeight, Shaping};
|
||||
use crate::core::{Color, Font, Pixels, Point, Rectangle};
|
||||
use crate::core::{Color, Font, Pixels, Point, Rectangle, Size};
|
||||
use crate::graphics::color;
|
||||
use crate::graphics::text::cache::{self, Cache};
|
||||
use crate::graphics::text::editor;
|
||||
|
|
@ -149,6 +149,33 @@ impl Pipeline {
|
|||
);
|
||||
}
|
||||
|
||||
pub fn draw_raw(
|
||||
&mut self,
|
||||
buffer: &cosmic_text::Buffer,
|
||||
position: Point,
|
||||
color: Color,
|
||||
scale_factor: f32,
|
||||
pixels: &mut tiny_skia::PixmapMut<'_>,
|
||||
clip_mask: Option<&tiny_skia::Mask>,
|
||||
) {
|
||||
let mut font_system = font_system().write().expect("Write font system");
|
||||
|
||||
let (width, height) = buffer.size();
|
||||
|
||||
draw(
|
||||
font_system.raw(),
|
||||
&mut self.glyph_cache,
|
||||
buffer,
|
||||
Rectangle::new(position, Size::new(width, height)),
|
||||
color,
|
||||
alignment::Horizontal::Left,
|
||||
alignment::Vertical::Top,
|
||||
scale_factor,
|
||||
pixels,
|
||||
clip_mask,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn trim_cache(&mut self) {
|
||||
self.cache.get_mut().trim();
|
||||
self.glyph_cache.trim();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue