mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
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:
parent
cfc3ffcd54
commit
13e494d74f
2 changed files with 32 additions and 3 deletions
|
@ -3,6 +3,7 @@
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use crate::style_ext::{Direction, WritingMode};
|
use crate::style_ext::{Direction, WritingMode};
|
||||||
|
use std::fmt;
|
||||||
use std::ops::{Add, AddAssign, Sub};
|
use std::ops::{Add, AddAssign, Sub};
|
||||||
use style::values::computed::{Length, LengthOrAuto, LengthPercentage, LengthPercentageOrAuto};
|
use style::values::computed::{Length, LengthOrAuto, LengthPercentage, LengthPercentageOrAuto};
|
||||||
use style::Zero;
|
use style::Zero;
|
||||||
|
@ -13,7 +14,7 @@ pub type Size<U> = euclid::Size2D<f32, U>;
|
||||||
pub type Rect<U> = euclid::Rect<f32, U>;
|
pub type Rect<U> = euclid::Rect<f32, U>;
|
||||||
|
|
||||||
pub(crate) mod physical {
|
pub(crate) mod physical {
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct Vec2<T> {
|
pub(crate) struct Vec2<T> {
|
||||||
pub x: T,
|
pub x: T,
|
||||||
pub y: T,
|
pub y: T,
|
||||||
|
@ -35,7 +36,7 @@ pub(crate) mod physical {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) mod flow_relative {
|
pub(crate) mod flow_relative {
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct Vec2<T> {
|
pub(crate) struct Vec2<T> {
|
||||||
pub inline: T,
|
pub inline: T,
|
||||||
pub block: 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>
|
impl<T> Add<&'_ physical::Vec2<T>> for &'_ physical::Vec2<T>
|
||||||
where
|
where
|
||||||
T: Add<Output = T> + Copy,
|
T: Add<Output = T> + Copy,
|
||||||
|
|
|
@ -611,7 +611,6 @@ impl Size {
|
||||||
Clone,
|
Clone,
|
||||||
ComputeSquaredDistance,
|
ComputeSquaredDistance,
|
||||||
Copy,
|
Copy,
|
||||||
Debug,
|
|
||||||
MallocSizeOf,
|
MallocSizeOf,
|
||||||
PartialEq,
|
PartialEq,
|
||||||
PartialOrd,
|
PartialOrd,
|
||||||
|
@ -623,6 +622,13 @@ impl Size {
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct CSSPixelLength(CSSFloat);
|
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 {
|
impl CSSPixelLength {
|
||||||
/// Return a new CSSPixelLength.
|
/// Return a new CSSPixelLength.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue