More compact debug output for CSS values

```
Rect {
    start_corner: Vec2 { i: 0.0 px, b: 0.0 px },
    size: Vec2 { i: 1024.0 px, b: 20.0 px },
}
```

… instead of:

```
Rect {
    start_corner: Vec2 {
        inline: CSSPixelLength(
            0.0,
        ),
        block: CSSPixelLength(
            0.0,
        ),
    },
    size: Vec2 {
        inline: CSSPixelLength(
            1024.0,
        ),
        block: CSSPixelLength(
            0.0,
        ),
    },
}
```
This commit is contained in:
Simon Sapin 2019-10-15 17:55:57 +02:00
parent cfc3ffcd54
commit 13e494d74f
2 changed files with 32 additions and 3 deletions

View file

@ -3,6 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::style_ext::{Direction, WritingMode};
use std::fmt;
use std::ops::{Add, AddAssign, Sub};
use style::values::computed::{Length, LengthOrAuto, LengthPercentage, LengthPercentageOrAuto};
use style::Zero;
@ -13,7 +14,7 @@ pub type Size<U> = euclid::Size2D<f32, U>;
pub type Rect<U> = euclid::Rect<f32, U>;
pub(crate) mod physical {
#[derive(Clone, Debug)]
#[derive(Clone)]
pub(crate) struct Vec2<T> {
pub x: T,
pub y: T,
@ -35,7 +36,7 @@ pub(crate) mod physical {
}
pub(crate) mod flow_relative {
#[derive(Clone, Debug)]
#[derive(Clone)]
pub(crate) struct Vec2<T> {
pub inline: T,
pub block: T,
@ -56,6 +57,28 @@ pub(crate) mod flow_relative {
}
}
impl<T: fmt::Debug> fmt::Debug for physical::Vec2<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// Not using f.debug_struct on purpose here, to keep {:?} output somewhat compact
f.write_str("Vec2 { x: ")?;
self.x.fmt(f)?;
f.write_str(", y: ")?;
self.y.fmt(f)?;
f.write_str(" }")
}
}
impl<T: fmt::Debug> fmt::Debug for flow_relative::Vec2<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// Not using f.debug_struct on purpose here, to keep {:?} output somewhat compact
f.write_str("Vec2 { i: ")?;
self.inline.fmt(f)?;
f.write_str(", b: ")?;
self.block.fmt(f)?;
f.write_str(" }")
}
}
impl<T> Add<&'_ physical::Vec2<T>> for &'_ physical::Vec2<T>
where
T: Add<Output = T> + Copy,

View file

@ -611,7 +611,6 @@ impl Size {
Clone,
ComputeSquaredDistance,
Copy,
Debug,
MallocSizeOf,
PartialEq,
PartialOrd,
@ -623,6 +622,13 @@ impl Size {
#[repr(C)]
pub struct CSSPixelLength(CSSFloat);
impl fmt::Debug for CSSPixelLength {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)?;
f.write_str(" px")
}
}
impl CSSPixelLength {
/// Return a new CSSPixelLength.
#[inline]