euv-ui 0.48.8

Cross-platform UI component library and 17-scheme design system for the euv framework with pixel-consistent rendering across Web, Android, iOS, iPadOS, macOS, Windows, and Linux.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
use super::*;

/// Ordered Strategy Chain facade selecting the optimal chrome geometry for any hardware posture.
impl EuvChromeLayoutPolicy {
    /// Resolves the complete `ResolvedChromeLayout` for `metrics` by evaluating the ordered Strategy Chain.
    ///
    /// # Arguments
    ///
    /// - `&ShellViewportMetrics` - Live viewport, safe-area, and chrome visibility snapshot.
    ///
    /// # Returns
    ///
    /// - `ResolvedChromeLayout` - Complete deterministic chrome and clipped route-stage geometry.
    #[must_use]
    pub fn resolve(metrics: &ShellViewportMetrics) -> ResolvedChromeLayout {
        let desktop: DesktopSidebarStrategy = DesktopSidebarStrategy;
        if desktop.matches(metrics) {
            return desktop.resolve(metrics);
        }
        let watch: WatchCompactStrategy = WatchCompactStrategy;
        if watch.matches(metrics) {
            return watch.resolve(metrics);
        }
        let side_rail: VerticalSafeRailStrategy = VerticalSafeRailStrategy;
        if side_rail.matches(metrics) {
            return side_rail.resolve(metrics);
        }
        let edge_strip: EdgeSafeStripStrategy = EdgeSafeStripStrategy;
        if edge_strip.matches(metrics) {
            return edge_strip.resolve(metrics);
        }
        BottomFloatingDockStrategy.resolve(metrics)
    }
}

/// Desktop / PC / wide landscape tablet strategy (`>= 960dp`).
impl ChromeLayoutStrategy for DesktopSidebarStrategy {
    /// Matches desktop-width viewports (`>= DESKTOP_LAYOUT_BREAKPOINT`).
    ///
    /// # Arguments
    ///
    /// - `&Self` - Strategy instance.
    /// - `&ShellViewportMetrics` - Live viewport snapshot.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` for desktop viewports.
    fn matches(&self, metrics: &ShellViewportMetrics) -> bool {
        metrics.get_viewport_width().max(CHROME_MIN_VIEWPORT_CLAMP) >= DESKTOP_LAYOUT_BREAKPOINT
    }

    /// Resolves desktop layout with persistent left sidebar and zero floating bottom dock.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Strategy instance.
    /// - `&ShellViewportMetrics` - Live viewport snapshot.
    ///
    /// # Returns
    ///
    /// - `ResolvedChromeLayout` - Desktop layout plan.
    fn resolve(&self, metrics: &ShellViewportMetrics) -> ResolvedChromeLayout {
        let safe: SafeAreaInsets = metrics.get_safe_area();
        let top_stage: f32 = if metrics.get_is_chrome_hidden() && !metrics.get_is_fullscreen() {
            safe.get_top().max(0.0)
        } else {
            0.0
        };
        let stage_right: f32 = if metrics.get_is_fullscreen() {
            0.0
        } else {
            safe.get_right().max(0.0)
        };
        ResolvedChromeLayout {
            posture: ChromePosture::Desktop,
            dock_placement: NavDockPlacement::Hidden,
            dock_orientation: NavDockOrientation::Horizontal,
            dock_icon_only: false,
            show_dock: false,
            dock_left: 0.0,
            dock_top: None,
            dock_bottom: None,
            dock_width: 0.0,
            dock_height: 0.0,
            dock_hide_dx: 0.0,
            dock_hide_dy: 0.0,
            mobile_header_top_inset: safe.get_top().max(0.0),
            route_stage_insets: Edges::new(top_stage, stage_right, 0.0, 0.0),
            content_extra_bottom_pad: safe.get_bottom().max(0.0),
            top_divider_left_inset: 0.0,
            top_divider_right_inset: 0.0,
        }
    }
}

/// Compact smartwatch strategy (`< 300dp` on either axis).
impl ChromeLayoutStrategy for WatchCompactStrategy {
    /// Matches smartwatch viewports (`< CHROME_WATCH_VIEWPORT_MAX`).
    ///
    /// # Arguments
    ///
    /// - `&Self` - Strategy instance.
    /// - `&ShellViewportMetrics` - Live viewport snapshot.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` for smartwatch viewports.
    fn matches(&self, metrics: &ShellViewportMetrics) -> bool {
        let w: f32 = metrics.get_viewport_width().max(CHROME_MIN_VIEWPORT_CLAMP);
        let h: f32 = metrics.get_viewport_height().max(CHROME_MIN_VIEWPORT_CLAMP);
        w < CHROME_WATCH_VIEWPORT_MAX || h < CHROME_WATCH_VIEWPORT_MAX
    }

