From 13e494d74f6ae4f6e41eaa96a89dec392bd33d93 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 15 Oct 2019 17:55:57 +0200 Subject: [PATCH] More compact debug output for CSS values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` 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, ), }, } ``` --- components/layout_2020/geom.rs | 27 ++++++++++++++++++++-- components/style/values/computed/length.rs | 8 ++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/components/layout_2020/geom.rs b/components/layout_2020/geom.rs index a56ee5c7613..f37685821a3 100644 --- a/components/layout_2020/geom.rs +++ b/components/layout_2020/geom.rs @@ -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 = euclid::Size2D; pub type Rect = euclid::Rect; pub(crate) mod physical { - #[derive(Clone, Debug)] + #[derive(Clone)] pub(crate) struct Vec2 { 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 { pub inline: T, pub block: T, @@ -56,6 +57,28 @@ pub(crate) mod flow_relative { } } +impl fmt::Debug for physical::Vec2 { + 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 fmt::Debug for flow_relative::Vec2 { + 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 Add<&'_ physical::Vec2> for &'_ physical::Vec2 where T: Add + Copy, diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 9bfad708a64..6d61198d364 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -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]