style/values/computed/
resolution.rs1use crate::derives::*;
10use crate::typed_om::{NumericValue, ToTyped, TypedValue, UnitValue};
11use crate::values::CSSFloat;
12use std::{
13 fmt::{self, Write},
14 ops::AddAssign,
15};
16use style_traits::{CssString, CssWriter, ToCss};
17use thin_vec::ThinVec;
18
19#[repr(C)]
21#[derive(
22 Animate,
23 Copy,
24 Clone,
25 Debug,
26 Deserialize,
27 MallocSizeOf,
28 PartialEq,
29 PartialOrd,
30 Serialize,
31 ToAnimatedZero,
32 ToResolvedValue,
33 ToShmem,
34)]
35pub struct Resolution(CSSFloat);
36
37impl Resolution {
38 #[inline]
40 pub fn dppx(&self) -> CSSFloat {
41 self.0
42 }
43
44 #[inline]
46 pub fn from_dppx(dppx: CSSFloat) -> Self {
47 Resolution(dppx)
48 }
49}
50
51impl ToCss for Resolution {
52 fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
53 where
54 W: fmt::Write,
55 {
56 self.dppx().to_css(dest)?;
57 dest.write_str("dppx")
58 }
59}
60
61impl ToTyped for Resolution {
62 fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()> {
63 dest.push(TypedValue::Numeric(NumericValue::Unit(UnitValue {
64 value: self.dppx(),
65 unit: CssString::from("dppx"),
66 })));
67 Ok(())
68 }
69}
70
71impl AddAssign for Resolution {
72 fn add_assign(&mut self, rhs: Self) {
73 self.0 += rhs.0
74 }
75}