    /// Resolves round/squircle watch layout with centered icon-only bottom dock inside the lower chord.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Strategy instance.
    /// - `&ShellViewportMetrics` - Live viewport snapshot.
    ///
    /// # Returns
    ///
    /// - `ResolvedChromeLayout` - Watch layout plan.
    fn resolve(&self, metrics: &ShellViewportMetrics) -> ResolvedChromeLayout {
        let vp_w: f32 = metrics.get_viewport_width().max(CHROME_MIN_VIEWPORT_CLAMP);
        let safe: SafeAreaInsets = metrics.get_safe_area();
        let top_raw: f32 = safe.get_top().max(0.0);
        let right_raw: f32 = safe.get_right().max(0.0);
        let bottom_raw: f32 = safe.get_bottom().max(0.0);
        let left_raw: f32 = safe.get_left().max(0.0);
        let show_dock: bool = metrics.get_has_bottom_nav() && !metrics.get_is_fullscreen();
        let dock_h: f32 = CHROME_WATCH_DOCK_HEIGHT;
        let dock_bottom: f32 = (bottom_raw * 0.60).max(16.0);
        let max_w: f32 = (vp_w - 32.0).max(124.0);
        let dock_w: f32 = (vp_w - (left_raw + right_raw) * 0.85).clamp(124.0, max_w);
        let dock_left: f32 = ((vp_w - dock_w) * 0.5).max(12.0);
        let stage_left: f32 = if metrics.get_is_fullscreen() {
            0.0
        } else {
            (left_raw * 0.55).max(8.0)
        };
        let stage_right: f32 = if metrics.get_is_fullscreen() {
            0.0
        } else {
            (right_raw * 0.55).max(8.0)
        };
        let extra_bottom: f32 = if show_dock && !metrics.get_is_chrome_hidden() {
            dock_h + dock_bottom + 8.0
        } else {
            bottom_raw
        };
        ResolvedChromeLayout {
            posture: ChromePosture::WatchCompact,
            dock_placement: if show_dock {
                NavDockPlacement::WatchBottomCompact
            } else {
                NavDockPlacement::Hidden
            },
            dock_orientation: NavDockOrientation::Horizontal,
            dock_icon_only: true,
            show_dock,
            dock_left,
            dock_top: None,
            dock_bottom: Some(dock_bottom),
            dock_width: dock_w,
            dock_height: dock_h,
            dock_hide_dx: 0.0,
            dock_hide_dy: dock_h + dock_bottom + 12.0,
            mobile_header_top_inset: (top_raw * 0.55).min(20.0),
            route_stage_insets: Edges::new(0.0, stage_right, 0.0, stage_left),
            content_extra_bottom_pad: extra_bottom,
            top_divider_left_inset: stage_left,
            top_divider_right_inset: stage_right,
        }
    }
}

/// Vertical safe-area rail strategy for iPhone Duo folded/unfolded/split and landscape side cutouts.
impl ChromeLayoutStrategy for VerticalSafeRailStrategy {
    /// Matches mobile/foldable/split viewports where the right or left safe-area strip is wide enough for a vertical navigation rail.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Strategy instance.
    /// - `&ShellViewportMetrics` - Live viewport snapshot.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` when right or left safe-area strip meets minimum vertical rail dimensions.
    fn matches(&self, metrics: &ShellViewportMetrics) -> bool {
        let vp_h: f32 = metrics.get_viewport_height().max(CHROME_MIN_VIEWPORT_CLAMP);
        let safe: SafeAreaInsets = metrics.get_safe_area();
        let max_side: f32 = safe.get_right().max(safe.get_left());
        metrics.get_has_bottom_nav()
            && max_side >= CHROME_SIDE_SAFE_RAIL_MIN_WIDTH
            && vp_h >= CHROME_SIDE_SAFE_RAIL_MIN_HEIGHT
    }

