1use std::{fmt, time::Duration};
4
5use serde::{Deserialize, Serialize};
6
7use zng_txt::Txt;
8use zng_unit::{Dip, DipSize, Rgba};
9
10#[derive(Debug, Clone, Copy, Serialize, PartialEq, Eq, Deserialize)]
12#[non_exhaustive]
13pub struct MultiClickConfig {
14 pub time: Duration,
18
19 pub area: DipSize,
23}
24impl MultiClickConfig {
25 pub fn new(time: Duration, area: DipSize) -> Self {
27 Self { time, area }
28 }
29}
30impl Default for MultiClickConfig {
31 fn default() -> Self {
33 Self {
34 time: Duration::from_millis(500),
35 area: DipSize::splat(Dip::new(4)),
36 }
37 }
38}
39
40#[derive(Debug, Clone, Copy, Serialize, PartialEq, Eq, Deserialize)]
42#[non_exhaustive]
43pub struct TouchConfig {
44 pub tap_area: DipSize,
49
50 pub double_tap_area: DipSize,
54
55 pub tap_max_time: Duration,
59
60 pub double_tap_max_time: Duration,
62
63 pub min_fling_velocity: Dip,
65
66 pub max_fling_velocity: Dip,
68}
69
70impl TouchConfig {
71 pub fn new(
73 tap_area: DipSize,
74 double_tap_area: DipSize,
75 tap_max_time: Duration,
76 double_tap_max_time: Duration,
77 min_fling_velocity: Dip,
78 max_fling_velocity: Dip,
79 ) -> Self {
80 Self {
81 tap_area,
82 double_tap_area,
83 tap_max_time,
84 double_tap_max_time,
85 min_fling_velocity,
86 max_fling_velocity,
87 }
88 }
89}
90impl Default for TouchConfig {
91 fn default() -> Self {
92 Self {
93 tap_area: DipSize::splat(Dip::new(8)),
94 double_tap_area: DipSize::splat(Dip::new(28)),
95 tap_max_time: Duration::from_millis(500),
96 double_tap_max_time: Duration::from_millis(500),
97 min_fling_velocity: Dip::new(50),
98 max_fling_velocity: Dip::new(8000),
99 }
100 }
101}
102
103#[derive(Debug, Clone, Copy, Serialize, PartialEq, Eq, Deserialize)]
105#[non_exhaustive]
106pub struct KeyRepeatConfig {
107 pub start_delay: Duration,
109 pub interval: Duration,
111}
112impl KeyRepeatConfig {
113 pub fn new(start_delay: Duration, interval: Duration) -> Self {
115 Self { start_delay, interval }
116 }
117}
118impl Default for KeyRepeatConfig {
119 fn default() -> Self {
121 Self {
122 start_delay: Duration::from_millis(600),
123 interval: Duration::from_millis(100),
124 }
125 }
126}
127
128#[derive(Debug, Clone, Copy, Serialize, PartialEq, Eq, Deserialize)]
130#[non_exhaustive]
131pub struct AnimationsConfig {
132 pub enabled: bool,
136
137 pub caret_blink_interval: Duration,
141 pub caret_blink_timeout: Duration,
143}
144impl AnimationsConfig {
145 pub fn new(enabled: bool, caret_blink_interval: Duration, caret_blink_timeout: Duration) -> Self {
147 Self {
148 enabled,
149 caret_blink_interval,
150 caret_blink_timeout,
151 }
152 }
153}
154impl Default for AnimationsConfig {
155 fn default() -> Self {
157 Self {
158 enabled: true,
159 caret_blink_interval: Duration::from_millis(530),
160 caret_blink_timeout: Duration::from_secs(5),
161 }
162 }
163}
164
165#[derive(Debug, Clone, Serialize, PartialEq, Eq, Deserialize, Default)]
167#[non_exhaustive]
168pub struct LocaleConfig {
169 pub langs: Vec<Txt>,
171}
172impl LocaleConfig {
173 pub fn new(langs: Vec<Txt>) -> Self {
175 Self { langs }
176 }
177}
178
179#[derive(Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
181#[non_exhaustive]
182pub enum FontAntiAliasing {
183 #[default]
185 Default,
186 Subpixel,
188 Alpha,
190 Mono,
192}
193impl fmt::Debug for FontAntiAliasing {
194 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
195 if f.alternate() {
196 write!(f, "FontAntiAliasing::")?;
197 }
198 match self {
199 FontAntiAliasing::Default => write!(f, "Default"),
200 FontAntiAliasing::Subpixel => write!(f, "Subpixel"),
201 FontAntiAliasing::Alpha => write!(f, "Alpha"),
202 FontAntiAliasing::Mono => write!(f, "Mono"),
203 }
204 }
205}
206
207#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
209#[non_exhaustive]
210pub enum ColorScheme {
211 Light,
213
214 Dark,
216}
217impl Default for ColorScheme {
218 fn default() -> Self {
220 ColorScheme::Light
221 }
222}
223
224#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
226#[non_exhaustive]
227pub struct ColorsConfig {
228 pub scheme: ColorScheme,
230 pub accent: Rgba,
236}
237impl ColorsConfig {
238 pub fn new(scheme: ColorScheme, accent: Rgba) -> Self {
240 Self { scheme, accent }
241 }
242}
243impl Default for ColorsConfig {
244 fn default() -> Self {
245 Self {
246 scheme: Default::default(),
247 accent: Rgba::new(10, 10, 200, 255),
248 }
249 }
250}
251
252#[cfg(feature = "var")]
253zng_var::impl_from_and_into_var! {
254 fn from(some: ColorScheme) -> Option<ColorScheme>;
255}
256
257#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
259#[non_exhaustive]
260pub struct ChromeConfig {
261 pub prefer_custom: bool,
265
266 pub provided: bool,
271}
272impl ChromeConfig {
273 pub fn new(prefer_custom: bool, provided: bool) -> Self {
275 Self { prefer_custom, provided }
276 }
277
278 pub fn needs_custom(&self) -> bool {
282 self.prefer_custom && !self.provided
283 }
284}
285impl Default for ChromeConfig {
286 fn default() -> Self {
287 Self {
288 prefer_custom: false,
289 provided: true,
290 }
291 }
292}