mirror of
https://github.com/typst/typst
synced 2025-05-13 12:36:23 +08:00
Frame debugging tools
This commit is contained in:
parent
760936af49
commit
a2d77e36ba
50
src/doc.rs
50
src/doc.rs
@ -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 {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
f.debug_list()
|
||||
|
Loading…
x
Reference in New Issue
Block a user