    /// Docks navigation vertically inside the signal-bearing right or left safe-area strip while clearing the signal cluster and clipping route transitions strictly inside the remaining content stage.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Strategy instance.
    /// - `&ShellViewportMetrics` - Live viewport snapshot.
    ///
    /// # Returns
    ///
    /// - `ResolvedChromeLayout` - Vertical side-rail layout plan.
    fn resolve(&self, metrics: &ShellViewportMetrics) -> ResolvedChromeLayout {
        let vp_w: f32 = metrics.get_viewport_width().max(CHROME_MIN_VIEWPORT_CLAMP);
        let vp_h: f32 = metrics.get_viewport_height().max(CHROME_MIN_VIEWPORT_CLAMP);
        let safe: SafeAreaInsets = metrics.get_safe_area();
        let top_raw: f32 = safe.get_top().max(0.0);
        let right_raw: f32 = safe.get_right().max(0.0);
        let bottom_raw: f32 = safe.get_bottom().max(0.0);
        let left_raw: f32 = safe.get_left().max(0.0);
        let on_right: bool = right_raw >= left_raw;
        let rail_strip_w: f32 = if on_right { right_raw } else { left_raw };
        let show_dock: bool = metrics.get_has_bottom_nav() && !metrics.get_is_fullscreen();
        let dock_w: f32 = (rail_strip_w - CHROME_SIDE_RAIL_INSET_PAD * 2.0)
            .clamp(CHROME_SIDE_RAIL_MIN_DOCK_W, CHROME_SIDE_RAIL_MAX_DOCK_W)
            .min((rail_strip_w - 4.0).max(40.0));
        let dock_left: f32 = if on_right {
            vp_w - rail_strip_w + (rail_strip_w - dock_w) * 0.5
        } else {
            (rail_strip_w - dock_w) * 0.5
        };
        let signal_top: f32 = compute_side_rail_signal_clearance(vp_w, vp_h, safe);
        let bottom_clear: f32 = bottom_raw.max(CHROME_SIDE_RAIL_BOTTOM_CORNER_GAP);
        let available_h: f32 = (vp_h - signal_top - bottom_clear).max(160.0);
        let icon_only: bool = available_h < CHROME_VERTICAL_RAIL_LABEL_MIN_HEIGHT || dock_w < 54.0;
        let target_h: f32 = if icon_only {
            available_h.clamp(160.0, 260.0)
        } else {
            available_h.clamp(
                CHROME_VERTICAL_RAIL_LABEL_MIN_HEIGHT,
                CHROME_SIDE_RAIL_MAX_DOCK_H,
            )
        };
        let dock_h: f32 = target_h.min(available_h);
        let dock_top: f32 = signal_top + ((available_h - dock_h) * 0.5).max(0.0);
        let stage_top: f32 = if metrics.get_is_chrome_hidden() && !metrics.get_is_fullscreen() {
            top_raw
        } else {
            0.0
        };
        let stage_left: f32 = if metrics.get_is_fullscreen() {
            0.0
        } else {
            left_raw
        };
        let stage_right: f32 = if metrics.get_is_fullscreen() {
            0.0
        } else {
            right_raw
        };
        let hide_dx: f32 = if on_right {
            rail_strip_w + 16.0
        } else {
            -(rail_strip_w + 16.0)
        };
        ResolvedChromeLayout {
            posture: if on_right {
                ChromePosture::SideSafeRailRight
            } else {
                ChromePosture::SideSafeRailLeft
            },
            dock_placement: if !show_dock {
                NavDockPlacement::Hidden
            } else if on_right {
                NavDockPlacement::RightSafeRail
            } else {
                NavDockPlacement::LeftSafeRail
            },
            dock_orientation: NavDockOrientation::Vertical,
            dock_icon_only: icon_only,
            show_dock,
            dock_left,
            dock_top: Some(dock_top),
            dock_bottom: None,
            dock_width: dock_w,
            dock_height: dock_h,
            dock_hide_dx: hide_dx,
            dock_hide_dy: 0.0,
            mobile_header_top_inset: top_raw,
            route_stage_insets: Edges::new(stage_top, stage_right, 0.0, stage_left),
            content_extra_bottom_pad: bottom_raw,
            top_divider_left_inset: left_raw,
            top_divider_right_inset: right_raw,
        }
    }
}

