Frame debugging tools

This commit is contained in:
Laurenz 2023-01-22 13:21:35 +01:00
parent 760936af49
commit a2d77e36ba

View File

@ -362,6 +362,56 @@ impl Frame {
} }
} }
/// Tools for debugging.
impl Frame {
/// Add a full size aqua background and a red baseline for debugging.
pub fn debug(mut self) -> Self {
self.insert(
0,
Point::zero(),
Element::Shape(
Geometry::Rect(self.size)
.filled(RgbaColor { a: 100, ..Color::TEAL.to_rgba() }.into()),
),
);
self.insert(
1,
Point::with_y(self.baseline()),
Element::Shape(
Geometry::Line(Point::with_x(self.size.x)).stroked(Stroke {
paint: Color::RED.into(),
thickness: Abs::pt(1.0),
}),
),
);
self
}
/// Add a green marker at a position for debugging.
pub fn mark_point(&mut self, pos: Point) {
let radius = Abs::pt(2.0);
self.push(
pos - Point::splat(radius),
Element::Shape(geom::ellipse(
Size::splat(2.0 * radius),
Some(Color::GREEN.into()),
None,
)),
);
}
/// Add a green marker line at a position for debugging.
pub fn mark_line(&mut self, y: Abs) {
self.push(
Point::with_y(y),
Element::Shape(Geometry::Line(Point::with_x(self.size.x)).stroked(Stroke {
paint: Color::GREEN.into(),
thickness: Abs::pt(1.0),
})),
);
}
}
impl Debug for Frame { impl Debug for Frame {
fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn fmt(&self, f: &mut Formatter) -> fmt::Result {
f.debug_list() f.debug_list()