leptos_css/
touch_action.rs1use std::fmt;
2
3use crate::checked_value::impl_checked_value;
4use crate::serialization::CssWriteTo;
5
6#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
10#[non_exhaustive]
11pub enum TouchActionHorizontalPan {
12 PanX,
14 PanLeft,
16 PanRight,
18}
19
20impl CssWriteTo for TouchActionHorizontalPan {
21 fn css_fmt<W: fmt::Write>(&self, w: &mut W) -> fmt::Result {
22 w.write_str(match self {
23 Self::PanX => "pan-x",
24 Self::PanLeft => "pan-left",
25 Self::PanRight => "pan-right",
26 })
27 }
28}
29
30#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
34#[non_exhaustive]
35pub enum TouchActionVerticalPan {
36 PanY,
38 PanUp,
40 PanDown,
42}
43
44impl CssWriteTo for TouchActionVerticalPan {
45 fn css_fmt<W: fmt::Write>(&self, w: &mut W) -> fmt::Result {
46 w.write_str(match self {
47 Self::PanY => "pan-y",
48 Self::PanUp => "pan-up",
49 Self::PanDown => "pan-down",
50 })
51 }
52}
53
54#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
62pub struct TouchActionGestures {
63 horizontal: Option<TouchActionHorizontalPan>,
64 vertical: Option<TouchActionVerticalPan>,
65 pinch_zoom: bool,
66}
67
68impl TouchActionGestures {
69 pub const fn horizontal(horizontal: TouchActionHorizontalPan) -> Self {
71 Self {
72 horizontal: Some(horizontal),
73 vertical: None,
74 pinch_zoom: false,
75 }
76 }
77
78 pub const fn vertical(vertical: TouchActionVerticalPan) -> Self {
80 Self {
81 horizontal: None,
82 vertical: Some(vertical),
83 pinch_zoom: false,
84 }
85 }
86
87 pub const fn pinch_zoom() -> Self {
89 Self {
90 horizontal: None,
91 vertical: None,
92 pinch_zoom: true,
93 }
94 }
95
96 #[must_use]
98 pub const fn with_horizontal(mut self, horizontal: TouchActionHorizontalPan) -> Self {
99 self.horizontal = Some(horizontal);
100 self
101 }
102
103 #[must_use]
105 pub const fn with_vertical(mut self, vertical: TouchActionVerticalPan) -> Self {
106 self.vertical = Some(vertical);
107 self
108 }
109
110 #[must_use]
112 pub const fn with_pinch_zoom(mut self) -> Self {
113 self.pinch_zoom = true;
114 self
115 }
116}
117
118impl CssWriteTo for TouchActionGestures {
119 fn css_fmt<W: fmt::Write>(&self, w: &mut W) -> fmt::Result {
120 let mut has_previous = false;
121
122 if let Some(horizontal) = self.horizontal {
123 horizontal.css_fmt(w)?;
124 has_previous = true;
125 }
126 if let Some(vertical) = self.vertical {
127 if has_previous {
128 w.write_char(' ')?;
129 }
130 vertical.css_fmt(w)?;
131 has_previous = true;
132 }
133 if self.pinch_zoom {
134 if has_previous {
135 w.write_char(' ')?;
136 }
137 w.write_str("pinch-zoom")?;
138 }
139
140 Ok(())
141 }
142}
143
144#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
153#[non_exhaustive]
154pub enum TouchAction {
155 Auto,
157 None,
159 Manipulation,
161 Gestures(TouchActionGestures),
163}
164
165impl From<TouchActionGestures> for TouchAction {
166 fn from(value: TouchActionGestures) -> Self {
167 Self::Gestures(value)
168 }
169}
170
171impl CssWriteTo for TouchAction {
172 fn css_fmt<W: fmt::Write>(&self, w: &mut W) -> fmt::Result {
173 match self {
174 Self::Auto => w.write_str("auto"),
175 Self::None => w.write_str("none"),
176 Self::Manipulation => w.write_str("manipulation"),
177 Self::Gestures(value) => value.css_fmt(w),
178 }
179 }
180}
181
182impl_checked_value!(
183 TouchActionHorizontalPan,
184 TouchActionVerticalPan,
185 TouchActionGestures,
186 TouchAction,
187);