use super::{Smart, StyleChain}; use crate::geom::{Abs, Axes, Corners, Em, Length, Numeric, Rel, Sides}; use crate::library::text::TextNode; /// A property that is resolved with other properties from the style chain. pub trait Resolve { /// The type of the resolved output. type Output; /// Resolve the value using the style chain. fn resolve(self, styles: StyleChain) -> Self::Output; } impl Resolve for Em { type Output = Abs; fn resolve(self, styles: StyleChain) -> Self::Output { if self.is_zero() { Abs::zero() } else { self.at(styles.get(TextNode::SIZE)) } } } impl Resolve for Length { type Output = Abs; fn resolve(self, styles: StyleChain) -> Self::Output { self.abs + self.em.resolve(styles) } } impl Resolve for Option { type Output = Option; fn resolve(self, styles: StyleChain) -> Self::Output { self.map(|v| v.resolve(styles)) } } impl Resolve for Smart { type Output = Smart; fn resolve(self, styles: StyleChain) -> Self::Output { self.map(|v| v.resolve(styles)) } } impl Resolve for Axes { type Output = Axes; fn resolve(self, styles: StyleChain) -> Self::Output { self.map(|v| v.resolve(styles)) } } impl Resolve for Sides { type Output = Sides; fn resolve(self, styles: StyleChain) -> Self::Output { self.map(|v| v.resolve(styles)) } } impl Resolve for Corners { type Output = Corners; fn resolve(self, styles: StyleChain) -> Self::Output { self.map(|v| v.resolve(styles)) } } impl Resolve for Rel where T: Resolve + Numeric, ::Output: Numeric, { type Output = Rel<::Output>; fn resolve(self, styles: StyleChain) -> Self::Output { self.map(|abs| abs.resolve(styles)) } }