diff options
author | 2023-02-26 23:59:00 +0100 | |
---|---|---|
committer | 2023-02-26 23:59:00 +0100 | |
commit | 53573cf7cfd48f9bfd97d9e8b82308a0290d2b9d (patch) | |
tree | 99e8570bd92fab0efc52befac3c539e2d7d6ef4d /tiny_skia | |
parent | 4067c427db19eb59c4ec6c8c6d6658a9643df580 (diff) | |
download | iced-53573cf7cfd48f9bfd97d9e8b82308a0290d2b9d.tar.gz iced-53573cf7cfd48f9bfd97d9e8b82308a0290d2b9d.tar.bz2 iced-53573cf7cfd48f9bfd97d9e8b82308a0290d2b9d.zip |
Draw debug overlay in `iced_tiny_skia`
Diffstat (limited to 'tiny_skia')
-rw-r--r-- | tiny_skia/src/backend.rs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/tiny_skia/src/backend.rs b/tiny_skia/src/backend.rs index 5e743479..cefed71f 100644 --- a/tiny_skia/src/backend.rs +++ b/tiny_skia/src/backend.rs @@ -1,5 +1,6 @@ use crate::{Color, Font, Settings, Size, Viewport}; +use iced_graphics::alignment; use iced_graphics::backend; use iced_graphics::text; use iced_graphics::{Background, Primitive, Rectangle, Vector}; @@ -27,7 +28,7 @@ impl Backend { primitives: &[Primitive], viewport: &Viewport, background_color: Color, - _overlay: &[T], + overlay: &[T], ) { pixels.fill(into_color(background_color)); @@ -43,6 +44,31 @@ impl Backend { ); } + for (i, text) in overlay.iter().enumerate() { + const OVERLAY_TEXT_SIZE: f32 = 20.0; + + self.draw_primitive( + &Primitive::Text { + content: text.as_ref().to_owned(), + size: OVERLAY_TEXT_SIZE, + bounds: Rectangle { + x: 10.0, + y: 10.0 + i as f32 * OVERLAY_TEXT_SIZE * 1.2, + width: f32::INFINITY, + height: f32::INFINITY, + }, + color: Color::BLACK, + font: Font::Monospace, + horizontal_alignment: alignment::Horizontal::Left, + vertical_alignment: alignment::Vertical::Top, + }, + pixels, + None, + scale_factor, + Vector::ZERO, + ); + } + self.text_pipeline.end_frame(); } |