Draw debug overlay in iced_tiny_skia

This commit is contained in:
Héctor Ramón Jiménez 2023-02-26 23:59:00 +01:00
parent 4067c427db
commit 53573cf7cf
No known key found for this signature in database
GPG key ID: 140CC052C94F138E

View file

@ -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();
}