Skip to content

Commit

Permalink
Add a custom Debug formatter for ClippingRegion
Browse files Browse the repository at this point in the history
This will make display list dumps more likely to fit on a single line.
  • Loading branch information
mrobinson committed Oct 11, 2016
1 parent cad5a4e commit 3474a2f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion components/gfx/display_list/mod.rs
Expand Up @@ -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>,
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 3474a2f

Please sign in to comment.