Add a custom Debug formatter for ClippingRegion

This will make display list dumps more likely to fit on a single line.
This commit is contained in:
Martin Robinson 2016-10-11 12:18:23 +02:00
parent cad5a4e326
commit 3474a2f9e1

View file

@ -897,7 +897,7 @@ impl BaseDisplayItem {
/// A clipping region for a display item. Currently, this can describe rectangles, rounded
/// rectangles (for `border-radius`), or arbitrary intersections of the two. Arbitrary transforms
/// are not supported because those are handled by the higher-level `StackingContext` abstraction.
#[derive(Clone, PartialEq, Debug, HeapSizeOf, Deserialize, Serialize)]
#[derive(Clone, PartialEq, HeapSizeOf, Deserialize, Serialize)]
pub struct ClippingRegion {
/// The main rectangular region. This does not include any corners.
pub main: Rect<Au>,
@ -1043,6 +1043,20 @@ impl ClippingRegion {
}
}
impl fmt::Debug for ClippingRegion {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if *self == ClippingRegion::max() {
write!(f, "ClippingRegion::Max")
} else if *self == ClippingRegion::empty() {
write!(f, "ClippingRegion::Empty")
} else if self.main == max_rect() {
write!(f, "ClippingRegion(Complex={:?})", self.complex)
} else {
write!(f, "ClippingRegion(Rect={:?}, Complex={:?})", self.main, self.complex)
}
}
}
impl ComplexClippingRegion {
// TODO(pcwalton): This could be more aggressive by considering points that touch the inside of
// the border radius ellipse.