/// Rotated wide top or bottom hardware safe-area strip strategy (e.g. rotated iPhone Duo landscape).
impl ChromeLayoutStrategy for EdgeSafeStripStrategy {
    /// Matches wide viewports (`>= 460dp`) whose top (`>= 72dp`) or bottom (`>= 68dp`) safe-area strip hosts the signal bar with horizontal space for navigation.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Strategy instance.
    /// - `&ShellViewportMetrics` - Live viewport snapshot.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` when wide rotated top/bottom hardware strip should host navigation.
    fn matches(&self, metrics: &ShellViewportMetrics) -> bool {
        let vp_w: f32 = metrics.get_viewport_width().max(CHROME_MIN_VIEWPORT_CLAMP);
        let safe: SafeAreaInsets = metrics.get_safe_area();
        let top_match: bool = safe.get_top() >= CHROME_TOP_SAFE_RAIL_MIN_HEIGHT
            && vp_w >= CHROME_TOP_SAFE_RAIL_MIN_VIEWPORT_WIDTH;
        let bottom_match: bool = safe.get_bottom() >= CHROME_BOTTOM_SAFE_RAIL_MIN_HEIGHT
            && vp_w >= CHROME_TOP_SAFE_RAIL_MIN_VIEWPORT_WIDTH;
        metrics.get_has_bottom_nav() && (top_match || bottom_match)
    }

    /// Docks navigation horizontally inside the wide top or bottom safe-area strip, offset clear of the signal cluster.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Strategy instance.
    /// - `&ShellViewportMetrics` - Live viewport snapshot.
    ///
    /// # Returns
    ///
    /// - `ResolvedChromeLayout` - Edge safe-strip layout plan.
    fn resolve(&self, metrics: &ShellViewportMetrics) -> ResolvedChromeLayout {
        let vp_w: f32 = metrics.get_viewport_width().max(CHROME_MIN_VIEWPORT_CLAMP);
        let safe: SafeAreaInsets = metrics.get_safe_area();
        let top_raw: f32 = safe.get_top().max(0.0);
        let right_raw: f32 = safe.get_right().max(0.0);
        let bottom_raw: f32 = safe.get_bottom().max(0.0);
        let left_raw: f32 = safe.get_left().max(0.0);
        let use_top: bool = top_raw >= CHROME_TOP_SAFE_RAIL_MIN_HEIGHT && top_raw >= bottom_raw;
        let show_dock: bool = metrics.get_has_bottom_nav() && !metrics.get_is_fullscreen();
        let strip_h: f32 = if use_top { top_raw } else { bottom_raw };
        let dock_h: f32 = (strip_h - 12.0).clamp(40.0, CHROME_EDGE_STRIP_BAR_HEIGHT);
        let free_start_x: f32 = left_raw.max(CHROME_HORIZONTAL_SIGNAL_CLEARANCE);
        let free_end_x: f32 = vp_w - right_raw.max(16.0);
        let avail_w: f32 = (free_end_x - free_start_x).max(220.0);
        let dock_w: f32 = avail_w.clamp(220.0, SHELL_BOTTOM_NAV_MAX_WIDTH);
        let dock_left: f32 = free_start_x + ((avail_w - dock_w) * 0.5).max(0.0);
        let edge_offset: f32 = ((strip_h - dock_h) * 0.5).max(6.0);
        let stage_left: f32 = if metrics.get_is_fullscreen() {
            0.0
        } else {
            left_raw
        };
        let stage_right: f32 = if metrics.get_is_fullscreen() {
            0.0
        } else {
            right_raw
        };
        let stage_top: f32 = if metrics.get_is_chrome_hidden() && !metrics.get_is_fullscreen() {
            top_raw
        } else {
            0.0
        };
        let stage_bottom: f32 = if !use_top && !metrics.get_is_fullscreen() {
            bottom_raw
        } else {
            0.0
        };
        ResolvedChromeLayout {
            posture: if use_top {
                ChromePosture::TopSafeRail
            } else {
                ChromePosture::BottomSafeRail
            },
            dock_placement: if !show_dock {
                NavDockPlacement::Hidden
            } else if use_top {
                NavDockPlacement::TopSafeStrip
            } else {
                NavDockPlacement::BottomSafeStrip
            },
            dock_orientation: NavDockOrientation::Horizontal,
            dock_icon_only: dock_h < 46.0,
            show_dock,
            dock_left,
            dock_top: if use_top { Some(edge_offset) } else { None },
            dock_bottom: if use_top { None } else { Some(edge_offset) },
            dock_width: dock_w,
            dock_height: dock_h,
            dock_hide_dx: 0.0,
            dock_hide_dy: if use_top {
                -(strip_h + 12.0)
            } else {
                strip_h + 12.0
            },
            mobile_header_top_inset: top_raw,
            route_stage_insets: Edges::new(stage_top, stage_right, stage_bottom, stage_left),
            content_extra_bottom_pad: if use_top { bottom_raw } else { 0.0 },
            top_divider_left_inset: left_raw,
            top_divider_right_inset: right_raw,
        }
    }
}

