use std::fmt;
use crate::checked_value::impl_checked_value;
use crate::serialization::CssWriteTo;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum TouchActionHorizontalPan {
PanX,
PanLeft,
PanRight,
}
impl CssWriteTo for TouchActionHorizontalPan {
fn css_fmt<W: fmt::Write>(&self, w: &mut W) -> fmt::Result {
w.write_str(match self {
Self::PanX => "pan-x",
Self::PanLeft => "pan-left",
Self::PanRight => "pan-right",
})
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum TouchActionVerticalPan {
PanY,
PanUp,
PanDown,
}
impl CssWriteTo for TouchActionVerticalPan {
fn css_fmt<W: fmt::Write>(&self, w: &mut W) -> fmt::Result {
w.write_str(match self {
Self::PanY => "pan-y",
Self::PanUp => "pan-up",
Self::PanDown => "pan-down",
})
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct TouchActionGestures {
horizontal: Option<TouchActionHorizontalPan>,
vertical: Option<TouchActionVerticalPan>,
pinch_zoom: bool,
}
impl TouchActionGestures {
pub const fn horizontal(horizontal: TouchActionHorizontalPan) -> Self {
Self {
horizontal: Some(horizontal),
vertical: None,
pinch_zoom: false,
}
}
pub const fn vertical(vertical: TouchActionVerticalPan) -> Self {
Self {
horizontal: None,
vertical: Some(vertical),
pinch_zoom: false,
}
}
pub const fn pinch_zoom() -> Self {
Self {
horizontal: None,
vertical: None,
pinch_zoom: true,
}
}
#[must_use]
pub const fn with_horizontal(mut self, horizontal: TouchActionHorizontalPan) -> Self {
self.horizontal = Some(horizontal);
self
}
#[must_use]
pub const fn with_vertical(mut self, vertical: TouchActionVerticalPan) -> Self {
self.vertical = Some(vertical);
self
}
#[must_use]
pub const fn with_pinch_zoom(mut self) -> Self {
self.pinch_zoom = true;
self
}
}
impl CssWriteTo for TouchActionGestures {
fn css_fmt<W: fmt::Write>(&self, w: &mut W) -> fmt::Result {
let mut has_previous = false;
if let Some(horizontal) = self.horizontal {
horizontal.css_fmt(w)?;
has_previous = true;
}
if let Some(vertical) = self.vertical {
if has_previous {
w.write_char(' ')?;
}
vertical.css_fmt(w)?;
has_previous = true;
}
if self.pinch_zoom {
if has_previous {
w.write_char(' ')?;
}
w.write_str("pinch-zoom")?;
}
Ok(())
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum TouchAction {
Auto,
None,
Manipulation,
Gestures(TouchActionGestures),
}
impl From<TouchActionGestures> for TouchAction {
fn from(value: TouchActionGestures) -> Self {
Self::Gestures(value)
}
}
impl CssWriteTo for TouchAction {
fn css_fmt<W: fmt::Write>(&self, w: &mut W) -> fmt::Result {
match self {
Self::Auto => w.write_str("auto"),
Self::None => w.write_str("none"),
Self::Manipulation => w.write_str("manipulation"),
Self::Gestures(value) => value.css_fmt(w),
}
}
}
impl_checked_value!(
TouchActionHorizontalPan,
TouchActionVerticalPan,
TouchActionGestures,
TouchAction,
);