use crate::values::computed::{Integer, LengthPercentage, NonNegativeNumber, Percentage};
use crate::values::generics::position::GenericAnchorFunction;
use crate::values::generics::position::Position as GenericPosition;
use crate::values::generics::position::PositionComponent as GenericPositionComponent;
use crate::values::generics::position::PositionOrAuto as GenericPositionOrAuto;
use crate::values::generics::position::ZIndex as GenericZIndex;
use crate::values::generics::position::{AspectRatio as GenericAspectRatio, GenericInset};
pub use crate::values::specified::position::{
AnchorName, AnchorScope, DashedIdentAndOrTryTactic, PositionAnchor, PositionArea,
PositionAreaKeyword, PositionTryFallbacks, PositionTryOrder, PositionVisibility,
};
pub use crate::values::specified::position::{GridAutoFlow, GridTemplateAreas, MasonryAutoFlow};
use crate::Zero;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};
pub type Position = GenericPosition<HorizontalPosition, VerticalPosition>;
pub type PositionOrAuto = GenericPositionOrAuto<Position>;
pub type HorizontalPosition = LengthPercentage;
pub type VerticalPosition = LengthPercentage;
pub type AnchorFunction = GenericAnchorFunction<Percentage, LengthPercentage>;
pub type Inset = GenericInset<Percentage, LengthPercentage>;
impl Position {
#[inline]
pub fn center() -> Self {
Self::new(
LengthPercentage::new_percent(Percentage(0.5)),
LengthPercentage::new_percent(Percentage(0.5)),
)
}
#[inline]
pub fn zero() -> Self {
Self::new(LengthPercentage::zero(), LengthPercentage::zero())
}
}
impl ToCss for Position {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
self.horizontal.to_css(dest)?;
dest.write_char(' ')?;
self.vertical.to_css(dest)
}
}
impl GenericPositionComponent for LengthPercentage {
fn is_center(&self) -> bool {
match self.to_percentage() {
Some(Percentage(per)) => per == 0.5,
_ => false,
}
}
}
pub type ZIndex = GenericZIndex<Integer>;
pub type AspectRatio = GenericAspectRatio<NonNegativeNumber>;