/// Standard mobile / tablet portrait / MiniApp / QuickApp strategy preserving the canonical floating bottom dock.
impl ChromeLayoutStrategy for BottomFloatingDockStrategy {
    /// Catch-all fallback strategy for standard mobile viewports.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Strategy instance.
    /// - `&ShellViewportMetrics` - Live viewport snapshot.
    ///
    /// # Returns
    ///
    /// - `bool` - Always `true`.
    fn matches(&self, _metrics: &ShellViewportMetrics) -> bool {
        true
    }

    /// Resolves standard mobile layout with floating horizontal bottom dock and safe-area-clipped route stage.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Strategy instance.
    /// - `&ShellViewportMetrics` - Live viewport snapshot.
    ///
    /// # Returns
    ///
    /// - `ResolvedChromeLayout` - Standard mobile layout plan.
    fn resolve(&self, metrics: &ShellViewportMetrics) -> ResolvedChromeLayout {
        let vp_w: f32 = metrics.get_viewport_width().max(CHROME_MIN_VIEWPORT_CLAMP);
        let safe: SafeAreaInsets = metrics.get_safe_area();
        let top_raw: f32 = safe.get_top().max(0.0);
        let right_raw: f32 = safe.get_right().max(0.0);
        let bottom_raw: f32 = safe.get_bottom().max(0.0);
        let left_raw: f32 = safe.get_left().max(0.0);
        let show_dock: bool = metrics.get_has_bottom_nav() && !metrics.get_is_fullscreen();
        let float_gap: f32 = if metrics.get_is_compact_bp() {
            SHELL_BOTTOM_NAV_FLOAT_COMPACT
        } else {
            SHELL_BOTTOM_NAV_FLOAT_WIDE
        };
        let dock_h: f32 = SHELL_BOTTOM_NAV_HEIGHT;
        let dock_bottom: f32 = float_gap + bottom_raw;
        let usable_w: f32 = (vp_w - left_raw - right_raw).max(200.0);
        let side_margin: f32 = if metrics.get_is_compact_bp() {
            SHELL_BOTTOM_NAV_SIDE_MARGIN
        } else {
            SHELL_BOTTOM_NAV_SIDE_MARGIN_WIDE
        };
        let min_dock_w: f32 = 240.0_f32.min((usable_w - 16.0).max(160.0));
        let dock_w: f32 =
            (usable_w - side_margin * 2.0).clamp(min_dock_w, SHELL_BOTTOM_NAV_MAX_WIDTH);
        let dock_left: f32 = left_raw + ((usable_w - dock_w) * 0.5).max(8.0);
        let stage_top: f32 = if metrics.get_is_chrome_hidden() && !metrics.get_is_fullscreen() {
            top_raw
        } else {
            0.0
        };
        let stage_left: f32 = if metrics.get_is_fullscreen() {
            0.0
        } else {
            left_raw
        };
        let stage_right: f32 = if metrics.get_is_fullscreen() {
            0.0
        } else {
            right_raw
        };
        let extra_bottom: f32 = if show_dock && !metrics.get_is_chrome_hidden() {
            dock_h + dock_bottom + 12.0
        } else {
            bottom_raw
        };
        ResolvedChromeLayout {
            posture: ChromePosture::StandardMobile,
            dock_placement: if show_dock {
                NavDockPlacement::BottomHorizontal
            } else {
                NavDockPlacement::Hidden
            },
            dock_orientation: NavDockOrientation::Horizontal,
            dock_icon_only: false,
            show_dock,
            dock_left,
            dock_top: None,
            dock_bottom: Some(dock_bottom),
            dock_width: dock_w,
            dock_height: dock_h,
            dock_hide_dx: 0.0,
            dock_hide_dy: dock_h + dock_bottom + 12.0,
            mobile_header_top_inset: top_raw,
            route_stage_insets: Edges::new(stage_top, stage_right, 0.0, stage_left),
            content_extra_bottom_pad: extra_bottom,
            top_divider_left_inset: left_raw,
            top_divider_right_inset: right_raw,
        }
    }
}