Skip to main content

euv_ui/component/layout/
impl.rs

1use super::*;
2
3/// Breakpoint classification helpers for `EuvShellLayoutMode`.
4impl EuvShellLayoutMode {
5    /// Classifies a logical viewport width into `Desktop` (`>= 960px`) or `Mobile` (`< 960px`).
6    ///
7    /// # Arguments
8    ///
9    /// - `f32` - Logical viewport width in pixels.
10    ///
11    /// # Returns
12    ///
13    /// - `Self` - Matching `EuvShellLayoutMode`.
14    #[must_use]
15    pub fn from_viewport_width(width: f32) -> Self {
16        if width.is_finite() && width >= DESKTOP_LAYOUT_BREAKPOINT {
17            Self::Desktop
18        } else {
19            Self::Mobile
20        }
21    }
22
23    /// Returns `true` when the layout mode is Desktop / PC (`>= 960px`).
24    ///
25    /// # Arguments
26    ///
27    /// - `Self` - Layout mode value.
28    ///
29    /// # Returns
30    ///
31    /// - `bool` - `true` for `Desktop`.
32    #[must_use]
33    pub fn is_desktop(self) -> bool {
34        self == Self::Desktop
35    }
36
37    /// Returns `true` when the layout mode is Mobile (`< 960px`).
38    ///
39    /// # Arguments
40    ///
41    /// - `Self` - Layout mode value.
42    ///
43    /// # Returns
44    ///
45    /// - `bool` - `true` for `Mobile`.
46    #[must_use]
47    pub fn is_mobile(self) -> bool {
48        self == Self::Mobile
49    }
50}
51
52/// Hysteresis state machine helpers for `ChromeScrollAutoHideState`.
53impl ChromeScrollAutoHideState {
54    /// Seeds or resets hysteresis tracking for `node` at vertical offset `scroll_y`.
55    ///
56    /// # Arguments
57    ///
58    /// - `&Self` - Mutable tracker state.
59    /// - `NodeId` - Active scroll container node handle.
60    /// - `f32` - Current vertical scroll offset in logical pixels.
61    pub(crate) fn reset(&mut self, node: NodeId, scroll_y: f32) {
62        self.set_active_scroll_node(node);
63        self.set_has_sample(true);
64        self.set_last_scroll_y(scroll_y.max(0.0));
65        self.set_accum_delta_y(0.0);
66        self.set_suppress_hide_ticks(0);
67    }
68
69    /// Clears scroll tracking and suppresses `ticks` subsequent downward coasting events after a resize reveal.
70    ///
71    /// # Arguments
72    ///
73    /// - `&Self` - Mutable tracker state.
74    /// - `u8` - Number of downward inertia samples to absorb while re-anchoring.
75    pub(crate) fn reset_with_suppression(&mut self, ticks: u8) {
76        self.set_active_scroll_node(NodeId::default());
77        self.set_has_sample(false);
78        self.set_last_scroll_y(0.0);
79        self.set_accum_delta_y(0.0);
80        self.set_suppress_hide_ticks(ticks);
81    }
82
83    /// Processes a vertical scroll sample and returns `Some(next_hidden)` when chrome visibility should toggle.
84    ///
85    /// # Arguments
86    ///
87    /// - `&Self` - Mutable tracker state.
88    /// - `NodeId` - Scrolled container node handle.
89    /// - `f32` - Latest vertical scroll offset in logical pixels.
90    /// - `f32` - Event vertical scroll delta in logical pixels.
91    /// - `bool` - Current chrome hidden state.
92    ///
93    /// # Returns
94    ///
95    /// - `Option<bool>` - Desired next `chrome_hidden` state, or `None` when unchanged.
96    #[must_use]
97    pub(crate) fn on_scroll(
98        &mut self,
99        node: NodeId,
100        scroll_y: f32,
101        event_dy: f32,
102        currently_hidden: bool,
103    ) -> Option<bool> {
104        let clamped_y: f32 = scroll_y.max(0.0);
105        let dy: f32 = if self.get_active_scroll_node() != node || !self.get_has_sample() {
106            self.set_active_scroll_node(node);
107            self.set_has_sample(true);
108            self.set_last_scroll_y(clamped_y);
109            self.set_accum_delta_y(0.0);
110            if event_dy.abs() > 0.5 && (clamped_y > 0.5 || event_dy < 0.0) {
111                event_dy
112            } else {
113                0.0
114            }
115        } else {
116            let prev_y: f32 = self.get_last_scroll_y();
117            self.set_last_scroll_y(clamped_y);
118            let raw_dy: f32 = clamped_y - prev_y;
119            if raw_dy.abs() > 0.5 { raw_dy } else { 0.0 }
120        };
121        if clamped_y <= SHELL_AUTO_HIDE_TOP_REVEAL_Y {
122            self.set_accum_delta_y(0.0);
123            self.set_suppress_hide_ticks(0);
124            return if currently_hidden && (dy < -0.5 || event_dy < -0.5) {
125                Some(false)
126            } else {
127                None
128            };
129        }
130        if dy.abs() <= 0.5 {
131            return None;
132        }
133        if dy > 0.0 && self.get_suppress_hide_ticks() > 0 {
134            self.set_suppress_hide_ticks(self.get_suppress_hide_ticks() - 1);
135            self.set_accum_delta_y(0.0);
136            return None;
137        }
138        if dy < 0.0 && self.get_suppress_hide_ticks() > 0 {
139            self.set_suppress_hide_ticks(0);
140        }
141        let prev_acc: f32 = self.get_accum_delta_y();
142        let next_acc: f32 = if (prev_acc > 0.0 && dy < 0.0) || (prev_acc < 0.0 && dy > 0.0) {
143            dy
144        } else {
145            prev_acc + dy
146        };
147        self.set_accum_delta_y(next_acc);
148        if !currently_hidden
149            && clamped_y > SHELL_AUTO_HIDE_MIN_SCROLL_Y
150            && next_acc > SHELL_AUTO_HIDE_DOWN_THRESHOLD
151        {
152            self.set_accum_delta_y(0.0);
153            return Some(true);
154        }
155        if currently_hidden && next_acc < -SHELL_AUTO_HIDE_UP_THRESHOLD {
156            self.set_accum_delta_y(0.0);
157            return Some(false);
158        }
159        None
160    }
161}
162
163/// Scroll observation helpers for `ChromeScrollObserver`.
164impl ChromeScrollObserver {
165    /// Returns whether scroll-driven chrome auto-hide is currently enabled (respecting reactive overrides).
166    ///
167    /// # Arguments
168    ///
169    /// - `&Self` - Shared scroll observer handle.
170    ///
171    /// # Returns
172    ///
173    /// - `bool` - `true` when scroll auto-hide is active.
174    #[must_use]
175    pub(crate) fn is_enabled(&self) -> bool {
176        self.get_auto_hide_signal()
177            .map_or(self.get_enabled(), |sig: Signal<bool>| sig.get_untracked())
178    }
179
180    /// Reveals hidden chrome when an upward scroll bubbles past a scroll view already resting at `scroll_y == 0`.
181    ///
182    /// # Arguments
183    ///
184    /// - `&Self` - Shared scroll observer handle.
185    /// - `&UiEvent` - Dispatched scroll event payload.
186    pub(crate) fn observe_unconsumed_up(&self, ev: &UiEvent) {
187        if !self.is_enabled() || !self.get_chrome_hidden().get_untracked() {
188            return;
189        }
190        if is_fullscreen_active()
191            || self.get_ctx_fs().get_untracked()
192            || self.get_menu_open().get_untracked()
193            || EuvOverlayStack::active_count() > 0
194        {
195            return;
196        }
197        let event_dy: f32 = match ev.get_kind() {
198            UiEventKind::Scroll(delta) => delta.get_y(),
199            _ => 0.0,
200        };
201        if event_dy < -0.5 {
202            self.get_state().set(ChromeScrollAutoHideState::default());
203            let _: bool = self.get_chrome_hidden().set_if_changed(false);
204        }
205    }
206
207    /// Processes a scroll event emitted by `scroll_node` and updates the shell's chrome visibility signal.
208    ///
209    /// # Arguments
210    ///
211    /// - `&Self` - Shared scroll observer handle.
212    /// - `NodeId` - Scrolled container node handle.
213    /// - `&UiEvent` - Dispatched scroll event payload.
214    pub(crate) fn observe(&self, scroll_node: NodeId, ev: &UiEvent) {
215        if !self.is_enabled() {
216            return;
217        }
218        if is_fullscreen_active()
219            || self.get_ctx_fs().get_untracked()
220            || self.get_menu_open().get_untracked()
221            || EuvOverlayStack::active_count() > 0
222        {
223            return;
224        }
225        let event_dy: f32 = match ev.get_kind() {
226            UiEventKind::Scroll(delta) => delta.get_y(),
227            _ => 0.0,
228        };
229        let (visible, scroll_y): (bool, f32) = self.get_scene().with_read(
230            |tree: &SceneTree| {
231                tree.get_node(scroll_node)
232                    .map(|n: &SceneNode| {
233                        let vis: bool = n.get_alive()
234                            && n.style_ref().get_layout().get_display() != Display::None;
235                        (vis, n.get_layout_box().get_scroll_offset().get_y())
236                    })
237                    .unwrap_or((false, 0.0))
238            },
239            (false, 0.0),
240        );
241        if !visible {
242            return;
243        }
244        let mut tracker: ChromeScrollAutoHideState = self.get_state().get();
245        let next_opt: Option<bool> = tracker.on_scroll(
246            scroll_node,
247            scroll_y,
248            event_dy,
249            self.get_chrome_hidden().get_untracked(),
250        );
251        self.get_state().set(tracker);
252        if let Some(next_hidden) = next_opt {
253            let _: bool = self.get_chrome_hidden().set_if_changed(next_hidden);
254        }
255    }
256}
257
258/// Builder helpers for `EuvAppShell`.
259impl EuvAppShell {
260    /// Binds an active route signal so compact mobile navigation drawers auto-close on route change.
261    ///
262    /// # Arguments
263    ///
264    /// - `Self` - Source app shell.
265    /// - `Signal<String>` - Active route path signal.
266    ///
267    /// # Returns
268    ///
269    /// - `Self` - Updated app shell.
270    #[must_use]
271    pub fn route(mut self, route_signal: Signal<String>) -> Self {
272        self.set_route_signal(Some(route_signal));
273        self
274    }
275
276    /// Attaches global header actions (e.g. Command Palette button, Theme Toggle) to the persistent top chrome bar.
277    ///
278    /// # Arguments
279    ///
280    /// - `Self` - Source app shell.
281    /// - `NodeId` - Mounted header actions row node.
282    ///
283    /// # Returns
284    ///
285    /// - `Self` - Updated app shell.
286    #[must_use]
287    pub fn top_bar_actions(mut self, actions: NodeId) -> Self {
288        self.set_top_bar_actions(Some(actions));
289        self
290    }
291
292    /// Attaches compact inline actions rendered beside the mobile header `Menu` button.
293    ///
294    /// # Arguments
295    ///
296    /// - `Self` - Source app shell.
297    /// - `NodeId` - Mounted compact actions node.
298    ///
299    /// # Returns
300    ///
301    /// - `Self` - Updated app shell.
302    #[must_use]
303    pub fn mobile_header_actions(mut self, actions: NodeId) -> Self {
304        self.set_mobile_header_actions(Some(actions));
305        self
306    }
307
308    /// Attaches a footer widget (e.g. theme/DPI indicator) pinned below the sidebar navigation list.
309    ///
310    /// # Arguments
311    ///
312    /// - `Self` - Source app shell.
313    /// - `NodeId` - Mounted sidebar footer node.
314    ///
315    /// # Returns
316    ///
317    /// - `Self` - Updated app shell.
318    #[must_use]
319    pub fn sidebar_footer(mut self, footer: NodeId) -> Self {
320        self.set_sidebar_footer(Some(footer));
321        self
322    }
323
324    /// Binds a reactive breadcrumb string displayed in the persistent desktop/tablet top header bar.
325    ///
326    /// # Arguments
327    ///
328    /// - `Self` - Source app shell.
329    /// - `Signal<String>` - Reactive breadcrumb text signal.
330    ///
331    /// # Returns
332    ///
333    /// - `Self` - Updated app shell.
334    #[must_use]
335    pub fn breadcrumb(mut self, breadcrumb: Signal<String>) -> Self {
336        self.set_breadcrumb(Some(breadcrumb));
337        self
338    }
339
340    /// Attaches a mobile bottom navigation bar displayed exclusively on Mobile (`< 960px`) and hidden with zero bottom reservation on Desktop (`>= 960px`).
341    ///
342    /// # Arguments
343    ///
344    /// - `Self` - Source app shell.
345    /// - `NodeId` - Mounted bottom navigation bar node (typically `EuvBottomNav`).
346    ///
347    /// # Returns
348    ///
349    /// - `Self` - Updated app shell.
350    #[must_use]
351    pub fn bottom_nav(mut self, bottom_bar: NodeId) -> Self {
352        self.set_bottom_nav(Some(bottom_bar));
353        self
354    }
355
356    /// Configures ordered route paths navigated directly via horizontal left/right viewport swipes.
357    ///
358    /// # Arguments
359    ///
360    /// - `Self` - Source app shell.
361    /// - `Vec<String>` - Ordered route path list.
362    ///
363    /// # Returns
364    ///
365    /// - `Self` - Updated app shell.
366    #[must_use]
367    pub fn swipe_routes(mut self, routes: Vec<String>) -> Self {
368        self.set_swipe_routes(routes);
369        self
370    }
371
372    /// Enables or disables the live real-time FPS telemetry badge in the top navigation bar.
373    ///
374    /// # Arguments
375    ///
376    /// - `Self` - Source app shell.
377    /// - `bool` - Whether the live FPS badge is displayed.
378    ///
379    /// # Returns
380    ///
381    /// - `Self` - Updated app shell.
382    #[must_use]
383    pub fn show_fps(mut self, show: bool) -> Self {
384        self.set_show_fps(show);
385        self
386    }
387
388    /// Connects a reactive `UiThemeState` so toggling Light/Dark or switching schemes updates shell chrome in-place without tearing down mounted pages.
389    ///
390    /// # Arguments
391    ///
392    /// - `Self` - Source app shell.
393    /// - `UiThemeState` - Reactive theme controller.
394    ///
395    /// # Returns
396    ///
397    /// - `Self` - Updated app shell.
398    #[must_use]
399    pub fn theme(mut self, theme: UiThemeState) -> Self {
400        self.set_theme(Some(theme));
401        self
402    }
403
404    /// Connects a shared reactive `Signal<Edges>` updated with the shell's responsive page padding (including safe area and bottom-nav clearance).
405    ///
406    /// # Arguments
407    ///
408    /// - `Self` - Source app shell.
409    /// - `Signal<Edges>` - Shared page padding signal consumed by `EuvRouterOutlet::with_page_padding`.
410    ///
411    /// # Returns
412    ///
413    /// - `Self` - Updated app shell.
414    #[must_use]
415    pub fn page_padding(mut self, padding: Signal<Edges>) -> Self {
416        self.set_page_padding(Some(padding));
417        self
418    }
419
420    /// Enables or disables Twitter/X-style animated auto-hide and reveal of the top bar and bottom navigation bar during vertical scrolling.
421    ///
422    /// # Arguments
423    ///
424    /// - `Self` - Source app shell.
425    /// - `bool` - `true` to hide chrome when scrolling down and reveal on upward scroll.
426    ///
427    /// # Returns
428    ///
429    /// - `Self` - Updated app shell.
430    #[must_use]
431    pub fn auto_hide_chrome_on_scroll(mut self, enabled: bool) -> Self {
432        self.set_auto_hide_chrome_on_scroll(enabled);
433        self
434    }
435
436    /// Binds a reactive signal that enables or disables scroll-driven top/bottom chrome auto-hide live.
437    ///
438    /// Setting the signal to `false` immediately restores hidden chrome; setting it to `true` activates scroll hiding.
439    ///
440    /// # Arguments
441    ///
442    /// - `Self` - Source app shell.
443    /// - `Signal<bool>` - Reactive chrome auto-hide toggle.
444    ///
445    /// # Returns
446    ///
447    /// - `Self` - Updated app shell.
448    #[must_use]
449    pub fn auto_hide_chrome_signal(mut self, enabled: Signal<bool>) -> Self {
450        self.set_auto_hide_chrome_signal(Some(enabled));
451        self
452    }
453
454    /// Binds a reactive signal that toggles visibility of the live FPS telemetry pill in the top navigation bar.
455    ///
456    /// # Arguments
457    ///
458    /// - `Self` - Source app shell.
459    /// - `Signal<bool>` - Reactive FPS pill visibility signal.
460    ///
461    /// # Returns
462    ///
463    /// - `Self` - Updated app shell.
464    #[must_use]
465    pub fn show_fps_signal(mut self, show: Signal<bool>) -> Self {
466        self.set_show_fps_signal(Some(show));
467        self
468    }
469
470    /// Binds a reactive signal that enables or disables horizontal swipe route navigation live.
471    ///
472    /// # Arguments
473    ///
474    /// - `Self` - Source app shell.
475    /// - `Signal<bool>` - Reactive horizontal swipe navigation toggle.
476    ///
477    /// # Returns
478    ///
479    /// - `Self` - Updated app shell.
480    #[must_use]
481    pub fn swipe_routes_enabled(mut self, enabled: Signal<bool>) -> Self {
482        self.set_swipe_routes_enabled(Some(enabled));
483        self
484    }
485
486    /// Sets an explicit external URL opened via `open_url` when clicking the brand header (by default clicking the brand opens the left sidebar drawer).
487    ///
488    /// # Arguments
489    ///
490    /// - `Self` - Source app shell.
491    /// - `impl Into<String>` - Target URL string.
492    ///
493    /// # Returns
494    ///
495    /// - `Self` - Updated app shell.
496    #[must_use]
497    pub fn brand_url(mut self, url: impl Into<String>) -> Self {
498        self.set_brand_url(Some(url.into()));
499        self
500    }
501
502    /// Registers an explicit click handler overriding the default brand click action (by default clicking the brand opens the mobile drawer on Mobile).
503    ///
504    /// # Arguments
505    ///
506    /// - `Self` - Source app shell.
507    /// - `F` - Click callback invoked when the brand emblem or title is clicked.
508    ///
509    /// # Returns
510    ///
511    /// - `Self` - Updated app shell.
512    #[must_use]
513    pub fn on_brand_click<F>(mut self, handler: F) -> Self
514    where
515        F: Fn(&UiEvent) + 'static,
516    {
517        self.set_on_brand_click(Some(Rc::new(handler)));
518        self
519    }
520
521    /// Sets an explicit raster logo image rendered inside the topbar and drawer brand badge instead of a fallback text initial.
522    ///
523    /// # Arguments
524    ///
525    /// - `Self` - Source app shell.
526    /// - `ImageBuffer` - Raster brand logo image buffer (for example `euv_brand_logo_image()`).
527    ///
528    /// # Returns
529    ///
530    /// - `Self` - Updated app shell.
531    #[must_use]
532    pub fn brand_logo(mut self, logo: ImageBuffer) -> Self {
533        self.set_brand_logo(Some(logo));
534        self
535    }
536
537    /// Binds an external reactive signal controlling and observing the Mobile overlay drawer open state.
538    ///
539    /// Entering Desktop (`>= 960px`) or Fullscreen automatically resets the signal to `false`.
540    ///
541    /// # Arguments
542    ///
543    /// - `Self` - Source app shell.
544    /// - `Signal<bool>` - Reactive Mobile drawer open-state signal.
545    ///
546    /// # Returns
547    ///
548    /// - `Self` - Updated app shell.
549    #[must_use]
550    pub fn drawer_open(mut self, open: Signal<bool>) -> Self {
551        self.set_drawer_open(Some(open));
552        self
553    }
554
555    /// Binds a reactive output signal synchronized with the shell's active `EuvShellLayoutMode` (`Desktop` >= 960px, `Mobile` < 960px).
556    ///
557    /// # Arguments
558    ///
559    /// - `Self` - Source app shell.
560    /// - `Signal<EuvShellLayoutMode>` - Reactive layout mode signal.
561    ///
562    /// # Returns
563    ///
564    /// - `Self` - Updated app shell.
565    #[must_use]
566    pub fn layout_mode(mut self, mode: Signal<EuvShellLayoutMode>) -> Self {
567        self.set_layout_mode(Some(mode));
568        self
569    }
570
571    /// Marks every alive descendant `Canvas` node under `root_id` dirty for paint so vector icons repaint immediately after a theme change.
572    ///
573    /// # Arguments
574    ///
575    /// - `&mut SceneTree` - Mutable retained scene tree.
576    /// - `NodeId` - Subtree root node handle.
577    fn mark_descendant_canvases_dirty(tree: &mut SceneTree, root_id: NodeId) {
578        let mut stack: Vec<NodeId> = vec![root_id];
579        while let Some(nid) = stack.pop() {
580            let is_canvas: bool = match tree.get_node(nid) {
581                Some(n) if n.get_alive() => matches!(n.get_kind(), NodeKind::Canvas(_)),
582                _ => continue,
583            };
584            stack.extend(tree.children_iter(nid));
585            if is_canvas {
586                tree.mark_dirty(nid, DIRTY_PAINT);
587            }
588        }
589    }
590
591    /// Hooks every direct `ScrollView` child under a managed outlet `main_content` into the shell's scroll auto-hide observer without replacing existing handlers.
592    ///
593    /// # Arguments
594    ///
595    /// - `&SceneHandle` - Shared scene handle.
596    /// - `NodeId` - Managed router outlet host node handle.
597    /// - `&Rc<RefCell<Vec<NodeId>>>` - Deduplication registry of already-hooked scroll wrappers.
598    /// - `&ChromeScrollObserver` - Shared scroll observer handle.
599    fn attach_outlet_scroll_observers(
600        scene: &SceneHandle,
601        outlet_host: NodeId,
602        hooked: &Rc<RefCell<Vec<NodeId>>>,
603        observer: &ChromeScrollObserver,
604    ) {
605        let needs_hook: bool = scene.with_read(
606            |tree: &SceneTree| {
607                let Ok(list) = hooked.try_borrow() else {
608                    return false;
609                };
610                tree.children_iter(outlet_host).any(|kid: NodeId| {
611                    !list.contains(&kid)
612                        && tree.get_node(kid).is_some_and(|n: &SceneNode| {
613                            matches!(n.get_kind(), NodeKind::ScrollView)
614                        })
615                })
616            },
617            false,
618        );
619        if !needs_hook {
620            return;
621        }
622        scene.with_write(
623            |tree: &mut SceneTree| {
624                let kids: Vec<NodeId> = tree.children_vec(outlet_host);
625                for kid in kids.into_iter() {
626                    let already_hooked: bool = hooked
627                        .try_borrow()
628                        .ok()
629                        .map(|list: Ref<'_, Vec<NodeId>>| list.contains(&kid))
630                        .unwrap_or(false);
631                    if already_hooked {
632                        continue;
633                    }
634                    let is_scroll: bool = tree
635                        .get_node(kid)
636                        .map(|n: &SceneNode| matches!(n.get_kind(), NodeKind::ScrollView))
637                        .unwrap_or(false);
638                    if !is_scroll {
639                        continue;
640                    }
641                    if let Some(wn) = tree.get_node_mut(kid) {
642                        let prev_handler: Option<UiEventHandler> = wn
643                            .get_handlers()
644                            .handler_for(&UiEventKind::Scroll(Point::default()));
645                        let obs_c: ChromeScrollObserver = observer.clone();
646                        let wrapped: UiEventHandler = Rc::new(RefCell::new(move |ev: &UiEvent| {
647                            if let Some(prev) = prev_handler.as_ref()
648                                && let Ok(mut f) = prev.try_borrow_mut()
649                            {
650                                f(ev);
651                            }
652                            obs_c.observe(kid, ev);
653                        }));
654                        wn.get_mut_handlers().set_on_scroll(Some(wrapped));
655                        if let Ok(mut list) = hooked.try_borrow_mut() {
656                            list.push(kid);
657                        }
658                    }
659                }
660            },
661            (),
662        );
663    }
664
665    /// Draws the official `Euv Studio` brand logo decoded from `https://devhub.vip/pages/docs/img/euv.png`.
666    ///
667    /// # Arguments
668    ///
669    /// - `Rect` - Emblem canvas bounds in logical pixels.
670    /// - `&mut DisplayList` - Target display list.
671    fn draw_euv_brand_emblem(bounds: Rect, dl: &mut DisplayList) {
672        let x: f32 = bounds.get_x();
673        let y: f32 = bounds.get_y();
674        let w: f32 = bounds.get_width().max(1.0);
675        let h: f32 = bounds.get_height().max(1.0);
676        let s: f32 = w.min(h);
677        let rect: Rect = Rect::new(x + (w - s) * 0.5, y + (h - s) * 0.5, s, s);
678        dl.push(DrawCommand::Image {
679            rect,
680            buffer: euv_brand_logo_image(),
681            radius: CornerRadius::default(),
682        });
683    }
684
685    /// Mounts the unified brand emblem (`NodeKind::Image` when explicit `custom_logo` is provided, canonical Euv emblem, or a theme-synced initial badge) shared across top navbar, desktop sidebar, and mobile drawer.
686    ///
687    /// # Arguments
688    ///
689    /// - `&str` - Single-character brand initial text.
690    /// - `Option<&ImageBuffer>` - Optional explicit raster brand logo image override.
691    /// - `ThemeTokens` - Active design tokens.
692    /// - `Option<&str>` - Optional interactive accessibility label when mounted as a button emblem in the top navbar.
693    ///
694    /// # Returns
695    ///
696    /// - `(NodeId, Option<NodeId>)` - Mounted brand logo badge root handle and optional fallback initial text node.
697    fn mount_brand_logo(
698        brand_initial: &str,
699        custom_logo: Option<&ImageBuffer>,
700        tokens: ThemeTokens,
701        interactive_a11y: Option<&str>,
702    ) -> (NodeId, Option<NodeId>) {
703        let p: ThemePalette = tokens.get_palette();
704        let g: ThemeGeometry = tokens.get_geometry();
705        let badge_r: f32 = g.get_radius_md();
706        let primary: SurfaceColors = p.surface(SurfaceRole::Primary);
707        let is_euv_mark: bool = brand_initial.eq_ignore_ascii_case(SHELL_DEFAULT_INITIAL);
708        let initial_owned: String = brand_initial.to_string();
709        if let Some(a11y_lbl) = interactive_a11y {
710            let lbl_owned: String = a11y_lbl.to_string();
711            if let Some(logo_buf) = custom_logo.cloned() {
712                let badge: NodeId = view! {
713                    row {
714                        style: {
715                            width: Length::Px(SHELL_BRAND_BADGE_SIZE)
716                            height: Length::Px(SHELL_BRAND_BADGE_SIZE)
717                            flex_shrink: 0.0
718                            radius: badge_r
719                            background: p.get_background()
720                            border: (g.get_border_width(), p.get_border())
721                            justify: JustifyContent::Center
722                            align: AlignItems::Center
723                            overflow: Overflow::Hidden
724                            cursor: CursorIcon::Pointer
725                        }
726                        role: A11yRole::Button
727                        a11y_label: lbl_owned
728                        image {
729                            source: logo_buf
730                            style: {
731                                width: Length::Px(SHELL_BRAND_BADGE_SIZE)
732                                height: Length::Px(SHELL_BRAND_BADGE_SIZE)
733                            }
734                        }
735                    }
736                };
737                (badge, None)
738            } else if is_euv_mark {
739                let paint_emblem = move |bounds: Rect, dl: &mut DisplayList| {
740                    Self::draw_euv_brand_emblem(bounds, dl);
741                };
742                let badge: NodeId = view! {
743                    row {
744                        style: {
745                            width: Length::Px(SHELL_BRAND_BADGE_SIZE)
746                            height: Length::Px(SHELL_BRAND_BADGE_SIZE)
747                            flex_shrink: 0.0
748                            radius: badge_r
749                            background: p.get_background()
750                            border: (g.get_border_width(), p.get_border())
751                            justify: JustifyContent::Center
752                            align: AlignItems::Center
753                            overflow: Overflow::Hidden
754                            cursor: CursorIcon::Pointer
755                        }
756                        role: A11yRole::Button
757                        a11y_label: lbl_owned
758                        canvas {
759                            style: {
760                                width: Length::Px(SHELL_BRAND_BADGE_SIZE)
761                                height: Length::Px(SHELL_BRAND_BADGE_SIZE)
762                            }
763                            caching: CanvasCaching::RetainedStatic
764                            painter: paint_emblem
765                        }
766                    }
767                };
768                (badge, None)
769            } else {
770                let mut txt_id: NodeId = NodeId::default();
771                let badge: NodeId = view! {
772                    row {
773                        style: {
774                            width: Length::Px(SHELL_BRAND_BADGE_SIZE)
775                            height: Length::Px(SHELL_BRAND_BADGE_SIZE)
776                            flex_shrink: 0.0
777                            radius: badge_r
778                            background: primary.get_bg()
779                            border: (g.get_border_width(), primary.get_border())
780                            overflow: Overflow::Hidden
781                            justify: JustifyContent::Center
782                            align: AlignItems::Center
783                            cursor: CursorIcon::Pointer
784                        }
785                        role: A11yRole::Button
786                        a11y_label: lbl_owned
787                        text {
788                            node_ref: txt_id
789                            style: {
790                                font_size: 13.0
791                                font_weight: FontWeight::Bold
792                                color: primary.get_fg()
793                                text_align: TextAlign::Center
794                                text_overflow: TextOverflow::Clip
795                            }
796                            { initial_owned }
797                        }
798                    }
799                };
800                (badge, Some(txt_id))
801            }
802        } else if let Some(logo_buf) = custom_logo.cloned() {
803            let badge: NodeId = view! {
804                row {
805                    style: {
806                        width: Length::Px(SHELL_BRAND_BADGE_SIZE)
807                        height: Length::Px(SHELL_BRAND_BADGE_SIZE)
808                        flex_shrink: 0.0
809                        radius: badge_r
810                        background: p.get_background()
811                        border: (g.get_border_width(), p.get_border())
812                        justify: JustifyContent::Center
813                        align: AlignItems::Center
814                        overflow: Overflow::Hidden
815                    }
816                    role: A11yRole::Group
817                    a11y_label: SHELL_BRAND_A11Y_LABEL.to_string()
818                    image {
819                        source: logo_buf
820                        style: {
821                            width: Length::Px(SHELL_BRAND_BADGE_SIZE)
822                            height: Length::Px(SHELL_BRAND_BADGE_SIZE)
823                        }
824                    }
825                }
826            };
827            (badge, None)
828        } else if is_euv_mark {
829            let paint_emblem = move |bounds: Rect, dl: &mut DisplayList| {
830                Self::draw_euv_brand_emblem(bounds, dl);
831            };
832            let badge: NodeId = view! {
833                row {
834                    style: {
835                        width: Length::Px(SHELL_BRAND_BADGE_SIZE)
836                        height: Length::Px(SHELL_BRAND_BADGE_SIZE)
837                        flex_shrink: 0.0
838                        radius: badge_r
839                        background: p.get_background()
840                        border: (g.get_border_width(), p.get_border())
841                        justify: JustifyContent::Center
842                        align: AlignItems::Center
843                        overflow: Overflow::Hidden
844                    }
845                    role: A11yRole::Group
846                    a11y_label: SHELL_BRAND_A11Y_LABEL.to_string()
847                    canvas {
848                        style: {
849                            width: Length::Px(SHELL_BRAND_BADGE_SIZE)
850                            height: Length::Px(SHELL_BRAND_BADGE_SIZE)
851                        }
852                        caching: CanvasCaching::RetainedStatic
853                        painter: paint_emblem
854                    }
855                }
856            };
857            (badge, None)
858        } else {
859            let mut txt_id: NodeId = NodeId::default();
860            let badge: NodeId = view! {
861                row {
862                    style: {
863                        width: Length::Px(SHELL_BRAND_BADGE_SIZE)
864                        height: Length::Px(SHELL_BRAND_BADGE_SIZE)
865                        flex_shrink: 0.0
866                        radius: badge_r
867                        background: primary.get_bg()
868                        border: (g.get_border_width(), primary.get_border())
869                        overflow: Overflow::Hidden
870                        justify: JustifyContent::Center
871                        align: AlignItems::Center
872                    }
873                    role: A11yRole::Group
874                    a11y_label: SHELL_BRAND_A11Y_LABEL.to_string()
875                    text {
876                        node_ref: txt_id
877                        style: {
878                            font_size: 13.0
879                            font_weight: FontWeight::Bold
880                            color: primary.get_fg()
881                            text_align: TextAlign::Center
882                            text_overflow: TextOverflow::Clip
883                        }
884                        { initial_owned }
885                    }
886                }
887            };
888            (badge, Some(txt_id))
889        }
890    }
891}
892
893/// Declarative `#[component]` implementation for `EuvAppShell`.
894#[component]
895/// Inherent implementation of [`EuvAppShell`].
896impl EuvAppShell {
897    /// Renders `EuvAppShell` into the ambient framework-managed `Context`.
898    ///
899    /// # Arguments
900    ///
901    /// - `&Self` - Component descriptor reference.
902    ///
903    /// # Returns
904    ///
905    /// - `NodeId` - Mounted root scene node handle.
906    fn render(&self) -> NodeId {
907        let mut ctx: Context = current_context();
908        bind_fullscreen_context(&ctx);
909        let tokens: ThemeTokens = self.get_tokens();
910        let bp_sig: Signal<Breakpoint> = ctx.get_breakpoint();
911        let vp_sig: Signal<Size> = ctx.get_viewport_size();
912        let safe_sig: Signal<SafeAreaInsets> = ctx.get_safe_area();
913        let gesture_sig: Signal<Option<GestureEvent>> = ctx.get_gesture();
914        let swipe_drag_sig: Signal<f32> = ctx.get_swipe_drag_offset();
915        let fps_sig: Signal<f32> = ctx.get_live_fps();
916        let refresh_sig: Signal<f32> = ctx.get_display_refresh_rate();
917        let app_state_sig: Signal<AppState> = ctx.get_app_state();
918        let fs_active_sig: Signal<bool> = use_fullscreen_active();
919        let ctx_fs_sig: Signal<bool> = ctx.immersive_fullscreen_signal();
920        let overlay_count_sig: Signal<usize> = EuvOverlayStack::active_count_signal();
921        let show_fps: bool = self.get_show_fps();
922        let auto_hide_enabled: bool = self.get_auto_hide_chrome_on_scroll();
923        let Self {
924            brand,
925            sidebar,
926            main_content,
927            route_signal,
928            top_bar_actions,
929            mobile_header_actions,
930            sidebar_footer,
931            breadcrumb,
932            bottom_nav,
933            swipe_routes,
934            swipe_routes_enabled,
935            show_fps_signal,
936            theme,
937            page_padding,
938            auto_hide_chrome_signal,
939            brand_url,
940            on_brand_click,
941            brand_logo,
942            drawer_open,
943            layout_mode,
944            ..
945        } = self;
946        let sidebar: NodeId = *sidebar;
947        let main_content: NodeId = *main_content;
948        let route_signal: Option<Signal<String>> = *route_signal;
949        let top_bar_actions: Option<NodeId> = *top_bar_actions;
950        let mobile_header_actions: Option<NodeId> = *mobile_header_actions;
951        let sidebar_footer: Option<NodeId> = *sidebar_footer;
952        let breadcrumb: Option<Signal<String>> = *breadcrumb;
953        let bottom_nav: Option<NodeId> = *bottom_nav;
954        let page_padding: Option<Signal<Edges>> = *page_padding;
955        let swipe_routes_enabled: Option<Signal<bool>> = *swipe_routes_enabled;
956        let show_fps_signal: Option<Signal<bool>> = *show_fps_signal;
957        let auto_hide_chrome_signal: Option<Signal<bool>> = *auto_hide_chrome_signal;
958        let brand_url_opt: Option<String> = brand_url.clone();
959        let on_brand_click_opt: Option<ShellBrandClickHandler> = on_brand_click.clone();
960        let brand_logo_ref: Option<&ImageBuffer> = brand_logo.as_ref();
961        let drawer_open_opt: Option<Signal<bool>> = *drawer_open;
962        let layout_mode_opt: Option<Signal<EuvShellLayoutMode>> = *layout_mode;
963        let brand_owned: String = brand.clone();
964        let init_vp: Size = vp_sig.get_untracked();
965        let init_mode: EuvShellLayoutMode =
966            EuvShellLayoutMode::from_viewport_width(init_vp.get_width());
967        let init_desktop: bool = init_mode.is_desktop();
968        if let Some(mode_sig) = layout_mode_opt {
969            let _: bool = mode_sig.set_if_changed(init_mode);
970        }
971        let auto_hide_capable: bool = auto_hide_enabled || auto_hide_chrome_signal.is_some();
972        let mount_fps_pills: bool = show_fps || show_fps_signal.is_some();
973        let init_show_fps: bool =
974            show_fps_signal.map_or(show_fps, |sig: Signal<bool>| sig.get_untracked());
975        let has_custom_brand_action: bool = on_brand_click_opt.is_some() || brand_url_opt.is_some();
976        let swipe_routes_rc: Rc<[String]> = Rc::from(swipe_routes.as_slice());
977        let theme_state_opt: Option<UiThemeState> = theme.clone();
978        if let Some(theme_ref) = theme_state_opt.as_ref() {
979            provide_theme(theme_ref.clone());
980        }
981        let init_tok: ThemeTokens = live_tokens_untracked(tokens);
982        let p: ThemePalette = init_tok.get_palette();
983        let g: ThemeGeometry = init_tok.get_geometry();
984        let has_managed_outlet: bool = ctx.get_scene().with_read(
985            |tree: &SceneTree| {
986                tree.get_node(main_content)
987                    .map(|n: &SceneNode| {
988                        let lay: LayoutStyle = n.style_ref().get_layout();
989                        matches!(n.get_kind(), NodeKind::View)
990                            && lay.get_overflow() == Overflow::Hidden
991                            && lay.get_height() == Length::Percent(100.0)
992                    })
993                    .unwrap_or(false)
994            },
995            false,
996        );
997        let has_bottom_nav: bool = bottom_nav.is_some();
998        let dock_radius: f32 = g.get_radius_lg();
999        let dock_host_pad: Edges = Edges::symmetric(CONTROL_INSET, CONTROL_INSET * 0.5);
1000        let brand_initial: String = brand
1001            .chars()
1002            .next()
1003            .map(|c: char| c.to_ascii_uppercase().to_string())
1004            .unwrap_or_else(|| SHELL_DEFAULT_INITIAL.to_string());
1005        let menu_open: Signal<bool> = drawer_open_opt.unwrap_or_else(|| Signal::new(false));
1006        if init_desktop {
1007            let _: bool = menu_open.set_if_changed(false);
1008        }
1009        let drawer_expanded: Signal<bool> = Signal::new(false);
1010        let chrome_hidden: Signal<bool> = Signal::new(false);
1011        let scroll_hide_state: Rc<Cell<ChromeScrollAutoHideState>> =
1012            Rc::new(Cell::new(ChromeScrollAutoHideState::default()));
1013        let hooked_scroll_nodes: Rc<RefCell<Vec<NodeId>>> = Rc::new(RefCell::new(Vec::new()));
1014        let drawer_drag_active: Rc<Cell<bool>> = Rc::new(Cell::new(false));
1015        let drawer_drag_start_x: Rc<Cell<f32>> = Rc::new(Cell::new(0.0));
1016        let drawer_drag_base_w: Rc<Cell<f32>> = Rc::new(Cell::new(248.0));
1017        let drawer_drag_moved: Rc<Cell<bool>> = Rc::new(Cell::new(false));
1018        let div_h: f32 = g.get_border_width().max(1.0);
1019        let mut top_bar_chrome: NodeId = NodeId::default();
1020        let mut top_bar: NodeId = NodeId::default();
1021        let mut top_bar_divider: NodeId = NodeId::default();
1022        let mut top_title_txt: NodeId = NodeId::default();
1023        let mut body_row: NodeId = NodeId::default();
1024        let mut nav_rail: NodeId = NodeId::default();
1025        let mut nav_divider: NodeId = NodeId::default();
1026        let mut content_column: NodeId = NodeId::default();
1027        let mut desktop_top_chrome: NodeId = NodeId::default();
1028        let mut desktop_top_bar: NodeId = NodeId::default();
1029        let mut desktop_top_divider: NodeId = NodeId::default();
1030        let mut desktop_brand_row: NodeId = NodeId::default();
1031        let mut desktop_brand_txt: NodeId = NodeId::default();
1032        let mut desktop_crumb_sep: NodeId = NodeId::default();
1033        let mut crumb_txt: NodeId = NodeId::default();
1034        let mut main_area: NodeId = NodeId::default();
1035        let mut bottom_bar_host: NodeId = NodeId::default();
1036        let mut drawer_portal: NodeId = NodeId::default();
1037        let mut drawer_panel: NodeId = NodeId::default();
1038        let mut drawer_scroll: NodeId = NodeId::default();
1039        let mut drawer_brand_txt: NodeId = NodeId::default();
1040        let mut drawer_grabber: NodeId = NodeId::default();
1041        let mut drawer_grabber_pill: NodeId = NodeId::default();
1042        let mut menu_btn_node: NodeId = NodeId::default();
1043        let mut top_brand_row: NodeId = NodeId::default();
1044        let mut menu_icon_node: NodeId = NodeId::default();
1045        let init_fps: f32 = fps_sig.get_untracked();
1046        let init_hz: f32 = refresh_sig.get_untracked().clamp(30.0, 480.0);
1047        let init_good_fps: f32 = (init_hz * 0.75).clamp(45.0, 90.0);
1048        let init_warn_fps: f32 = (init_hz * 0.45).clamp(24.0, 50.0);
1049        let init_dot_col: Color = if !init_fps.is_finite() || init_fps <= SHELL_FPS_ACTIVE_THRESHOLD
1050        {
1051            p.get_muted_foreground()
1052        } else if init_fps >= init_good_fps {
1053            p.get_success()
1054        } else if init_fps >= init_warn_fps {
1055            p.get_warning()
1056        } else {
1057            p.get_destructive()
1058        };
1059        let init_topbar_ctrl_fg: Color = p.surface(SurfaceRole::Background).get_fg();
1060        let init_fps_disp: Display = if init_show_fps {
1061            Display::Flex
1062        } else {
1063            Display::None
1064        };
1065        let mut mobile_fps_dot: Option<NodeId> = None;
1066        let mut mobile_fps_txt: Option<NodeId> = None;
1067        let mobile_fps_pill: Option<NodeId> = if mount_fps_pills {
1068            let mut dot_node: NodeId = NodeId::default();
1069            let mut txt_node: NodeId = NodeId::default();
1070            let fps_text_mob = move || -> String {
1071                let raw: f32 = fps_sig.get();
1072                if !raw.is_finite() || raw <= SHELL_FPS_ACTIVE_THRESHOLD {
1073                    SHELL_FPS_IDLE_LABEL.to_string()
1074                } else {
1075                    let v: f32 = raw.clamp(1.0, 999.0);
1076                    format!("{v:.0}")
1077                }
1078            };
1079            let pill: NodeId = view! {
1080                row {
1081                    style: {
1082                        display: init_fps_disp
1083                        min_width: Length::Px(48.0)
1084                        height: Length::Px(SHELL_TOPBAR_CONTROL_HEIGHT)
1085                        padding: Edges::symmetric(0.0, SPACE_SM)
1086                        radius: g.get_radius_md()
1087                        justify: JustifyContent::Center
1088                        align: AlignItems::Center
1089                        gap: SPACE_XS
1090                        background: p.get_background()
1091                        border: (g.get_border_width(), p.get_border())
1092                        overflow: Overflow::Hidden
1093                    }
1094                    role: A11yRole::Group
1095                    a11y_label: SHELL_FPS_A11Y_LABEL.to_string()
1096                    view {
1097                        node_ref: dot_node
1098                        style: {
1099                            width: Length::Px(6.0)
1100                            height: Length::Px(6.0)
1101                            radius: RADIUS_PILL
1102                            background: init_dot_col
1103                        }
1104                    }
1105                    text {
1106                        node_ref: txt_node
1107                        style: {
1108                            font_size: 11.0
1109                            font_family: FontFamily::Monospace
1110                            font_weight: FontWeight::Bold
1111                            color: init_topbar_ctrl_fg
1112                            text_align: TextAlign::Center
1113                            text_overflow: TextOverflow::Clip
1114                        }
1115                        { fps_text_mob }
1116                    }
1117                }
1118            };
1119            mobile_fps_dot = Some(dot_node);
1120            mobile_fps_txt = Some(txt_node);
1121            Some(pill)
1122        } else {
1123            None
1124        };
1125        let mut desktop_fps_dot: Option<NodeId> = None;
1126        let mut desktop_fps_txt: Option<NodeId> = None;
1127        let desktop_fps_pill: Option<NodeId> = if mount_fps_pills {
1128            let mut dot_node: NodeId = NodeId::default();
1129            let mut txt_node: NodeId = NodeId::default();
1130            let fps_text_desk = move || -> String {
1131                let raw: f32 = fps_sig.get();
1132                let hz: f32 = refresh_sig.get().clamp(30.0, 480.0);
1133                if !raw.is_finite() || raw <= SHELL_FPS_ACTIVE_THRESHOLD {
1134                    format!("{SHELL_FPS_IDLE_LABEL} · {hz:.0}Hz")
1135                } else {
1136                    let v: f32 = raw.clamp(1.0, 999.0);
1137                    format!("{v:.0} · {hz:.0}Hz")
1138                }
1139            };
1140            let pill: NodeId = view! {
1141                row {
1142                    style: {
1143                        display: init_fps_disp
1144                        min_width: Length::Px(84.0)
1145                        height: Length::Px(SHELL_TOPBAR_CONTROL_HEIGHT)
1146                        padding: Edges::symmetric(0.0, SPACE_SM)
1147                        radius: g.get_radius_md()
1148                        justify: JustifyContent::Center
1149                        align: AlignItems::Center
1150                        gap: SPACE_XS
1151                        background: p.get_background()
1152                        border: (g.get_border_width(), p.get_border())
1153                        overflow: Overflow::Hidden
1154                    }
1155                    role: A11yRole::Group
1156                    a11y_label: SHELL_FPS_A11Y_LABEL.to_string()
1157                    view {
1158                        node_ref: dot_node
1159                        style: {
1160                            width: Length::Px(6.0)
1161                            height: Length::Px(6.0)
1162                            radius: RADIUS_PILL
1163                            background: init_dot_col
1164                        }
1165                    }
1166                    text {
1167                        node_ref: txt_node
1168                        style: {
1169                            font_size: 11.0
1170                            font_family: FontFamily::Monospace
1171                            font_weight: FontWeight::Bold
1172                            color: init_topbar_ctrl_fg
1173                            text_align: TextAlign::Center
1174                            text_overflow: TextOverflow::Clip
1175                        }
1176                        { fps_text_desk }
1177                    }
1178                }
1179            };
1180            desktop_fps_dot = Some(dot_node);
1181            desktop_fps_txt = Some(txt_node);
1182            Some(pill)
1183        } else {
1184            None
1185        };
1186        let paint_menu_icon = move |bounds: Rect, dl: &mut DisplayList| {
1187            let live_p: ThemePalette = live_tokens_untracked(tokens).get_palette();
1188            draw_euv_icon(
1189                EuvIconName::Menu,
1190                bounds,
1191                dl,
1192                live_p.surface(SurfaceRole::Background).get_fg(),
1193            );
1194        };
1195        let on_toggle_menu_btn = move |_: &UiEvent| {
1196            let _: bool = menu_open.update(|v: &mut bool| *v = !*v);
1197        };
1198        let show_menu_btn: bool =
1199            !has_bottom_nav || (has_custom_brand_action && drawer_open_opt.is_none());
1200        let top_brand_cb: Option<ShellBrandClickHandler> = on_brand_click_opt.clone();
1201        let top_brand_url: Option<String> = brand_url_opt.clone();
1202        let on_top_brand_click = move |ev: &UiEvent| {
1203            if let Some(cb) = top_brand_cb.as_ref() {
1204                cb(ev);
1205            } else if let Some(url) = top_brand_url.as_ref() {
1206                let _: bool = dispatch_native_action(SHELL_OPEN_URL_ACTION, url.as_str(), "");
1207            } else {
1208                let _: bool = menu_open.update(|v: &mut bool| *v = !*v);
1209            }
1210        };
1211        let drawer_brand_cb: Option<ShellBrandClickHandler> = on_brand_click_opt.clone();
1212        let drawer_brand_url: Option<String> = brand_url_opt.clone();
1213        let on_drawer_brand_click = move |ev: &UiEvent| {
1214            if let Some(cb) = drawer_brand_cb.as_ref() {
1215                cb(ev);
1216            } else if let Some(url) = drawer_brand_url.as_ref() {
1217                let _: bool = dispatch_native_action(SHELL_OPEN_URL_ACTION, url.as_str(), "");
1218            } else {
1219                let _: bool = menu_open.set_if_changed(false);
1220            }
1221        };
1222        let desktop_brand_cb: Option<ShellBrandClickHandler> = on_brand_click_opt;
1223        let desktop_brand_url: Option<String> = brand_url_opt;
1224        let mut euv_brand_badges: Vec<NodeId> = Vec::with_capacity(3);
1225        let mut initial_brand_badges: Vec<(NodeId, NodeId)> = Vec::with_capacity(3);
1226        let top_brand_badge: Option<NodeId> = {
1227            let badge_a11y: &str = if show_menu_btn || has_custom_brand_action {
1228                SHELL_BRAND_A11Y_LABEL
1229            } else {
1230                SHELL_MENU_LABEL
1231            };
1232            let (badge_id, txt_opt): (NodeId, Option<NodeId>) =
1233                Self::mount_brand_logo(&brand_initial, brand_logo_ref, init_tok, Some(badge_a11y));
1234            if let Some(tid) = txt_opt {
1235                initial_brand_badges.push((badge_id, tid));
1236            } else {
1237                euv_brand_badges.push(badge_id);
1238            }
1239            Some(badge_id)
1240        };
1241        let (desktop_brand_badge, desktop_badge_txt_opt): (NodeId, Option<NodeId>) =
1242            Self::mount_brand_logo(&brand_initial, brand_logo_ref, init_tok, None);
1243        if let Some(tid) = desktop_badge_txt_opt {
1244            initial_brand_badges.push((desktop_brand_badge, tid));
1245        } else {
1246            euv_brand_badges.push(desktop_brand_badge);
1247        }
1248        let (drawer_brand_badge, drawer_badge_txt_opt): (NodeId, Option<NodeId>) =
1249            Self::mount_brand_logo(&brand_initial, brand_logo_ref, init_tok, None);
1250        if let Some(tid) = drawer_badge_txt_opt {
1251            initial_brand_badges.push((drawer_brand_badge, tid));
1252        } else {
1253            euv_brand_badges.push(drawer_brand_badge);
1254        }
1255        let sidebar_safe_spacer: NodeId = view! {
1256            view {
1257                style: {
1258                    display: Display::None
1259                    width: Length::Percent(100.0)
1260                    height: Length::Px(0.0)
1261                    flex_shrink: 0.0
1262                }
1263            }
1264        };
1265        let desktop_brand_cursor: CursorIcon = if has_custom_brand_action {
1266            CursorIcon::Pointer
1267        } else {
1268            CursorIcon::Default
1269        };
1270        let root: NodeId = view! {
1271            column {
1272                style: {
1273                    width: Length::Percent(100.0)
1274                    height: Length::Percent(100.0)
1275                    background: p.get_background()
1276                    overflow: Overflow::Hidden
1277                }
1278                column {
1279                    node_ref: top_bar_chrome
1280                    style: {
1281                        display: if init_desktop { Display::None } else { Display::Flex }
1282                        width: Length::Percent(100.0)
1283                        flex_shrink: 0.0
1284                        overflow: Overflow::Hidden
1285                        z_index: Z_INDEX_CHROME
1286                    }
1287                    row {
1288                        node_ref: top_bar
1289                        style: {
1290                            width: Length::Percent(100.0)
1291                            height: Length::Px(MOBILE_HEADER_HEIGHT)
1292                            justify: JustifyContent::SpaceBetween
1293                            align: AlignItems::Center
1294                            gap: SPACE_XS
1295                            background: p.get_card()
1296                            overflow: Overflow::Hidden
1297                        }
1298                        row {
1299                            node_ref: top_brand_row
1300                            style: {
1301                                flex_grow: 1.0
1302                                flex_shrink: 1.0
1303                                min_width: Length::Px(0.0)
1304                                align: AlignItems::Center
1305                                gap: SPACE_XS
1306                                overflow: Overflow::Hidden
1307                                cursor: CursorIcon::Pointer
1308                            }
1309                            on_click: on_top_brand_click
1310                            if let Some(badge_node) = top_brand_badge {
1311                                { badge_node }
1312                            }
1313                            text {
1314                                node_ref: top_title_txt
1315                                style: {
1316                                    flex_grow: 1.0
1317                                    flex_shrink: 1.0
1318                                    min_width: Length::Px(0.0)
1319                                    font_size: 14.0
1320                                    font_weight: FontWeight::Bold
1321                                    color: p.get_foreground()
1322                                    overflow: Overflow::Hidden
1323                                    text_overflow: TextOverflow::Ellipsis
1324                                }
1325                                { brand.clone() }
1326                            }
1327                        }
1328                        row {
1329                            style: {
1330                                flex_shrink: 0.0
1331                                align: AlignItems::Center
1332                                gap: SPACE_XS
1333                            }
1334                            if let Some(fps_node) = mobile_fps_pill {
1335                                { fps_node }
1336                            }
1337                            if let Some(mob_act) = mobile_header_actions {
1338                                { mob_act }
1339                            }
1340                            if show_menu_btn {
1341                                row {
1342                                    node_ref: menu_btn_node
1343                                    style: {
1344                                        width: Length::Px(SHELL_TOPBAR_CONTROL_HEIGHT)
1345                                        height: Length::Px(SHELL_TOPBAR_CONTROL_HEIGHT)
1346                                        justify: JustifyContent::Center
1347                                        align: AlignItems::Center
1348                                        radius: g.get_radius_md()
1349                                        background: p.get_background()
1350                                        border: (g.get_border_width(), p.get_border())
1351                                        overflow: Overflow::Hidden
1352                                        cursor: CursorIcon::Pointer
1353                                    }
1354                                    role: A11yRole::Button
1355                                    a11y_label: SHELL_MENU_LABEL.to_string()
1356                                    on_click: on_toggle_menu_btn
1357                                    canvas {
1358                                        node_ref: menu_icon_node
1359                                        style: {
1360                                            width: Length::Px(15.0)
1361                                            height: Length::Px(15.0)
1362                                        }
1363                                        painter: paint_menu_icon
1364                                    }
1365                                }
1366                            }
1367                        }
1368                    }
1369                    view {
1370                        node_ref: top_bar_divider
1371                        style: {
1372                            width: Length::Percent(100.0)
1373                            height: Length::Px(div_h)
1374                            background: p.get_border()
1375                        }
1376                    }
1377                }
1378                column {
1379                    node_ref: desktop_top_chrome
1380                    style: {
1381                        display: if init_desktop { Display::Flex } else { Display::None }
1382                        width: Length::Percent(100.0)
1383                        flex_shrink: 0.0
1384                        overflow: Overflow::Hidden
1385                        z_index: Z_INDEX_CHROME
1386                    }
1387                    row {
1388                        node_ref: desktop_top_bar
1389                        style: {
1390                            width: Length::Percent(100.0)
1391                            height: Length::Px(SHELL_DESKTOP_HEADER_HEIGHT)
1392                            justify: JustifyContent::SpaceBetween
1393                            align: AlignItems::Center
1394                            gap: SPACE_MD
1395                            padding: Edges::symmetric(0.0, SPACE_MD)
1396                            background: p.get_card()
1397                            overflow: Overflow::Hidden
1398                        }
1399                        row {
1400                            style: {
1401                                flex_grow: 1.0
1402                                flex_shrink: 1.0
1403                                min_width: Length::Px(0.0)
1404                                align: AlignItems::Center
1405                                gap: SPACE_SM
1406                                overflow: Overflow::Hidden
1407                            }
1408                            row {
1409                                node_ref: desktop_brand_row
1410                                style: {
1411                                    flex_shrink: 0.0
1412                                    align: AlignItems::Center
1413                                    gap: SPACE_SM
1414                                    cursor: desktop_brand_cursor
1415                                }
1416                                { desktop_brand_badge }
1417                                text {
1418                                    node_ref: desktop_brand_txt
1419                                    style: {
1420                                        font_size: 15.0
1421                                        font_weight: FontWeight::Bold
1422                                        color: p.get_foreground()
1423                                    }
1424                                    { brand.clone() }
1425                                }
1426                            }
1427                            text {
1428                                node_ref: desktop_crumb_sep
1429                                style: {
1430                                    display: Display::None
1431                                    flex_shrink: 0.0
1432                                    font_size: 13.0
1433                                    font_weight: FontWeight::Normal
1434                                    color: p.get_muted_foreground()
1435                                }
1436                                { SHELL_BREADCRUMB_SEP }
1437                            }
1438                            text {
1439                                node_ref: crumb_txt
1440                                style: {
1441                                    display: Display::None
1442                                    flex_grow: 1.0
1443                                    flex_shrink: 1.0
1444                                    min_width: Length::Px(0.0)
1445                                    font_size: 13.0
1446                                    font_weight: FontWeight::Medium
1447                                    color: p.get_muted_foreground()
1448                                    overflow: Overflow::Hidden
1449                                    text_overflow: TextOverflow::Ellipsis
1450                                }
1451                                { String::new() }
1452                            }
1453                        }
1454                        row {
1455                            style: {
1456                                flex_shrink: 0.0
1457                                align: AlignItems::Center
1458                                gap: SPACE_SM
1459                            }
1460                            if let Some(fps_d) = desktop_fps_pill {
1461                                { fps_d }
1462                            }
1463                            if let Some(actions_node) = top_bar_actions {
1464                                { actions_node }
1465                            }
1466                        }
1467                    }
1468                    view {
1469                        node_ref: desktop_top_divider
1470                        style: {
1471                            width: Length::Percent(100.0)
1472                            height: Length::Px(div_h)
1473                            background: p.get_border()
1474                        }
1475                    }
1476                }
1477                row {
1478                    node_ref: body_row
1479                    style: {
1480                        flex_grow: 1.0
1481                        width: Length::Percent(100.0)
1482                        height: Length::Percent(100.0)
1483                        overflow: Overflow::Hidden
1484                    }
1485                    scroll {
1486                        node_ref: nav_rail
1487                        style: {
1488                            Style::default().column()
1489                            display: if init_desktop { Display::Flex } else { Display::None }
1490                            width: Length::Px(SHELL_DESKTOP_SIDEBAR_WIDTH)
1491                            height: Length::Percent(100.0)
1492                            min_height: Length::Px(0.0)
1493                            flex_shrink: 0.0
1494                            overflow: Overflow::Scroll
1495                            gap: SPACE_MD
1496                            background: p.get_card()
1497                            z_index: Z_INDEX_CHROME
1498                        }
1499                    }
1500                    view {
1501                        node_ref: nav_divider
1502                        style: {
1503                            display: if init_desktop { Display::Flex } else { Display::None }
1504                            width: Length::Px(div_h)
1505                            height: Length::Percent(100.0)
1506                            flex_shrink: 0.0
1507                            background: p.get_border()
1508                        }
1509                    }
1510                    column {
1511                        node_ref: content_column
1512                        style: {
1513                            flex_grow: 1.0
1514                            flex_shrink: 1.0
1515                            min_width: Length::Px(0.0)
1516                            height: Length::Percent(100.0)
1517                            overflow: Overflow::Hidden
1518                        }
1519                        scroll {
1520                            node_ref: main_area
1521                            style: {
1522                                Style::default().column()
1523                                flex_grow: 1.0
1524                                width: Length::Percent(100.0)
1525                                height: Length::Percent(100.0)
1526                                min_width: Length::Px(0.0)
1527                                align: AlignItems::Center
1528                                overflow: if has_managed_outlet { Overflow::Hidden } else { Overflow::Scroll }
1529                                gap: if has_managed_outlet { 0.0 } else { SPACE_LG }
1530                            }
1531                            { main_content }
1532                        }
1533                    }
1534                }
1535                row {
1536                    node_ref: bottom_bar_host
1537                    style: {
1538                        display: if has_bottom_nav && !init_desktop { Display::Flex } else { Display::None }
1539                        position: Position::Fixed
1540                        inset: (None, None, Some(SHELL_BOTTOM_NAV_FLOAT_COMPACT), Some(SHELL_BOTTOM_NAV_SIDE_MARGIN))
1541                        width: Length::Px(340.0)
1542                        height: Length::Px(SHELL_BOTTOM_NAV_HEIGHT)
1543                        padding: dock_host_pad
1544                        justify: JustifyContent::Center
1545                        align: AlignItems::Center
1546                        background: p.get_card().with_alpha(SHELL_BOTTOM_NAV_BG_ALPHA)
1547                        border: (g.get_border_width(), p.get_border())
1548                        radius: dock_radius
1549                        shadow: g.get_shadow_lg()
1550                        overflow: Overflow::Hidden
1551                        stop_scroll_propagation: true
1552                        z_index: Z_INDEX_CHROME
1553                    }
1554                    if let Some(bn) = bottom_nav {
1555                        { bn }
1556                    }
1557                }
1558                portal {
1559                    node_ref: drawer_portal
1560                    style: {
1561                        Style::default().row()
1562                        display: Display::None
1563                        position: Position::Fixed
1564                        inset: (Some(0.0), Some(0.0), Some(0.0), Some(0.0))
1565                        width: Length::Percent(100.0)
1566                        height: Length::Percent(100.0)
1567                        justify: JustifyContent::Start
1568                        background: p.get_overlay()
1569                        stop_scroll_propagation: true
1570                        z_index: Z_INDEX_DRAWER
1571                    }
1572                    row {
1573                        node_ref: drawer_panel
1574                        style: {
1575                            width: Length::Px(248.0)
1576                            max_width: Length::Percent(92.0)
1577                            height: Length::Percent(100.0)
1578                            background: p.get_card()
1579                            border: (g.get_border_width(), p.get_border())
1580                            shadow: g.get_shadow_lg()
1581                            overflow: Overflow::Hidden
1582                        }
1583                        scroll {
1584                            node_ref: drawer_scroll
1585                            style: {
1586                                Style::default().column()
1587                                flex_grow: 1.0
1588                                flex_shrink: 1.0
1589                                min_width: Length::Px(0.0)
1590                                min_height: Length::Px(0.0)
1591                                height: Length::Percent(100.0)
1592                                overflow: Overflow::Scroll
1593                                gap: SPACE_SM
1594                                stop_scroll_propagation: true
1595                            }
1596                            row {
1597                                style: {
1598                                    width: Length::Percent(100.0)
1599                                    flex_shrink: 0.0
1600                                    align: AlignItems::Center
1601                                    gap: SPACE_SM
1602                                    padding: Edges::new(0.0, 0.0, SPACE_XS, 0.0)
1603                                    cursor: CursorIcon::Pointer
1604                                }
1605                                on_click: on_drawer_brand_click
1606                                { drawer_brand_badge }
1607                                text {
1608                                    node_ref: drawer_brand_txt
1609                                    style: {
1610                                        font_size: 14.5
1611                                        font_weight: FontWeight::Bold
1612                                        color: p.get_foreground()
1613                                    }
1614                                    { brand.clone() }
1615                                }
1616                            }
1617                        }
1618                        row {
1619                            node_ref: drawer_grabber
1620                            style: {
1621                                width: Length::Px(20.0)
1622                                height: Length::Percent(100.0)
1623                                flex_shrink: 0.0
1624                                justify: JustifyContent::Center
1625                                align: AlignItems::Center
1626                                cursor: CursorIcon::EwResize
1627                                stop_scroll_propagation: true
1628                                stop_event_propagation: true
1629                            }
1630                            view {
1631                                node_ref: drawer_grabber_pill
1632                                style: {
1633                                    width: Length::Px(4.0)
1634                                    height: Length::Px(46.0)
1635                                    radius: RADIUS_PILL
1636                                    background: p.get_muted_foreground().with_alpha(128)
1637                                }
1638                            }
1639                        }
1640                    }
1641                }
1642            }
1643        };
1644        if has_custom_brand_action {
1645            let brand_a11y: String = brand.clone();
1646            ctx.get_scene().with_write(
1647                |tree: &mut SceneTree| {
1648                    for target_row in [desktop_brand_row, top_brand_row].into_iter() {
1649                        if let Some(n) = tree.get_node_mut(target_row) {
1650                            let _: &mut SceneNode = n.set_a11y(Some(A11yProps::new(
1651                                A11yRole::Button,
1652                                brand_a11y.clone(),
1653                            )));
1654                        }
1655                    }
1656                },
1657                (),
1658            );
1659            ctx.on_click(desktop_brand_row, move |ev: &UiEvent| {
1660                if let Some(cb) = desktop_brand_cb.as_ref() {
1661                    cb(ev);
1662                } else if let Some(url) = desktop_brand_url.as_ref() {
1663                    let _: bool = dispatch_native_action(SHELL_OPEN_URL_ACTION, url.as_str(), "");
1664                }
1665            });
1666        }
1667        let scroll_observer: ChromeScrollObserver = ChromeScrollObserver::new(
1668            auto_hide_enabled,
1669            auto_hide_chrome_signal,
1670            ctx.get_scene().clone(),
1671            Rc::clone(&scroll_hide_state),
1672            ctx_fs_sig,
1673            menu_open,
1674            chrome_hidden,
1675        );
1676        if auto_hide_capable {
1677            let reveal_scroll_obs: ChromeScrollObserver = scroll_observer.clone();
1678            ctx.on_scroll(content_column, move |ev: &UiEvent| {
1679                reveal_scroll_obs.observe_unconsumed_up(ev);
1680            });
1681        }
1682        if !has_managed_outlet {
1683            let main_clamp_scene: SceneHandle = ctx.get_scene().clone();
1684            let main_scroll_obs: ChromeScrollObserver = scroll_observer.clone();
1685            ctx.on_scroll(main_area, move |ev: &UiEvent| {
1686                main_clamp_scene.with_write(
1687                    |tree: &mut SceneTree| {
1688                        if let Some(cur) = tree
1689                            .get_node(main_area)
1690                            .map(|n: &SceneNode| n.get_layout_box().get_scroll_offset())
1691                            && cur.get_x().abs() > 0.01
1692                        {
1693                            tree.set_scroll_offset(main_area, Point::new(0.0, cur.get_y()));
1694                        }
1695                    },
1696                    (),
1697                );
1698                main_scroll_obs.observe(main_area, ev);
1699            });
1700        } else if auto_hide_capable {
1701            Self::attach_outlet_scroll_observers(
1702                ctx.get_scene(),
1703                main_content,
1704                &hooked_scroll_nodes,
1705                &scroll_observer,
1706            );
1707            let scene_pe: SceneHandle = ctx.get_scene().clone();
1708            let hooked_pe: Rc<RefCell<Vec<NodeId>>> = Rc::clone(&hooked_scroll_nodes);
1709            let obs_pe: ChromeScrollObserver = scroll_observer.clone();
1710            ctx.on_pointer_enter(main_area, move |_: &UiEvent| {
1711                Self::attach_outlet_scroll_observers(&scene_pe, main_content, &hooked_pe, &obs_pe);
1712            });
1713        }
1714        let d_down_active: Rc<Cell<bool>> = drawer_drag_active.clone();
1715        let d_down_x: Rc<Cell<f32>> = drawer_drag_start_x.clone();
1716        let d_down_w: Rc<Cell<f32>> = drawer_drag_base_w.clone();
1717        let d_down_moved: Rc<Cell<bool>> = drawer_drag_moved.clone();
1718        let h_down: SceneHandle = ctx.get_scene().clone();
1719        ctx.on_pointer_down(drawer_grabber, move |ev: &UiEvent| {
1720            if let UiEventKind::PointerDown(pt) = ev.get_kind() {
1721                h_down.with_write(
1722                    |tree: &mut SceneTree| {
1723                        tree.cancel_subtree_transitions(drawer_panel);
1724                    },
1725                    (),
1726                );
1727                let vp_w: f32 = vp_sig.get_untracked().get_width().max(320.0);
1728                let def_w: f32 = (vp_w * 0.68).clamp(224.0, 256.0);
1729                let cur_w: f32 = h_down
1730                    .node_screen_bounds(drawer_panel)
1731                    .map(|r: Rect| r.get_width())
1732                    .filter(|w: &f32| *w > 40.0)
1733                    .unwrap_or(def_w);
1734                d_down_active.set(true);
1735                d_down_x.set(pt.get_x());
1736                d_down_w.set(cur_w);
1737                d_down_moved.set(false);
1738            }
1739        });
1740        let d_scrim_moved: Rc<Cell<bool>> = drawer_drag_moved.clone();
1741        ctx.on_pointer_down(drawer_portal, move |_: &UiEvent| {
1742            d_scrim_moved.set(false);
1743        });
1744        for target_node in [drawer_grabber, drawer_panel, drawer_portal].into_iter() {
1745            let h_move: SceneHandle = ctx.get_scene().clone();
1746            let da_move: Rc<Cell<bool>> = drawer_drag_active.clone();
1747            let sx_move: Rc<Cell<f32>> = drawer_drag_start_x.clone();
1748            let bw_move: Rc<Cell<f32>> = drawer_drag_base_w.clone();
1749            let dm_move: Rc<Cell<bool>> = drawer_drag_moved.clone();
1750            ctx.on_pointer_move(target_node, move |ev: &UiEvent| {
1751                if !da_move.get() {
1752                    return;
1753                }
1754                if let UiEventKind::PointerMove(pt) = ev.get_kind() {
1755                    let dx: f32 = pt.get_x() - sx_move.get();
1756                    if dx.abs() > 4.0 {
1757                        dm_move.set(true);
1758                    }
1759                    let vp_w: f32 = vp_sig.get_untracked().get_width().max(320.0);
1760                    let def_w: f32 = (vp_w * 0.68).clamp(224.0, 256.0);
1761                    let max_w: f32 = (vp_w * 0.88).clamp(def_w + 40.0, 380.0);
1762                    let raw_w: f32 = bw_move.get() + dx;
1763                    let (next_w, tx): (f32, f32) = if raw_w >= def_w {
1764                        (raw_w.min(max_w), 0.0)
1765                    } else {
1766                        (def_w, (raw_w - def_w).min(0.0))
1767                    };
1768                    h_move.with_write(
1769                        |tree: &mut SceneTree| {
1770                            if let Some(n) = tree.get_node_mut(drawer_panel) {
1771                                let st: &mut Style = n.get_mut_style();
1772                                st.get_mut_layout().set_width(Length::Px(next_w));
1773                                st.get_mut_paint()
1774                                    .set_transform(Transform2D::new(tx, 0.0, 1.0, 1.0, 0.0));
1775                                let layout_dirty: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
1776                                tree.mark_dirty(drawer_panel, layout_dirty | DIRTY_PAINT);
1777                            }
1778                        },
1779                        (),
1780                    );
1781                }
1782            });
1783            let h_up: SceneHandle = ctx.get_scene().clone();
1784            let da_up: Rc<Cell<bool>> = drawer_drag_active.clone();
1785            let sx_up: Rc<Cell<f32>> = drawer_drag_start_x.clone();
1786            ctx.on_pointer_up(target_node, move |ev: &UiEvent| {
1787                if !da_up.replace(false) {
1788                    return;
1789                }
1790                let dx: f32 = match ev.get_kind() {
1791                    UiEventKind::PointerUp(pt) => pt.get_x() - sx_up.get(),
1792                    _ => 0.0,
1793                };
1794                let vp_w: f32 = vp_sig.get_untracked().get_width().max(320.0);
1795                let def_w: f32 = (vp_w * 0.68).clamp(224.0, 256.0);
1796                let max_w: f32 = (vp_w * 0.88).clamp(def_w + 40.0, 380.0);
1797                let is_exp: bool = drawer_expanded.get_untracked();
1798                if dx < -52.0 {
1799                    if is_exp && dx > -140.0 {
1800                        let _: bool = drawer_expanded.set_if_changed(false);
1801                    } else {
1802                        let _: bool = menu_open.set_if_changed(false);
1803                        return;
1804                    }
1805                } else if dx > 40.0 {
1806                    let _: bool = drawer_expanded.set_if_changed(true);
1807                }
1808                let target_w: f32 = if drawer_expanded.get_untracked() {
1809                    max_w
1810                } else {
1811                    def_w
1812                };
1813                h_up.with_write(
1814                    |tree: &mut SceneTree| {
1815                        let cur_tx: f32 = tree
1816                            .get_node(drawer_panel)
1817                            .map(|n: &SceneNode| {
1818                                n.style_ref().get_paint().get_transform().get_translate_x()
1819                            })
1820                            .unwrap_or(0.0);
1821                        tree.cancel_subtree_transitions(drawer_panel);
1822                        if let Some(n) = tree.get_node_mut(drawer_panel) {
1823                            let st: &mut Style = n.get_mut_style();
1824                            st.get_mut_layout().set_width(Length::Px(target_w));
1825                            if cur_tx.abs() <= 0.5 {
1826                                st.get_mut_paint().set_transform(Transform2D::default());
1827                            }
1828                            let layout_dirty: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
1829                            tree.mark_dirty(drawer_panel, layout_dirty | DIRTY_PAINT);
1830                        }
1831                        if cur_tx.abs() > 0.5 {
1832                            tree.start_transition(
1833                                NodeTransition::slide_fade(
1834                                    drawer_panel,
1835                                    Point::new(cur_tx, 0.0),
1836                                    Point::default(),
1837                                    1.0,
1838                                    1.0,
1839                                    motion_duration(MOTION_EMPHASIZED_SECS),
1840                                    false,
1841                                )
1842                                .with_easing(MOTION_EASE_ENTER),
1843                            );
1844                        }
1845                    },
1846                    (),
1847                );
1848            });
1849            let h_cancel: SceneHandle = ctx.get_scene().clone();
1850            let da_cancel: Rc<Cell<bool>> = drawer_drag_active.clone();
1851            let dm_cancel: Rc<Cell<bool>> = drawer_drag_moved.clone();
1852            ctx.on_pointer_cancel(target_node, move |_: &UiEvent| {
1853                if !da_cancel.replace(false) {
1854                    return;
1855                }
1856                dm_cancel.set(false);
1857                h_cancel.with_write(
1858                    |tree: &mut SceneTree| {
1859                        if let Some(n) = tree.get_node_mut(drawer_panel) {
1860                            n.get_mut_style()
1861                                .get_mut_paint()
1862                                .set_transform(Transform2D::default());
1863                            tree.mark_dirty(drawer_panel, DIRTY_PAINT);
1864                        }
1865                    },
1866                    (),
1867                );
1868            });
1869        }
1870        let drawer_click_moved: Rc<Cell<bool>> = drawer_drag_moved.clone();
1871        ctx.on_click(drawer_portal, move |ev: &UiEvent| {
1872            if drawer_click_moved.replace(false) {
1873                return;
1874            }
1875            if ev.get_target() == drawer_portal {
1876                let _: bool = menu_open.set_if_changed(false);
1877            }
1878        });
1879        let handle: SceneHandle = ctx.get_scene().clone();
1880        let handle_layout: SceneHandle = handle.clone();
1881        let handle_crumb: SceneHandle = handle.clone();
1882        let handle_state: SceneHandle = handle.clone();
1883        let drawer_da_close: Rc<Cell<bool>> = drawer_drag_active.clone();
1884        let drawer_dm_close: Rc<Cell<bool>> = drawer_drag_moved.clone();
1885        let drawer_da_layout: Rc<Cell<bool>> = drawer_drag_active.clone();
1886        let drawer_dm_layout: Rc<Cell<bool>> = drawer_drag_moved.clone();
1887        let drawer_da_state: Rc<Cell<bool>> = drawer_drag_active;
1888        let drawer_dm_state: Rc<Cell<bool>> = drawer_drag_moved;
1889        let prev_open: Rc<Cell<bool>> = Rc::new(Cell::new(false));
1890        let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
1891            let _: Effect =
1892                EuvOverlayStack::bind_signal(menu_open, SHELL_DRAWER_OVERLAY_NAME, Z_INDEX_DRAWER);
1893            let _: Effect = Effect::new(move || {
1894                if app_state_sig.get() != AppState::Active && drawer_da_state.replace(false) {
1895                    drawer_dm_state.set(false);
1896                    handle_state.with_write(
1897                        |tree: &mut SceneTree| {
1898                            if let Some(n) = tree.get_node_mut(drawer_panel) {
1899                                n.get_mut_style()
1900                                    .get_mut_paint()
1901                                    .set_transform(Transform2D::default());
1902                                tree.mark_dirty(drawer_panel, DIRTY_PAINT);
1903                            }
1904                        },
1905                        (),
1906                    );
1907                }
1908            });
1909            if mobile_fps_dot.is_some() || desktop_fps_dot.is_some() {
1910                let handle_fps: SceneHandle = handle.clone();
1911                let prev_dot_col: Cell<Color> = Cell::new(init_dot_col);
1912                let _: Effect = Effect::new(move || {
1913                    let live_p: ThemePalette = use_live_tokens(tokens).get_palette();
1914                    let raw: f32 = fps_sig.get();
1915                    let target_hz: f32 = refresh_sig.get().clamp(30.0, 480.0);
1916                    let good_fps: f32 = (target_hz * 0.75).clamp(45.0, 90.0);
1917                    let warn_fps: f32 = (target_hz * 0.45).clamp(24.0, 50.0);
1918                    let dot_col: Color = if !raw.is_finite() || raw <= SHELL_FPS_ACTIVE_THRESHOLD {
1919                        live_p.get_muted_foreground()
1920                    } else if raw >= good_fps {
1921                        live_p.get_success()
1922                    } else if raw >= warn_fps {
1923                        live_p.get_warning()
1924                    } else {
1925                        live_p.get_destructive()
1926                    };
1927                    if prev_dot_col.replace(dot_col) == dot_col {
1928                        return;
1929                    }
1930                    handle_fps.with_write(
1931                        |tree: &mut SceneTree| {
1932                            if let Some(dot_id) = mobile_fps_dot
1933                                && let Some(n) = tree.get_node_mut(dot_id)
1934                            {
1935                                n.get_mut_style()
1936                                    .get_mut_paint()
1937                                    .set_background(Some(dot_col));
1938                                tree.mark_dirty(dot_id, DIRTY_PAINT);
1939                            }
1940                            if let Some(dot_id) = desktop_fps_dot
1941                                && let Some(n) = tree.get_node_mut(dot_id)
1942                            {
1943                                n.get_mut_style()
1944                                    .get_mut_paint()
1945                                    .set_background(Some(dot_col));
1946                                tree.mark_dirty(dot_id, DIRTY_PAINT);
1947                            }
1948                        },
1949                        (),
1950                    );
1951                });
1952            }
1953            if let Some(fps_vis_sig) = show_fps_signal {
1954                let handle_fps_vis: SceneHandle = handle.clone();
1955                let _: Effect = Effect::new(move || {
1956                    let next_disp: Display = if fps_vis_sig.get() {
1957                        Display::Flex
1958                    } else {
1959                        Display::None
1960                    };
1961                    handle_fps_vis.with_write(
1962                        |tree: &mut SceneTree| {
1963                            let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
1964                            let dirty_all: u16 = dirty_l | DIRTY_PAINT;
1965                            if let Some(pill_id) = mobile_fps_pill
1966                                && let Some(n) = tree.get_node_mut(pill_id)
1967                            {
1968                                n.get_mut_style().get_mut_layout().set_display(next_disp);
1969                                tree.mark_dirty(pill_id, dirty_all);
1970                                tree.mark_dirty(top_bar, dirty_all);
1971                            }
1972                            if let Some(pill_id) = desktop_fps_pill
1973                                && let Some(n) = tree.get_node_mut(pill_id)
1974                            {
1975                                n.get_mut_style().get_mut_layout().set_display(next_disp);
1976                                tree.mark_dirty(pill_id, dirty_all);
1977                                tree.mark_dirty(desktop_top_bar, dirty_all);
1978                            }
1979                        },
1980                        (),
1981                    );
1982                });
1983            }
1984            if let Some(crumb_sig) = breadcrumb {
1985                let scene_crumb_hook: SceneHandle = handle.clone();
1986                let hooked_for_crumb: Rc<RefCell<Vec<NodeId>>> = Rc::clone(&hooked_scroll_nodes);
1987                let obs_for_crumb: ChromeScrollObserver = scroll_observer.clone();
1988                let brand_for_crumb: String = brand_owned;
1989                let _: Effect = Effect::new(move || {
1990                    let full: String = crumb_sig.get();
1991                    if auto_hide_capable && has_managed_outlet {
1992                        Self::attach_outlet_scroll_observers(
1993                            &scene_crumb_hook,
1994                            main_content,
1995                            &hooked_for_crumb,
1996                            &obs_for_crumb,
1997                        );
1998                    }
1999                    let trimmed: &str = full.trim();
2000                    let mobile_text: String = if trimmed.is_empty() {
2001                        brand_for_crumb.clone()
2002                    } else if let Some((_, leaf)) = trimmed.rsplit_once(" / ") {
2003                        leaf.to_string()
2004                    } else {
2005                        trimmed.to_string()
2006                    };
2007                    let show_desktop_crumb: bool =
2008                        !trimmed.is_empty() && !trimmed.eq_ignore_ascii_case(&brand_for_crumb);
2009                    let desktop_crumb_disp: Display = if show_desktop_crumb {
2010                        Display::Flex
2011                    } else {
2012                        Display::None
2013                    };
2014                    let desktop_text: String = if show_desktop_crumb {
2015                        trimmed.to_string()
2016                    } else {
2017                        String::new()
2018                    };
2019                    handle_crumb.with_write(
2020                        |tree: &mut SceneTree| {
2021                            let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
2022                            let dirty_all: u16 = dirty_l | DIRTY_PAINT;
2023                            if let Some(n) = tree.get_node_mut(top_title_txt) {
2024                                n.set_kind(NodeKind::Text(mobile_text));
2025                                tree.mark_dirty(top_title_txt, dirty_all);
2026                            }
2027                            if let Some(n) = tree.get_node_mut(desktop_crumb_sep) {
2028                                n.get_mut_style()
2029                                    .get_mut_layout()
2030                                    .set_display(desktop_crumb_disp);
2031                                tree.mark_dirty(desktop_crumb_sep, dirty_all);
2032                            }
2033                            if let Some(n) = tree.get_node_mut(crumb_txt) {
2034                                n.get_mut_style()
2035                                    .get_mut_layout()
2036                                    .set_display(desktop_crumb_disp);
2037                                n.set_kind(NodeKind::Text(desktop_text));
2038                                tree.mark_dirty(crumb_txt, dirty_all);
2039                            }
2040                        },
2041                        (),
2042                    );
2043                });
2044            }
2045            let mut scratch_children: Vec<NodeId> = Vec::new();
2046            let prev_chrome_hidden: Rc<Cell<bool>> = Rc::new(Cell::new(false));
2047            let prev_fullscreen: Rc<Cell<bool>> = Rc::new(Cell::new(false));
2048            let prev_vp_size: Rc<Cell<Size>> = Rc::new(Cell::new(vp_sig.get_untracked()));
2049            let hooked_for_layout: Rc<RefCell<Vec<NodeId>>> = Rc::clone(&hooked_scroll_nodes);
2050            let scroll_obs_for_layout: ChromeScrollObserver = scroll_observer.clone();
2051            let hide_state_for_layout: Rc<Cell<ChromeScrollAutoHideState>> =
2052                Rc::clone(&scroll_hide_state);
2053            let _: Effect = Effect::new(move || {
2054                let bp: Breakpoint = bp_sig.get();
2055                let vp: Size = vp_sig.get();
2056                let safe: SafeAreaInsets = safe_sig.get();
2057                let is_fullscreen: bool = fs_active_sig.get() || ctx_fs_sig.get();
2058                let was_fullscreen: bool = prev_fullscreen.replace(is_fullscreen);
2059                let exited_fullscreen: bool = was_fullscreen && !is_fullscreen;
2060                let auto_hide_active: bool = auto_hide_chrome_signal
2061                    .map_or(auto_hide_enabled, |sig: Signal<bool>| sig.get());
2062                let prev_vp: Size = prev_vp_size.replace(vp);
2063                let vp_resized: bool = (prev_vp.get_width() - vp.get_width()).abs() > 1.0
2064                    || (prev_vp.get_height() - vp.get_height()).abs() > 1.0;
2065                let reset_hide_for_fs: bool = is_fullscreen || exited_fullscreen;
2066                if !auto_hide_active {
2067                    let _: bool = chrome_hidden.set_if_changed(false);
2068                    hide_state_for_layout.set(ChromeScrollAutoHideState::default());
2069                } else if reset_hide_for_fs || vp_resized {
2070                    let was_hidden_now: bool = chrome_hidden.get_untracked();
2071                    let _: bool = chrome_hidden.set_if_changed(false);
2072                    let mut next_tracker: ChromeScrollAutoHideState =
2073                        ChromeScrollAutoHideState::default();
2074                    if vp_resized && was_hidden_now {
2075                        next_tracker.reset_with_suppression(2);
2076                    }
2077                    hide_state_for_layout.set(next_tracker);
2078                }
2079                let is_chrome_hidden: bool =
2080                    auto_hide_active && !is_fullscreen && chrome_hidden.get();
2081                let was_chrome_hidden: bool = prev_chrome_hidden.replace(is_chrome_hidden);
2082                let chrome_toggled: bool = !vp_resized
2083                    && !is_fullscreen
2084                    && !exited_fullscreen
2085                    && was_chrome_hidden != is_chrome_hidden;
2086                if auto_hide_active && has_managed_outlet {
2087                    Self::attach_outlet_scroll_observers(
2088                        &handle_layout,
2089                        main_content,
2090                        &hooked_for_layout,
2091                        &scroll_obs_for_layout,
2092                    );
2093                }
2094                let vp_w: f32 = vp.get_width().max(240.0);
2095                let vp_h: f32 = vp.get_height().max(240.0);
2096                let shell_mode: EuvShellLayoutMode = EuvShellLayoutMode::from_viewport_width(vp_w);
2097                let is_desktop: bool = shell_mode.is_desktop();
2098                let is_mobile: bool = shell_mode.is_mobile();
2099                if let Some(mode_sig) = layout_mode_opt {
2100                    let _: bool = mode_sig.set_if_changed(shell_mode);
2101                }
2102                let show_bottom_nav: bool = has_bottom_nav && is_mobile && !is_fullscreen;
2103                let top_inset: f32 = safe.get_top();
2104                let bottom_inset: f32 = safe.get_bottom();
2105                let left_inset: f32 = safe.get_left();
2106                let right_inset: f32 = safe.get_right();
2107                let safe_bar_content_h: f32 = SHELL_TOPBAR_CONTROL_HEIGHT
2108                    + SHELL_TOPBAR_SAFE_TOP_GAP
2109                    + SHELL_TOPBAR_SAFE_BOTTOM_GAP;
2110                let mobile_bar_h: f32 = if top_inset > 0.0 {
2111                    top_inset + safe_bar_content_h
2112                } else {
2113                    MOBILE_HEADER_HEIGHT
2114                };
2115                let mobile_pad_top: f32 = if top_inset > 0.0 {
2116                    top_inset + SHELL_TOPBAR_SAFE_TOP_GAP
2117                } else {
2118                    0.0
2119                };
2120                let mobile_pad_bottom: f32 = if top_inset > 0.0 {
2121                    SHELL_TOPBAR_SAFE_BOTTOM_GAP
2122                } else {
2123                    0.0
2124                };
2125                let desktop_bar_h: f32 = if top_inset > 0.0 {
2126                    top_inset + SHELL_DESKTOP_HEADER_HEIGHT
2127                } else {
2128                    SHELL_DESKTOP_HEADER_HEIGHT
2129                };
2130                let desktop_pad_top: f32 = if top_inset > 0.0 { top_inset } else { 0.0 };
2131                let float_gap: f32 = if bp.is_compact() {
2132                    SHELL_BOTTOM_NAV_FLOAT_COMPACT
2133                } else {
2134                    SHELL_BOTTOM_NAV_FLOAT_WIDE
2135                };
2136                let dock_bottom: f32 = float_gap + bottom_inset;
2137                let usable_w: f32 = (vp_w - left_inset - right_inset).max(200.0);
2138                let side_margin: f32 = if bp.is_compact() {
2139                    SHELL_BOTTOM_NAV_SIDE_MARGIN
2140                } else {
2141                    SHELL_BOTTOM_NAV_SIDE_MARGIN_WIDE
2142                };
2143                let min_dock_w: f32 = 240.0_f32.min((usable_w - 16.0).max(160.0));
2144                let dock_w: f32 =
2145                    (usable_w - side_margin * 2.0).clamp(min_dock_w, SHELL_BOTTOM_NAV_MAX_WIDTH);
2146                let dock_left: f32 = left_inset + ((usable_w - dock_w) * 0.5).max(8.0);
2147                let active_top_h: f32 = if is_desktop {
2148                    desktop_bar_h
2149                } else {
2150                    mobile_bar_h
2151                };
2152                let top_reclaimed: bool = is_fullscreen || is_chrome_hidden;
2153                let body_h: f32 = if top_reclaimed {
2154                    vp_h
2155                } else {
2156                    (vp_h - active_top_h - div_h).max(120.0)
2157                };
2158                let main_h: f32 = body_h;
2159                if is_desktop || is_fullscreen {
2160                    let _: bool = menu_open.set_if_changed(false);
2161                    let _: bool = drawer_expanded.set_if_changed(false);
2162                    drawer_da_layout.set(false);
2163                    drawer_dm_layout.set(false);
2164                }
2165                let drawer_vp_w: f32 = vp.get_width().max(320.0);
2166                let drawer_vp_h: f32 = vp.get_height().max(240.0);
2167                let drawer_def_w: f32 = (drawer_vp_w * 0.68).clamp(224.0, 256.0);
2168                let drawer_max_w: f32 = (drawer_vp_w * 0.88).clamp(drawer_def_w + 40.0, 380.0);
2169                let drawer_target_w: f32 = if drawer_expanded.get() {
2170                    drawer_max_w
2171                } else {
2172                    drawer_def_w
2173                };
2174                let desktop_disp: Display = if is_fullscreen || is_mobile {
2175                    Display::None
2176                } else {
2177                    Display::Flex
2178                };
2179                let bottom_hide_dy: f32 = SHELL_BOTTOM_NAV_HEIGHT + dock_bottom + 12.0;
2180                handle_layout.with_write(
2181                    |tree: &mut SceneTree| {
2182                        let target_sidebar_parent: NodeId =
2183                            if is_mobile { drawer_scroll } else { nav_rail };
2184                        let cur_parent: Option<NodeId> =
2185                            tree.get_node(sidebar).and_then(SceneNode::parent_id);
2186                        let reparented_sidebar: bool = cur_parent != Some(target_sidebar_parent);
2187                        if reparented_sidebar {
2188                            tree.append_child(target_sidebar_parent, sidebar);
2189                        }
2190                        if let Some(sn) = tree.get_node_mut(sidebar) {
2191                            sn.get_mut_style().get_mut_layout().set_flex_shrink(0.0);
2192                        }
2193                        if let Some(footer_id) = sidebar_footer {
2194                            let cur_f: Option<NodeId> =
2195                                tree.get_node(footer_id).and_then(SceneNode::parent_id);
2196                            if cur_f != Some(target_sidebar_parent) || reparented_sidebar {
2197                                tree.append_child(target_sidebar_parent, footer_id);
2198                            }
2199                            if let Some(fn_node) = tree.get_node_mut(footer_id) {
2200                                fn_node
2201                                    .get_mut_style()
2202                                    .get_mut_layout()
2203                                    .set_flex_shrink(0.0);
2204                            }
2205                        }
2206                        let cur_sp: Option<NodeId> = tree
2207                            .get_node(sidebar_safe_spacer)
2208                            .and_then(SceneNode::parent_id);
2209                        if cur_sp != Some(target_sidebar_parent) || reparented_sidebar {
2210                            tree.append_child(target_sidebar_parent, sidebar_safe_spacer);
2211                        }
2212                        let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
2213                        let mask_all: u16 = dirty_l | DIRTY_PAINT;
2214                        if let Some(sp_n) = tree.get_node_mut(sidebar_safe_spacer) {
2215                            let sp_height: f32 = SPACE_LG + bottom_inset;
2216                            sp_n.get_mut_style()
2217                                .get_mut_layout()
2218                                .set_display(Display::Flex)
2219                                .set_height(Length::Px(sp_height))
2220                                .set_flex_shrink(0.0);
2221                            tree.mark_dirty(sidebar_safe_spacer, mask_all);
2222                        }
2223                        tree.mark_dirty(sidebar, mask_all);
2224                        scratch_children.clear();
2225                        if tree.get_node(sidebar).is_some() {
2226                            scratch_children.extend(tree.children_iter(sidebar));
2227                        }
2228                        for child_id in scratch_children.iter().copied() {
2229                            tree.mark_dirty(child_id, mask_all);
2230                        }
2231                        if let Some(n) = tree.get_node_mut(top_bar) {
2232                            n.get_mut_style()
2233                                .get_mut_layout()
2234                                .set_display(Display::Flex)
2235                                .set_height(Length::Px(mobile_bar_h))
2236                                .set_padding(Edges::new(
2237                                    mobile_pad_top,
2238                                    SPACE_SM + right_inset,
2239                                    mobile_pad_bottom,
2240                                    SPACE_SM + left_inset,
2241                                ));
2242                            tree.mark_dirty(top_bar, mask_all);
2243                        }
2244                        if let Some(n) = tree.get_node_mut(top_bar_divider) {
2245                            n.get_mut_style()
2246                                .get_mut_layout()
2247                                .set_display(Display::Flex);
2248                            tree.mark_dirty(top_bar_divider, mask_all);
2249                        }
2250                        if let Some(n) = tree.get_node_mut(desktop_top_bar) {
2251                            n.get_mut_style()
2252                                .get_mut_layout()
2253                                .set_display(Display::Flex)
2254                                .set_height(Length::Px(desktop_bar_h))
2255                                .set_padding(Edges::new(
2256                                    desktop_pad_top,
2257                                    SPACE_MD + right_inset,
2258                                    0.0,
2259                                    SPACE_MD + left_inset,
2260                                ));
2261                            tree.mark_dirty(desktop_top_bar, mask_all);
2262                        }
2263                        if let Some(n) = tree.get_node_mut(desktop_top_divider) {
2264                            n.get_mut_style()
2265                                .get_mut_layout()
2266                                .set_display(Display::Flex);
2267                            tree.mark_dirty(desktop_top_divider, mask_all);
2268                        }
2269                        let mobile_chrome_active: bool = !is_fullscreen && is_mobile;
2270                        if !mobile_chrome_active {
2271                            tree.cancel_subtree_transitions(top_bar_chrome);
2272                            if let Some(n) = tree.get_node_mut(top_bar_chrome) {
2273                                let st: &mut Style = n.get_mut_style();
2274                                st.get_mut_layout()
2275                                    .set_display(Display::None)
2276                                    .set_position(Position::Relative)
2277                                    .set_top(None)
2278                                    .set_left(None)
2279                                    .set_right(None);
2280                                st.get_mut_paint()
2281                                    .set_pointer_events(PointerEvents::None)
2282                                    .set_opacity(1.0)
2283                                    .set_transform(Transform2D::default());
2284                            }
2285                            tree.mark_dirty(top_bar_chrome, mask_all);
2286                        } else if is_chrome_hidden {
2287                            let slide_h: f32 = mobile_bar_h + div_h;
2288                            if chrome_toggled {
2289                                tree.cancel_subtree_transitions(top_bar_chrome);
2290                                if let Some(n) = tree.get_node_mut(top_bar_chrome) {
2291                                    let st: &mut Style = n.get_mut_style();
2292                                    st.get_mut_layout()
2293                                        .set_display(Display::Flex)
2294                                        .set_position(Position::Absolute)
2295                                        .set_top(Some(0.0))
2296                                        .set_left(Some(0.0))
2297                                        .set_right(Some(0.0))
2298                                        .set_z_index(Z_INDEX_CHROME);
2299                                    st.get_mut_paint()
2300                                        .set_pointer_events(PointerEvents::None)
2301                                        .set_opacity(1.0)
2302                                        .set_transform(Transform2D::default());
2303                                }
2304                                tree.mark_dirty(top_bar_chrome, mask_all);
2305                                tree.start_transition(
2306                                    NodeTransition::slide_fade(
2307                                        top_bar_chrome,
2308                                        Point::new(0.0, 0.0),
2309                                        Point::new(0.0, -slide_h),
2310                                        1.0,
2311                                        0.0,
2312                                        motion_duration(MOTION_EMPHASIZED_SECS),
2313                                        true,
2314                                    )
2315                                    .with_easing(MOTION_EASE_EXIT),
2316                                );
2317                            } else {
2318                                tree.cancel_subtree_transitions(top_bar_chrome);
2319                                if let Some(n) = tree.get_node_mut(top_bar_chrome) {
2320                                    let st: &mut Style = n.get_mut_style();
2321                                    st.get_mut_layout()
2322                                        .set_display(Display::None)
2323                                        .set_position(Position::Absolute)
2324                                        .set_top(Some(0.0))
2325                                        .set_left(Some(0.0))
2326                                        .set_right(Some(0.0));
2327                                    st.get_mut_paint()
2328                                        .set_pointer_events(PointerEvents::None)
2329                                        .set_opacity(0.0)
2330                                        .set_transform(Transform2D::new(
2331                                            0.0, -slide_h, 1.0, 1.0, 0.0,
2332                                        ));
2333                                }
2334                                tree.mark_dirty(top_bar_chrome, mask_all);
2335                            }
2336                        } else {
2337                            let slide_h: f32 = mobile_bar_h + div_h;
2338                            tree.cancel_subtree_transitions(top_bar_chrome);
2339                            if let Some(n) = tree.get_node_mut(top_bar_chrome) {
2340                                let st: &mut Style = n.get_mut_style();
2341                                st.get_mut_layout()
2342                                    .set_display(Display::Flex)
2343                                    .set_position(Position::Relative)
2344                                    .set_top(None)
2345                                    .set_left(None)
2346                                    .set_right(None)
2347                                    .set_z_index(Z_INDEX_CHROME);
2348                                st.get_mut_paint()
2349                                    .set_pointer_events(PointerEvents::Auto)
2350                                    .set_opacity(if chrome_toggled { 0.0 } else { 1.0 })
2351                                    .set_transform(if chrome_toggled {
2352                                        Transform2D::new(0.0, -slide_h, 1.0, 1.0, 0.0)
2353                                    } else {
2354                                        Transform2D::default()
2355                                    });
2356                            }
2357                            tree.mark_dirty(top_bar_chrome, mask_all);
2358                            if chrome_toggled {
2359                                tree.start_transition(
2360                                    NodeTransition::slide_fade(
2361                                        top_bar_chrome,
2362                                        Point::new(0.0, -slide_h),
2363                                        Point::new(0.0, 0.0),
2364                                        0.0,
2365                                        1.0,
2366                                        motion_duration(MOTION_EMPHASIZED_SECS),
2367                                        false,
2368                                    )
2369                                    .with_easing(MOTION_EASE_ENTER),
2370                                );
2371                            }
2372                        }
2373                        let desktop_chrome_active: bool = !is_fullscreen && is_desktop;
2374                        if !desktop_chrome_active {
2375                            tree.cancel_subtree_transitions(desktop_top_chrome);
2376                            if let Some(n) = tree.get_node_mut(desktop_top_chrome) {
2377                                let st: &mut Style = n.get_mut_style();
2378                                st.get_mut_layout()
2379                                    .set_display(Display::None)
2380                                    .set_position(Position::Relative)
2381                                    .set_top(None)
2382                                    .set_left(None)
2383                                    .set_right(None);
2384                                st.get_mut_paint()
2385                                    .set_pointer_events(PointerEvents::None)
2386                                    .set_opacity(1.0)
2387                                    .set_transform(Transform2D::default());
2388                            }
2389                            tree.mark_dirty(desktop_top_chrome, mask_all);
2390                        } else if is_chrome_hidden {
2391                            let slide_h: f32 = desktop_bar_h + div_h;
2392                            if chrome_toggled {
2393                                tree.cancel_subtree_transitions(desktop_top_chrome);
2394                                if let Some(n) = tree.get_node_mut(desktop_top_chrome) {
2395                                    let st: &mut Style = n.get_mut_style();
2396                                    st.get_mut_layout()
2397                                        .set_display(Display::Flex)
2398                                        .set_position(Position::Absolute)
2399                                        .set_top(Some(0.0))
2400                                        .set_left(Some(0.0))
2401                                        .set_right(Some(0.0))
2402                                        .set_z_index(Z_INDEX_CHROME);
2403                                    st.get_mut_paint()
2404                                        .set_pointer_events(PointerEvents::None)
2405                                        .set_opacity(1.0)
2406                                        .set_transform(Transform2D::default());
2407                                }
2408                                tree.mark_dirty(desktop_top_chrome, mask_all);
2409                                tree.start_transition(
2410                                    NodeTransition::slide_fade(
2411                                        desktop_top_chrome,
2412                                        Point::new(0.0, 0.0),
2413                                        Point::new(0.0, -slide_h),
2414                                        1.0,
2415                                        0.0,
2416                                        motion_duration(MOTION_EMPHASIZED_SECS),
2417                                        true,
2418                                    )
2419                                    .with_easing(MOTION_EASE_EXIT),
2420                                );
2421                            } else {
2422                                tree.cancel_subtree_transitions(desktop_top_chrome);
2423                                if let Some(n) = tree.get_node_mut(desktop_top_chrome) {
2424                                    let st: &mut Style = n.get_mut_style();
2425                                    st.get_mut_layout()
2426                                        .set_display(Display::None)
2427                                        .set_position(Position::Absolute)
2428                                        .set_top(Some(0.0))
2429                                        .set_left(Some(0.0))
2430                                        .set_right(Some(0.0));
2431                                    st.get_mut_paint()
2432                                        .set_pointer_events(PointerEvents::None)
2433                                        .set_opacity(0.0)
2434                                        .set_transform(Transform2D::new(
2435                                            0.0, -slide_h, 1.0, 1.0, 0.0,
2436                                        ));
2437                                }
2438                                tree.mark_dirty(desktop_top_chrome, mask_all);
2439                            }
2440                        } else {
2441                            let slide_h: f32 = desktop_bar_h + div_h;
2442                            tree.cancel_subtree_transitions(desktop_top_chrome);
2443                            if let Some(n) = tree.get_node_mut(desktop_top_chrome) {
2444                                let st: &mut Style = n.get_mut_style();
2445                                st.get_mut_layout()
2446                                    .set_display(Display::Flex)
2447                                    .set_position(Position::Relative)
2448                                    .set_top(None)
2449                                    .set_left(None)
2450                                    .set_right(None)
2451                                    .set_z_index(Z_INDEX_CHROME);
2452                                st.get_mut_paint()
2453                                    .set_pointer_events(PointerEvents::Auto)
2454                                    .set_opacity(if chrome_toggled { 0.0 } else { 1.0 })
2455                                    .set_transform(if chrome_toggled {
2456                                        Transform2D::new(0.0, -slide_h, 1.0, 1.0, 0.0)
2457                                    } else {
2458                                        Transform2D::default()
2459                                    });
2460                            }
2461                            tree.mark_dirty(desktop_top_chrome, mask_all);
2462                            if chrome_toggled {
2463                                tree.start_transition(
2464                                    NodeTransition::slide_fade(
2465                                        desktop_top_chrome,
2466                                        Point::new(0.0, -slide_h),
2467                                        Point::new(0.0, 0.0),
2468                                        0.0,
2469                                        1.0,
2470                                        motion_duration(MOTION_EMPHASIZED_SECS),
2471                                        false,
2472                                    )
2473                                    .with_easing(MOTION_EASE_ENTER),
2474                                );
2475                            }
2476                        }
2477                        if let Some(n) = tree.get_node_mut(body_row) {
2478                            n.get_mut_style()
2479                                .get_mut_layout()
2480                                .set_height(Length::Px(body_h));
2481                            tree.mark_dirty(body_row, mask_all);
2482                        }
2483                        if let Some(n) = tree.get_node_mut(content_column) {
2484                            let st: &mut Style = n.get_mut_style();
2485                            st.get_mut_layout().set_height(Length::Px(body_h));
2486                            st.get_mut_paint()
2487                                .set_stop_scroll_propagation(is_chrome_hidden);
2488                            tree.mark_dirty(content_column, mask_all);
2489                        }
2490                        if let Some(n) = tree.get_node_mut(nav_divider) {
2491                            n.get_mut_style()
2492                                .get_mut_layout()
2493                                .set_display(desktop_disp)
2494                                .set_height(Length::Px(body_h));
2495                            tree.mark_dirty(nav_divider, mask_all);
2496                        }
2497                        if let Some(n) = tree.get_node_mut(nav_rail) {
2498                            let rail_top_pad: f32 = if is_chrome_hidden && top_inset > 0.0 {
2499                                SPACE_MD + top_inset
2500                            } else {
2501                                SPACE_MD
2502                            };
2503                            n.get_mut_style()
2504                                .get_mut_layout()
2505                                .set_display(desktop_disp)
2506                                .set_width(Length::Px(SHELL_DESKTOP_SIDEBAR_WIDTH))
2507                                .set_height(Length::Px(body_h))
2508                                .set_padding(Edges::new(
2509                                    rail_top_pad,
2510                                    SPACE_SM,
2511                                    0.0,
2512                                    SPACE_SM + left_inset,
2513                                ));
2514                            tree.mark_dirty(nav_rail, mask_all);
2515                        }
2516                        let main_pad: f32 = if is_desktop {
2517                            SPACE_MD
2518                        } else if bp.is_compact() {
2519                            SPACE_SM
2520                        } else {
2521                            SPACE_MD
2522                        };
2523                        let page_top_pad: f32 = if is_chrome_hidden && top_inset > 0.0 {
2524                            main_pad + top_inset
2525                        } else {
2526                            main_pad
2527                        };
2528                        let main_left_pad: f32 = if is_desktop && !is_fullscreen {
2529                            main_pad
2530                        } else {
2531                            main_pad + left_inset
2532                        };
2533                        let main_bottom_pad: f32 = if show_bottom_nav && !is_chrome_hidden {
2534                            main_pad + SHELL_BOTTOM_NAV_HEIGHT + dock_bottom + 12.0
2535                        } else {
2536                            main_pad + bottom_inset
2537                        };
2538                        let page_edges: Edges = Edges::new(
2539                            page_top_pad,
2540                            main_pad + right_inset,
2541                            main_bottom_pad,
2542                            main_left_pad,
2543                        );
2544                        if let Some(pad_sig) = page_padding {
2545                            let _: bool = pad_sig.set_if_changed(page_edges);
2546                        }
2547                        if let Some(n) = tree.get_node_mut(main_area) {
2548                            let lay: &mut LayoutStyle = n.get_mut_style().get_mut_layout();
2549                            lay.set_height(Length::Px(main_h));
2550                            if has_managed_outlet {
2551                                lay.set_padding(Edges::all(0.0))
2552                                    .set_overflow(Overflow::Hidden)
2553                                    .set_row_gap(0.0)
2554                                    .set_column_gap(0.0);
2555                            } else {
2556                                let main_gap: f32 = if is_mobile && bp.is_compact() {
2557                                    SPACE_MD
2558                                } else {
2559                                    SPACE_LG
2560                                };
2561                                lay.set_padding(page_edges)
2562                                    .set_row_gap(main_gap)
2563                                    .set_column_gap(main_gap);
2564                            }
2565                            tree.mark_dirty(main_area, mask_all);
2566                        }
2567                        if has_managed_outlet && page_padding.is_none() {
2568                            scratch_children.clear();
2569                            if tree.get_node(main_content).is_some() {
2570                                scratch_children.extend(tree.children_iter(main_content));
2571                            }
2572                            for kid in scratch_children.iter().copied() {
2573                                if let Some(kn) = tree.get_node_mut(kid)
2574                                    && matches!(kn.get_kind(), NodeKind::ScrollView)
2575                                {
2576                                    kn.get_mut_style().get_mut_layout().set_padding(page_edges);
2577                                    tree.mark_dirty(kid, mask_all);
2578                                }
2579                            }
2580                        }
2581                        if !show_bottom_nav {
2582                            tree.cancel_subtree_transitions(bottom_bar_host);
2583                            if let Some(n) = tree.get_node_mut(bottom_bar_host) {
2584                                let st: &mut Style = n.get_mut_style();
2585                                st.get_mut_layout().set_display(Display::None);
2586                                st.get_mut_paint()
2587                                    .set_pointer_events(PointerEvents::None)
2588                                    .set_opacity(1.0)
2589                                    .set_transform(Transform2D::default());
2590                            }
2591                            tree.mark_dirty(bottom_bar_host, mask_all);
2592                        } else if is_chrome_hidden {
2593                            if chrome_toggled {
2594                                tree.cancel_subtree_transitions(bottom_bar_host);
2595                                if let Some(n) = tree.get_node_mut(bottom_bar_host) {
2596                                    let st: &mut Style = n.get_mut_style();
2597                                    st.get_mut_layout()
2598                                        .set_display(Display::Flex)
2599                                        .set_width(Length::Px(dock_w))
2600                                        .set_height(Length::Px(SHELL_BOTTOM_NAV_HEIGHT))
2601                                        .set_left(Some(dock_left))
2602                                        .set_bottom(Some(dock_bottom))
2603                                        .set_right(None)
2604                                        .set_top(None)
2605                                        .set_padding(dock_host_pad);
2606                                    st.get_mut_paint()
2607                                        .set_pointer_events(PointerEvents::None)
2608                                        .set_opacity(1.0)
2609                                        .set_transform(Transform2D::default());
2610                                }
2611                                tree.mark_dirty(bottom_bar_host, mask_all);
2612                                tree.start_transition(
2613                                    NodeTransition::slide_fade(
2614                                        bottom_bar_host,
2615                                        Point::new(0.0, 0.0),
2616                                        Point::new(0.0, bottom_hide_dy),
2617                                        1.0,
2618                                        0.0,
2619                                        motion_duration(MOTION_EMPHASIZED_SECS),
2620                                        true,
2621                                    )
2622                                    .with_easing(MOTION_EASE_EXIT),
2623                                );
2624                            } else {
2625                                tree.cancel_subtree_transitions(bottom_bar_host);
2626                                if let Some(n) = tree.get_node_mut(bottom_bar_host) {
2627                                    let st: &mut Style = n.get_mut_style();
2628                                    st.get_mut_layout()
2629                                        .set_display(Display::None)
2630                                        .set_width(Length::Px(dock_w))
2631                                        .set_height(Length::Px(SHELL_BOTTOM_NAV_HEIGHT))
2632                                        .set_left(Some(dock_left))
2633                                        .set_bottom(Some(dock_bottom))
2634                                        .set_right(None)
2635                                        .set_top(None)
2636                                        .set_padding(dock_host_pad);
2637                                    st.get_mut_paint()
2638                                        .set_pointer_events(PointerEvents::None)
2639                                        .set_opacity(0.0)
2640                                        .set_transform(Transform2D::new(
2641                                            0.0,
2642                                            bottom_hide_dy,
2643                                            1.0,
2644                                            1.0,
2645                                            0.0,
2646                                        ));
2647                                }
2648                                tree.mark_dirty(bottom_bar_host, mask_all);
2649                            }
2650                        } else {
2651                            tree.cancel_subtree_transitions(bottom_bar_host);
2652                            if let Some(n) = tree.get_node_mut(bottom_bar_host) {
2653                                let st: &mut Style = n.get_mut_style();
2654                                st.get_mut_layout()
2655                                    .set_display(Display::Flex)
2656                                    .set_width(Length::Px(dock_w))
2657                                    .set_height(Length::Px(SHELL_BOTTOM_NAV_HEIGHT))
2658                                    .set_left(Some(dock_left))
2659                                    .set_bottom(Some(dock_bottom))
2660                                    .set_right(None)
2661                                    .set_top(None)
2662                                    .set_padding(dock_host_pad);
2663                                st.get_mut_paint()
2664                                    .set_pointer_events(PointerEvents::Auto)
2665                                    .set_opacity(if chrome_toggled { 0.0 } else { 1.0 })
2666                                    .set_transform(if chrome_toggled {
2667                                        Transform2D::new(0.0, bottom_hide_dy, 1.0, 1.0, 0.0)
2668                                    } else {
2669                                        Transform2D::default()
2670                                    });
2671                            }
2672                            tree.mark_dirty(bottom_bar_host, mask_all);
2673                            if let Some(bn_node) = bottom_nav {
2674                                tree.mark_dirty(bn_node, mask_all);
2675                            }
2676                            if chrome_toggled {
2677                                tree.start_transition(
2678                                    NodeTransition::slide_fade(
2679                                        bottom_bar_host,
2680                                        Point::new(0.0, bottom_hide_dy),
2681                                        Point::new(0.0, 0.0),
2682                                        0.0,
2683                                        1.0,
2684                                        motion_duration(MOTION_EMPHASIZED_SECS),
2685                                        false,
2686                                    )
2687                                    .with_easing(MOTION_EASE_ENTER),
2688                                );
2689                            }
2690                        }
2691                        if is_desktop || is_fullscreen {
2692                            tree.cancel_subtree_transitions(drawer_portal);
2693                            tree.cancel_subtree_transitions(drawer_panel);
2694                            if let Some(n) = tree.get_node_mut(drawer_portal) {
2695                                let st: &mut Style = n.get_mut_style();
2696                                st.get_mut_layout().set_display(Display::None);
2697                                st.get_mut_paint()
2698                                    .set_pointer_events(PointerEvents::None)
2699                                    .set_opacity(1.0)
2700                                    .set_transform(Transform2D::default());
2701                            }
2702                            if let Some(n) = tree.get_node_mut(drawer_panel) {
2703                                n.get_mut_style()
2704                                    .get_mut_paint()
2705                                    .set_opacity(1.0)
2706                                    .set_transform(Transform2D::default());
2707                            }
2708                            tree.mark_dirty(drawer_portal, mask_all);
2709                        }
2710                        if let Some(n) = tree.get_node_mut(drawer_portal) {
2711                            n.get_mut_style()
2712                                .get_mut_layout()
2713                                .set_height(Length::Px(drawer_vp_h));
2714                            tree.mark_dirty(drawer_portal, mask_all);
2715                        }
2716                        if let Some(n) = tree.get_node_mut(drawer_panel) {
2717                            n.get_mut_style()
2718                                .get_mut_layout()
2719                                .set_height(Length::Px(drawer_vp_h));
2720                            tree.mark_dirty(drawer_panel, mask_all);
2721                        }
2722                        if let Some(n) = tree.get_node_mut(drawer_scroll) {
2723                            let drawer_top_pad: f32 = if top_inset > 0.0 {
2724                                SPACE_SM + top_inset
2725                            } else {
2726                                SPACE_MD
2727                            };
2728                            n.get_mut_style()
2729                                .get_mut_layout()
2730                                .set_height(Length::Px(drawer_vp_h))
2731                                .set_padding(Edges::new(
2732                                    drawer_top_pad,
2733                                    SPACE_SM,
2734                                    SPACE_MD + bottom_inset,
2735                                    SPACE_SM + left_inset,
2736                                ));
2737                            tree.mark_dirty(drawer_scroll, mask_all);
2738                        }
2739                        let drawer_closing: bool = !menu_open.get_untracked()
2740                            && tree.get_node(drawer_portal).is_some_and(|n: &SceneNode| {
2741                                n.style_ref().get_layout().get_display() != Display::None
2742                            });
2743                        if !drawer_closing {
2744                            let drawer_w_len: Length = Length::Px(drawer_target_w);
2745                            let drawer_resized: bool =
2746                                if let Some(n) = tree.get_node_mut(drawer_panel) {
2747                                    let changed: bool =
2748                                        n.style_ref().get_layout().get_width() != drawer_w_len;
2749                                    n.get_mut_style().get_mut_layout().set_width(drawer_w_len);
2750                                    if changed {
2751                                        n.get_mut_style()
2752                                            .get_mut_paint()
2753                                            .set_transform(Transform2D::default());
2754                                    }
2755                                    tree.mark_dirty(drawer_panel, mask_all);
2756                                    changed
2757                                } else {
2758                                    false
2759                                };
2760                            if drawer_resized {
2761                                tree.cancel_subtree_transitions(drawer_panel);
2762                            }
2763                        }
2764                        tree.mark_dirty(root, mask_all);
2765                    },
2766                    (),
2767                );
2768                if is_fullscreen != was_fullscreen {
2769                    notify_frame_needed();
2770                }
2771            });
2772            let last_g_seq: Rc<Cell<u64>> = Rc::new(Cell::new(
2773                gesture_sig
2774                    .get_untracked()
2775                    .map(|ev: GestureEvent| ev.get_sequence())
2776                    .unwrap_or(0),
2777            ));
2778            let handle_swipe: SceneHandle = handle.clone();
2779            let drag_was_active: Rc<Cell<bool>> = Rc::new(Cell::new(false));
2780            let swipe_route_committed: Rc<Cell<bool>> = Rc::new(Cell::new(false));
2781            let swipe_route_committed_drag: Rc<Cell<bool>> = Rc::clone(&swipe_route_committed);
2782            let swipe_routes_drag: Rc<[String]> = Rc::clone(&swipe_routes_rc);
2783            let _: Effect = Effect::new(move || {
2784                let raw_dx: f32 = swipe_drag_sig.get();
2785                let app_state: AppState = app_state_sig.get();
2786                let is_fullscreen: bool = fs_active_sig.get() || ctx_fs_sig.get();
2787                let overlay_count: usize = overlay_count_sig.get();
2788                let swipe_enabled: bool =
2789                    swipe_routes_enabled.is_none_or(|sig: Signal<bool>| sig.get());
2790                if has_managed_outlet
2791                    || menu_open.get_untracked()
2792                    || overlay_count > 0
2793                    || is_fullscreen
2794                    || app_state != AppState::Active
2795                    || !swipe_enabled
2796                    || swipe_routes_drag.is_empty()
2797                {
2798                    if drag_was_active.replace(false) {
2799                        handle_swipe.with_write(
2800                            |tree: &mut SceneTree| {
2801                                tree.cancel_subtree_transitions(main_area);
2802                                if let Some(n) = tree.get_node_mut(main_area) {
2803                                    n.get_mut_style()
2804                                        .get_mut_paint()
2805                                        .set_transform(Transform2D::default());
2806                                    tree.mark_dirty(main_area, DIRTY_PAINT);
2807                                }
2808                            },
2809                            (),
2810                        );
2811                    }
2812                    return;
2813                }
2814                if raw_dx.abs() > 1.0 {
2815                    drag_was_active.set(true);
2816                    let damped_tx: f32 = (raw_dx * 0.36).clamp(-120.0, 120.0);
2817                    handle_swipe.with_write(
2818                        |tree: &mut SceneTree| {
2819                            tree.cancel_subtree_transitions(main_area);
2820                            if let Some(n) = tree.get_node_mut(main_area) {
2821                                n.get_mut_style()
2822                                    .get_mut_paint()
2823                                    .set_transform(Transform2D::new(damped_tx, 0.0, 1.0, 1.0, 0.0));
2824                                tree.mark_dirty(main_area, DIRTY_PAINT);
2825                            }
2826                        },
2827                        (),
2828                    );
2829                } else if drag_was_active.replace(false) {
2830                    if swipe_route_committed_drag.replace(false) {
2831                        handle_swipe.with_write(
2832                            |tree: &mut SceneTree| {
2833                                tree.cancel_subtree_transitions(main_area);
2834                                if let Some(n) = tree.get_node_mut(main_area) {
2835                                    n.get_mut_style()
2836                                        .get_mut_paint()
2837                                        .set_transform(Transform2D::default());
2838                                    tree.mark_dirty(main_area, DIRTY_PAINT);
2839                                }
2840                            },
2841                            (),
2842                        );
2843                    } else {
2844                        handle_swipe.with_write(
2845                            |tree: &mut SceneTree| {
2846                                let cur_tx: f32 = tree
2847                                    .get_node(main_area)
2848                                    .map(|n: &SceneNode| {
2849                                        n.style_ref().get_paint().get_transform().get_translate_x()
2850                                    })
2851                                    .unwrap_or(0.0);
2852                                if cur_tx.abs() > 0.5 {
2853                                    tree.start_transition(
2854                                        NodeTransition::slide_fade(
2855                                            main_area,
2856                                            Point::new(cur_tx, 0.0),
2857                                            Point::new(0.0, 0.0),
2858                                            1.0,
2859                                            1.0,
2860                                            motion_duration(MOTION_STANDARD_SECS),
2861                                            false,
2862                                        )
2863                                        .with_easing(MOTION_EASE_ENTER),
2864                                    );
2865                                }
2866                            },
2867                            (),
2868                        );
2869                    }
2870                }
2871            });
2872            let handle_swipe_reset: SceneHandle = handle.clone();
2873            let hide_state_for_gesture: Rc<Cell<ChromeScrollAutoHideState>> =
2874                Rc::clone(&scroll_hide_state);
2875            let _: Effect = Effect::new(move || {
2876                if let Some(ev) = gesture_sig.get() {
2877                    let seq: u64 = ev.get_sequence();
2878                    if seq != last_g_seq.replace(seq) {
2879                        if menu_open.get_untracked() {
2880                            if ev.get_kind() == GestureEventKind::SwipeLeft {
2881                                let _: bool = menu_open.set_if_changed(false);
2882                            }
2883                            return;
2884                        }
2885                        if EuvOverlayStack::active_count() > 0 || is_fullscreen_active() {
2886                            return;
2887                        }
2888                        let auto_hide_active: bool = auto_hide_chrome_signal
2889                            .map_or(auto_hide_enabled, |sig: Signal<bool>| sig.get_untracked());
2890                        if ev.get_kind() == GestureEventKind::SwipeDown
2891                            && auto_hide_active
2892                            && chrome_hidden.get_untracked()
2893                        {
2894                            hide_state_for_gesture.set(ChromeScrollAutoHideState::default());
2895                            let _: bool = chrome_hidden.set_if_changed(false);
2896                            return;
2897                        }
2898                        let is_mobile_now: bool = EuvShellLayoutMode::from_viewport_width(
2899                            vp_sig.get_untracked().get_width(),
2900                        )
2901                        .is_mobile();
2902                        let swipe_enabled: bool = swipe_routes_enabled
2903                            .is_none_or(|sig: Signal<bool>| sig.get_untracked());
2904                        let drawer_intent: bool =
2905                            ev.get_origin().get_x() <= 72.0 || ev.get_delta().get_x() >= 96.0;
2906                        if swipe_enabled
2907                            && !swipe_routes_rc.is_empty()
2908                            && let Some(route_sig) = route_signal
2909                        {
2910                            let cur_path: String = route_sig.get_untracked();
2911                            let cur_idx: usize = swipe_routes_rc
2912                                .iter()
2913                                .position(|r: &String| r.as_str() == cur_path.as_str())
2914                                .unwrap_or(0);
2915                            if ev.get_kind() == GestureEventKind::SwipeLeft
2916                                && cur_idx + 1 < swipe_routes_rc.len()
2917                            {
2918                                let next_path: String = swipe_routes_rc[cur_idx + 1].clone();
2919                                if route_sig.set_if_changed(next_path) {
2920                                    swipe_route_committed.set(true);
2921                                    handle_swipe_reset.with_write(
2922                                        |tree: &mut SceneTree| {
2923                                            tree.cancel_subtree_transitions(main_area);
2924                                            if let Some(n) = tree.get_node_mut(main_area) {
2925                                                n.get_mut_style()
2926                                                    .get_mut_paint()
2927                                                    .set_transform(Transform2D::default());
2928                                                tree.mark_dirty(main_area, DIRTY_PAINT);
2929                                            }
2930                                        },
2931                                        (),
2932                                    );
2933                                }
2934                            } else if ev.get_kind() == GestureEventKind::SwipeRight {
2935                                if cur_idx > 0 {
2936                                    let prev_path: String = swipe_routes_rc[cur_idx - 1].clone();
2937                                    if route_sig.set_if_changed(prev_path) {
2938                                        swipe_route_committed.set(true);
2939                                        handle_swipe_reset.with_write(
2940                                            |tree: &mut SceneTree| {
2941                                                tree.cancel_subtree_transitions(main_area);
2942                                                if let Some(n) = tree.get_node_mut(main_area) {
2943                                                    n.get_mut_style()
2944                                                        .get_mut_paint()
2945                                                        .set_transform(Transform2D::default());
2946                                                    tree.mark_dirty(main_area, DIRTY_PAINT);
2947                                                }
2948                                            },
2949                                            (),
2950                                        );
2951                                    }
2952                                } else if is_mobile_now && drawer_intent {
2953                                    let _: bool = menu_open.set_if_changed(true);
2954                                }
2955                            }
2956                        } else if is_mobile_now
2957                            && ev.get_kind() == GestureEventKind::SwipeRight
2958                            && drawer_intent
2959                        {
2960                            let _: bool = menu_open.set_if_changed(true);
2961                        }
2962                    }
2963                }
2964            });
2965            let applied_shell_tokens: Rc<Cell<ThemeTokens>> = Rc::new(Cell::new(init_tok));
2966            let handle_theme: SceneHandle = handle.clone();
2967            let _: Effect = Effect::new(move || {
2968                let next_tok: ThemeTokens = match theme_state_opt.as_ref() {
2969                    Some(ts) => ts.get_tokens().get(),
2970                    None => use_live_tokens(tokens),
2971                };
2972                let prev_tok: ThemeTokens = applied_shell_tokens.replace(next_tok);
2973                if prev_tok == next_tok {
2974                    return;
2975                }
2976                let next_p: ThemePalette = next_tok.get_palette();
2977                let next_g: ThemeGeometry = next_tok.get_geometry();
2978                let next_bw: f32 = next_g.get_border_width();
2979                let next_div_h: f32 = next_bw.max(1.0);
2980                let next_dock_r: f32 = next_g.get_radius_lg();
2981                let next_rad_md: CornerRadius = CornerRadius::all(next_g.get_radius_md());
2982                let next_topbar_fg: Color = next_p.surface(SurfaceRole::Background).get_fg();
2983                let next_primary: SurfaceColors = next_p.surface(SurfaceRole::Primary);
2984                handle_theme.with_write(
2985                    |tree: &mut SceneTree| {
2986                        if let Some(n) = tree.get_node_mut(root) {
2987                            n.get_mut_style()
2988                                .get_mut_paint()
2989                                .set_background(Some(next_p.get_background()));
2990                            tree.mark_dirty(root, DIRTY_PAINT);
2991                        }
2992                        if let Some(n) = tree.get_node_mut(top_bar) {
2993                            n.get_mut_style()
2994                                .get_mut_paint()
2995                                .set_background(Some(next_p.get_card()));
2996                            tree.mark_dirty(top_bar, DIRTY_PAINT);
2997                        }
2998                        if let Some(n) = tree.get_node_mut(top_bar_divider) {
2999                            let st: &mut Style = n.get_mut_style();
3000                            st.get_mut_layout().set_height(Length::Px(next_div_h));
3001                            st.get_mut_paint().set_background(Some(next_p.get_border()));
3002                            tree.mark_dirty(top_bar_divider, DIRTY_LAYOUT | DIRTY_PAINT);
3003                        }
3004                        if let Some(n) = tree.get_node_mut(top_title_txt) {
3005                            n.get_mut_style()
3006                                .get_mut_text()
3007                                .set_color(next_p.get_foreground());
3008                            tree.mark_dirty(top_title_txt, DIRTY_PAINT);
3009                        }
3010                        if let Some(n) = tree.get_node_mut(desktop_top_bar) {
3011                            n.get_mut_style()
3012                                .get_mut_paint()
3013                                .set_background(Some(next_p.get_card()));
3014                            tree.mark_dirty(desktop_top_bar, DIRTY_PAINT);
3015                        }
3016                        if let Some(n) = tree.get_node_mut(desktop_top_divider) {
3017                            let st: &mut Style = n.get_mut_style();
3018                            st.get_mut_layout().set_height(Length::Px(next_div_h));
3019                            st.get_mut_paint().set_background(Some(next_p.get_border()));
3020                            tree.mark_dirty(desktop_top_divider, DIRTY_LAYOUT | DIRTY_PAINT);
3021                        }
3022                        if let Some(n) = tree.get_node_mut(desktop_brand_txt) {
3023                            n.get_mut_style()
3024                                .get_mut_text()
3025                                .set_color(next_p.get_foreground());
3026                            tree.mark_dirty(desktop_brand_txt, DIRTY_PAINT);
3027                        }
3028                        if let Some(n) = tree.get_node_mut(desktop_crumb_sep) {
3029                            n.get_mut_style()
3030                                .get_mut_text()
3031                                .set_color(next_p.get_muted_foreground());
3032                            tree.mark_dirty(desktop_crumb_sep, DIRTY_PAINT);
3033                        }
3034                        if let Some(n) = tree.get_node_mut(crumb_txt) {
3035                            n.get_mut_style()
3036                                .get_mut_text()
3037                                .set_color(next_p.get_muted_foreground());
3038                            tree.mark_dirty(crumb_txt, DIRTY_PAINT);
3039                        }
3040                        for (pill_opt, txt_opt) in [
3041                            (mobile_fps_pill, mobile_fps_txt),
3042                            (desktop_fps_pill, desktop_fps_txt),
3043                        ]
3044                        .into_iter()
3045                        {
3046                            if let Some(pill_id) = pill_opt
3047                                && let Some(n) = tree.get_node_mut(pill_id)
3048                            {
3049                                n.get_mut_style()
3050                                    .get_mut_paint()
3051                                    .set_background(Some(next_p.get_background()))
3052                                    .set_border(Border::new(next_bw, next_p.get_border()))
3053                                    .set_radius(next_rad_md);
3054                                tree.mark_dirty(pill_id, DIRTY_PAINT);
3055                            }
3056                            if let Some(txt_id) = txt_opt
3057                                && let Some(n) = tree.get_node_mut(txt_id)
3058                            {
3059                                n.get_mut_style().get_mut_text().set_color(next_topbar_fg);
3060                                tree.mark_dirty(txt_id, DIRTY_PAINT);
3061                            }
3062                        }
3063                        if show_menu_btn {
3064                            if let Some(n) = tree.get_node_mut(menu_btn_node) {
3065                                n.get_mut_style()
3066                                    .get_mut_paint()
3067                                    .set_background(Some(next_p.get_background()))
3068                                    .set_border(Border::new(next_bw, next_p.get_border()))
3069                                    .set_radius(next_rad_md);
3070                                tree.mark_dirty(menu_btn_node, DIRTY_PAINT);
3071                            }
3072                            if tree.get_node(menu_icon_node).is_some() {
3073                                tree.mark_dirty(menu_icon_node, DIRTY_PAINT);
3074                            }
3075                        }
3076                        for &badge_id in euv_brand_badges.iter() {
3077                            if let Some(n) = tree.get_node_mut(badge_id) {
3078                                n.get_mut_style()
3079                                    .get_mut_paint()
3080                                    .set_background(Some(next_p.get_background()))
3081                                    .set_border(Border::new(next_bw, next_p.get_border()))
3082                                    .set_radius(next_rad_md);
3083                                tree.mark_dirty(badge_id, DIRTY_PAINT);
3084                            }
3085                        }
3086                        for &(badge_id, txt_id) in initial_brand_badges.iter() {
3087                            if let Some(n) = tree.get_node_mut(badge_id) {
3088                                n.get_mut_style()
3089                                    .get_mut_paint()
3090                                    .set_background(Some(next_primary.get_bg()))
3091                                    .set_border(Border::new(next_bw, next_primary.get_border()))
3092                                    .set_radius(next_rad_md);
3093                                tree.mark_dirty(badge_id, DIRTY_PAINT);
3094                            }
3095                            if let Some(n) = tree.get_node_mut(txt_id) {
3096                                n.get_mut_style()
3097                                    .get_mut_text()
3098                                    .set_color(next_primary.get_fg());
3099                                tree.mark_dirty(txt_id, DIRTY_PAINT);
3100                            }
3101                        }
3102                        if let Some(n) = tree.get_node_mut(nav_rail) {
3103                            n.get_mut_style()
3104                                .get_mut_paint()
3105                                .set_background(Some(next_p.get_card()));
3106                            tree.mark_dirty(nav_rail, DIRTY_PAINT);
3107                        }
3108                        if let Some(n) = tree.get_node_mut(nav_divider) {
3109                            let st: &mut Style = n.get_mut_style();
3110                            st.get_mut_layout().set_width(Length::Px(next_div_h));
3111                            st.get_mut_paint().set_background(Some(next_p.get_border()));
3112                            tree.mark_dirty(nav_divider, DIRTY_LAYOUT | DIRTY_PAINT);
3113                        }
3114                        if let Some(n) = tree.get_node_mut(drawer_portal) {
3115                            n.get_mut_style()
3116                                .get_mut_paint()
3117                                .set_background(Some(next_p.get_overlay()));
3118                            tree.mark_dirty(drawer_portal, DIRTY_PAINT);
3119                        }
3120                        if let Some(n) = tree.get_node_mut(drawer_panel) {
3121                            n.get_mut_style()
3122                                .get_mut_paint()
3123                                .set_background(Some(next_p.get_card()))
3124                                .set_border(Border::new(next_bw, next_p.get_border()))
3125                                .set_shadow(Some(next_g.get_shadow_lg()));
3126                            tree.mark_dirty(drawer_panel, DIRTY_PAINT);
3127                        }
3128                        if let Some(n) = tree.get_node_mut(drawer_brand_txt) {
3129                            n.get_mut_style()
3130                                .get_mut_text()
3131                                .set_color(next_p.get_foreground());
3132                            tree.mark_dirty(drawer_brand_txt, DIRTY_PAINT);
3133                        }
3134                        if let Some(n) = tree.get_node_mut(drawer_grabber_pill) {
3135                            n.get_mut_style().get_mut_paint().set_background(Some(
3136                                next_p.get_muted_foreground().with_alpha(128),
3137                            ));
3138                            tree.mark_dirty(drawer_grabber_pill, DIRTY_PAINT);
3139                        }
3140                        if has_bottom_nav && let Some(bn) = tree.get_node_mut(bottom_bar_host) {
3141                            bn.get_mut_style()
3142                                .get_mut_paint()
3143                                .set_background(Some(
3144                                    next_p.get_card().with_alpha(SHELL_BOTTOM_NAV_BG_ALPHA),
3145                                ))
3146                                .set_border(Border::new(next_bw, next_p.get_border()))
3147                                .set_radius(CornerRadius::all(next_dock_r))
3148                                .set_shadow(Some(next_g.get_shadow_lg()));
3149                            tree.mark_dirty(bottom_bar_host, DIRTY_PAINT);
3150                        }
3151                        if let Some(actions_node) = top_bar_actions {
3152                            Self::mark_descendant_canvases_dirty(tree, actions_node);
3153                        }
3154                        if let Some(mob_act) = mobile_header_actions {
3155                            Self::mark_descendant_canvases_dirty(tree, mob_act);
3156                        }
3157                        if let Some(footer_id) = sidebar_footer {
3158                            remap_subtree_theme_in_place(tree, footer_id, prev_tok, next_tok);
3159                        }
3160                        if !has_managed_outlet {
3161                            remap_subtree_theme_in_place(tree, main_content, prev_tok, next_tok);
3162                        }
3163                    },
3164                    (),
3165                );
3166            });
3167            if let Some(route_sig) = route_signal {
3168                let prev_route: Rc<RefCell<String>> =
3169                    Rc::new(RefCell::new(route_sig.get_untracked()));
3170                let saved_scrolls: Rc<RefCell<HashMap<String, Point>>> =
3171                    Rc::new(RefCell::new(HashMap::new()));
3172                let handle_route_scroll: SceneHandle = handle.clone();
3173                let hooked_for_route: Rc<RefCell<Vec<NodeId>>> = Rc::clone(&hooked_scroll_nodes);
3174                let scroll_obs_for_route: ChromeScrollObserver = scroll_observer.clone();
3175                let hide_state_for_route: Rc<Cell<ChromeScrollAutoHideState>> =
3176                    Rc::clone(&scroll_hide_state);
3177                let _: Effect = Effect::new(move || {
3178                    let next_r: String = route_sig.get();
3179                    let prev_changed: Option<String> = prev_route.try_borrow_mut().ok().and_then(
3180                        |mut guard: RefMut<'_, String>| {
3181                            if *guard != next_r {
3182                                let old: String = guard.clone();
3183                                *guard = next_r.clone();
3184                                Some(old)
3185                            } else {
3186                                None
3187                            }
3188                        },
3189                    );
3190                    if let Some(old_r) = prev_changed {
3191                        let _: bool = menu_open.set_if_changed(false);
3192                        let auto_hide_active: bool = auto_hide_chrome_signal
3193                            .map_or(auto_hide_enabled, |sig: Signal<bool>| sig.get_untracked());
3194                        if auto_hide_active {
3195                            let mut next_tracker: ChromeScrollAutoHideState =
3196                                ChromeScrollAutoHideState::default();
3197                            if has_managed_outlet {
3198                                Self::attach_outlet_scroll_observers(
3199                                    &handle_route_scroll,
3200                                    main_content,
3201                                    &hooked_for_route,
3202                                    &scroll_obs_for_route,
3203                                );
3204                                let active_scroll_seed: Option<(NodeId, f32)> = handle_route_scroll
3205                                    .with_read(
3206                                        |tree: &SceneTree| {
3207                                            for kid in tree.children_iter(main_content) {
3208                                                if let Some(kn) = tree.get_node(kid)
3209                                                    && kn.get_alive()
3210                                                    && matches!(kn.get_kind(), NodeKind::ScrollView)
3211                                                    && kn.style_ref().get_layout().get_display()
3212                                                        != Display::None
3213                                                {
3214                                                    return Some((
3215                                                        kid,
3216                                                        kn.get_layout_box()
3217                                                            .get_scroll_offset()
3218                                                            .get_y(),
3219                                                    ));
3220                                                }
3221                                            }
3222                                            None
3223                                        },
3224                                        None,
3225                                    );
3226                                if let Some((active_node, seed_y)) = active_scroll_seed {
3227                                    next_tracker.reset(active_node, seed_y);
3228                                }
3229                            }
3230                            hide_state_for_route.set(next_tracker);
3231                        }
3232                        if !has_managed_outlet {
3233                            let mut restored_y: f32 = 0.0;
3234                            handle_route_scroll.with_write(
3235                                |tree: &mut SceneTree| {
3236                                    let cur_off: Point = tree
3237                                        .get_node(main_area)
3238                                        .map(|n: &SceneNode| n.get_layout_box().get_scroll_offset())
3239                                        .unwrap_or_default();
3240                                    let restore_off: Point = saved_scrolls
3241                                        .try_borrow_mut()
3242                                        .ok()
3243                                        .map(|mut map: RefMut<'_, HashMap<String, Point>>| {
3244                                            let _: Option<Point> = map.insert(old_r, cur_off);
3245                                            map.get(&next_r).copied().unwrap_or_default()
3246                                        })
3247                                        .unwrap_or_default();
3248                                    restored_y = restore_off.get_y();
3249                                    tree.set_scroll_offset(main_area, restore_off);
3250                                },
3251                                (),
3252                            );
3253                            if auto_hide_active {
3254                                let mut next_tracker: ChromeScrollAutoHideState =
3255                                    ChromeScrollAutoHideState::default();
3256                                next_tracker.reset(main_area, restored_y);
3257                                hide_state_for_route.set(next_tracker);
3258                            }
3259                        }
3260                    }
3261                });
3262            }
3263            Effect::new(move || {
3264                let is_open: bool = menu_open.get();
3265                let raw_vp_w: f32 = vp_sig.get_untracked().get_width();
3266                let is_desktop_now: bool =
3267                    EuvShellLayoutMode::from_viewport_width(raw_vp_w).is_desktop();
3268                if is_open
3269                    && (is_desktop_now || is_fullscreen_active() || ctx_fs_sig.get_untracked())
3270                {
3271                    prev_open.set(false);
3272                    let _: bool = menu_open.set_if_changed(false);
3273                    return;
3274                }
3275                let was_open: bool = prev_open.replace(is_open);
3276                if is_open == was_open {
3277                    return;
3278                }
3279                let vp_w: f32 = raw_vp_w.max(320.0);
3280                let vp_h: f32 = vp_sig.get_untracked().get_height().max(240.0);
3281                let def_w: f32 = (vp_w * 0.68).clamp(224.0, 256.0);
3282                if is_open {
3283                    let auto_hide_active: bool = auto_hide_chrome_signal
3284                        .map_or(auto_hide_enabled, |sig: Signal<bool>| sig.get_untracked());
3285                    if auto_hide_active {
3286                        let _: bool = chrome_hidden.set_if_changed(false);
3287                    }
3288                    let _: bool = drawer_expanded.set_if_changed(false);
3289                    handle.with_write(
3290                        |tree: &mut SceneTree| {
3291                            let was_visible: bool =
3292                                tree.get_node(drawer_portal).is_some_and(|n: &SceneNode| {
3293                                    n.style_ref().get_layout().get_display() != Display::None
3294                                });
3295                            let start_opacity: f32 = if was_visible {
3296                                tree.get_node(drawer_portal)
3297                                    .map(|n: &SceneNode| {
3298                                        n.style_ref().get_paint().get_opacity().clamp(0.0, 1.0)
3299                                    })
3300                                    .unwrap_or(0.0)
3301                            } else {
3302                                0.0
3303                            };
3304                            let start_tx: f32 = if was_visible {
3305                                tree.get_node(drawer_panel)
3306                                    .map(|n: &SceneNode| {
3307                                        n.style_ref()
3308                                            .get_paint()
3309                                            .get_transform()
3310                                            .get_translate_x()
3311                                            .clamp(-def_w, 0.0)
3312                                    })
3313                                    .unwrap_or(-def_w)
3314                            } else {
3315                                -def_w
3316                            };
3317                            tree.cancel_subtree_transitions(drawer_portal);
3318                            tree.cancel_subtree_transitions(drawer_panel);
3319                            if let Some(n) = tree.get_node_mut(drawer_portal) {
3320                                let st: &mut Style = n.get_mut_style();
3321                                st.get_mut_layout()
3322                                    .set_display(Display::Flex)
3323                                    .set_height(Length::Px(vp_h));
3324                                st.get_mut_paint()
3325                                    .set_pointer_events(PointerEvents::Auto)
3326                                    .set_opacity(start_opacity)
3327                                    .set_transform(Transform2D::default());
3328                            }
3329                            let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
3330                            tree.mark_dirty(drawer_portal, dirty_l | DIRTY_PAINT);
3331                            if let Some(n) = tree.get_node_mut(drawer_panel) {
3332                                let st: &mut Style = n.get_mut_style();
3333                                st.get_mut_layout()
3334                                    .set_width(Length::Px(def_w))
3335                                    .set_height(Length::Px(vp_h));
3336                                st.get_mut_paint()
3337                                    .set_opacity(1.0)
3338                                    .set_transform(Transform2D::new(start_tx, 0.0, 1.0, 1.0, 0.0));
3339                                tree.mark_dirty(drawer_panel, dirty_l | DIRTY_PAINT);
3340                            }
3341                            if let Some(n) = tree.get_node_mut(drawer_scroll) {
3342                                n.get_mut_style()
3343                                    .get_mut_layout()
3344                                    .set_height(Length::Px(vp_h));
3345                                tree.mark_dirty(drawer_scroll, dirty_l | DIRTY_PAINT);
3346                            }
3347                            let cur_y: f32 = tree
3348                                .get_node(drawer_scroll)
3349                                .map(|n: &SceneNode| n.get_layout_box().get_scroll_offset().get_y())
3350                                .unwrap_or(0.0);
3351                            tree.set_scroll_offset(drawer_scroll, Point::new(0.0, cur_y));
3352                            drop(tree.update_focus(None));
3353                            tree.start_transition(
3354                                NodeTransition::fade(
3355                                    drawer_portal,
3356                                    start_opacity,
3357                                    1.0,
3358                                    motion_duration(MOTION_EMPHASIZED_SECS),
3359                                    false,
3360                                )
3361                                .with_easing(MOTION_EASE_ENTER),
3362                            );
3363                            tree.start_transition(
3364                                NodeTransition::slide_fade(
3365                                    drawer_panel,
3366                                    Point::new(start_tx, 0.0),
3367                                    Point::new(0.0, 0.0),
3368                                    1.0,
3369                                    1.0,
3370                                    motion_duration(MOTION_EMPHASIZED_SECS),
3371                                    false,
3372                                )
3373                                .with_easing(MOTION_EASE_ENTER),
3374                            );
3375                        },
3376                        (),
3377                    );
3378                } else {
3379                    drawer_da_close.set(false);
3380                    drawer_dm_close.set(false);
3381                    handle.with_write(
3382                        |tree: &mut SceneTree| {
3383                            let is_visible: bool =
3384                                tree.get_node(drawer_portal).is_some_and(|n: &SceneNode| {
3385                                    n.style_ref().get_layout().get_display() != Display::None
3386                                });
3387                            let cur_opacity: f32 = tree
3388                                .get_node(drawer_portal)
3389                                .map(|n: &SceneNode| {
3390                                    n.style_ref().get_paint().get_opacity().clamp(0.0, 1.0)
3391                                })
3392                                .unwrap_or(1.0);
3393                            let (cur_tx, panel_w): (f32, f32) = tree
3394                                .get_node(drawer_panel)
3395                                .map(|n: &SceneNode| {
3396                                    let tx: f32 =
3397                                        n.style_ref().get_paint().get_transform().get_translate_x();
3398                                    let layout_w: f32 = n.get_layout_box().get_bounds().get_width();
3399                                    let styled_w: f32 = match n.style_ref().get_layout().get_width()
3400                                    {
3401                                        Length::Px(px) if px > 40.0 => px,
3402                                        _ => def_w,
3403                                    };
3404                                    let w: f32 = if layout_w > 40.0 { layout_w } else { styled_w };
3405                                    (tx, w)
3406                                })
3407                                .unwrap_or((0.0, def_w));
3408                            tree.cancel_subtree_transitions(drawer_portal);
3409                            tree.cancel_subtree_transitions(drawer_panel);
3410                            let mut hover_stack: Vec<NodeId> = vec![drawer_portal];
3411                            while let Some(cur_id) = hover_stack.pop() {
3412                                if let Some(cur_n) = tree.get_node_mut(cur_id) {
3413                                    cur_n.get_mut_interaction().set_hovered(false);
3414                                    hover_stack.extend(tree.children_iter(cur_id));
3415                                }
3416                            }
3417                            if let Some(n) = tree.get_node_mut(drawer_portal) {
3418                                n.get_mut_style()
3419                                    .get_mut_paint()
3420                                    .set_pointer_events(PointerEvents::None);
3421                            }
3422                            if !is_visible {
3423                                if let Some(n) = tree.get_node_mut(drawer_portal) {
3424                                    let st: &mut Style = n.get_mut_style();
3425                                    st.get_mut_layout().set_display(Display::None);
3426                                    st.get_mut_paint()
3427                                        .set_opacity(1.0)
3428                                        .set_transform(Transform2D::default());
3429                                }
3430                                if let Some(n) = tree.get_node_mut(drawer_panel) {
3431                                    n.get_mut_style()
3432                                        .get_mut_paint()
3433                                        .set_opacity(1.0)
3434                                        .set_transform(Transform2D::default());
3435                                }
3436                                let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
3437                                tree.mark_dirty(drawer_portal, dirty_l | DIRTY_PAINT);
3438                                return;
3439                            }
3440                            tree.mark_dirty(drawer_portal, DIRTY_PAINT);
3441                            tree.start_transition(
3442                                NodeTransition::fade(
3443                                    drawer_portal,
3444                                    cur_opacity,
3445                                    0.0,
3446                                    motion_duration(MOTION_EMPHASIZED_SECS),
3447                                    true,
3448                                )
3449                                .with_easing(MOTION_EASE_EXIT),
3450                            );
3451                            tree.start_transition(
3452                                NodeTransition::slide_fade(
3453                                    drawer_panel,
3454                                    Point::new(cur_tx, 0.0),
3455                                    Point::new(-panel_w, 0.0),
3456                                    1.0,
3457                                    1.0,
3458                                    motion_duration(MOTION_EMPHASIZED_SECS),
3459                                    false,
3460                                )
3461                                .with_easing(MOTION_EASE_EXIT),
3462                            );
3463                        },
3464                        (),
3465                    );
3466                }
3467            })
3468        });
3469        ctx.get_scene().with_write(
3470            |tree: &mut SceneTree| {
3471                let mut owned_dots: Vec<NodeId> = Vec::with_capacity(2);
3472                if let Some(dot) = mobile_fps_dot {
3473                    owned_dots.push(dot);
3474                }
3475                if let Some(dot) = desktop_fps_dot {
3476                    owned_dots.push(dot);
3477                }
3478                if !owned_dots.is_empty() {
3479                    mark_theme_owned(tree, owned_dots.as_slice());
3480                }
3481                tree.attach_scope(root, scope);
3482            },
3483            (),
3484        );
3485        root
3486    }
3487}
3488
3489/// Construction and mounting for `EuvDivider`.
3490impl EuvDivider {
3491    /// Creates a horizontal divider.
3492    ///
3493    /// # Arguments
3494    ///
3495    /// - `ThemeTokens` - Active design tokens.
3496    ///
3497    /// # Returns
3498    ///
3499    /// - `Self` - Horizontal divider.
3500    #[must_use]
3501    pub fn horizontal(tokens: ThemeTokens) -> Self {
3502        Self {
3503            vertical: false,
3504            tokens,
3505        }
3506    }
3507
3508    /// Creates a vertical divider.
3509    ///
3510    /// # Arguments
3511    ///
3512    /// - `ThemeTokens` - Active design tokens.
3513    ///
3514    /// # Returns
3515    ///
3516    /// - `Self` - Vertical divider.
3517    #[must_use]
3518    pub fn vertical(tokens: ThemeTokens) -> Self {
3519        Self {
3520            vertical: true,
3521            tokens,
3522        }
3523    }
3524}
3525
3526/// Declarative `#[component]` implementation for `EuvDivider`.
3527#[component]
3528/// Inherent implementation of [`EuvDivider`].
3529impl EuvDivider {
3530    /// Renders `EuvDivider` into the ambient framework-managed `Context`.
3531    ///
3532    /// # Arguments
3533    ///
3534    /// - `&Self` - Component descriptor reference.
3535    ///
3536    /// # Returns
3537    ///
3538    /// - `NodeId` - Mounted root scene node handle.
3539    fn render(&self) -> NodeId {
3540        let tok: ThemeTokens = live_tokens_untracked(self.get_tokens());
3541        let border_color: Color = tok.get_palette().get_border();
3542        let line_w: f32 = tok.get_geometry().get_border_width().max(1.0);
3543        let is_vert: bool = self.get_vertical();
3544        view! {
3545            view {
3546                style: {
3547                    width: if is_vert { Length::Px(line_w) } else { Length::Percent(100.0) }
3548                    height: if is_vert { Length::Percent(100.0) } else { Length::Px(line_w) }
3549                    background: border_color
3550                }
3551            }
3552        }
3553    }
3554}
3555
3556/// Fluent section composition helpers for `EuvPage`.
3557impl EuvPage {
3558    /// Appends a section node below the page header.
3559    ///
3560    /// # Arguments
3561    ///
3562    /// - `Self` - Source page wrapper.
3563    /// - `NodeId` - Mounted section node.
3564    ///
3565    /// # Returns
3566    ///
3567    /// - `Self` - Updated page wrapper.
3568    #[must_use]
3569    pub fn section(mut self, node: NodeId) -> Self {
3570        self.get_mut_sections().push(node);
3571        self
3572    }
3573
3574    /// Sets optional style overrides merged onto the root page container (default is full fluid width).
3575    ///
3576    /// # Arguments
3577    ///
3578    /// - `Self` - Source page wrapper.
3579    /// - `impl Into<Option<Style>>` - Style override or `None` for fluid width.
3580    ///
3581    /// # Returns
3582    ///
3583    /// - `Self` - Updated page wrapper.
3584    #[must_use]
3585    pub fn style(mut self, style: impl Into<Option<Style>>) -> Self {
3586        self.set_style(style.into());
3587        self
3588    }
3589}
3590
3591/// Declarative `#[component]` implementation for `EuvPage`.
3592#[component]
3593/// Inherent implementation of [`EuvPage`].
3594impl EuvPage {
3595    /// Renders `EuvPage` into the ambient framework-managed `Context`.
3596    ///
3597    /// # Arguments
3598    ///
3599    /// - `&Self` - Component descriptor reference.
3600    ///
3601    /// # Returns
3602    ///
3603    /// - `NodeId` - Mounted root scene node handle.
3604    fn render(&self) -> NodeId {
3605        let mut ctx: Context = current_context();
3606        let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
3607        let opt_style: Option<Style> = self.get_style();
3608        let Self {
3609            title,
3610            subtitle,
3611            sections,
3612            ..
3613        } = self;
3614        let mut page_style: Style = Style::default();
3615        page_style
3616            .get_mut_layout()
3617            .set_flex_direction(FlexDirection::Column)
3618            .set_width(Length::Percent(100.0))
3619            .set_row_gap(SPACE_LG)
3620            .set_column_gap(SPACE_LG);
3621        if let Some(ov) = opt_style {
3622            let ov_lay: LayoutStyle = ov.get_layout();
3623            let def_lay: LayoutStyle = LayoutStyle::default();
3624            let dst_lay: &mut LayoutStyle = page_style.get_mut_layout();
3625            if ov_lay.get_width() != def_lay.get_width() {
3626                dst_lay.set_width(ov_lay.get_width());
3627            }
3628            if ov_lay.get_height() != def_lay.get_height() {
3629                dst_lay.set_height(ov_lay.get_height());
3630            }
3631            if ov_lay.get_min_width() != def_lay.get_min_width() {
3632                dst_lay.set_min_width(ov_lay.get_min_width());
3633            }
3634            if ov_lay.get_max_width() != def_lay.get_max_width() {
3635                dst_lay.set_max_width(ov_lay.get_max_width());
3636            }
3637            if ov_lay.get_min_height() != def_lay.get_min_height() {
3638                dst_lay.set_min_height(ov_lay.get_min_height());
3639            }
3640            if ov_lay.get_max_height() != def_lay.get_max_height() {
3641                dst_lay.set_max_height(ov_lay.get_max_height());
3642            }
3643            if ov_lay.get_padding() != def_lay.get_padding() {
3644                dst_lay.set_padding(ov_lay.get_padding());
3645            }
3646            if ov_lay.get_margin() != def_lay.get_margin() {
3647                dst_lay.set_margin(ov_lay.get_margin());
3648            }
3649            if ov_lay.get_row_gap() != def_lay.get_row_gap() {
3650                dst_lay.set_row_gap(ov_lay.get_row_gap());
3651            }
3652            if ov_lay.get_column_gap() != def_lay.get_column_gap() {
3653                dst_lay.set_column_gap(ov_lay.get_column_gap());
3654            }
3655            let ov_paint: PaintStyle = ov.get_paint();
3656            if let Some(bg) = ov_paint.background_color() {
3657                page_style.get_mut_paint().set_background(Some(bg));
3658            }
3659            let ov_text: TextStyle = ov.get_text();
3660            if ov_text.get_text_select() != TextStyle::default().get_text_select() {
3661                page_style
3662                    .get_mut_text()
3663                    .set_text_select(Some(ov_text.get_text_select()));
3664            }
3665        }
3666        let root: NodeId = view! {
3667            column {
3668                style: page_style
3669                EuvHeader {
3670                    title: title.clone()
3671                    subtitle: subtitle.clone()
3672                    tokens: tokens
3673                }
3674            }
3675        };
3676        if !sections.is_empty() {
3677            ctx.append_many(root, sections.as_slice());
3678        }
3679        root
3680    }
3681}
3682
3683/// Fluent child composition helpers for `EuvActionRow`.
3684impl EuvActionRow {
3685    /// Appends a control node to the wrapping horizontal action bar.
3686    ///
3687    /// # Arguments
3688    ///
3689    /// - `Self` - Source action row.
3690    /// - `NodeId` - Mounted control node.
3691    ///
3692    /// # Returns
3693    ///
3694    /// - `Self` - Updated action row.
3695    #[must_use]
3696    pub fn child(mut self, node: NodeId) -> Self {
3697        self.get_mut_children().push(node);
3698        self
3699    }
3700}
3701
3702/// Declarative `#[component]` implementation for `EuvActionRow`.
3703#[component]
3704/// Inherent implementation of [`EuvActionRow`].
3705impl EuvActionRow {
3706    /// Renders `EuvActionRow` into the ambient framework-managed `Context`.
3707    ///
3708    /// # Arguments
3709    ///
3710    /// - `&Self` - Component descriptor reference.
3711    ///
3712    /// # Returns
3713    ///
3714    /// - `NodeId` - Mounted root scene node handle.
3715    fn render(&self) -> NodeId {
3716        let mut ctx: Context = current_context();
3717        let Self { children } = self;
3718        let root: NodeId = view! {
3719            row {
3720                style: {
3721                    width: Length::Percent(100.0)
3722                    flex_wrap: FlexWrap::Wrap
3723                    align: AlignItems::Center
3724                    gap: SPACE_SM
3725                }
3726            }
3727        };
3728        if !children.is_empty() {
3729            ctx.get_scene().with_write(
3730                |tree: &mut SceneTree| {
3731                    for cid in children.iter().copied() {
3732                        let (label_len, is_switch_like): (usize, bool) = tree
3733                            .get_node(cid)
3734                            .map(|n: &SceneNode| {
3735                                let direct: usize = match n.get_kind() {
3736                                    NodeKind::Text(t) => t.chars().count(),
3737                                    _ => 0,
3738                                };
3739                                let child_max: usize = tree
3740                                    .children_iter(cid)
3741                                    .filter_map(|sub: NodeId| tree.get_node(sub))
3742                                    .map(|sub_n: &SceneNode| match sub_n.get_kind() {
3743                                        NodeKind::Text(t) => t.chars().count(),
3744                                        _ => 0,
3745                                    })
3746                                    .max()
3747                                    .unwrap_or(0);
3748                                let switch_like: bool = tree.child_count(cid) > 1
3749                                    || matches!(
3750                                        n.a11y_props().map(|a: A11yProps| a.get_role()),
3751                                        Some(A11yRole::Switch | A11yRole::Checkbox)
3752                                    );
3753                                (direct.max(child_max), switch_like)
3754                            })
3755                            .unwrap_or((0, false));
3756                        if let Some(n) = tree.get_node_mut(cid) {
3757                            let lay: &mut LayoutStyle = n.get_mut_style().get_mut_layout();
3758                            let fixed_w: bool = !matches!(lay.get_width(), Length::Auto);
3759                            if !fixed_w {
3760                                lay.set_flex_grow(1.0).set_flex_shrink(1.0);
3761                                if matches!(lay.get_min_width(), Length::Auto) {
3762                                    let min_w: f32 = if is_switch_like {
3763                                        ACTION_ROW_SWITCH_MIN_WIDTH
3764                                    } else {
3765                                        ((label_len as f32) * 7.2 + 24.0).clamp(
3766                                            ACTION_ROW_MIN_BTN_WIDTH,
3767                                            ACTION_ROW_MAX_BTN_WIDTH,
3768                                        )
3769                                    };
3770                                    lay.set_min_width(Length::Px(min_w));
3771                                }
3772                            }
3773                        }
3774                    }
3775                },
3776                (),
3777            );
3778            ctx.append_many(root, children.as_slice());
3779        }
3780        root
3781    }
3782}
3783
3784/// Fluent card composition helpers for `EuvStatGrid`.
3785impl EuvStatGrid {
3786    /// Appends a KPI stat card node to the responsive grid.
3787    ///
3788    /// # Arguments
3789    ///
3790    /// - `Self` - Source stat grid.
3791    /// - `NodeId` - Mounted stat card node.
3792    ///
3793    /// # Returns
3794    ///
3795    /// - `Self` - Updated stat grid.
3796    #[must_use]
3797    pub fn card(mut self, node: NodeId) -> Self {
3798        self.get_mut_cards().push(node);
3799        self
3800    }
3801}
3802
3803/// Declarative `#[component]` implementation for `EuvStatGrid`.
3804#[component]
3805/// Inherent implementation of [`EuvStatGrid`].
3806impl EuvStatGrid {
3807    /// Renders `EuvStatGrid` into the ambient framework-managed `Context`.
3808    ///
3809    /// # Arguments
3810    ///
3811    /// - `&Self` - Component descriptor reference.
3812    ///
3813    /// # Returns
3814    ///
3815    /// - `NodeId` - Mounted root scene node handle.
3816    fn render(&self) -> NodeId {
3817        let mut ctx: Context = current_context();
3818        let bp_sig: Signal<Breakpoint> = ctx.get_breakpoint();
3819        let Self { cards } = self;
3820        let max_cols: u16 = (cards.len() as u16).clamp(1, 3);
3821        let init_cols: u16 = match bp_sig.get_untracked() {
3822            Breakpoint::Compact => 1,
3823            Breakpoint::Medium => max_cols.min(2),
3824            Breakpoint::Expanded => max_cols,
3825        };
3826        let root: NodeId = view! {
3827            grid {
3828                style: {
3829                    columns: init_cols
3830                    width: Length::Percent(100.0)
3831                    gap: SPACE_MD
3832                }
3833            }
3834        };
3835        if !cards.is_empty() {
3836            ctx.append_many(root, cards.as_slice());
3837        }
3838        let handle: SceneHandle = ctx.get_scene().clone();
3839        let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
3840            Effect::new(move || {
3841                let cols: u16 = match bp_sig.get() {
3842                    Breakpoint::Compact => 1,
3843                    Breakpoint::Medium => max_cols.min(2),
3844                    Breakpoint::Expanded => max_cols,
3845                };
3846                handle.with_write(
3847                    |tree: &mut SceneTree| {
3848                        let changed: bool = if let Some(n) = tree.get_node_mut(root) {
3849                            if n.style_ref().get_layout().get_grid_columns() != cols {
3850                                n.get_mut_style().get_mut_layout().set_grid_columns(cols);
3851                                true
3852                            } else {
3853                                false
3854                            }
3855                        } else {
3856                            false
3857                        };
3858                        if changed {
3859                            let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
3860                            tree.mark_dirty(root, dirty_l | DIRTY_PAINT);
3861                        }
3862                    },
3863                    (),
3864                );
3865            })
3866        });
3867        ctx.get_scene().with_write(
3868            |tree: &mut SceneTree| {
3869                tree.attach_scope(root, scope);
3870            },
3871            (),
3872        );
3873        root
3874    }
3875}