use crate::derives::*;
use crate::typed_om::{NumericValue, ToTyped, TypedValue, UnitValue};
use crate::values::CSSFloat;
use std::{
fmt::{self, Write},
ops::AddAssign,
};
use style_traits::{CssString, CssWriter, ToCss};
use thin_vec::ThinVec;
#[repr(C)]
#[derive(
Animate,
Copy,
Clone,
Debug,
Deserialize,
MallocSizeOf,
PartialEq,
PartialOrd,
Serialize,
ToAnimatedZero,
ToResolvedValue,
ToShmem,
)]
pub struct Resolution(CSSFloat);
impl Resolution {
#[inline]
pub fn dppx(&self) -> CSSFloat {
self.0
}
#[inline]
pub fn from_dppx(dppx: CSSFloat) -> Self {
Resolution(dppx)
}
}
impl ToCss for Resolution {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: fmt::Write,
{
self.dppx().to_css(dest)?;
dest.write_str("dppx")
}
}
impl ToTyped for Resolution {
fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()> {
dest.push(TypedValue::Numeric(NumericValue::Unit(UnitValue {
value: self.dppx(),
unit: CssString::from("dppx"),
})));
Ok(())
}
}
impl AddAssign for Resolution {
fn add_assign(&mut self, rhs: Self) {
self.0 += rhs.0
}
}