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, ui_event: &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 ui_event.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, ui_event: &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 ui_event.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(|scene_node: &SceneNode| {
233                        let vis: bool = scene_node.get_alive()
234                            && scene_node.style_ref().get_layout().get_display() != Display::None;
235                        (vis, scene_node.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    /// - `CallbackFn` - 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<CallbackFn>(mut self, handler: CallbackFn) -> Self
514    where
515        CallbackFn: 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    /// Resolves unified bottom padding for both the desktop `nav_rail` and mobile `drawer_scroll` containers.
572    ///
573    /// Preserves a compact `SIDEBAR_BOTTOM_SPACER_PX` (`8.0px`) margin on rectangular viewports while respecting
574    /// `bottom_inset` without double-stacking extra padding on top of hardware safe areas.
575    ///
576    /// # Arguments
577    ///
578    /// - `f32` - Active bottom safe-area inset in logical pixels.
579    ///
580    /// # Returns
581    ///
582    /// - `f32` - Bottom clearance in logical pixels below the last sidebar item.
583    #[must_use]
584    pub(crate) fn resolve_sidebar_bottom_padding(bottom_inset: f32) -> f32 {
585        bottom_inset.max(0.0).max(SIDEBAR_BOTTOM_SPACER_PX)
586    }
587
588    /// Applies either frameless safe-area rail presentation (zero border, background, shadow, and host padding) or the canonical floating bottom capsule surface onto `bottom_bar_host`.
589    ///
590    /// # Arguments
591    ///
592    /// - `&mut Style` - Target `bottom_bar_host` mutable style.
593    /// - `bool` - When `true`, renders borderless directly on the hardware safe-area surface.
594    /// - `Edges` - Framed floating capsule host padding.
595    /// - `ThemeTokens` - Active design tokens.
596    fn apply_dock_host_surface(
597        st: &mut Style,
598        frameless: bool,
599        dock_host_pad: Edges,
600        tok: ThemeTokens,
601    ) {
602        if frameless {
603            st.get_mut_layout().set_padding(Edges::all(0.0));
604            st.get_mut_paint()
605                .set_background(None)
606                .set_border(Border::new(0.0, COLOR_TRANSPARENT))
607                .set_radius(CornerRadius::all(0.0))
608                .set_shadow(None);
609        } else {
610            let live_p: ThemePalette = tok.get_palette();
611            let live_g: ThemeGeometry = tok.get_geometry();
612            st.get_mut_layout().set_padding(dock_host_pad);
613            st.get_mut_paint()
614                .set_background(Some(
615                    live_p.get_card().with_alpha(SHELL_BOTTOM_NAV_BG_ALPHA),
616                ))
617                .set_border(Border::new(live_g.get_border_width(), live_p.get_border()))
618                .set_radius(CornerRadius::all(live_g.get_radius_lg()))
619                .set_shadow(Some(live_g.get_shadow_lg()));
620        }
621    }
622
623    /// Synchronizes a mobile or desktop top chrome bar container inside its active host (`top_chrome_inflow_slot` or `top_chrome_portal`) for smooth zero-jump slide transitions.
624    ///
625    /// # Arguments
626    ///
627    /// - `&mut SceneTree` - Mutable retained scene tree.
628    /// - `NodeId` - Top chrome container node (`top_bar_chrome` or `desktop_top_chrome`).
629    /// - `bool` - Whether this chrome container is active in the current breakpoint and fullscreen state.
630    /// - `bool` - Whether the chrome bar is currently hidden.
631    /// - `bool` - Whether `hidden` toggled during this frame and should animate smoothly.
632    /// - `f32` - Total vertical slide distance in logical pixels (`bar_h + divider_h`).
633    fn sync_top_chrome_bar(
634        tree: &mut SceneTree,
635        chrome_node: NodeId,
636        active: bool,
637        hidden: bool,
638        toggled: bool,
639        slide_h: f32,
640    ) {
641        let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
642        let mask_all: u16 = dirty_l | DIRTY_PAINT;
643        if !active {
644            tree.cancel_subtree_transitions(chrome_node);
645            let mut changed: bool = false;
646            if let Some(node_mut) = tree.get_node_mut(chrome_node) {
647                let st: &mut Style = node_mut.get_mut_style();
648                let was_hidden: bool = st.get_layout().get_display() == Display::None
649                    && st.get_paint().get_pointer_events() == PointerEvents::None;
650                st.get_mut_layout()
651                    .set_display(Display::None)
652                    .set_position(Position::Relative)
653                    .set_top(None)
654                    .set_left(None)
655                    .set_right(None);
656                st.get_mut_paint()
657                    .set_pointer_events(PointerEvents::None)
658                    .set_opacity(1.0)
659                    .set_transform(Transform2D::default());
660                changed = !was_hidden;
661            }
662            if changed {
663                tree.mark_dirty(chrome_node, mask_all);
664            }
665            return;
666        }
667        if hidden {
668            if toggled {
669                tree.cancel_subtree_transitions(chrome_node);
670                if let Some(n) = tree.get_node_mut(chrome_node) {
671                    let st: &mut Style = n.get_mut_style();
672                    st.get_mut_layout()
673                        .set_display(Display::Flex)
674                        .set_position(Position::Relative)
675                        .set_top(None)
676                        .set_left(None)
677                        .set_right(None)
678                        .set_z_index(Z_INDEX_CHROME);
679                    st.get_mut_paint()
680                        .set_pointer_events(PointerEvents::None)
681                        .set_opacity(1.0)
682                        .set_transform(Transform2D::default());
683                }
684                tree.mark_dirty(chrome_node, mask_all);
685                tree.start_transition(
686                    NodeTransition::slide_fade(
687                        chrome_node,
688                        Point::new(0.0, 0.0),
689                        Point::new(0.0, -slide_h),
690                        1.0,
691                        0.0,
692                        motion_duration(MOTION_EMPHASIZED_SECS),
693                        true,
694                    )
695                    .with_easing(MOTION_EASE_EXIT),
696                );
697            } else {
698                tree.cancel_subtree_transitions(chrome_node);
699                if let Some(n) = tree.get_node_mut(chrome_node) {
700                    let st: &mut Style = n.get_mut_style();
701                    st.get_mut_layout()
702                        .set_display(Display::None)
703                        .set_position(Position::Relative)
704                        .set_top(None)
705                        .set_left(None)
706                        .set_right(None)
707                        .set_z_index(Z_INDEX_CHROME);
708                    st.get_mut_paint()
709                        .set_pointer_events(PointerEvents::None)
710                        .set_opacity(0.0)
711                        .set_transform(Transform2D::new(0.0, -slide_h, 1.0, 1.0, 0.0));
712                }
713                tree.mark_dirty(chrome_node, mask_all);
714            }
715            return;
716        }
717        tree.cancel_subtree_transitions(chrome_node);
718        if let Some(n) = tree.get_node_mut(chrome_node) {
719            let st: &mut Style = n.get_mut_style();
720            st.get_mut_layout()
721                .set_display(Display::Flex)
722                .set_position(Position::Relative)
723                .set_top(None)
724                .set_left(None)
725                .set_right(None)
726                .set_z_index(Z_INDEX_CHROME);
727            st.get_mut_paint()
728                .set_pointer_events(PointerEvents::Auto)
729                .set_opacity(if toggled { 0.0 } else { 1.0 })
730                .set_transform(if toggled {
731                    Transform2D::new(0.0, -slide_h, 1.0, 1.0, 0.0)
732                } else {
733                    Transform2D::default()
734                });
735        }
736        tree.mark_dirty(chrome_node, mask_all);
737        if toggled {
738            tree.start_transition(
739                NodeTransition::slide_fade(
740                    chrome_node,
741                    Point::new(0.0, -slide_h),
742                    Point::new(0.0, 0.0),
743                    0.0,
744                    1.0,
745                    motion_duration(MOTION_EMPHASIZED_SECS),
746                    false,
747                )
748                .with_easing(MOTION_EASE_ENTER),
749            );
750        }
751    }
752
753    /// Marks every alive descendant `Canvas` node under `root_id` dirty for paint so vector icons repaint immediately after a theme change.
754    ///
755    /// # Arguments
756    ///
757    /// - `&mut SceneTree` - Mutable retained scene tree.
758    /// - `NodeId` - Subtree root node handle.
759    fn mark_descendant_canvases_dirty(tree: &mut SceneTree, root_id: NodeId) {
760        let mut stack: Vec<NodeId> = vec![root_id];
761        while let Some(nid) = stack.pop() {
762            let is_canvas: bool = match tree.get_node(nid) {
763                Some(item_count) if item_count.get_alive() => {
764                    matches!(item_count.get_kind(), NodeKind::Canvas(_))
765                }
766                _ => continue,
767            };
768            stack.extend(tree.children_iter(nid));
769            if is_canvas {
770                tree.mark_dirty(nid, DIRTY_PAINT);
771            }
772        }
773    }
774
775    /// Hooks every direct `ScrollView` child under a managed outlet `main_content` into the shell's scroll auto-hide observer without replacing existing handlers.
776    ///
777    /// # Arguments
778    ///
779    /// - `&SceneHandle` - Shared scene handle.
780    /// - `NodeId` - Managed router outlet host node handle.
781    /// - `&Rc<RefCell<Vec<NodeId>>>` - Deduplication registry of already-hooked scroll wrappers.
782    /// - `&ChromeScrollObserver` - Shared scroll observer handle.
783    fn attach_outlet_scroll_observers(
784        scene: &SceneHandle,
785        outlet_host: NodeId,
786        hooked: &Rc<RefCell<Vec<NodeId>>>,
787        observer: &ChromeScrollObserver,
788    ) {
789        let needs_hook: bool = scene.with_read(
790            |tree: &SceneTree| {
791                let Ok(list) = hooked.try_borrow() else {
792                    return false;
793                };
794                tree.children_iter(outlet_host).any(|kid: NodeId| {
795                    !list.contains(&kid)
796                        && tree.get_node(kid).is_some_and(|scene_node: &SceneNode| {
797                            matches!(scene_node.get_kind(), NodeKind::ScrollView)
798                        })
799                })
800            },
801            false,
802        );
803        if !needs_hook {
804            return;
805        }
806        scene.with_write(
807            |tree: &mut SceneTree| {
808                let kids: Vec<NodeId> = tree.children_vec(outlet_host);
809                for kid in kids.into_iter() {
810                    let already_hooked: bool = hooked
811                        .try_borrow()
812                        .ok()
813                        .map(|list: Ref<'_, Vec<NodeId>>| list.contains(&kid))
814                        .unwrap_or(false);
815                    if already_hooked {
816                        continue;
817                    }
818                    let is_scroll: bool = tree
819                        .get_node(kid)
820                        .map(|node_entry: &SceneNode| {
821                            matches!(node_entry.get_kind(), NodeKind::ScrollView)
822                        })
823                        .unwrap_or(false);
824                    if !is_scroll {
825                        continue;
826                    }
827                    if let Some(wn) = tree.get_node_mut(kid) {
828                        let prev_handler: Option<UiEventHandler> = wn
829                            .get_handlers()
830                            .handler_for(&UiEventKind::Scroll(Point::default()));
831                        let obs_c: ChromeScrollObserver = observer.clone();
832                        let wrapped: UiEventHandler =
833                            Rc::new(RefCell::new(move |ui_event: &UiEvent| {
834                                if let Some(prev) = prev_handler.as_ref()
835                                    && let Ok(mut factor_val) = prev.try_borrow_mut()
836                                {
837                                    factor_val(ui_event);
838                                }
839                                obs_c.observe(kid, ui_event);
840                            }));
841                        wn.get_mut_handlers().set_on_scroll(Some(wrapped));
842                        if let Ok(mut list) = hooked.try_borrow_mut() {
843                            list.push(kid);
844                        }
845                    }
846                }
847            },
848            (),
849        );
850    }
851
852    /// Draws the official `Euv Studio` brand logo decoded from `https://devhub.vip/pages/docs/img/euv.png`.
853    ///
854    /// # Arguments
855    ///
856    /// - `Rect` - Emblem canvas bounds in logical pixels.
857    /// - `&mut DisplayList` - Target display list.
858    fn draw_euv_brand_emblem(bounds: Rect, display_list: &mut DisplayList) {
859        let pos_x: f32 = bounds.get_x();
860        let pos_y: f32 = bounds.get_y();
861        let width_val: f32 = bounds.get_width().max(1.0);
862        let height_val: f32 = bounds.get_height().max(1.0);
863        let source_val: f32 = width_val.min(height_val);
864        let rect: Rect = Rect::new(
865            pos_x + (width_val - source_val) * 0.5,
866            pos_y + (height_val - source_val) * 0.5,
867            source_val,
868            source_val,
869        );
870        display_list.push(DrawCommand::Image {
871            rect,
872            buffer: euv_brand_logo_image(),
873            radius: CornerRadius::default(),
874        });
875    }
876
877    /// 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.
878    ///
879    /// # Arguments
880    ///
881    /// - `&str` - Single-character brand initial text.
882    /// - `Option<&ImageBuffer>` - Optional explicit raster brand logo image override.
883    /// - `ThemeTokens` - Active design tokens.
884    /// - `Option<&str>` - Optional interactive accessibility label when mounted as a button emblem in the top navbar.
885    ///
886    /// # Returns
887    ///
888    /// - `(NodeId, Option<NodeId>)` - Mounted brand logo badge root handle and optional fallback initial text node.
889    fn mount_brand_logo(
890        brand_initial: &str,
891        custom_logo: Option<&ImageBuffer>,
892        tokens: ThemeTokens,
893        interactive_a11y: Option<&str>,
894    ) -> (NodeId, Option<NodeId>) {
895        let palette: ThemePalette = tokens.get_palette();
896        let geometry: ThemeGeometry = tokens.get_geometry();
897        let badge_r: f32 = geometry.get_radius_md();
898        let primary: SurfaceColors = palette.surface(SurfaceRole::Primary);
899        let is_euv_mark: bool = brand_initial.eq_ignore_ascii_case(SHELL_DEFAULT_INITIAL);
900        let initial_owned: String = brand_initial.to_string();
901        if let Some(a11y_lbl) = interactive_a11y {
902            let lbl_owned: String = a11y_lbl.to_string();
903            if let Some(logo_buf) = custom_logo.cloned() {
904                let row_group_beta_style: Style = style! {
905                    Width(Length::Px(SHELL_BRAND_BADGE_SIZE))
906                    Height(Length::Px(SHELL_BRAND_BADGE_SIZE))
907                    FlexShrink(0.0)
908                    Radius(badge_r)
909                    Background(palette.get_background())
910                    Border::new(geometry.get_border_width(), palette.get_border())
911                    JustifyContent::Center
912                    AlignItems::Center
913                    Overflow::Hidden
914                    CursorIcon::Pointer
915                };
916                let image_secondary_style: Style = style! {
917                    Width(Length::Px(SHELL_BRAND_BADGE_SIZE))
918                    Height(Length::Px(SHELL_BRAND_BADGE_SIZE))
919                };
920                let badge: NodeId = view! {
921                    row {
922                        style: row_group_beta_style
923                        role: A11yRole::Button
924                        a11y_label: lbl_owned
925                        image {
926                            source: logo_buf
927                            style: image_secondary_style
928                        }
929                    }
930                };
931                (badge, None)
932            } else if is_euv_mark {
933                let paint_emblem = move |bounds: Rect, display_list: &mut DisplayList| {
934                    Self::draw_euv_brand_emblem(bounds, display_list);
935                };
936                let row_group_alpha_style: Style = style! {
937                    Width(Length::Px(SHELL_BRAND_BADGE_SIZE))
938                    Height(Length::Px(SHELL_BRAND_BADGE_SIZE))
939                    FlexShrink(0.0)
940                    Radius(badge_r)
941                    Background(palette.get_background())
942                    Border::new(geometry.get_border_width(), palette.get_border())
943                    JustifyContent::Center
944                    AlignItems::Center
945                    Overflow::Hidden
946                    CursorIcon::Pointer
947                };
948                let canvas_tertiary_style: Style = style! {
949                    Width(Length::Px(SHELL_BRAND_BADGE_SIZE))
950                    Height(Length::Px(SHELL_BRAND_BADGE_SIZE))
951                };
952                let badge: NodeId = view! {
953                    row {
954                        style: row_group_alpha_style
955                        role: A11yRole::Button
956                        a11y_label: lbl_owned
957                        canvas {
958                            style: canvas_tertiary_style
959                            caching: CanvasCaching::RetainedStatic
960                            painter: paint_emblem
961                        }
962                    }
963                };
964                (badge, None)
965            } else {
966                let mut txt_id: NodeId = NodeId::default();
967                let row_twentieth_style: Style = style! {
968                    Width(Length::Px(SHELL_BRAND_BADGE_SIZE))
969                    Height(Length::Px(SHELL_BRAND_BADGE_SIZE))
970                    FlexShrink(0.0)
971                    Radius(badge_r)
972                    Background(primary.get_bg())
973                    Border::new(geometry.get_border_width(), primary.get_border())
974                    Overflow::Hidden
975                    JustifyContent::Center
976                    AlignItems::Center
977                    CursorIcon::Pointer
978                };
979                let text_ninth_style: Style = style! {
980                    FontSize(13.0)
981                    FontWeight::Bold
982                    TextColor(primary.get_fg())
983                    TextAlign::Center
984                    TextOverflow::Clip
985                };
986                let badge: NodeId = view! {
987                    row {
988                        style: row_twentieth_style
989                        role: A11yRole::Button
990                        a11y_label: lbl_owned
991                        text {
992                            node_ref: txt_id
993                            style: text_ninth_style
994                            { initial_owned }
995                        }
996                    }
997                };
998                (badge, Some(txt_id))
999            }
1000        } else if let Some(logo_buf) = custom_logo.cloned() {
1001            let row_nineteenth_style: Style = style! {
1002                Width(Length::Px(SHELL_BRAND_BADGE_SIZE))
1003                Height(Length::Px(SHELL_BRAND_BADGE_SIZE))
1004                FlexShrink(0.0)
1005                Radius(badge_r)
1006                Background(palette.get_background())
1007                Border::new(geometry.get_border_width(), palette.get_border())
1008                JustifyContent::Center
1009                AlignItems::Center
1010                Overflow::Hidden
1011            };
1012            let image_style: Style = style! {
1013                Width(Length::Px(SHELL_BRAND_BADGE_SIZE))
1014                Height(Length::Px(SHELL_BRAND_BADGE_SIZE))
1015            };
1016            let badge: NodeId = view! {
1017                row {
1018                    style: row_nineteenth_style
1019                    role: A11yRole::Group
1020                    a11y_label: SHELL_BRAND_A11Y_LABEL.to_string()
1021                    image {
1022                        source: logo_buf
1023                        style: image_style
1024                    }
1025                }
1026            };
1027            (badge, None)
1028        } else if is_euv_mark {
1029            let paint_emblem = move |bounds: Rect, draw_commands: &mut DisplayList| {
1030                Self::draw_euv_brand_emblem(bounds, draw_commands);
1031            };
1032            let row_eighteenth_style: Style = style! {
1033                Width(Length::Px(SHELL_BRAND_BADGE_SIZE))
1034                Height(Length::Px(SHELL_BRAND_BADGE_SIZE))
1035                FlexShrink(0.0)
1036                Radius(badge_r)
1037                Background(palette.get_background())
1038                Border::new(geometry.get_border_width(), palette.get_border())
1039                JustifyContent::Center
1040                AlignItems::Center
1041                Overflow::Hidden
1042            };
1043            let canvas_secondary_style: Style = style! {
1044                Width(Length::Px(SHELL_BRAND_BADGE_SIZE))
1045                Height(Length::Px(SHELL_BRAND_BADGE_SIZE))
1046            };
1047            let badge: NodeId = view! {
1048                row {
1049                    style: row_eighteenth_style
1050                    role: A11yRole::Group
1051                    a11y_label: SHELL_BRAND_A11Y_LABEL.to_string()
1052                    canvas {
1053                        style: canvas_secondary_style
1054                        caching: CanvasCaching::RetainedStatic
1055                        painter: paint_emblem
1056                    }
1057                }
1058            };
1059            (badge, None)
1060        } else {
1061            let mut txt_id: NodeId = NodeId::default();
1062            let row_seventeenth_style: Style = style! {
1063                Width(Length::Px(SHELL_BRAND_BADGE_SIZE))
1064                Height(Length::Px(SHELL_BRAND_BADGE_SIZE))
1065                FlexShrink(0.0)
1066                Radius(badge_r)
1067                Background(primary.get_bg())
1068                Border::new(geometry.get_border_width(), primary.get_border())
1069                Overflow::Hidden
1070                JustifyContent::Center
1071                AlignItems::Center
1072            };
1073            let text_eighth_style: Style = style! {
1074                FontSize(13.0)
1075                FontWeight::Bold
1076                TextColor(primary.get_fg())
1077                TextAlign::Center
1078                TextOverflow::Clip
1079            };
1080            let badge: NodeId = view! {
1081                row {
1082                    style: row_seventeenth_style
1083                    role: A11yRole::Group
1084                    a11y_label: SHELL_BRAND_A11Y_LABEL.to_string()
1085                    text {
1086                        node_ref: txt_id
1087                        style: text_eighth_style
1088                        { initial_owned }
1089                    }
1090                }
1091            };
1092            (badge, Some(txt_id))
1093        }
1094    }
1095}
1096
1097/// Declarative `#[component]` implementation for `EuvAppShell`.
1098#[component]
1099/// Inherent implementation of [`EuvAppShell`].
1100impl EuvAppShell {
1101    /// Renders `EuvAppShell` into the ambient framework-managed `Context`.
1102    ///
1103    /// # Arguments
1104    ///
1105    /// - `&Self` - Component descriptor reference.
1106    ///
1107    /// # Returns
1108    ///
1109    /// - `NodeId` - Mounted root scene node handle.
1110    fn render(&self) -> NodeId {
1111        let mut ctx: Context = current_context();
1112        bind_fullscreen_context(&ctx);
1113        let tokens: ThemeTokens = self.get_tokens();
1114        let bp_sig: Signal<Breakpoint> = ctx.get_breakpoint();
1115        let vp_sig: Signal<Size> = ctx.get_viewport_size();
1116        let safe_sig: Signal<SafeAreaInsets> = ctx.get_safe_area();
1117        let gesture_sig: Signal<Option<GestureEvent>> = ctx.get_gesture();
1118        let swipe_drag_sig: Signal<f32> = ctx.get_swipe_drag_offset();
1119        let fps_sig: Signal<f32> = ctx.get_live_fps();
1120        let refresh_sig: Signal<f32> = ctx.get_display_refresh_rate();
1121        let idle_sig: Signal<bool> = ctx.get_is_idle();
1122        let app_state_sig: Signal<AppState> = ctx.get_app_state();
1123        let fs_active_sig: Signal<bool> = use_fullscreen_active();
1124        let ctx_fs_sig: Signal<bool> = ctx.immersive_fullscreen_signal();
1125        let overlay_count_sig: Signal<usize> = EuvOverlayStack::active_count_signal();
1126        let show_fps: bool = self.get_show_fps();
1127        let auto_hide_enabled: bool = self.get_auto_hide_chrome_on_scroll();
1128        let Self {
1129            brand,
1130            sidebar,
1131            main_content,
1132            route_signal,
1133            top_bar_actions,
1134            mobile_header_actions,
1135            sidebar_footer,
1136            breadcrumb,
1137            bottom_nav,
1138            swipe_routes,
1139            swipe_routes_enabled,
1140            show_fps_signal,
1141            theme,
1142            page_padding,
1143            auto_hide_chrome_signal,
1144            brand_url,
1145            on_brand_click,
1146            brand_logo,
1147            drawer_open,
1148            layout_mode,
1149            ..
1150        } = self;
1151        let sidebar: NodeId = *sidebar;
1152        let main_content: NodeId = *main_content;
1153        let route_signal: Option<Signal<String>> = *route_signal;
1154        let top_bar_actions: Option<NodeId> = *top_bar_actions;
1155        let mobile_header_actions: Option<NodeId> = *mobile_header_actions;
1156        let sidebar_footer: Option<NodeId> = *sidebar_footer;
1157        let breadcrumb: Option<Signal<String>> = *breadcrumb;
1158        let bottom_nav: Option<NodeId> = *bottom_nav;
1159        let page_padding: Option<Signal<Edges>> = *page_padding;
1160        let swipe_routes_enabled: Option<Signal<bool>> = *swipe_routes_enabled;
1161        let show_fps_signal: Option<Signal<bool>> = *show_fps_signal;
1162        let auto_hide_chrome_signal: Option<Signal<bool>> = *auto_hide_chrome_signal;
1163        let brand_url_opt: Option<String> = brand_url.clone();
1164        let on_brand_click_opt: Option<ShellBrandClickHandler> = on_brand_click.clone();
1165        let brand_logo_ref: Option<&ImageBuffer> = brand_logo.as_ref();
1166        let drawer_open_opt: Option<Signal<bool>> = *drawer_open;
1167        let layout_mode_opt: Option<Signal<EuvShellLayoutMode>> = *layout_mode;
1168        let brand_owned: String = brand.clone();
1169        let init_vp: Size = vp_sig.get_untracked();
1170        let init_mode: EuvShellLayoutMode =
1171            EuvShellLayoutMode::from_viewport_width(init_vp.get_width());
1172        let init_desktop: bool = init_mode.is_desktop();
1173        if let Some(mode_sig) = layout_mode_opt {
1174            let _: bool = mode_sig.set_if_changed(init_mode);
1175        }
1176        let auto_hide_capable: bool = auto_hide_enabled || auto_hide_chrome_signal.is_some();
1177        let mount_fps_pills: bool = show_fps || show_fps_signal.is_some();
1178        let init_show_fps: bool =
1179            show_fps_signal.map_or(show_fps, |sig: Signal<bool>| sig.get_untracked());
1180        let has_custom_brand_action: bool = on_brand_click_opt.is_some() || brand_url_opt.is_some();
1181        let swipe_routes_rc: Rc<[String]> = Rc::from(swipe_routes.as_slice());
1182        let theme_state_opt: Option<UiThemeState> = theme.clone();
1183        if let Some(theme_ref) = theme_state_opt.as_ref() {
1184            provide_theme(theme_ref.clone());
1185        }
1186        let init_tok: ThemeTokens = live_tokens_untracked(tokens);
1187        let palette: ThemePalette = init_tok.get_palette();
1188        let geometry: ThemeGeometry = init_tok.get_geometry();
1189        let has_managed_outlet: bool = ctx.get_scene().with_read(
1190            |tree: &SceneTree| {
1191                tree.get_node(main_content)
1192                    .map(|scene_node: &SceneNode| {
1193                        let lay: LayoutStyle = scene_node.style_ref().get_layout();
1194                        matches!(scene_node.get_kind(), NodeKind::View)
1195                            && lay.get_overflow() == Overflow::Hidden
1196                            && lay.get_height() == Length::Percent(100.0)
1197                    })
1198                    .unwrap_or(false)
1199            },
1200            false,
1201        );
1202        let has_bottom_nav: bool = bottom_nav.is_some();
1203        let dock_radius: f32 = geometry.get_radius_lg();
1204        let dock_host_pad: Edges = Edges::symmetric(CONTROL_INSET, CONTROL_INSET * 0.5);
1205        let init_vp_size: Size = vp_sig.get_untracked();
1206        let init_safe_insets: SafeAreaInsets = safe_sig.get_untracked();
1207        let init_chrome: ResolvedChromeLayout =
1208            EuvChromeLayoutPolicy::resolve(&ShellViewportMetrics::new(
1209                init_vp_size.get_width().max(CHROME_MIN_VIEWPORT_CLAMP),
1210                init_vp_size.get_height().max(CHROME_MIN_VIEWPORT_CLAMP),
1211                init_safe_insets,
1212                has_bottom_nav,
1213                false,
1214                false,
1215                bp_sig.get_untracked().is_compact(),
1216            ));
1217        let init_frameless_dock: bool = init_chrome.get_dock_frameless();
1218        let dock_frameless_cell: Rc<Cell<bool>> = Rc::new(Cell::new(init_frameless_dock));
1219        let dock_frameless_layout: Rc<Cell<bool>> = Rc::clone(&dock_frameless_cell);
1220        let dock_frameless_theme: Rc<Cell<bool>> = Rc::clone(&dock_frameless_cell);
1221        let brand_initial: String = brand
1222            .chars()
1223            .next()
1224            .map(|char_value: char| char_value.to_ascii_uppercase().to_string())
1225            .unwrap_or_else(|| SHELL_DEFAULT_INITIAL.to_string());
1226        let menu_open: Signal<bool> = drawer_open_opt.unwrap_or_else(|| Signal::new(false));
1227        if init_desktop {
1228            let _: bool = menu_open.set_if_changed(false);
1229        }
1230        let drawer_expanded: Signal<bool> = Signal::new(false);
1231        let chrome_hidden: Signal<bool> = Signal::new(false);
1232        let scroll_hide_state: Rc<Cell<ChromeScrollAutoHideState>> =
1233            Rc::new(Cell::new(ChromeScrollAutoHideState::default()));
1234        let hooked_scroll_nodes: Rc<RefCell<Vec<NodeId>>> = Rc::new(RefCell::new(Vec::new()));
1235        let drawer_drag_active: Rc<Cell<bool>> = Rc::new(Cell::new(false));
1236        let drawer_drag_start_x: Rc<Cell<f32>> = Rc::new(Cell::new(0.0));
1237        let drawer_drag_base_w: Rc<Cell<f32>> = Rc::new(Cell::new(248.0));
1238        let drawer_drag_moved: Rc<Cell<bool>> = Rc::new(Cell::new(false));
1239        let drawer_portal_left_cell: Rc<Cell<f32>> = Rc::new(Cell::new(0.0));
1240        let drawer_logo_anchor_cell: Rc<Cell<(f32, f32, f32, f32)>> =
1241            Rc::new(Cell::new((SPACE_SM, SPACE_SM, 0.0, 0.0)));
1242        let div_h: f32 = geometry.get_border_width().max(1.0);
1243        let mut top_chrome_inflow_slot: NodeId = NodeId::default();
1244        let mut top_chrome_portal: NodeId = NodeId::default();
1245        let mut top_bar_chrome: NodeId = NodeId::default();
1246        let mut top_bar: NodeId = NodeId::default();
1247        let mut top_bar_divider: NodeId = NodeId::default();
1248        let mut top_title_txt: NodeId = NodeId::default();
1249        let mut body_row: NodeId = NodeId::default();
1250        let mut nav_rail: NodeId = NodeId::default();
1251        let mut nav_divider: NodeId = NodeId::default();
1252        let mut content_column: NodeId = NodeId::default();
1253        let mut desktop_top_chrome: NodeId = NodeId::default();
1254        let mut desktop_top_bar: NodeId = NodeId::default();
1255        let mut desktop_top_divider: NodeId = NodeId::default();
1256        let mut desktop_brand_row: NodeId = NodeId::default();
1257        let mut desktop_brand_txt: NodeId = NodeId::default();
1258        let mut desktop_crumb_sep: NodeId = NodeId::default();
1259        let mut crumb_txt: NodeId = NodeId::default();
1260        let mut main_area: NodeId = NodeId::default();
1261        let mut bottom_bar_host: NodeId = NodeId::default();
1262        let mut drawer_portal: NodeId = NodeId::default();
1263        let mut drawer_panel: NodeId = NodeId::default();
1264        let mut drawer_scroll: NodeId = NodeId::default();
1265        let mut drawer_brand_txt: NodeId = NodeId::default();
1266        let mut drawer_grabber: NodeId = NodeId::default();
1267        let mut drawer_grabber_pill: NodeId = NodeId::default();
1268        let mut menu_btn_node: NodeId = NodeId::default();
1269        let mut top_brand_row: NodeId = NodeId::default();
1270        let mut menu_icon_node: NodeId = NodeId::default();
1271        let init_idle: bool = idle_sig.get_untracked();
1272        let init_fps_bucket: u16 = resolve_shell_fps_bucket(0, fps_sig.get_untracked(), init_idle);
1273        let init_hz_bucket: u16 = resolve_shell_hz_bucket(0, refresh_sig.get_untracked());
1274        let fps_bucket_sig: Signal<u16> = Signal::new(init_fps_bucket);
1275        let hz_bucket_sig: Signal<u16> = Signal::new(init_hz_bucket);
1276        let init_hz: f32 = init_hz_bucket as f32;
1277        let init_good_fps: f32 = (init_hz * 0.75).clamp(45.0, 90.0);
1278        let init_warn_fps: f32 = (init_hz * 0.45).clamp(24.0, 50.0);
1279        let init_dot_col: Color = if init_fps_bucket == 0 {
1280            palette.get_muted_foreground()
1281        } else if (init_fps_bucket as f32) >= init_good_fps {
1282            palette.get_success()
1283        } else if (init_fps_bucket as f32) >= init_warn_fps {
1284            palette.get_warning()
1285        } else {
1286            palette.get_destructive()
1287        };
1288        let init_topbar_ctrl_fg: Color = palette.surface(SurfaceRole::Background).get_fg();
1289        let init_fps_disp: Display = if init_show_fps {
1290            Display::Flex
1291        } else {
1292            Display::None
1293        };
1294        let mut mobile_fps_dot: Option<NodeId> = None;
1295        let mut mobile_fps_txt: Option<NodeId> = None;
1296        let mobile_fps_pill: Option<NodeId> = if mount_fps_pills {
1297            let mut dot_node: NodeId = NodeId::default();
1298            let mut txt_node: NodeId = NodeId::default();
1299            let fps_text_mob = move || -> String {
1300                let fps_bucket: u16 = fps_bucket_sig.get();
1301                format_shell_fps_mobile_label(fps_bucket)
1302            };
1303            let row_sixteenth_style: Style = style! {
1304                init_fps_disp
1305                MinWidth(Length::Px(48.0))
1306                Height(Length::Px(SHELL_TOPBAR_CONTROL_HEIGHT))
1307                Padding(Edges::symmetric(0.0, SPACE_SM))
1308                Radius(geometry.get_radius_md())
1309                JustifyContent::Center
1310                AlignItems::Center
1311                Gap(SPACE_XS)
1312                Background(palette.get_background())
1313                Border::new(geometry.get_border_width(), palette.get_border())
1314                Overflow::Hidden
1315            };
1316            let view_seventh_style: Style = style! {
1317                Width(Length::Px(6.0))
1318                Height(Length::Px(6.0))
1319                Radius(RADIUS_PILL)
1320                Background(init_dot_col)
1321            };
1322            let text_seventh_style: Style = style! {
1323                FontSize(11.0)
1324                FontFamily::Monospace
1325                FontWeight::Bold
1326                TextColor(init_topbar_ctrl_fg)
1327                TextAlign::Center
1328                TextOverflow::Clip
1329            };
1330            let pill: NodeId = view! {
1331                row {
1332                    style: row_sixteenth_style
1333                    role: A11yRole::Group
1334                    a11y_label: SHELL_FPS_A11Y_LABEL.to_string()
1335                    view {
1336                        node_ref: dot_node
1337                        style: view_seventh_style
1338                    }
1339                    text {
1340                        node_ref: txt_node
1341                        style: text_seventh_style
1342                        { fps_text_mob }
1343                    }
1344                }
1345            };
1346            mobile_fps_dot = Some(dot_node);
1347            mobile_fps_txt = Some(txt_node);
1348            Some(pill)
1349        } else {
1350            None
1351        };
1352        let mut desktop_fps_dot: Option<NodeId> = None;
1353        let mut desktop_fps_txt: Option<NodeId> = None;
1354        let desktop_fps_pill: Option<NodeId> = if mount_fps_pills {
1355            let mut dot_node: NodeId = NodeId::default();
1356            let mut txt_node: NodeId = NodeId::default();
1357            let fps_text_desk = move || -> String {
1358                format_shell_fps_desktop_label(fps_bucket_sig.get(), hz_bucket_sig.get())
1359            };
1360            let row_fifteenth_style: Style = style! {
1361                init_fps_disp
1362                MinWidth(Length::Px(84.0))
1363                Height(Length::Px(SHELL_TOPBAR_CONTROL_HEIGHT))
1364                Padding(Edges::symmetric(0.0, SPACE_SM))
1365                Radius(geometry.get_radius_md())
1366                JustifyContent::Center
1367                AlignItems::Center
1368                Gap(SPACE_XS)
1369                Background(palette.get_background())
1370                Border::new(geometry.get_border_width(), palette.get_border())
1371                Overflow::Hidden
1372            };
1373            let view_sixth_style: Style = style! {
1374                Width(Length::Px(6.0))
1375                Height(Length::Px(6.0))
1376                Radius(RADIUS_PILL)
1377                Background(init_dot_col)
1378            };
1379            let text_sixth_style: Style = style! {
1380                FontSize(11.0)
1381                FontFamily::Monospace
1382                FontWeight::Bold
1383                TextColor(init_topbar_ctrl_fg)
1384                TextAlign::Center
1385                TextOverflow::Clip
1386            };
1387            let pill: NodeId = view! {
1388                row {
1389                    style: row_fifteenth_style
1390                    role: A11yRole::Group
1391                    a11y_label: SHELL_FPS_A11Y_LABEL.to_string()
1392                    view {
1393                        node_ref: dot_node
1394                        style: view_sixth_style
1395                    }
1396                    text {
1397                        node_ref: txt_node
1398                        style: text_sixth_style
1399                        { fps_text_desk }
1400                    }
1401                }
1402            };
1403            desktop_fps_dot = Some(dot_node);
1404            desktop_fps_txt = Some(txt_node);
1405            Some(pill)
1406        } else {
1407            None
1408        };
1409        let paint_menu_icon = move |bounds: Rect, display_list: &mut DisplayList| {
1410            let live_p: ThemePalette = live_tokens_untracked(tokens).get_palette();
1411            draw_euv_icon(
1412                EuvIconName::Menu,
1413                bounds,
1414                display_list,
1415                live_p.surface(SurfaceRole::Background).get_fg(),
1416            );
1417        };
1418        let on_toggle_menu_btn = move |_: &UiEvent| {
1419            let _: bool = menu_open.set(!menu_open.get_untracked());
1420        };
1421        let show_menu_btn: bool =
1422            !has_bottom_nav || (has_custom_brand_action && drawer_open_opt.is_none());
1423        let top_brand_cb: Option<ShellBrandClickHandler> = on_brand_click_opt.clone();
1424        let top_brand_url: Option<String> = brand_url_opt.clone();
1425        let on_top_brand_click = move |ui_event: &UiEvent| {
1426            if let Some(callback_fn) = top_brand_cb.as_ref() {
1427                callback_fn(ui_event);
1428            } else if let Some(url) = top_brand_url.as_ref() {
1429                let _: bool = dispatch_native_action(SHELL_OPEN_URL_ACTION, url.as_str(), "");
1430            } else {
1431                let _: bool = menu_open.set(!menu_open.get_untracked());
1432            }
1433        };
1434        let drawer_brand_cb: Option<ShellBrandClickHandler> = on_brand_click_opt.clone();
1435        let drawer_brand_url: Option<String> = brand_url_opt.clone();
1436        let on_drawer_brand_click = move |interaction_event: &UiEvent| {
1437            if let Some(handler_cb) = drawer_brand_cb.as_ref() {
1438                handler_cb(interaction_event);
1439            } else if let Some(url) = drawer_brand_url.as_ref() {
1440                let _: bool = dispatch_native_action(SHELL_OPEN_URL_ACTION, url.as_str(), "");
1441            } else {
1442                let _: bool = menu_open.set_if_changed(false);
1443            }
1444        };
1445        let desktop_brand_cb: Option<ShellBrandClickHandler> = on_brand_click_opt;
1446        let desktop_brand_url: Option<String> = brand_url_opt;
1447        let mut euv_brand_badges: Vec<NodeId> = Vec::with_capacity(3);
1448        let mut initial_brand_badges: Vec<(NodeId, NodeId)> = Vec::with_capacity(3);
1449        let top_brand_badge: Option<NodeId> = {
1450            let badge_a11y: &str = if show_menu_btn || has_custom_brand_action {
1451                SHELL_BRAND_A11Y_LABEL
1452            } else {
1453                SHELL_MENU_LABEL
1454            };
1455            let (badge_id, txt_opt): (NodeId, Option<NodeId>) =
1456                Self::mount_brand_logo(&brand_initial, brand_logo_ref, init_tok, Some(badge_a11y));
1457            if let Some(tid) = txt_opt {
1458                initial_brand_badges.push((badge_id, tid));
1459            } else {
1460                euv_brand_badges.push(badge_id);
1461            }
1462            Some(badge_id)
1463        };
1464        let (desktop_brand_badge, desktop_badge_txt_opt): (NodeId, Option<NodeId>) =
1465            Self::mount_brand_logo(&brand_initial, brand_logo_ref, init_tok, None);
1466        if let Some(tid) = desktop_badge_txt_opt {
1467            initial_brand_badges.push((desktop_brand_badge, tid));
1468        } else {
1469            euv_brand_badges.push(desktop_brand_badge);
1470        }
1471        let (drawer_brand_badge, drawer_badge_txt_opt): (NodeId, Option<NodeId>) =
1472            Self::mount_brand_logo(&brand_initial, brand_logo_ref, init_tok, None);
1473        if let Some(tid) = drawer_badge_txt_opt {
1474            initial_brand_badges.push((drawer_brand_badge, tid));
1475        } else {
1476            euv_brand_badges.push(drawer_brand_badge);
1477        }
1478        let desktop_brand_cursor: CursorIcon = if has_custom_brand_action {
1479            CursorIcon::Pointer
1480        } else {
1481            CursorIcon::Default
1482        };
1483        let column_style: Style = style! {
1484            Width(Length::Percent(100.0))
1485            Height(Length::Percent(100.0))
1486            Background(palette.get_background())
1487            Overflow::Hidden
1488        };
1489        let column_secondary_style: Style = style! {
1490            if init_desktop { Display::None } else { Display::Flex }
1491            if init_desktop { Position::Relative } else { Position::Absolute }
1492            Inset(Some(0.0), Some(0.0), None, Some(0.0))
1493            Width(Length::Percent(100.0))
1494            FlexShrink(0.0)
1495            Overflow::Hidden
1496            ZIndex(Z_INDEX_CHROME)
1497        };
1498        let row_secondary_style: Style = style! {
1499            Width(Length::Percent(100.0))
1500            Height(Length::Px(MOBILE_HEADER_HEIGHT))
1501            JustifyContent::SpaceBetween
1502            AlignItems::Center
1503            Gap(SPACE_XS)
1504            Background(palette.get_card())
1505            Overflow::Hidden
1506        };
1507        let row_tertiary_style: Style = style! {
1508            FlexGrow(1.0)
1509            FlexShrink(1.0)
1510            MinWidth(Length::Px(0.0))
1511            Height(Length::Px(SHELL_TOPBAR_CONTROL_HEIGHT))
1512            Padding(Edges::new(0.0, SPACE_SM, 0.0, 0.0))
1513            Radius(geometry.get_radius_md())
1514            AlignItems::Center
1515            Gap(SPACE_XS)
1516            Overflow::Hidden
1517            CursorIcon::Pointer
1518        };
1519        let text_style: Style = style! {
1520            FlexGrow(1.0)
1521            FlexShrink(1.0)
1522            MinWidth(Length::Px(0.0))
1523            FontSize(14.0)
1524            FontWeight::Bold
1525            TextColor(palette.get_foreground())
1526            Overflow::Hidden
1527            TextOverflow::Ellipsis
1528        };
1529        let row_quaternary_style: Style = style! {
1530            FlexShrink(0.0)
1531            AlignItems::Center
1532            Gap(SPACE_XS)
1533        };
1534        let row_fifth_style: Style = style! {
1535            Width(Length::Px(SHELL_TOPBAR_CONTROL_HEIGHT))
1536            Height(Length::Px(SHELL_TOPBAR_CONTROL_HEIGHT))
1537            JustifyContent::Center
1538            AlignItems::Center
1539            Radius(geometry.get_radius_md())
1540            Background(palette.get_background())
1541            Border::new(geometry.get_border_width(), palette.get_border())
1542            Overflow::Hidden
1543            CursorIcon::Pointer
1544        };
1545        let canvas_style: Style = style! {
1546            Width(Length::Px(15.0))
1547            Height(Length::Px(15.0))
1548        };
1549        let view_secondary_style: Style = style! {
1550            Width(Length::Percent(100.0))
1551            Height(Length::Px(div_h))
1552            Background(palette.get_border())
1553        };
1554        let column_tertiary_style: Style = style! {
1555            if init_desktop { Display::Flex } else { Display::None }
1556            if init_desktop { Position::Absolute } else { Position::Relative }
1557            Inset(Some(0.0), Some(0.0), None, Some(0.0))
1558            Width(Length::Percent(100.0))
1559            FlexShrink(0.0)
1560            Overflow::Hidden
1561            ZIndex(Z_INDEX_CHROME)
1562        };
1563        let row_sixth_style: Style = style! {
1564            Width(Length::Percent(100.0))
1565            Height(Length::Px(SHELL_DESKTOP_HEADER_HEIGHT))
1566            JustifyContent::SpaceBetween
1567            AlignItems::Center
1568            Gap(SPACE_MD)
1569            Padding(Edges::symmetric(0.0, SPACE_MD))
1570            Background(palette.get_card())
1571            Overflow::Hidden
1572        };
1573        let row_seventh_style: Style = style! {
1574            FlexGrow(1.0)
1575            FlexShrink(1.0)
1576            MinWidth(Length::Px(0.0))
1577            AlignItems::Center
1578            Gap(SPACE_SM)
1579            Overflow::Hidden
1580        };
1581        let row_eighth_style: Style = style! {
1582            FlexShrink(0.0)
1583            Height(Length::Px(SHELL_TOPBAR_CONTROL_HEIGHT))
1584            if has_custom_brand_action {
1585                Padding(Edges::symmetric(0.0, SPACE_SM))
1586            } else {
1587                Padding(Edges::all(0.0))
1588            }
1589            Radius(geometry.get_radius_md())
1590            AlignItems::Center
1591            Gap(SPACE_SM)
1592            desktop_brand_cursor
1593        };
1594        let text_secondary_style: Style = style! {
1595            FontSize(15.0)
1596            FontWeight::Bold
1597            TextColor(palette.get_foreground())
1598        };
1599        let text_tertiary_style: Style = style! {
1600            Display::None
1601            FlexShrink(0.0)
1602            FontSize(13.0)
1603            FontWeight::Normal
1604            TextColor(palette.get_muted_foreground())
1605        };
1606        let text_quaternary_style: Style = style! {
1607            Display::None
1608            FlexGrow(1.0)
1609            FlexShrink(1.0)
1610            MinWidth(Length::Px(0.0))
1611            FontSize(13.0)
1612            FontWeight::Medium
1613            TextColor(palette.get_muted_foreground())
1614            Overflow::Hidden
1615            TextOverflow::Ellipsis
1616        };
1617        let row_ninth_style: Style = style! {
1618            FlexShrink(0.0)
1619            AlignItems::Center
1620            Gap(SPACE_SM)
1621        };
1622        let row_tenth_style: Style = style! {
1623            FlexGrow(1.0)
1624            Width(Length::Percent(100.0))
1625            Height(Length::Percent(100.0))
1626            Padding(Edges::all(0.0))
1627            Overflow::Hidden
1628        };
1629        let scroll_style: Style = style! {
1630            FlexDirection::Column
1631            if init_desktop { Display::Flex } else { Display::None }
1632            Width(Length::Px(SHELL_DESKTOP_SIDEBAR_WIDTH))
1633            Height(Length::Percent(100.0))
1634            MinHeight(Length::Px(0.0))
1635            FlexShrink(0.0)
1636            Overflow::Scroll
1637            Gap(SPACE_MD)
1638            Background(palette.get_card())
1639            ZIndex(Z_INDEX_CHROME)
1640        };
1641        let view_tertiary_style: Style = style! {
1642            if init_desktop { Display::Flex } else { Display::None }
1643            Width(Length::Px(div_h))
1644            Height(Length::Percent(100.0))
1645            FlexShrink(0.0)
1646            Background(palette.get_border())
1647        };
1648        let column_quaternary_style: Style = style! {
1649            FlexGrow(1.0)
1650            FlexShrink(1.0)
1651            MinWidth(Length::Px(0.0))
1652            Height(Length::Percent(100.0))
1653            Overflow::Hidden
1654        };
1655        let scroll_secondary_style: Style = style! {
1656            FlexDirection::Column
1657            FlexGrow(1.0)
1658            Width(Length::Percent(100.0))
1659            Height(Length::Percent(100.0))
1660            MinWidth(Length::Px(0.0))
1661            AlignItems::Center
1662            if has_managed_outlet { Overflow::Hidden } else { Overflow::Scroll }
1663            Gap(if has_managed_outlet { 0.0 } else { SPACE_LG })
1664        };
1665        let top_chrome_inflow_slot_style: Style = style! {
1666            Width(Length::Percent(100.0))
1667            FlexShrink(0.0)
1668            Overflow::Hidden
1669        };
1670        let top_chrome_portal_style: Style = style! {
1671            FlexDirection::Column
1672            Display::None
1673            Position::Absolute
1674            Inset(Some(0.0), Some(0.0), None, Some(0.0))
1675            Width(Length::Percent(100.0))
1676            Height(Length::Px(MOBILE_HEADER_HEIGHT + div_h))
1677            Overflow::Hidden
1678            PointerEvents::None
1679            ZIndex(Z_INDEX_CHROME - 1)
1680        };
1681        let row_eleventh_style: Style = style! {
1682            if has_bottom_nav && !init_desktop { Display::Flex } else { Display::None }
1683            Position::Fixed
1684            Inset(None, None, Some(SHELL_BOTTOM_NAV_FLOAT_COMPACT), Some(SHELL_BOTTOM_NAV_SIDE_MARGIN))
1685            Width(Length::Px(340.0))
1686            Height(Length::Px(SHELL_BOTTOM_NAV_HEIGHT))
1687            Padding(if init_frameless_dock { Edges::all(0.0) } else { dock_host_pad })
1688            JustifyContent::Center
1689            AlignItems::Center
1690            Background(if init_frameless_dock { COLOR_TRANSPARENT } else { palette.get_card().with_alpha(SHELL_BOTTOM_NAV_BG_ALPHA) })
1691            Border::new(if init_frameless_dock { 0.0 } else { geometry.get_border_width() }, if init_frameless_dock { COLOR_TRANSPARENT } else { palette.get_border() })
1692            Radius(if init_frameless_dock { 0.0 } else { dock_radius })
1693            if init_frameless_dock { Shadow::default() } else { geometry.get_shadow_lg() }
1694            Overflow::Hidden
1695            if has_bottom_nav && !init_desktop { PointerEvents::Auto } else { PointerEvents::None }
1696            StopScrollPropagation(true)
1697            ZIndex(Z_INDEX_CHROME)
1698        };
1699        let portal_style: Style = style! {
1700            FlexDirection::Row
1701            Display::None
1702            Position::Fixed
1703            Inset(Some(0.0), Some(0.0), Some(0.0), Some(0.0))
1704            Width(Length::Percent(100.0))
1705            Height(Length::Percent(100.0))
1706            JustifyContent::Start
1707            Background(palette.get_overlay())
1708            Overflow::Hidden
1709            PointerEvents::None
1710            StopScrollPropagation(true)
1711            ZIndex(Z_INDEX_DRAWER)
1712        };
1713        let row_twelfth_style: Style = style! {
1714            Width(Length::Px(248.0))
1715            MaxWidth(Length::Percent(92.0))
1716            Height(Length::Percent(100.0))
1717            Background(palette.get_card())
1718            Border::new(geometry.get_border_width(), palette.get_border())
1719            geometry.get_shadow_lg()
1720            Overflow::Hidden
1721        };
1722        let scroll_tertiary_style: Style = style! {
1723            FlexDirection::Column
1724            FlexGrow(1.0)
1725            FlexShrink(1.0)
1726            MinWidth(Length::Px(0.0))
1727            MinHeight(Length::Px(0.0))
1728            Height(Length::Percent(100.0))
1729            Overflow::Scroll
1730            Gap(SPACE_SM)
1731            StopScrollPropagation(true)
1732        };
1733        let row_thirteenth_style: Style = style! {
1734            Width(Length::Percent(100.0))
1735            FlexShrink(0.0)
1736            AlignItems::Center
1737            Gap(SPACE_SM)
1738            Padding(Edges::new(0.0, 0.0, SPACE_XS, 0.0))
1739            CursorIcon::Pointer
1740        };
1741        let text_fifth_style: Style = style! {
1742            FontSize(14.5)
1743            FontWeight::Bold
1744            TextColor(palette.get_foreground())
1745        };
1746        let row_fourteenth_style: Style = style! {
1747            Width(Length::Px(20.0))
1748            Height(Length::Percent(100.0))
1749            FlexShrink(0.0)
1750            JustifyContent::Center
1751            AlignItems::Center
1752            CursorIcon::EwResize
1753            StopScrollPropagation(true)
1754            StopEventPropagation(true)
1755        };
1756        let view_quaternary_style: Style = style! {
1757            Width(Length::Px(4.0))
1758            Height(Length::Px(46.0))
1759            Radius(RADIUS_PILL)
1760            Background(palette.get_muted_foreground().with_alpha(128))
1761        };
1762        let root: NodeId = view! {
1763            column {
1764                style: column_style
1765                column {
1766                    node_ref: top_chrome_inflow_slot
1767                    style: top_chrome_inflow_slot_style
1768                    column {
1769                        node_ref: top_bar_chrome
1770                        style: column_secondary_style
1771                        row {
1772                            node_ref: top_bar
1773                            style: row_secondary_style
1774                            row {
1775                                node_ref: top_brand_row
1776                                style: row_tertiary_style
1777                                on_click: on_top_brand_click
1778                                if let Some(badge_node) = top_brand_badge {
1779                                    { badge_node }
1780                                }
1781                                text {
1782                                    node_ref: top_title_txt
1783                                    style: text_style
1784                                    { brand.clone() }
1785                                }
1786                            }
1787                            row {
1788                                style: row_quaternary_style
1789                                if let Some(fps_node) = mobile_fps_pill {
1790                                    { fps_node }
1791                                }
1792                                if let Some(mob_act) = mobile_header_actions {
1793                                    { mob_act }
1794                                }
1795                                if show_menu_btn {
1796                                    row {
1797                                        node_ref: menu_btn_node
1798                                        style: row_fifth_style
1799                                        role: A11yRole::Button
1800                                        a11y_label: SHELL_MENU_LABEL.to_string()
1801                                        on_click: on_toggle_menu_btn
1802                                        canvas {
1803                                            node_ref: menu_icon_node
1804                                            caching: CanvasCaching::RetainedStatic
1805                                            style: canvas_style
1806                                            painter: paint_menu_icon
1807                                        }
1808                                    }
1809                                }
1810                            }
1811                        }
1812                        view {
1813                            node_ref: top_bar_divider
1814                            style: view_secondary_style
1815                        }
1816                    }
1817                    column {
1818                        node_ref: desktop_top_chrome
1819                        style: column_tertiary_style
1820                        row {
1821                            node_ref: desktop_top_bar
1822                            style: row_sixth_style
1823                            row {
1824                                style: row_seventh_style
1825                                row {
1826                                    node_ref: desktop_brand_row
1827                                    style: row_eighth_style
1828                                    { desktop_brand_badge }
1829                                    text {
1830                                        node_ref: desktop_brand_txt
1831                                        style: text_secondary_style
1832                                        { brand.clone() }
1833                                    }
1834                                }
1835                                text {
1836                                    node_ref: desktop_crumb_sep
1837                                    style: text_tertiary_style
1838                                    { SHELL_BREADCRUMB_SEP }
1839                                }
1840                                text {
1841                                    node_ref: crumb_txt
1842                                    style: text_quaternary_style
1843                                    { String::new() }
1844                                }
1845                            }
1846                            row {
1847                                style: row_ninth_style
1848                                if let Some(fps_d) = desktop_fps_pill {
1849                                    { fps_d }
1850                                }
1851                                if let Some(actions_node) = top_bar_actions {
1852                                    { actions_node }
1853                                }
1854                            }
1855                        }
1856                        view {
1857                            node_ref: desktop_top_divider
1858                            style: view_secondary_style
1859                        }
1860                    }
1861                }
1862                row {
1863                    node_ref: body_row
1864                    style: row_tenth_style
1865                    scroll {
1866                        node_ref: nav_rail
1867                        style: scroll_style
1868                    }
1869                    view {
1870                        node_ref: nav_divider
1871                        style: view_tertiary_style
1872                    }
1873                    column {
1874                        node_ref: content_column
1875                        style: column_quaternary_style
1876                        scroll {
1877                            node_ref: main_area
1878                            style: scroll_secondary_style
1879                            { main_content }
1880                        }
1881                    }
1882                }
1883                portal {
1884                    node_ref: top_chrome_portal
1885                    style: top_chrome_portal_style
1886                }
1887                row {
1888                    node_ref: bottom_bar_host
1889                    style: row_eleventh_style
1890                    if let Some(bn) = bottom_nav {
1891                        { bn }
1892                    }
1893                }
1894                portal {
1895                    node_ref: drawer_portal
1896                    style: portal_style
1897                    row {
1898                        node_ref: drawer_panel
1899                        style: row_twelfth_style
1900                        scroll {
1901                            node_ref: drawer_scroll
1902                            style: scroll_tertiary_style
1903                            row {
1904                                style: row_thirteenth_style
1905                                on_click: on_drawer_brand_click
1906                                { drawer_brand_badge }
1907                                text {
1908                                    node_ref: drawer_brand_txt
1909                                    style: text_fifth_style
1910                                    { brand.clone() }
1911                                }
1912                            }
1913                        }
1914                        row {
1915                            node_ref: drawer_grabber
1916                            style: row_fourteenth_style
1917                            view {
1918                                node_ref: drawer_grabber_pill
1919                                style: view_quaternary_style
1920                            }
1921                        }
1922                    }
1923                }
1924            }
1925        };
1926        if has_custom_brand_action {
1927            let brand_a11y: String = brand.clone();
1928            ctx.get_scene().with_write(
1929                |tree: &mut SceneTree| {
1930                    for target_row in [desktop_brand_row, top_brand_row].into_iter() {
1931                        if let Some(item_count) = tree.get_node_mut(target_row) {
1932                            let _: &mut SceneNode = item_count.set_a11y(Some(A11yProps::new(
1933                                A11yRole::Button,
1934                                brand_a11y.clone(),
1935                            )));
1936                        }
1937                    }
1938                },
1939                (),
1940            );
1941            ctx.on_click(desktop_brand_row, move |event_payload: &UiEvent| {
1942                if let Some(callback_fn_primary) = desktop_brand_cb.as_ref() {
1943                    callback_fn_primary(event_payload);
1944                } else if let Some(url) = desktop_brand_url.as_ref() {
1945                    let _: bool = dispatch_native_action(SHELL_OPEN_URL_ACTION, url.as_str(), "");
1946                }
1947            });
1948        }
1949        let scroll_observer: ChromeScrollObserver = ChromeScrollObserver::new(
1950            auto_hide_enabled,
1951            auto_hide_chrome_signal,
1952            ctx.get_scene().clone(),
1953            Rc::clone(&scroll_hide_state),
1954            ctx_fs_sig,
1955            menu_open,
1956            chrome_hidden,
1957        );
1958        if auto_hide_capable {
1959            let reveal_scroll_obs: ChromeScrollObserver = scroll_observer.clone();
1960            ctx.on_scroll(content_column, move |dispatched_event: &UiEvent| {
1961                reveal_scroll_obs.observe_unconsumed_up(dispatched_event);
1962            });
1963        }
1964        if !has_managed_outlet {
1965            let main_clamp_scene: SceneHandle = ctx.get_scene().clone();
1966            let main_scroll_obs: ChromeScrollObserver = scroll_observer.clone();
1967            ctx.on_scroll(main_area, move |event_item: &UiEvent| {
1968                main_clamp_scene.with_write(
1969                    |tree: &mut SceneTree| {
1970                        if let Some(cur) = tree.get_node(main_area).map(|node_entry: &SceneNode| {
1971                            node_entry.get_layout_box().get_scroll_offset()
1972                        }) && cur.get_x().abs() > 0.01
1973                        {
1974                            tree.set_scroll_offset(main_area, Point::new(0.0, cur.get_y()));
1975                        }
1976                    },
1977                    (),
1978                );
1979                main_scroll_obs.observe(main_area, event_item);
1980            });
1981        } else if auto_hide_capable {
1982            Self::attach_outlet_scroll_observers(
1983                ctx.get_scene(),
1984                main_content,
1985                &hooked_scroll_nodes,
1986                &scroll_observer,
1987            );
1988            let scene_pe: SceneHandle = ctx.get_scene().clone();
1989            let hooked_pe: Rc<RefCell<Vec<NodeId>>> = Rc::clone(&hooked_scroll_nodes);
1990            let obs_pe: ChromeScrollObserver = scroll_observer.clone();
1991            ctx.on_pointer_enter(main_area, move |_: &UiEvent| {
1992                Self::attach_outlet_scroll_observers(&scene_pe, main_content, &hooked_pe, &obs_pe);
1993            });
1994        }
1995        let d_down_active: Rc<Cell<bool>> = drawer_drag_active.clone();
1996        let d_down_x: Rc<Cell<f32>> = drawer_drag_start_x.clone();
1997        let d_down_w: Rc<Cell<f32>> = drawer_drag_base_w.clone();
1998        let d_down_moved: Rc<Cell<bool>> = drawer_drag_moved.clone();
1999        let d_down_portal_left: Rc<Cell<f32>> = drawer_portal_left_cell.clone();
2000        let h_down: SceneHandle = ctx.get_scene().clone();
2001        ctx.on_pointer_down(drawer_grabber, move |ui_event_primary: &UiEvent| {
2002            if let UiEventKind::PointerDown(sample_point) = ui_event_primary.get_kind() {
2003                h_down.with_write(
2004                    |tree: &mut SceneTree| {
2005                        tree.cancel_subtree_transitions(drawer_panel);
2006                    },
2007                    (),
2008                );
2009                let vp_w: f32 = vp_sig.get_untracked().get_width().max(320.0);
2010                let portal_w: f32 = (vp_w - d_down_portal_left.get()).max(120.0);
2011                let def_w: f32 = (portal_w.max(224.0) * 0.68)
2012                    .clamp(224.0, 256.0)
2013                    .min(portal_w);
2014                let cur_w: f32 = h_down
2015                    .node_screen_bounds(drawer_panel)
2016                    .map(|rect_bounds: Rect| rect_bounds.get_width())
2017                    .filter(|width_val: &f32| *width_val > 40.0)
2018                    .unwrap_or(def_w);
2019                d_down_active.set(true);
2020                d_down_x.set(sample_point.get_x());
2021                d_down_w.set(cur_w);
2022                d_down_moved.set(false);
2023            }
2024        });
2025        let d_scrim_moved: Rc<Cell<bool>> = drawer_drag_moved.clone();
2026        ctx.on_pointer_down(drawer_portal, move |_: &UiEvent| {
2027            d_scrim_moved.set(false);
2028        });
2029        for target_node in [drawer_grabber, drawer_panel, drawer_portal].into_iter() {
2030            let h_move: SceneHandle = ctx.get_scene().clone();
2031            let da_move: Rc<Cell<bool>> = drawer_drag_active.clone();
2032            let sx_move: Rc<Cell<f32>> = drawer_drag_start_x.clone();
2033            let bw_move: Rc<Cell<f32>> = drawer_drag_base_w.clone();
2034            let dm_move: Rc<Cell<bool>> = drawer_drag_moved.clone();
2035            let pl_move: Rc<Cell<f32>> = drawer_portal_left_cell.clone();
2036            ctx.on_pointer_move(target_node, move |ui_event_secondary: &UiEvent| {
2037                if !da_move.get() {
2038                    return;
2039                }
2040                if let UiEventKind::PointerMove(target_point) = ui_event_secondary.get_kind() {
2041                    let dx: f32 = target_point.get_x() - sx_move.get();
2042                    if dx.abs() > 4.0 {
2043                        dm_move.set(true);
2044                    }
2045                    let vp_w: f32 = vp_sig.get_untracked().get_width().max(320.0);
2046                    let portal_w: f32 = (vp_w - pl_move.get()).max(120.0);
2047                    let avail_w: f32 = portal_w.max(224.0);
2048                    let def_w: f32 = (avail_w * 0.68).clamp(224.0, 256.0).min(portal_w);
2049                    let max_w: f32 = (avail_w * 0.88).clamp(def_w + 40.0, 380.0).min(portal_w);
2050                    let raw_w: f32 = bw_move.get() + dx;
2051                    let (next_w, tx): (f32, f32) = if raw_w >= def_w {
2052                        (raw_w.min(max_w), 0.0)
2053                    } else {
2054                        (def_w, (raw_w - def_w).min(0.0))
2055                    };
2056                    h_move.with_write(
2057                        |tree: &mut SceneTree| {
2058                            if let Some(normal_vec) = tree.get_node_mut(drawer_panel) {
2059                                let computed_style: &mut Style = normal_vec.get_mut_style();
2060                                computed_style
2061                                    .get_mut_layout()
2062                                    .set_width(Length::Px(next_w));
2063                                computed_style
2064                                    .get_mut_paint()
2065                                    .set_transform(Transform2D::new(tx, 0.0, 1.0, 1.0, 0.0));
2066                                let layout_dirty: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
2067                                tree.mark_dirty(drawer_panel, layout_dirty | DIRTY_PAINT);
2068                            }
2069                        },
2070                        (),
2071                    );
2072                }
2073            });
2074            let h_up: SceneHandle = ctx.get_scene().clone();
2075            let da_up: Rc<Cell<bool>> = drawer_drag_active.clone();
2076            let sx_up: Rc<Cell<f32>> = drawer_drag_start_x.clone();
2077            let pl_up: Rc<Cell<f32>> = drawer_portal_left_cell.clone();
2078            ctx.on_pointer_up(target_node, move |ui_event_next: &UiEvent| {
2079                if !da_up.replace(false) {
2080                    return;
2081                }
2082                let dx: f32 = match ui_event_next.get_kind() {
2083                    UiEventKind::PointerUp(vertex_point) => vertex_point.get_x() - sx_up.get(),
2084                    _ => 0.0,
2085                };
2086                let vp_w: f32 = vp_sig.get_untracked().get_width().max(320.0);
2087                let portal_w: f32 = (vp_w - pl_up.get()).max(120.0);
2088                let avail_w: f32 = portal_w.max(224.0);
2089                let def_w: f32 = (avail_w * 0.68).clamp(224.0, 256.0).min(portal_w);
2090                let max_w: f32 = (avail_w * 0.88).clamp(def_w + 40.0, 380.0).min(portal_w);
2091                let is_exp: bool = drawer_expanded.get_untracked();
2092                if dx < -52.0 {
2093                    if is_exp && dx > -140.0 {
2094                        let _: bool = drawer_expanded.set_if_changed(false);
2095                    } else {
2096                        let _: bool = menu_open.set_if_changed(false);
2097                        return;
2098                    }
2099                } else if dx > 40.0 {
2100                    let _: bool = drawer_expanded.set_if_changed(true);
2101                }
2102                let target_w: f32 = if drawer_expanded.get_untracked() {
2103                    max_w
2104                } else {
2105                    def_w
2106                };
2107                h_up.with_write(
2108                    |tree: &mut SceneTree| {
2109                        let cur_tx: f32 = tree
2110                            .get_node(drawer_panel)
2111                            .map(|total_len: &SceneNode| {
2112                                total_len
2113                                    .style_ref()
2114                                    .get_paint()
2115                                    .get_transform()
2116                                    .get_translate_x()
2117                            })
2118                            .unwrap_or(0.0);
2119                        tree.cancel_subtree_transitions(drawer_panel);
2120                        if let Some(item_count_primary) = tree.get_node_mut(drawer_panel) {
2121                            let element_style: &mut Style = item_count_primary.get_mut_style();
2122                            element_style
2123                                .get_mut_layout()
2124                                .set_width(Length::Px(target_w));
2125                            if cur_tx.abs() <= 0.5 {
2126                                element_style
2127                                    .get_mut_paint()
2128                                    .set_transform(Transform2D::default());
2129                            }
2130                            let layout_dirty: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
2131                            tree.mark_dirty(drawer_panel, layout_dirty | DIRTY_PAINT);
2132                        }
2133                        if cur_tx.abs() > 0.5 {
2134                            tree.start_transition(
2135                                NodeTransition::slide_fade(
2136                                    drawer_panel,
2137                                    Point::new(cur_tx, 0.0),
2138                                    Point::default(),
2139                                    1.0,
2140                                    1.0,
2141                                    motion_duration(MOTION_EMPHASIZED_SECS),
2142                                    false,
2143                                )
2144                                .with_easing(MOTION_EASE_ENTER),
2145                            );
2146                        }
2147                    },
2148                    (),
2149                );
2150            });
2151            let h_cancel: SceneHandle = ctx.get_scene().clone();
2152            let da_cancel: Rc<Cell<bool>> = drawer_drag_active.clone();
2153            let dm_cancel: Rc<Cell<bool>> = drawer_drag_moved.clone();
2154            ctx.on_pointer_cancel(target_node, move |_: &UiEvent| {
2155                if !da_cancel.replace(false) {
2156                    return;
2157                }
2158                dm_cancel.set(false);
2159                h_cancel.with_write(
2160                    |tree: &mut SceneTree| {
2161                        if let Some(item_count_secondary) = tree.get_node_mut(drawer_panel) {
2162                            item_count_secondary
2163                                .get_mut_style()
2164                                .get_mut_paint()
2165                                .set_transform(Transform2D::default());
2166                            tree.mark_dirty(drawer_panel, DIRTY_PAINT);
2167                        }
2168                    },
2169                    (),
2170                );
2171            });
2172        }
2173        let drawer_click_moved: Rc<Cell<bool>> = drawer_drag_moved.clone();
2174        ctx.on_click(drawer_portal, move |ui_event_alt: &UiEvent| {
2175            if drawer_click_moved.replace(false) {
2176                return;
2177            }
2178            if ui_event_alt.get_target() == drawer_portal {
2179                let _: bool = menu_open.set_if_changed(false);
2180            }
2181        });
2182        let handle: SceneHandle = ctx.get_scene().clone();
2183        let handle_layout: SceneHandle = handle.clone();
2184        let handle_crumb: SceneHandle = handle.clone();
2185        let handle_state: SceneHandle = handle.clone();
2186        let drawer_da_close: Rc<Cell<bool>> = drawer_drag_active.clone();
2187        let drawer_dm_close: Rc<Cell<bool>> = drawer_drag_moved.clone();
2188        let drawer_da_layout: Rc<Cell<bool>> = drawer_drag_active.clone();
2189        let drawer_dm_layout: Rc<Cell<bool>> = drawer_drag_moved.clone();
2190        let drawer_da_state: Rc<Cell<bool>> = drawer_drag_active;
2191        let drawer_dm_state: Rc<Cell<bool>> = drawer_drag_moved;
2192        let prev_open: Rc<Cell<bool>> = Rc::new(Cell::new(false));
2193        let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
2194            let _: Effect =
2195                EuvOverlayStack::bind_signal(menu_open, SHELL_DRAWER_OVERLAY_NAME, Z_INDEX_DRAWER);
2196            let _: Effect = Effect::new(move || {
2197                if app_state_sig.get() != AppState::Active && drawer_da_state.replace(false) {
2198                    drawer_dm_state.set(false);
2199                    handle_state.with_write(
2200                        |tree: &mut SceneTree| {
2201                            if let Some(item_count_next) = tree.get_node_mut(drawer_panel) {
2202                                item_count_next
2203                                    .get_mut_style()
2204                                    .get_mut_paint()
2205                                    .set_transform(Transform2D::default());
2206                                tree.mark_dirty(drawer_panel, DIRTY_PAINT);
2207                            }
2208                        },
2209                        (),
2210                    );
2211                }
2212            });
2213            if mount_fps_pills {
2214                let _: Effect = Effect::new(move || {
2215                    let visible_now: bool =
2216                        show_fps_signal.map_or(show_fps, |sig: Signal<bool>| sig.get());
2217                    if !visible_now {
2218                        return;
2219                    }
2220                    let is_idle_now: bool = idle_sig.get();
2221                    if is_idle_now {
2222                        let _: bool = fps_bucket_sig.set_if_changed(0);
2223                        return;
2224                    }
2225                    let raw_fps: f32 = fps_sig.get();
2226                    let raw_hz: f32 = refresh_sig.get();
2227                    let prev_fps: u16 = fps_bucket_sig.get_untracked();
2228                    let next_fps: u16 = resolve_shell_fps_bucket(prev_fps, raw_fps, false);
2229                    let _: bool = fps_bucket_sig.set_if_changed(next_fps);
2230                    let prev_hz: u16 = hz_bucket_sig.get_untracked();
2231                    let next_hz: u16 = resolve_shell_hz_bucket(prev_hz, raw_hz);
2232                    let _: bool = hz_bucket_sig.set_if_changed(next_hz);
2233                });
2234            }
2235            if mobile_fps_dot.is_some() || desktop_fps_dot.is_some() {
2236                let handle_fps: SceneHandle = handle.clone();
2237                let prev_dot_col: Cell<Color> = Cell::new(init_dot_col);
2238                let _: Effect = Effect::new(move || {
2239                    let live_p: ThemePalette = use_live_tokens(tokens).get_palette();
2240                    let fps_bucket: u16 = fps_bucket_sig.get();
2241                    let target_hz: f32 = hz_bucket_sig.get() as f32;
2242                    let good_fps: f32 = (target_hz * 0.75).clamp(45.0, 90.0);
2243                    let warn_fps: f32 = (target_hz * 0.45).clamp(24.0, 50.0);
2244                    let dot_col: Color = if fps_bucket == 0 {
2245                        live_p.get_muted_foreground()
2246                    } else if (fps_bucket as f32) >= good_fps {
2247                        live_p.get_success()
2248                    } else if (fps_bucket as f32) >= warn_fps {
2249                        live_p.get_warning()
2250                    } else {
2251                        live_p.get_destructive()
2252                    };
2253                    if prev_dot_col.replace(dot_col) == dot_col {
2254                        return;
2255                    }
2256                    handle_fps.with_write(
2257                        |tree: &mut SceneTree| {
2258                            if let Some(dot_id) = mobile_fps_dot
2259                                && let Some(item_count_alt) = tree.get_node_mut(dot_id)
2260                            {
2261                                item_count_alt
2262                                    .get_mut_style()
2263                                    .get_mut_paint()
2264                                    .set_background(Some(dot_col));
2265                                tree.mark_dirty(dot_id, DIRTY_PAINT);
2266                            }
2267                            if let Some(dot_id) = desktop_fps_dot
2268                                && let Some(item_count_inner) = tree.get_node_mut(dot_id)
2269                            {
2270                                item_count_inner
2271                                    .get_mut_style()
2272                                    .get_mut_paint()
2273                                    .set_background(Some(dot_col));
2274                                tree.mark_dirty(dot_id, DIRTY_PAINT);
2275                            }
2276                        },
2277                        (),
2278                    );
2279                });
2280            }
2281            if let Some(fps_vis_sig) = show_fps_signal {
2282                let handle_fps_vis: SceneHandle = handle.clone();
2283                let _: Effect = Effect::new(move || {
2284                    let next_disp: Display = if fps_vis_sig.get() {
2285                        Display::Flex
2286                    } else {
2287                        Display::None
2288                    };
2289                    handle_fps_vis.with_write(
2290                        |tree: &mut SceneTree| {
2291                            let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
2292                            let dirty_all: u16 = dirty_l | DIRTY_PAINT;
2293                            if let Some(pill_id) = mobile_fps_pill
2294                                && let Some(item_count_local) = tree.get_node_mut(pill_id)
2295                            {
2296                                item_count_local
2297                                    .get_mut_style()
2298                                    .get_mut_layout()
2299                                    .set_display(next_disp);
2300                                tree.mark_dirty(pill_id, dirty_all);
2301                                tree.mark_dirty(top_bar, dirty_all);
2302                            }
2303                            if let Some(pill_id) = desktop_fps_pill
2304                                && let Some(item_count_cur) = tree.get_node_mut(pill_id)
2305                            {
2306                                item_count_cur
2307                                    .get_mut_style()
2308                                    .get_mut_layout()
2309                                    .set_display(next_disp);
2310                                tree.mark_dirty(pill_id, dirty_all);
2311                                tree.mark_dirty(desktop_top_bar, dirty_all);
2312                            }
2313                        },
2314                        (),
2315                    );
2316                });
2317            }
2318            if let Some(crumb_sig) = breadcrumb {
2319                let scene_crumb_hook: SceneHandle = handle.clone();
2320                let hooked_for_crumb: Rc<RefCell<Vec<NodeId>>> = Rc::clone(&hooked_scroll_nodes);
2321                let obs_for_crumb: ChromeScrollObserver = scroll_observer.clone();
2322                let brand_for_crumb: String = brand_owned;
2323                let _: Effect = Effect::new(move || {
2324                    let full: String = crumb_sig.get();
2325                    if auto_hide_capable && has_managed_outlet {
2326                        Self::attach_outlet_scroll_observers(
2327                            &scene_crumb_hook,
2328                            main_content,
2329                            &hooked_for_crumb,
2330                            &obs_for_crumb,
2331                        );
2332                    }
2333                    let trimmed: &str = full.trim();
2334                    let mobile_text: String = if trimmed.is_empty() {
2335                        brand_for_crumb.clone()
2336                    } else if let Some((_, leaf)) = trimmed.rsplit_once(" / ") {
2337                        leaf.to_string()
2338                    } else {
2339                        trimmed.to_string()
2340                    };
2341                    let show_desktop_crumb: bool =
2342                        !trimmed.is_empty() && !trimmed.eq_ignore_ascii_case(&brand_for_crumb);
2343                    let desktop_crumb_disp: Display = if show_desktop_crumb {
2344                        Display::Flex
2345                    } else {
2346                        Display::None
2347                    };
2348                    let desktop_text: String = if show_desktop_crumb {
2349                        trimmed.to_string()
2350                    } else {
2351                        String::new()
2352                    };
2353                    handle_crumb.with_write(
2354                        |tree: &mut SceneTree| {
2355                            let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
2356                            let dirty_all: u16 = dirty_l | DIRTY_PAINT;
2357                            if let Some(item_count_slot) = tree.get_node_mut(top_title_txt) {
2358                                item_count_slot.set_kind(NodeKind::Text(mobile_text));
2359                                tree.mark_dirty(top_title_txt, dirty_all);
2360                            }
2361                            if let Some(item_count_2) = tree.get_node_mut(desktop_crumb_sep) {
2362                                item_count_2
2363                                    .get_mut_style()
2364                                    .get_mut_layout()
2365                                    .set_display(desktop_crumb_disp);
2366                                tree.mark_dirty(desktop_crumb_sep, dirty_all);
2367                            }
2368                            if let Some(item_count_3) = tree.get_node_mut(crumb_txt) {
2369                                item_count_3
2370                                    .get_mut_style()
2371                                    .get_mut_layout()
2372                                    .set_display(desktop_crumb_disp);
2373                                item_count_3.set_kind(NodeKind::Text(desktop_text));
2374                                tree.mark_dirty(crumb_txt, dirty_all);
2375                            }
2376                        },
2377                        (),
2378                    );
2379                });
2380            }
2381            let mut scratch_children: Vec<NodeId> = Vec::new();
2382            let prev_top_hidden: Rc<Cell<bool>> = Rc::new(Cell::new(false));
2383            let prev_dock_hidden: Rc<Cell<bool>> = Rc::new(Cell::new(false));
2384            let prev_fullscreen: Rc<Cell<bool>> = Rc::new(Cell::new(false));
2385            let prev_vp_size: Rc<Cell<Size>> = Rc::new(Cell::new(vp_sig.get_untracked()));
2386            let hooked_for_layout: Rc<RefCell<Vec<NodeId>>> = Rc::clone(&hooked_scroll_nodes);
2387            let scroll_obs_for_layout: ChromeScrollObserver = scroll_observer.clone();
2388            let hide_state_for_layout: Rc<Cell<ChromeScrollAutoHideState>> =
2389                Rc::clone(&scroll_hide_state);
2390            let drawer_portal_left_layout: Rc<Cell<f32>> = Rc::clone(&drawer_portal_left_cell);
2391            let drawer_logo_anchor_layout: Rc<Cell<(f32, f32, f32, f32)>> =
2392                Rc::clone(&drawer_logo_anchor_cell);
2393            let _: Effect = Effect::new(move || {
2394                let breakpoint_tier: Breakpoint = bp_sig.get();
2395                let box_size: Size = vp_sig.get();
2396                let safe: SafeAreaInsets = safe_sig.get();
2397                let is_fullscreen: bool = fs_active_sig.get() || ctx_fs_sig.get();
2398                let was_fullscreen: bool = prev_fullscreen.replace(is_fullscreen);
2399                let exited_fullscreen: bool = was_fullscreen && !is_fullscreen;
2400                let auto_hide_active: bool = auto_hide_chrome_signal
2401                    .map_or(auto_hide_enabled, |sig: Signal<bool>| sig.get());
2402                let prev_vp: Size = prev_vp_size.replace(box_size);
2403                let vp_resized: bool = (prev_vp.get_width() - box_size.get_width()).abs() > 1.0
2404                    || (prev_vp.get_height() - box_size.get_height()).abs() > 1.0;
2405                let reset_hide_for_fs: bool = is_fullscreen || exited_fullscreen;
2406                if !auto_hide_active {
2407                    let _: bool = chrome_hidden.set_if_changed(false);
2408                    hide_state_for_layout.set(ChromeScrollAutoHideState::default());
2409                } else if reset_hide_for_fs || vp_resized {
2410                    let was_hidden_now: bool = chrome_hidden.get_untracked();
2411                    let _: bool = chrome_hidden.set_if_changed(false);
2412                    let mut next_tracker: ChromeScrollAutoHideState =
2413                        ChromeScrollAutoHideState::default();
2414                    if vp_resized && was_hidden_now {
2415                        next_tracker.reset_with_suppression(2);
2416                    }
2417                    hide_state_for_layout.set(next_tracker);
2418                }
2419                let is_chrome_hidden: bool =
2420                    auto_hide_active && !is_fullscreen && chrome_hidden.get();
2421                if auto_hide_active && has_managed_outlet {
2422                    Self::attach_outlet_scroll_observers(
2423                        &handle_layout,
2424                        main_content,
2425                        &hooked_for_layout,
2426                        &scroll_obs_for_layout,
2427                    );
2428                }
2429                let vp_w: f32 = box_size.get_width().max(CHROME_MIN_VIEWPORT_CLAMP);
2430                let vp_h: f32 = box_size.get_height().max(CHROME_MIN_VIEWPORT_CLAMP);
2431                let shell_mode: EuvShellLayoutMode = EuvShellLayoutMode::from_viewport_width(vp_w);
2432                let is_desktop: bool = shell_mode.is_desktop();
2433                let is_mobile: bool = shell_mode.is_mobile();
2434                if let Some(mode_sig) = layout_mode_opt {
2435                    let _: bool = mode_sig.set_if_changed(shell_mode);
2436                }
2437                let chrome_metrics: ShellViewportMetrics = ShellViewportMetrics::new(
2438                    vp_w,
2439                    vp_h,
2440                    safe,
2441                    has_bottom_nav,
2442                    is_fullscreen,
2443                    is_chrome_hidden,
2444                    breakpoint_tier.is_compact(),
2445                );
2446                let chrome: ResolvedChromeLayout = EuvChromeLayoutPolicy::resolve(&chrome_metrics);
2447                let show_bottom_nav: bool = chrome.get_show_dock();
2448                let dock_frameless: bool = chrome.get_dock_frameless();
2449                dock_frameless_layout.set(dock_frameless);
2450                let overlay_top_bar: bool =
2451                    !is_fullscreen && auto_hide_active && chrome.get_top_bar_allow_auto_hide();
2452                let top_hidden: bool = overlay_top_bar && is_chrome_hidden;
2453                let dock_hidden: bool = is_chrome_hidden && chrome.get_dock_allow_auto_hide();
2454                let was_top_hidden: bool = prev_top_hidden.replace(top_hidden);
2455                let was_dock_hidden: bool = prev_dock_hidden.replace(dock_hidden);
2456                let top_toggled: bool = !vp_resized
2457                    && !is_fullscreen
2458                    && !exited_fullscreen
2459                    && was_top_hidden != top_hidden;
2460                let dock_toggled: bool = !vp_resized
2461                    && !is_fullscreen
2462                    && !exited_fullscreen
2463                    && was_dock_hidden != dock_hidden;
2464                let live_layout_tok: ThemeTokens = live_tokens_untracked(tokens);
2465                let top_inset: f32 = safe.get_top().max(0.0);
2466                let bottom_inset: f32 = safe.get_bottom().max(0.0);
2467                let left_inset: f32 = safe.get_left().max(0.0);
2468                let right_inset: f32 = safe.get_right().max(0.0);
2469                let mobile_bar_h: f32 = chrome.get_mobile_header_height();
2470                let mobile_bar_pad: Edges = chrome.get_mobile_header_padding();
2471                let desktop_corner_top: f32 = if top_inset <= 0.0 && mobile_bar_pad.get_top() > 0.0
2472                {
2473                    mobile_bar_pad.get_top()
2474                } else {
2475                    0.0
2476                };
2477                let desktop_bar_h: f32 = if chrome.get_top_bar_in_safe_area() {
2478                    mobile_bar_h
2479                } else if top_inset > 0.0 {
2480                    top_inset + SHELL_DESKTOP_HEADER_HEIGHT
2481                } else {
2482                    desktop_corner_top + SHELL_DESKTOP_HEADER_HEIGHT
2483                };
2484                let desktop_bar_pad: Edges = if chrome.get_top_bar_in_safe_area() {
2485                    mobile_bar_pad
2486                } else {
2487                    Edges::new(
2488                        if top_inset > 0.0 {
2489                            top_inset
2490                        } else {
2491                            desktop_corner_top
2492                        },
2493                        (SPACE_MD + right_inset).max(mobile_bar_pad.get_right()),
2494                        0.0,
2495                        (SPACE_MD + left_inset).max(mobile_bar_pad.get_left()),
2496                    )
2497                };
2498                let dock_w: f32 = chrome.get_dock_width();
2499                let dock_h: f32 = chrome.get_dock_height();
2500                let dock_left: f32 = chrome.get_dock_left();
2501                let dock_top: Option<f32> = chrome.get_dock_top();
2502                let dock_bottom: Option<f32> = chrome.get_dock_bottom();
2503                let dock_hide_dx: f32 = chrome.get_dock_hide_dx();
2504                let dock_hide_dy: f32 = chrome.get_dock_hide_dy();
2505                let route_stage_insets: Edges = chrome.get_route_stage_insets();
2506                let active_top_h: f32 = if is_desktop {
2507                    desktop_bar_h
2508                } else {
2509                    mobile_bar_h
2510                };
2511                let body_h: f32 = if is_fullscreen || overlay_top_bar {
2512                    vp_h
2513                } else {
2514                    (vp_h - active_top_h - div_h).max(96.0)
2515                };
2516                let main_h: f32 =
2517                    (body_h - route_stage_insets.get_top() - route_stage_insets.get_bottom())
2518                        .max(64.0);
2519                if is_desktop || is_fullscreen {
2520                    let _: bool = menu_open.set_if_changed(false);
2521                    let _: bool = drawer_expanded.set_if_changed(false);
2522                    drawer_da_layout.set(false);
2523                    drawer_dm_layout.set(false);
2524                }
2525                let drawer_vp_w: f32 = box_size.get_width().max(320.0);
2526                let drawer_vp_h: f32 = box_size.get_height().max(240.0);
2527                let left_safe_rail_active: bool = show_bottom_nav
2528                    && chrome.get_dock_placement() == NavDockPlacement::LeftSafeRail;
2529                let drawer_portal_left: f32 = if left_safe_rail_active {
2530                    left_inset
2531                } else {
2532                    0.0
2533                };
2534                let drawer_portal_w: f32 = (drawer_vp_w - drawer_portal_left).max(120.0);
2535                drawer_portal_left_layout.set(drawer_portal_left);
2536                let drawer_avail_w: f32 = drawer_portal_w.max(224.0);
2537                let drawer_def_w: f32 = (drawer_avail_w * 0.68)
2538                    .clamp(224.0, 256.0)
2539                    .min(drawer_portal_w);
2540                let drawer_max_w: f32 = (drawer_avail_w * 0.88)
2541                    .clamp(drawer_def_w + 40.0, 380.0)
2542                    .min(drawer_portal_w);
2543                let drawer_target_w: f32 = if drawer_expanded.get() {
2544                    drawer_max_w
2545                } else {
2546                    drawer_def_w
2547                };
2548                let desktop_disp: Display = if is_fullscreen || is_mobile {
2549                    Display::None
2550                } else {
2551                    Display::Flex
2552                };
2553                let mut deferred_page_edges: Option<Edges> = None;
2554                handle_layout.with_write(
2555                    |tree: &mut SceneTree| {
2556                        let target_sidebar_parent: NodeId =
2557                            if is_mobile { drawer_scroll } else { nav_rail };
2558                        let cur_parent: Option<NodeId> =
2559                            tree.get_node(sidebar).and_then(SceneNode::parent_id);
2560                        let reparented_sidebar: bool = cur_parent != Some(target_sidebar_parent);
2561                        if reparented_sidebar {
2562                            tree.append_child(target_sidebar_parent, sidebar);
2563                        }
2564                        if let Some(sn) = tree.get_node_mut(sidebar) {
2565                            sn.get_mut_style().get_mut_layout().set_flex_shrink(0.0);
2566                        }
2567                        if let Some(footer_id) = sidebar_footer {
2568                            let cur_f: Option<NodeId> =
2569                                tree.get_node(footer_id).and_then(SceneNode::parent_id);
2570                            if cur_f != Some(target_sidebar_parent) || reparented_sidebar {
2571                                tree.append_child(target_sidebar_parent, footer_id);
2572                            }
2573                            if let Some(fn_node) = tree.get_node_mut(footer_id) {
2574                                fn_node
2575                                    .get_mut_style()
2576                                    .get_mut_layout()
2577                                    .set_flex_shrink(0.0);
2578                            }
2579                        }
2580                        let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
2581                        let mask_all: u16 = dirty_l | DIRTY_PAINT;
2582                        tree.mark_dirty(sidebar, mask_all);
2583                        scratch_children.clear();
2584                        if tree.get_node(sidebar).is_some() {
2585                            scratch_children.extend(tree.children_iter(sidebar));
2586                        }
2587                        for child_id in scratch_children.iter().copied() {
2588                            tree.mark_dirty(child_id, mask_all);
2589                        }
2590                        if let Some(item_count_4) = tree.get_node_mut(top_bar) {
2591                            item_count_4
2592                                .get_mut_style()
2593                                .get_mut_layout()
2594                                .set_display(Display::Flex)
2595                                .set_height(Length::Px(mobile_bar_h))
2596                                .set_padding(mobile_bar_pad);
2597                            tree.mark_dirty(top_bar, mask_all);
2598                        }
2599                        if let Some(item_count_5) = tree.get_node_mut(top_bar_divider) {
2600                            let div_l: f32 = chrome.get_top_divider_left_inset();
2601                            let div_r: f32 = chrome.get_top_divider_right_inset();
2602                            item_count_5
2603                                .get_mut_style()
2604                                .get_mut_layout()
2605                                .set_display(Display::Flex)
2606                                .set_width(Length::Px((vp_w - div_l - div_r).max(0.0)))
2607                                .set_margin(Edges::new(0.0, div_r, 0.0, div_l));
2608                            tree.mark_dirty(top_bar_divider, mask_all);
2609                        }
2610                        if let Some(item_count_6) = tree.get_node_mut(desktop_top_bar) {
2611                            item_count_6
2612                                .get_mut_style()
2613                                .get_mut_layout()
2614                                .set_display(Display::Flex)
2615                                .set_height(Length::Px(desktop_bar_h))
2616                                .set_padding(desktop_bar_pad);
2617                            tree.mark_dirty(desktop_top_bar, mask_all);
2618                        }
2619                        if let Some(item_count_7) = tree.get_node_mut(desktop_top_divider) {
2620                            item_count_7
2621                                .get_mut_style()
2622                                .get_mut_layout()
2623                                .set_display(Display::Flex);
2624                            tree.mark_dirty(desktop_top_divider, mask_all);
2625                        }
2626                        let target_top_host: NodeId = if overlay_top_bar {
2627                            top_chrome_portal
2628                        } else {
2629                            top_chrome_inflow_slot
2630                        };
2631                        for bar_chrome in [top_bar_chrome, desktop_top_chrome].into_iter() {
2632                            let cur_top_parent: Option<NodeId> =
2633                                tree.get_node(bar_chrome).and_then(SceneNode::parent_id);
2634                            if cur_top_parent != Some(target_top_host) {
2635                                tree.append_child(target_top_host, bar_chrome);
2636                            }
2637                        }
2638                        if let Some(inflow_node) = tree.get_node_mut(top_chrome_inflow_slot) {
2639                            inflow_node.get_mut_style().get_mut_layout().set_display(
2640                                if is_fullscreen || overlay_top_bar {
2641                                    Display::None
2642                                } else {
2643                                    Display::Flex
2644                                },
2645                            );
2646                            tree.mark_dirty(top_chrome_inflow_slot, mask_all);
2647                        }
2648                        if let Some(portal_node) = tree.get_node_mut(top_chrome_portal) {
2649                            let portal_st: &mut Style = portal_node.get_mut_style();
2650                            let show_top_portal: bool =
2651                                overlay_top_bar && (!top_hidden || top_toggled);
2652                            let was_portal_hidden: bool = portal_st.get_layout().get_display()
2653                                == Display::None
2654                                && portal_st.get_paint().get_pointer_events()
2655                                    == PointerEvents::None;
2656                            if show_top_portal {
2657                                portal_st
2658                                    .get_mut_layout()
2659                                    .set_display(Display::Flex)
2660                                    .set_width(Length::Px(vp_w))
2661                                    .set_height(Length::Px(active_top_h + div_h));
2662                                portal_st
2663                                    .get_mut_paint()
2664                                    .set_pointer_events(if !top_hidden {
2665                                        PointerEvents::Auto
2666                                    } else {
2667                                        PointerEvents::None
2668                                    });
2669                                tree.mark_dirty(top_chrome_portal, mask_all);
2670                            } else if !was_portal_hidden {
2671                                portal_st
2672                                    .get_mut_layout()
2673                                    .set_display(Display::None)
2674                                    .set_width(Length::Px(0.0))
2675                                    .set_height(Length::Px(0.0));
2676                                portal_st
2677                                    .get_mut_paint()
2678                                    .set_pointer_events(PointerEvents::None);
2679                                tree.mark_dirty(top_chrome_portal, mask_all);
2680                            }
2681                        }
2682                        let mobile_chrome_active: bool = !is_fullscreen && is_mobile;
2683                        Self::sync_top_chrome_bar(
2684                            tree,
2685                            top_bar_chrome,
2686                            mobile_chrome_active,
2687                            top_hidden,
2688                            top_toggled,
2689                            mobile_bar_h + div_h,
2690                        );
2691                        let desktop_chrome_active: bool = !is_fullscreen && is_desktop;
2692                        Self::sync_top_chrome_bar(
2693                            tree,
2694                            desktop_top_chrome,
2695                            desktop_chrome_active,
2696                            top_hidden,
2697                            top_toggled,
2698                            desktop_bar_h + div_h,
2699                        );
2700                        if let Some(item_count_16) = tree.get_node_mut(body_row) {
2701                            item_count_16
2702                                .get_mut_style()
2703                                .get_mut_layout()
2704                                .set_height(Length::Px(body_h));
2705                            tree.mark_dirty(body_row, mask_all);
2706                        }
2707                        if let Some(item_count_17) = tree.get_node_mut(content_column) {
2708                            let computed_style_inner: &mut Style = item_count_17.get_mut_style();
2709                            computed_style_inner
2710                                .get_mut_layout()
2711                                .set_height(Length::Px(body_h));
2712                            computed_style_inner
2713                                .get_mut_paint()
2714                                .set_stop_scroll_propagation(is_chrome_hidden);
2715                            tree.mark_dirty(content_column, mask_all);
2716                        }
2717                        if let Some(item_count_18) = tree.get_node_mut(nav_divider) {
2718                            item_count_18
2719                                .get_mut_style()
2720                                .get_mut_layout()
2721                                .set_display(desktop_disp)
2722                                .set_margin(Edges::all(0.0))
2723                                .set_height(Length::Px(body_h));
2724                            tree.mark_dirty(nav_divider, mask_all);
2725                        }
2726                        if let Some(item_count_19) = tree.get_node_mut(nav_rail) {
2727                            let rail_top_pad: f32 = if overlay_top_bar {
2728                                SPACE_MD + desktop_bar_h + div_h
2729                            } else {
2730                                SPACE_MD
2731                            };
2732                            let rail_left_pad: f32 =
2733                                (SPACE_SM + left_inset).max(mobile_bar_pad.get_left());
2734                            let rail_bottom_pad: f32 =
2735                                Self::resolve_sidebar_bottom_padding(bottom_inset);
2736                            item_count_19
2737                                .get_mut_style()
2738                                .get_mut_layout()
2739                                .set_display(desktop_disp)
2740                                .set_width(Length::Px(SHELL_DESKTOP_SIDEBAR_WIDTH))
2741                                .set_margin(Edges::all(0.0))
2742                                .set_height(Length::Px(body_h))
2743                                .set_padding(Edges::new(
2744                                    rail_top_pad,
2745                                    SPACE_SM,
2746                                    rail_bottom_pad,
2747                                    rail_left_pad,
2748                                ));
2749                            tree.mark_dirty(nav_rail, mask_all);
2750                        }
2751                        let main_pad: f32 = if is_desktop {
2752                            SPACE_MD
2753                        } else if breakpoint_tier.is_compact() {
2754                            SPACE_SM
2755                        } else {
2756                            SPACE_MD
2757                        };
2758                        let overlay_top_pad: f32 = if overlay_top_bar {
2759                            (active_top_h + div_h - route_stage_insets.get_top()).max(0.0)
2760                        } else {
2761                            0.0
2762                        };
2763                        let page_top_pad: f32 = main_pad + overlay_top_pad;
2764                        let main_bottom_pad: f32 = main_pad + chrome.get_content_extra_bottom_pad();
2765                        let extra_stage_left: f32 = if is_desktop || is_fullscreen {
2766                            0.0
2767                        } else {
2768                            (left_inset - route_stage_insets.get_left()).max(0.0)
2769                        };
2770                        let extra_stage_right: f32 = if is_fullscreen {
2771                            0.0
2772                        } else {
2773                            (right_inset - route_stage_insets.get_right()).max(0.0)
2774                        };
2775                        let page_edges: Edges = Edges::new(
2776                            page_top_pad,
2777                            main_pad + extra_stage_right,
2778                            main_bottom_pad,
2779                            main_pad + extra_stage_left,
2780                        );
2781                        deferred_page_edges = Some(page_edges);
2782                        if let Some(cn) = tree.get_node_mut(content_column) {
2783                            cn.get_mut_style()
2784                                .get_mut_layout()
2785                                .set_padding(route_stage_insets)
2786                                .set_overflow(Overflow::Hidden);
2787                            tree.mark_dirty(content_column, mask_all);
2788                        }
2789                        if let Some(item_count_20) = tree.get_node_mut(main_area) {
2790                            let lay: &mut LayoutStyle =
2791                                item_count_20.get_mut_style().get_mut_layout();
2792                            lay.set_height(Length::Px(main_h));
2793                            if has_managed_outlet {
2794                                lay.set_padding(Edges::all(0.0))
2795                                    .set_overflow(Overflow::Hidden)
2796                                    .set_row_gap(0.0)
2797                                    .set_column_gap(0.0);
2798                            } else {
2799                                let main_gap: f32 = if is_mobile && breakpoint_tier.is_compact() {
2800                                    SPACE_MD
2801                                } else {
2802                                    SPACE_LG
2803                                };
2804                                lay.set_padding(page_edges)
2805                                    .set_row_gap(main_gap)
2806                                    .set_column_gap(main_gap);
2807                            }
2808                            tree.mark_dirty(main_area, mask_all);
2809                        }
2810                        if has_managed_outlet && page_padding.is_none() {
2811                            scratch_children.clear();
2812                            if tree.get_node(main_content).is_some() {
2813                                scratch_children.extend(tree.children_iter(main_content));
2814                            }
2815                            for kid in scratch_children.iter().copied() {
2816                                if let Some(kn) = tree.get_node_mut(kid)
2817                                    && matches!(kn.get_kind(), NodeKind::ScrollView)
2818                                {
2819                                    kn.get_mut_style().get_mut_layout().set_padding(page_edges);
2820                                    tree.mark_dirty(kid, mask_all);
2821                                }
2822                            }
2823                        }
2824                        if !show_bottom_nav {
2825                            tree.cancel_subtree_transitions(bottom_bar_host);
2826                            let mut dock_changed: bool = false;
2827                            if let Some(item_count_21) = tree.get_node_mut(bottom_bar_host) {
2828                                let computed_style_local: &mut Style =
2829                                    item_count_21.get_mut_style();
2830                                let was_hidden: bool =
2831                                    computed_style_local.get_layout().get_display()
2832                                        == Display::None
2833                                        && computed_style_local.get_paint().get_pointer_events()
2834                                            == PointerEvents::None;
2835                                computed_style_local
2836                                    .get_mut_layout()
2837                                    .set_display(Display::None);
2838                                computed_style_local
2839                                    .get_mut_paint()
2840                                    .set_pointer_events(PointerEvents::None)
2841                                    .set_opacity(1.0)
2842                                    .set_transform(Transform2D::default());
2843                                dock_changed = !was_hidden;
2844                            }
2845                            if dock_changed {
2846                                tree.mark_dirty(bottom_bar_host, mask_all);
2847                            }
2848                        } else if dock_hidden {
2849                            if dock_toggled {
2850                                tree.cancel_subtree_transitions(bottom_bar_host);
2851                                if let Some(item_count_22) = tree.get_node_mut(bottom_bar_host) {
2852                                    let computed_style_cur: &mut Style =
2853                                        item_count_22.get_mut_style();
2854                                    computed_style_cur
2855                                        .get_mut_layout()
2856                                        .set_display(Display::Flex)
2857                                        .set_width(Length::Px(dock_w))
2858                                        .set_height(Length::Px(dock_h))
2859                                        .set_left(Some(dock_left))
2860                                        .set_bottom(dock_bottom)
2861                                        .set_right(None)
2862                                        .set_top(dock_top);
2863                                    Self::apply_dock_host_surface(
2864                                        computed_style_cur,
2865                                        dock_frameless,
2866                                        dock_host_pad,
2867                                        live_layout_tok,
2868                                    );
2869                                    computed_style_cur
2870                                        .get_mut_paint()
2871                                        .set_pointer_events(PointerEvents::None)
2872                                        .set_opacity(1.0)
2873                                        .set_transform(Transform2D::default());
2874                                }
2875                                tree.mark_dirty(bottom_bar_host, mask_all);
2876                                tree.start_transition(
2877                                    NodeTransition::slide_fade(
2878                                        bottom_bar_host,
2879                                        Point::new(0.0, 0.0),
2880                                        Point::new(dock_hide_dx, dock_hide_dy),
2881                                        1.0,
2882                                        0.0,
2883                                        motion_duration(MOTION_EMPHASIZED_SECS),
2884                                        true,
2885                                    )
2886                                    .with_easing(MOTION_EASE_EXIT),
2887                                );
2888                            } else {
2889                                tree.cancel_subtree_transitions(bottom_bar_host);
2890                                let mut dock_changed: bool = false;
2891                                if let Some(item_count_23) = tree.get_node_mut(bottom_bar_host) {
2892                                    let computed_style_slot: &mut Style =
2893                                        item_count_23.get_mut_style();
2894                                    let was_hidden: bool =
2895                                        computed_style_slot.get_layout().get_display()
2896                                            == Display::None
2897                                            && computed_style_slot.get_paint().get_pointer_events()
2898                                                == PointerEvents::None;
2899                                    computed_style_slot
2900                                        .get_mut_layout()
2901                                        .set_display(Display::None)
2902                                        .set_width(Length::Px(dock_w))
2903                                        .set_height(Length::Px(dock_h))
2904                                        .set_left(Some(dock_left))
2905                                        .set_bottom(dock_bottom)
2906                                        .set_right(None)
2907                                        .set_top(dock_top);
2908                                    Self::apply_dock_host_surface(
2909                                        computed_style_slot,
2910                                        dock_frameless,
2911                                        dock_host_pad,
2912                                        live_layout_tok,
2913                                    );
2914                                    computed_style_slot
2915                                        .get_mut_paint()
2916                                        .set_pointer_events(PointerEvents::None)
2917                                        .set_opacity(0.0)
2918                                        .set_transform(Transform2D::new(
2919                                            dock_hide_dx,
2920                                            dock_hide_dy,
2921                                            1.0,
2922                                            1.0,
2923                                            0.0,
2924                                        ));
2925                                    dock_changed = !was_hidden;
2926                                }
2927                                if dock_changed {
2928                                    tree.mark_dirty(bottom_bar_host, mask_all);
2929                                }
2930                            }
2931                        } else {
2932                            tree.cancel_subtree_transitions(bottom_bar_host);
2933                            if let Some(item_count_24) = tree.get_node_mut(bottom_bar_host) {
2934                                let computed_style_2: &mut Style = item_count_24.get_mut_style();
2935                                computed_style_2
2936                                    .get_mut_layout()
2937                                    .set_display(Display::Flex)
2938                                    .set_width(Length::Px(dock_w))
2939                                    .set_height(Length::Px(dock_h))
2940                                    .set_left(Some(dock_left))
2941                                    .set_bottom(dock_bottom)
2942                                    .set_right(None)
2943                                    .set_top(dock_top);
2944                                Self::apply_dock_host_surface(
2945                                    computed_style_2,
2946                                    dock_frameless,
2947                                    dock_host_pad,
2948                                    live_layout_tok,
2949                                );
2950                                computed_style_2
2951                                    .get_mut_paint()
2952                                    .set_pointer_events(PointerEvents::Auto)
2953                                    .set_opacity(if dock_toggled { 0.0 } else { 1.0 })
2954                                    .set_transform(if dock_toggled {
2955                                        Transform2D::new(dock_hide_dx, dock_hide_dy, 1.0, 1.0, 0.0)
2956                                    } else {
2957                                        Transform2D::default()
2958                                    });
2959                            }
2960                            tree.mark_dirty(bottom_bar_host, mask_all);
2961                            if let Some(bn_node) = bottom_nav {
2962                                tree.mark_dirty(bn_node, mask_all);
2963                            }
2964                            if dock_toggled {
2965                                tree.start_transition(
2966                                    NodeTransition::slide_fade(
2967                                        bottom_bar_host,
2968                                        Point::new(dock_hide_dx, dock_hide_dy),
2969                                        Point::new(0.0, 0.0),
2970                                        0.0,
2971                                        1.0,
2972                                        motion_duration(MOTION_EMPHASIZED_SECS),
2973                                        false,
2974                                    )
2975                                    .with_easing(MOTION_EASE_ENTER),
2976                                );
2977                            }
2978                        }
2979                        let top_logo_x: f32 = mobile_bar_pad.get_left();
2980                        let top_bar_inner_h: f32 =
2981                            (mobile_bar_h - mobile_bar_pad.get_top() - mobile_bar_pad.get_bottom())
2982                                .max(0.0);
2983                        let top_logo_y: f32 = mobile_bar_pad.get_top()
2984                            + ((top_bar_inner_h - SHELL_BRAND_BADGE_SIZE) * 0.5).max(0.0);
2985                        drawer_logo_anchor_layout.set((
2986                            top_logo_x,
2987                            top_logo_y,
2988                            drawer_portal_left,
2989                            bottom_inset,
2990                        ));
2991                        let drawer_open_now: bool = menu_open.get_untracked();
2992                        let drawer_visible_now: bool = tree.get_node(drawer_portal).is_some_and(
2993                            |scene_node_primary: &SceneNode| {
2994                                scene_node_primary.style_ref().get_layout().get_display()
2995                                    != Display::None
2996                            },
2997                        );
2998                        let drawer_dirty_needed: bool = !(is_desktop || is_fullscreen)
2999                            && (drawer_open_now || drawer_visible_now);
3000                        if is_desktop || is_fullscreen {
3001                            tree.cancel_subtree_transitions(drawer_portal);
3002                            tree.cancel_subtree_transitions(drawer_panel);
3003                            let mut drawer_changed: bool = false;
3004                            if let Some(item_count_25) = tree.get_node_mut(drawer_portal) {
3005                                let computed_style_3: &mut Style = item_count_25.get_mut_style();
3006                                let was_hidden: bool = computed_style_3.get_layout().get_display()
3007                                    == Display::None
3008                                    && computed_style_3.get_paint().get_pointer_events()
3009                                        == PointerEvents::None;
3010                                computed_style_3.get_mut_layout().set_display(Display::None);
3011                                computed_style_3
3012                                    .get_mut_paint()
3013                                    .set_pointer_events(PointerEvents::None)
3014                                    .set_opacity(1.0)
3015                                    .set_transform(Transform2D::default());
3016                                drawer_changed = !was_hidden;
3017                            }
3018                            if let Some(item_count_26) = tree.get_node_mut(drawer_panel) {
3019                                item_count_26
3020                                    .get_mut_style()
3021                                    .get_mut_paint()
3022                                    .set_opacity(1.0)
3023                                    .set_transform(Transform2D::default());
3024                            }
3025                            if drawer_changed {
3026                                tree.mark_dirty(drawer_portal, mask_all);
3027                            }
3028                        }
3029                        if let Some(item_count_27) = tree.get_node_mut(drawer_portal) {
3030                            item_count_27
3031                                .get_mut_style()
3032                                .get_mut_layout()
3033                                .set_left(Some(drawer_portal_left))
3034                                .set_right(Some(0.0))
3035                                .set_width(Length::Px(drawer_portal_w))
3036                                .set_height(Length::Px(drawer_vp_h))
3037                                .set_overflow(Overflow::Hidden);
3038                            if drawer_dirty_needed {
3039                                tree.mark_dirty(drawer_portal, mask_all);
3040                            }
3041                        }
3042                        if let Some(item_count_28) = tree.get_node_mut(drawer_panel) {
3043                            item_count_28
3044                                .get_mut_style()
3045                                .get_mut_layout()
3046                                .set_height(Length::Px(drawer_vp_h));
3047                            if drawer_dirty_needed {
3048                                tree.mark_dirty(drawer_panel, mask_all);
3049                            }
3050                        }
3051                        if let Some(item_count_29) = tree.get_node_mut(drawer_scroll) {
3052                            let drawer_bw: f32 = live_layout_tok.get_geometry().get_border_width();
3053                            let drawer_inner_h: f32 = (drawer_vp_h - drawer_bw * 2.0).max(0.0);
3054                            let drawer_top_pad: f32 = (top_logo_y - drawer_bw).max(0.0);
3055                            let drawer_left_pad: f32 =
3056                                (top_logo_x - drawer_portal_left - drawer_bw).max(0.0);
3057                            let drawer_bottom_pad: f32 =
3058                                (Self::resolve_sidebar_bottom_padding(bottom_inset) - drawer_bw)
3059                                    .max(0.0);
3060                            item_count_29
3061                                .get_mut_style()
3062                                .get_mut_layout()
3063                                .set_height(Length::Px(drawer_inner_h))
3064                                .set_padding(Edges::new(
3065                                    drawer_top_pad,
3066                                    SPACE_SM,
3067                                    drawer_bottom_pad,
3068                                    drawer_left_pad,
3069                                ));
3070                            if drawer_dirty_needed {
3071                                tree.mark_dirty(drawer_scroll, mask_all);
3072                            }
3073                        }
3074                        let drawer_closing: bool = !drawer_open_now && drawer_visible_now;
3075                        if !drawer_closing {
3076                            let drawer_w_len: Length = Length::Px(drawer_target_w);
3077                            let drawer_resized: bool =
3078                                if let Some(item_count_30) = tree.get_node_mut(drawer_panel) {
3079                                    let changed: bool =
3080                                        item_count_30.style_ref().get_layout().get_width()
3081                                            != drawer_w_len;
3082                                    item_count_30
3083                                        .get_mut_style()
3084                                        .get_mut_layout()
3085                                        .set_width(drawer_w_len);
3086                                    if changed {
3087                                        item_count_30
3088                                            .get_mut_style()
3089                                            .get_mut_paint()
3090                                            .set_transform(Transform2D::default());
3091                                    }
3092                                    if drawer_dirty_needed {
3093                                        tree.mark_dirty(drawer_panel, mask_all);
3094                                    }
3095                                    changed
3096                                } else {
3097                                    false
3098                                };
3099                            if drawer_resized && drawer_dirty_needed {
3100                                tree.cancel_subtree_transitions(drawer_panel);
3101                            }
3102                        }
3103                        tree.mark_dirty(root, mask_all);
3104                    },
3105                    (),
3106                );
3107                if let (Some(pad_sig), Some(edges)) = (page_padding, deferred_page_edges) {
3108                    let _: bool = pad_sig.set_if_changed(edges);
3109                }
3110                if is_fullscreen != was_fullscreen {
3111                    notify_frame_needed();
3112                }
3113            });
3114            let last_g_seq: Rc<Cell<u64>> = Rc::new(Cell::new(
3115                gesture_sig
3116                    .get_untracked()
3117                    .map(|ui_event_inner: GestureEvent| ui_event_inner.get_sequence())
3118                    .unwrap_or(0),
3119            ));
3120            let handle_swipe: SceneHandle = handle.clone();
3121            let drag_was_active: Rc<Cell<bool>> = Rc::new(Cell::new(false));
3122            let swipe_route_committed: Rc<Cell<bool>> = Rc::new(Cell::new(false));
3123            let swipe_route_committed_drag: Rc<Cell<bool>> = Rc::clone(&swipe_route_committed);
3124            let swipe_routes_drag: Rc<[String]> = Rc::clone(&swipe_routes_rc);
3125            let _: Effect = Effect::new(move || {
3126                let raw_dx: f32 = swipe_drag_sig.get();
3127                let app_state: AppState = app_state_sig.get();
3128                let is_fullscreen: bool = fs_active_sig.get() || ctx_fs_sig.get();
3129                let overlay_count: usize = overlay_count_sig.get();
3130                let swipe_enabled: bool =
3131                    swipe_routes_enabled.is_none_or(|sig: Signal<bool>| sig.get());
3132                if has_managed_outlet
3133                    || menu_open.get_untracked()
3134                    || overlay_count > 0
3135                    || is_fullscreen
3136                    || app_state != AppState::Active
3137                    || !swipe_enabled
3138                    || swipe_routes_drag.is_empty()
3139                {
3140                    if drag_was_active.replace(false) {
3141                        handle_swipe.with_write(
3142                            |tree: &mut SceneTree| {
3143                                tree.cancel_subtree_transitions(main_area);
3144                                if let Some(item_count_31) = tree.get_node_mut(main_area) {
3145                                    item_count_31
3146                                        .get_mut_style()
3147                                        .get_mut_paint()
3148                                        .set_transform(Transform2D::default());
3149                                    tree.mark_dirty(main_area, DIRTY_PAINT);
3150                                }
3151                            },
3152                            (),
3153                        );
3154                    }
3155                    return;
3156                }
3157                if raw_dx.abs() > 1.0 {
3158                    drag_was_active.set(true);
3159                    let damped_tx: f32 = (raw_dx * 0.36).clamp(-120.0, 120.0);
3160                    handle_swipe.with_write(
3161                        |tree: &mut SceneTree| {
3162                            tree.cancel_subtree_transitions(main_area);
3163                            if let Some(item_count_32) = tree.get_node_mut(main_area) {
3164                                item_count_32
3165                                    .get_mut_style()
3166                                    .get_mut_paint()
3167                                    .set_transform(Transform2D::new(damped_tx, 0.0, 1.0, 1.0, 0.0));
3168                                tree.mark_dirty(main_area, DIRTY_PAINT);
3169                            }
3170                        },
3171                        (),
3172                    );
3173                } else if drag_was_active.replace(false) {
3174                    if swipe_route_committed_drag.replace(false) {
3175                        handle_swipe.with_write(
3176                            |tree: &mut SceneTree| {
3177                                tree.cancel_subtree_transitions(main_area);
3178                                if let Some(item_count_33) = tree.get_node_mut(main_area) {
3179                                    item_count_33
3180                                        .get_mut_style()
3181                                        .get_mut_paint()
3182                                        .set_transform(Transform2D::default());
3183                                    tree.mark_dirty(main_area, DIRTY_PAINT);
3184                                }
3185                            },
3186                            (),
3187                        );
3188                    } else {
3189                        handle_swipe.with_write(
3190                            |tree: &mut SceneTree| {
3191                                let cur_tx: f32 = tree
3192                                    .get_node(main_area)
3193                                    .map(|scene_node_secondary: &SceneNode| {
3194                                        scene_node_secondary
3195                                            .style_ref()
3196                                            .get_paint()
3197                                            .get_transform()
3198                                            .get_translate_x()
3199                                    })
3200                                    .unwrap_or(0.0);
3201                                if cur_tx.abs() > 0.5 {
3202                                    tree.start_transition(
3203                                        NodeTransition::slide_fade(
3204                                            main_area,
3205                                            Point::new(cur_tx, 0.0),
3206                                            Point::new(0.0, 0.0),
3207                                            1.0,
3208                                            1.0,
3209                                            motion_duration(MOTION_STANDARD_SECS),
3210                                            false,
3211                                        )
3212                                        .with_easing(MOTION_EASE_ENTER),
3213                                    );
3214                                }
3215                            },
3216                            (),
3217                        );
3218                    }
3219                }
3220            });
3221            let handle_swipe_reset: SceneHandle = handle.clone();
3222            let hide_state_for_gesture: Rc<Cell<ChromeScrollAutoHideState>> =
3223                Rc::clone(&scroll_hide_state);
3224            let _: Effect = Effect::new(move || {
3225                if let Some(ui_event_local) = gesture_sig.get() {
3226                    let seq: u64 = ui_event_local.get_sequence();
3227                    if seq != last_g_seq.replace(seq) {
3228                        if menu_open.get_untracked() {
3229                            if ui_event_local.get_kind() == GestureEventKind::SwipeLeft {
3230                                let _: bool = menu_open.set_if_changed(false);
3231                            }
3232                            return;
3233                        }
3234                        if EuvOverlayStack::active_count() > 0 || is_fullscreen_active() {
3235                            return;
3236                        }
3237                        let auto_hide_active: bool = auto_hide_chrome_signal
3238                            .map_or(auto_hide_enabled, |sig: Signal<bool>| sig.get_untracked());
3239                        if ui_event_local.get_kind() == GestureEventKind::SwipeDown
3240                            && auto_hide_active
3241                            && chrome_hidden.get_untracked()
3242                        {
3243                            hide_state_for_gesture.set(ChromeScrollAutoHideState::default());
3244                            let _: bool = chrome_hidden.set_if_changed(false);
3245                            return;
3246                        }
3247                        let is_mobile_now: bool = EuvShellLayoutMode::from_viewport_width(
3248                            vp_sig.get_untracked().get_width(),
3249                        )
3250                        .is_mobile();
3251                        let swipe_enabled: bool = swipe_routes_enabled
3252                            .is_none_or(|sig: Signal<bool>| sig.get_untracked());
3253                        let drawer_intent: bool = ui_event_local.get_origin().get_x() <= 72.0
3254                            || ui_event_local.get_delta().get_x() >= 96.0;
3255                        if swipe_enabled
3256                            && !swipe_routes_rc.is_empty()
3257                            && let Some(route_sig) = route_signal
3258                        {
3259                            let cur_path: String = route_sig.get_untracked();
3260                            let cur_idx: usize = swipe_routes_rc
3261                                .iter()
3262                                .position(|text_value: &String| {
3263                                    text_value.as_str() == cur_path.as_str()
3264                                })
3265                                .unwrap_or(0);
3266                            if ui_event_local.get_kind() == GestureEventKind::SwipeLeft
3267                                && cur_idx + 1 < swipe_routes_rc.len()
3268                            {
3269                                let next_path: String = swipe_routes_rc[cur_idx + 1].clone();
3270                                if route_sig.set_if_changed(next_path) {
3271                                    swipe_route_committed.set(true);
3272                                    handle_swipe_reset.with_write(
3273                                        |tree: &mut SceneTree| {
3274                                            tree.cancel_subtree_transitions(main_area);
3275                                            if let Some(item_count_34) =
3276                                                tree.get_node_mut(main_area)
3277                                            {
3278                                                item_count_34
3279                                                    .get_mut_style()
3280                                                    .get_mut_paint()
3281                                                    .set_transform(Transform2D::default());
3282                                                tree.mark_dirty(main_area, DIRTY_PAINT);
3283                                            }
3284                                        },
3285                                        (),
3286                                    );
3287                                }
3288                            } else if ui_event_local.get_kind() == GestureEventKind::SwipeRight {
3289                                if cur_idx > 0 {
3290                                    let prev_path: String = swipe_routes_rc[cur_idx - 1].clone();
3291                                    if route_sig.set_if_changed(prev_path) {
3292                                        swipe_route_committed.set(true);
3293                                        handle_swipe_reset.with_write(
3294                                            |tree: &mut SceneTree| {
3295                                                tree.cancel_subtree_transitions(main_area);
3296                                                if let Some(item_count_35) =
3297                                                    tree.get_node_mut(main_area)
3298                                                {
3299                                                    item_count_35
3300                                                        .get_mut_style()
3301                                                        .get_mut_paint()
3302                                                        .set_transform(Transform2D::default());
3303                                                    tree.mark_dirty(main_area, DIRTY_PAINT);
3304                                                }
3305                                            },
3306                                            (),
3307                                        );
3308                                    }
3309                                } else if is_mobile_now && drawer_intent {
3310                                    let _: bool = menu_open.set_if_changed(true);
3311                                }
3312                            }
3313                        } else if is_mobile_now
3314                            && ui_event_local.get_kind() == GestureEventKind::SwipeRight
3315                            && drawer_intent
3316                        {
3317                            let _: bool = menu_open.set_if_changed(true);
3318                        }
3319                    }
3320                }
3321            });
3322            let applied_shell_tokens: Rc<Cell<ThemeTokens>> = Rc::new(Cell::new(init_tok));
3323            let handle_theme: SceneHandle = handle.clone();
3324            let drawer_logo_anchor_theme: Rc<Cell<(f32, f32, f32, f32)>> =
3325                Rc::clone(&drawer_logo_anchor_cell);
3326            let _: Effect = Effect::new(move || {
3327                let next_tok: ThemeTokens = match theme_state_opt.as_ref() {
3328                    Some(timestamp_val) => timestamp_val.get_tokens().get(),
3329                    None => use_live_tokens(tokens),
3330                };
3331                let prev_tok: ThemeTokens = applied_shell_tokens.replace(next_tok);
3332                if prev_tok == next_tok {
3333                    return;
3334                }
3335                let next_p: ThemePalette = next_tok.get_palette();
3336                let next_g: ThemeGeometry = next_tok.get_geometry();
3337                let next_bw: f32 = next_g.get_border_width();
3338                let next_div_h: f32 = next_bw.max(1.0);
3339                let next_rad_md: CornerRadius = CornerRadius::all(next_g.get_radius_md());
3340                let next_topbar_fg: Color = next_p.surface(SurfaceRole::Background).get_fg();
3341                let next_primary: SurfaceColors = next_p.surface(SurfaceRole::Primary);
3342                handle_theme.with_write(
3343                    |tree: &mut SceneTree| {
3344                        if let Some(item_count_36) = tree.get_node_mut(root) {
3345                            item_count_36
3346                                .get_mut_style()
3347                                .get_mut_paint()
3348                                .set_background(Some(next_p.get_background()));
3349                            tree.mark_dirty(root, DIRTY_PAINT);
3350                        }
3351                        if let Some(item_count_37) = tree.get_node_mut(top_bar) {
3352                            item_count_37
3353                                .get_mut_style()
3354                                .get_mut_paint()
3355                                .set_background(Some(next_p.get_card()));
3356                            tree.mark_dirty(top_bar, DIRTY_PAINT);
3357                        }
3358                        if let Some(item_count_38) = tree.get_node_mut(top_bar_divider) {
3359                            let computed_style_4: &mut Style = item_count_38.get_mut_style();
3360                            computed_style_4
3361                                .get_mut_layout()
3362                                .set_height(Length::Px(next_div_h));
3363                            computed_style_4
3364                                .get_mut_paint()
3365                                .set_background(Some(next_p.get_border()));
3366                            tree.mark_dirty(top_bar_divider, DIRTY_LAYOUT | DIRTY_PAINT);
3367                        }
3368                        if let Some(item_count_39) = tree.get_node_mut(top_title_txt) {
3369                            item_count_39
3370                                .get_mut_style()
3371                                .get_mut_text()
3372                                .set_color(next_p.get_foreground());
3373                            tree.mark_dirty(top_title_txt, DIRTY_PAINT);
3374                        }
3375                        if let Some(item_count_40) = tree.get_node_mut(desktop_top_bar) {
3376                            item_count_40
3377                                .get_mut_style()
3378                                .get_mut_paint()
3379                                .set_background(Some(next_p.get_card()));
3380                            tree.mark_dirty(desktop_top_bar, DIRTY_PAINT);
3381                        }
3382                        if let Some(item_count_41) = tree.get_node_mut(desktop_top_divider) {
3383                            let computed_style_5: &mut Style = item_count_41.get_mut_style();
3384                            computed_style_5
3385                                .get_mut_layout()
3386                                .set_height(Length::Px(next_div_h));
3387                            computed_style_5
3388                                .get_mut_paint()
3389                                .set_background(Some(next_p.get_border()));
3390                            tree.mark_dirty(desktop_top_divider, DIRTY_LAYOUT | DIRTY_PAINT);
3391                        }
3392                        if let Some(item_count_42) = tree.get_node_mut(desktop_brand_txt) {
3393                            item_count_42
3394                                .get_mut_style()
3395                                .get_mut_text()
3396                                .set_color(next_p.get_foreground());
3397                            tree.mark_dirty(desktop_brand_txt, DIRTY_PAINT);
3398                        }
3399                        if let Some(item_count_43) = tree.get_node_mut(desktop_crumb_sep) {
3400                            item_count_43
3401                                .get_mut_style()
3402                                .get_mut_text()
3403                                .set_color(next_p.get_muted_foreground());
3404                            tree.mark_dirty(desktop_crumb_sep, DIRTY_PAINT);
3405                        }
3406                        if let Some(item_count_44) = tree.get_node_mut(crumb_txt) {
3407                            item_count_44
3408                                .get_mut_style()
3409                                .get_mut_text()
3410                                .set_color(next_p.get_muted_foreground());
3411                            tree.mark_dirty(crumb_txt, DIRTY_PAINT);
3412                        }
3413                        for (pill_opt, txt_opt) in [
3414                            (mobile_fps_pill, mobile_fps_txt),
3415                            (desktop_fps_pill, desktop_fps_txt),
3416                        ]
3417                        .into_iter()
3418                        {
3419                            if let Some(pill_id) = pill_opt
3420                                && let Some(item_count_45) = tree.get_node_mut(pill_id)
3421                            {
3422                                item_count_45
3423                                    .get_mut_style()
3424                                    .get_mut_paint()
3425                                    .set_background(Some(next_p.get_background()))
3426                                    .set_border(Border::new(next_bw, next_p.get_border()))
3427                                    .set_radius(next_rad_md);
3428                                tree.mark_dirty(pill_id, DIRTY_PAINT);
3429                            }
3430                            if let Some(txt_id) = txt_opt
3431                                && let Some(item_count_46) = tree.get_node_mut(txt_id)
3432                            {
3433                                item_count_46
3434                                    .get_mut_style()
3435                                    .get_mut_text()
3436                                    .set_color(next_topbar_fg);
3437                                tree.mark_dirty(txt_id, DIRTY_PAINT);
3438                            }
3439                        }
3440                        if show_menu_btn {
3441                            if let Some(item_count_47) = tree.get_node_mut(menu_btn_node) {
3442                                item_count_47
3443                                    .get_mut_style()
3444                                    .get_mut_paint()
3445                                    .set_background(Some(next_p.get_background()))
3446                                    .set_border(Border::new(next_bw, next_p.get_border()))
3447                                    .set_radius(next_rad_md);
3448                                tree.mark_dirty(menu_btn_node, DIRTY_PAINT);
3449                            }
3450                            if tree.get_node(menu_icon_node).is_some() {
3451                                tree.mark_dirty(menu_icon_node, DIRTY_PAINT);
3452                            }
3453                        }
3454                        for &badge_id in euv_brand_badges.iter() {
3455                            if let Some(item_count_48) = tree.get_node_mut(badge_id) {
3456                                item_count_48
3457                                    .get_mut_style()
3458                                    .get_mut_paint()
3459                                    .set_background(Some(next_p.get_background()))
3460                                    .set_border(Border::new(next_bw, next_p.get_border()))
3461                                    .set_radius(next_rad_md);
3462                                tree.mark_dirty(badge_id, DIRTY_PAINT);
3463                            }
3464                        }
3465                        for &(badge_id, txt_id) in initial_brand_badges.iter() {
3466                            if let Some(item_count_49) = tree.get_node_mut(badge_id) {
3467                                item_count_49
3468                                    .get_mut_style()
3469                                    .get_mut_paint()
3470                                    .set_background(Some(next_primary.get_bg()))
3471                                    .set_border(Border::new(next_bw, next_primary.get_border()))
3472                                    .set_radius(next_rad_md);
3473                                tree.mark_dirty(badge_id, DIRTY_PAINT);
3474                            }
3475                            if let Some(item_count_50) = tree.get_node_mut(txt_id) {
3476                                item_count_50
3477                                    .get_mut_style()
3478                                    .get_mut_text()
3479                                    .set_color(next_primary.get_fg());
3480                                tree.mark_dirty(txt_id, DIRTY_PAINT);
3481                            }
3482                        }
3483                        if let Some(item_count_51) = tree.get_node_mut(nav_rail) {
3484                            item_count_51
3485                                .get_mut_style()
3486                                .get_mut_paint()
3487                                .set_background(Some(next_p.get_card()));
3488                            tree.mark_dirty(nav_rail, DIRTY_PAINT);
3489                        }
3490                        if let Some(item_count_52) = tree.get_node_mut(nav_divider) {
3491                            let computed_style_6: &mut Style = item_count_52.get_mut_style();
3492                            computed_style_6
3493                                .get_mut_layout()
3494                                .set_width(Length::Px(next_div_h));
3495                            computed_style_6
3496                                .get_mut_paint()
3497                                .set_background(Some(next_p.get_border()));
3498                            tree.mark_dirty(nav_divider, DIRTY_LAYOUT | DIRTY_PAINT);
3499                        }
3500                        if let Some(item_count_53) = tree.get_node_mut(drawer_portal) {
3501                            item_count_53
3502                                .get_mut_style()
3503                                .get_mut_paint()
3504                                .set_background(Some(next_p.get_overlay()));
3505                            tree.mark_dirty(drawer_portal, DIRTY_PAINT);
3506                        }
3507                        if let Some(item_count_54) = tree.get_node_mut(drawer_panel) {
3508                            item_count_54
3509                                .get_mut_style()
3510                                .get_mut_paint()
3511                                .set_background(Some(next_p.get_card()))
3512                                .set_border(Border::new(next_bw, next_p.get_border()))
3513                                .set_shadow(Some(next_g.get_shadow_lg()));
3514                            tree.mark_dirty(drawer_panel, DIRTY_PAINT);
3515                        }
3516                        if let Some(drawer_scroll_node) = tree.get_node_mut(drawer_scroll) {
3517                            let (logo_x, logo_y, portal_l, bot_in): (f32, f32, f32, f32) =
3518                                drawer_logo_anchor_theme.get();
3519                            let d_top: f32 = (logo_y - next_bw).max(0.0);
3520                            let d_left: f32 = (logo_x - portal_l - next_bw).max(0.0);
3521                            let d_bottom: f32 =
3522                                (Self::resolve_sidebar_bottom_padding(bot_in) - next_bw).max(0.0);
3523                            drawer_scroll_node
3524                                .get_mut_style()
3525                                .get_mut_layout()
3526                                .set_padding(Edges::new(d_top, SPACE_SM, d_bottom, d_left));
3527                            let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
3528                            tree.mark_dirty(drawer_scroll, dirty_l | DIRTY_PAINT);
3529                        }
3530                        if let Some(item_count_55) = tree.get_node_mut(drawer_brand_txt) {
3531                            item_count_55
3532                                .get_mut_style()
3533                                .get_mut_text()
3534                                .set_color(next_p.get_foreground());
3535                            tree.mark_dirty(drawer_brand_txt, DIRTY_PAINT);
3536                        }
3537                        if let Some(item_count_56) = tree.get_node_mut(drawer_grabber_pill) {
3538                            item_count_56
3539                                .get_mut_style()
3540                                .get_mut_paint()
3541                                .set_background(Some(
3542                                    next_p.get_muted_foreground().with_alpha(128),
3543                                ));
3544                            tree.mark_dirty(drawer_grabber_pill, DIRTY_PAINT);
3545                        }
3546                        if has_bottom_nav && let Some(bn) = tree.get_node_mut(bottom_bar_host) {
3547                            Self::apply_dock_host_surface(
3548                                bn.get_mut_style(),
3549                                dock_frameless_theme.get(),
3550                                dock_host_pad,
3551                                next_tok,
3552                            );
3553                            tree.mark_dirty(bottom_bar_host, DIRTY_PAINT);
3554                        }
3555                        if let Some(actions_node) = top_bar_actions {
3556                            Self::mark_descendant_canvases_dirty(tree, actions_node);
3557                        }
3558                        if let Some(mob_act) = mobile_header_actions {
3559                            Self::mark_descendant_canvases_dirty(tree, mob_act);
3560                        }
3561                        if let Some(footer_id) = sidebar_footer {
3562                            remap_subtree_theme_in_place(tree, footer_id, prev_tok, next_tok);
3563                        }
3564                        if !has_managed_outlet {
3565                            remap_subtree_theme_in_place(tree, main_content, prev_tok, next_tok);
3566                        }
3567                    },
3568                    (),
3569                );
3570            });
3571            if let Some(route_sig) = route_signal {
3572                let prev_route: Rc<RefCell<String>> =
3573                    Rc::new(RefCell::new(route_sig.get_untracked()));
3574                let saved_scrolls: Rc<RefCell<HashMap<String, Point>>> =
3575                    Rc::new(RefCell::new(HashMap::new()));
3576                let handle_route_scroll: SceneHandle = handle.clone();
3577                let hooked_for_route: Rc<RefCell<Vec<NodeId>>> = Rc::clone(&hooked_scroll_nodes);
3578                let scroll_obs_for_route: ChromeScrollObserver = scroll_observer.clone();
3579                let hide_state_for_route: Rc<Cell<ChromeScrollAutoHideState>> =
3580                    Rc::clone(&scroll_hide_state);
3581                let _: Effect = Effect::new(move || {
3582                    let next_r: String = route_sig.get();
3583                    let prev_changed: Option<String> = prev_route.try_borrow_mut().ok().and_then(
3584                        |mut guard: RefMut<'_, String>| {
3585                            if *guard != next_r {
3586                                let old: String = guard.clone();
3587                                *guard = next_r.clone();
3588                                Some(old)
3589                            } else {
3590                                None
3591                            }
3592                        },
3593                    );
3594                    if let Some(old_r) = prev_changed {
3595                        let _: bool = menu_open.set_if_changed(false);
3596                        let auto_hide_active: bool = auto_hide_chrome_signal
3597                            .map_or(auto_hide_enabled, |sig: Signal<bool>| sig.get_untracked());
3598                        if auto_hide_active {
3599                            let mut next_tracker: ChromeScrollAutoHideState =
3600                                ChromeScrollAutoHideState::default();
3601                            if has_managed_outlet {
3602                                Self::attach_outlet_scroll_observers(
3603                                    &handle_route_scroll,
3604                                    main_content,
3605                                    &hooked_for_route,
3606                                    &scroll_obs_for_route,
3607                                );
3608                                let active_scroll_seed: Option<(NodeId, f32)> = handle_route_scroll
3609                                    .with_read(
3610                                        |tree: &SceneTree| {
3611                                            for kid in tree.children_iter(main_content) {
3612                                                if let Some(kn) = tree.get_node(kid)
3613                                                    && kn.get_alive()
3614                                                    && matches!(kn.get_kind(), NodeKind::ScrollView)
3615                                                    && kn.style_ref().get_layout().get_display()
3616                                                        != Display::None
3617                                                {
3618                                                    return Some((
3619                                                        kid,
3620                                                        kn.get_layout_box()
3621                                                            .get_scroll_offset()
3622                                                            .get_y(),
3623                                                    ));
3624                                                }
3625                                            }
3626                                            None
3627                                        },
3628                                        None,
3629                                    );
3630                                if let Some((active_node, seed_y)) = active_scroll_seed {
3631                                    next_tracker.reset(active_node, seed_y);
3632                                }
3633                            }
3634                            hide_state_for_route.set(next_tracker);
3635                        }
3636                        if !has_managed_outlet {
3637                            let mut restored_y: f32 = 0.0;
3638                            handle_route_scroll.with_write(
3639                                |tree: &mut SceneTree| {
3640                                    let cur_off: Point = tree
3641                                        .get_node(main_area)
3642                                        .map(|scene_node_next: &SceneNode| {
3643                                            scene_node_next.get_layout_box().get_scroll_offset()
3644                                        })
3645                                        .unwrap_or_default();
3646                                    let restore_off: Point = saved_scrolls
3647                                        .try_borrow_mut()
3648                                        .ok()
3649                                        .map(|mut map: RefMut<'_, HashMap<String, Point>>| {
3650                                            let _: Option<Point> = map.insert(old_r, cur_off);
3651                                            map.get(&next_r).copied().unwrap_or_default()
3652                                        })
3653                                        .unwrap_or_default();
3654                                    restored_y = restore_off.get_y();
3655                                    tree.set_scroll_offset(main_area, restore_off);
3656                                },
3657                                (),
3658                            );
3659                            if auto_hide_active {
3660                                let mut next_tracker: ChromeScrollAutoHideState =
3661                                    ChromeScrollAutoHideState::default();
3662                                next_tracker.reset(main_area, restored_y);
3663                                hide_state_for_route.set(next_tracker);
3664                            }
3665                        }
3666                    }
3667                });
3668            }
3669            Effect::new(move || {
3670                let is_open: bool = menu_open.get();
3671                let raw_vp_w: f32 = vp_sig.get_untracked().get_width();
3672                let is_desktop_now: bool =
3673                    EuvShellLayoutMode::from_viewport_width(raw_vp_w).is_desktop();
3674                if is_open
3675                    && (is_desktop_now || is_fullscreen_active() || ctx_fs_sig.get_untracked())
3676                {
3677                    prev_open.set(false);
3678                    let _: bool = menu_open.set_if_changed(false);
3679                    return;
3680                }
3681                let was_open: bool = prev_open.replace(is_open);
3682                if is_open == was_open {
3683                    return;
3684                }
3685                let vp_w: f32 = raw_vp_w.max(320.0);
3686                let vp_h: f32 = vp_sig.get_untracked().get_height().max(240.0);
3687                let portal_left: f32 = drawer_portal_left_cell.get();
3688                let portal_w: f32 = (vp_w - portal_left).max(120.0);
3689                let def_w: f32 = (portal_w.max(224.0) * 0.68)
3690                    .clamp(224.0, 256.0)
3691                    .min(portal_w);
3692                if is_open {
3693                    let auto_hide_active: bool = auto_hide_chrome_signal
3694                        .map_or(auto_hide_enabled, |sig: Signal<bool>| sig.get_untracked());
3695                    if auto_hide_active {
3696                        let _: bool = chrome_hidden.set_if_changed(false);
3697                    }
3698                    let _: bool = drawer_expanded.set_if_changed(false);
3699                    handle.with_write(
3700                        |tree: &mut SceneTree| {
3701                            let was_visible: bool = tree.get_node(drawer_portal).is_some_and(
3702                                |scene_node_alt: &SceneNode| {
3703                                    scene_node_alt.style_ref().get_layout().get_display()
3704                                        != Display::None
3705                                },
3706                            );
3707                            let start_opacity: f32 = if was_visible {
3708                                tree.get_node(drawer_portal)
3709                                    .map(|scene_node_inner: &SceneNode| {
3710                                        scene_node_inner
3711                                            .style_ref()
3712                                            .get_paint()
3713                                            .get_opacity()
3714                                            .clamp(0.0, 1.0)
3715                                    })
3716                                    .unwrap_or(0.0)
3717                            } else {
3718                                0.0
3719                            };
3720                            let start_tx: f32 = if was_visible {
3721                                tree.get_node(drawer_panel)
3722                                    .map(|scene_node_local: &SceneNode| {
3723                                        scene_node_local
3724                                            .style_ref()
3725                                            .get_paint()
3726                                            .get_transform()
3727                                            .get_translate_x()
3728                                            .clamp(-def_w, 0.0)
3729                                    })
3730                                    .unwrap_or(-def_w)
3731                            } else {
3732                                -def_w
3733                            };
3734                            tree.cancel_subtree_transitions(drawer_portal);
3735                            tree.cancel_subtree_transitions(drawer_panel);
3736                            if let Some(item_count_57) = tree.get_node_mut(drawer_portal) {
3737                                let computed_style_7: &mut Style = item_count_57.get_mut_style();
3738                                computed_style_7
3739                                    .get_mut_layout()
3740                                    .set_display(Display::Flex)
3741                                    .set_left(Some(portal_left))
3742                                    .set_right(Some(0.0))
3743                                    .set_width(Length::Px(portal_w))
3744                                    .set_height(Length::Px(vp_h))
3745                                    .set_overflow(Overflow::Hidden);
3746                                computed_style_7
3747                                    .get_mut_paint()
3748                                    .set_pointer_events(PointerEvents::Auto)
3749                                    .set_opacity(start_opacity)
3750                                    .set_transform(Transform2D::default());
3751                            }
3752                            let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
3753                            tree.mark_dirty(drawer_portal, dirty_l | DIRTY_PAINT);
3754                            if let Some(item_count_58) = tree.get_node_mut(drawer_panel) {
3755                                let computed_style_8: &mut Style = item_count_58.get_mut_style();
3756                                computed_style_8
3757                                    .get_mut_layout()
3758                                    .set_width(Length::Px(def_w))
3759                                    .set_height(Length::Px(vp_h));
3760                                computed_style_8
3761                                    .get_mut_paint()
3762                                    .set_opacity(1.0)
3763                                    .set_transform(Transform2D::new(start_tx, 0.0, 1.0, 1.0, 0.0));
3764                                tree.mark_dirty(drawer_panel, dirty_l | DIRTY_PAINT);
3765                            }
3766                            if let Some(item_count_59) = tree.get_node_mut(drawer_scroll) {
3767                                let (top_logo_x, top_logo_y, anchor_left, bot_in): (
3768                                    f32,
3769                                    f32,
3770                                    f32,
3771                                    f32,
3772                                ) = drawer_logo_anchor_cell.get();
3773                                let drawer_bw: f32 = live_tokens_untracked(tokens)
3774                                    .get_geometry()
3775                                    .get_border_width();
3776                                let drawer_inner_h: f32 = (vp_h - drawer_bw * 2.0).max(0.0);
3777                                let drawer_top_pad: f32 = (top_logo_y - drawer_bw).max(0.0);
3778                                let drawer_left_pad: f32 =
3779                                    (top_logo_x - anchor_left - drawer_bw).max(0.0);
3780                                let drawer_bottom_pad: f32 =
3781                                    (Self::resolve_sidebar_bottom_padding(bot_in) - drawer_bw)
3782                                        .max(0.0);
3783                                item_count_59
3784                                    .get_mut_style()
3785                                    .get_mut_layout()
3786                                    .set_height(Length::Px(drawer_inner_h))
3787                                    .set_padding(Edges::new(
3788                                        drawer_top_pad,
3789                                        SPACE_SM,
3790                                        drawer_bottom_pad,
3791                                        drawer_left_pad,
3792                                    ));
3793                                tree.mark_dirty(drawer_scroll, dirty_l | DIRTY_PAINT);
3794                            }
3795                            let cur_y: f32 = tree
3796                                .get_node(drawer_scroll)
3797                                .map(|scene_node_cur: &SceneNode| {
3798                                    scene_node_cur.get_layout_box().get_scroll_offset().get_y()
3799                                })
3800                                .unwrap_or(0.0);
3801                            tree.set_scroll_offset(drawer_scroll, Point::new(0.0, cur_y));
3802                            let mut active_sidebar_row: Option<NodeId> = None;
3803                            let mut scan_stack: Vec<NodeId> = vec![sidebar];
3804                            while let Some(scan_id) = scan_stack.pop() {
3805                                if let Some(scan_node) = tree.get_node(scan_id)
3806                                    && scan_node.get_alive()
3807                                {
3808                                    if scan_node
3809                                        .a11y_props()
3810                                        .and_then(|a11y: A11yProps| a11y.checked_state())
3811                                        == Some(true)
3812                                    {
3813                                        active_sidebar_row = Some(scan_id);
3814                                        break;
3815                                    }
3816                                    scan_stack.extend(tree.children_iter(scan_id));
3817                                }
3818                            }
3819                            if let Some(active_row_id) = active_sidebar_row {
3820                                tree.request_scroll_into_view(active_row_id);
3821                            }
3822                            drop(tree.update_focus(None));
3823                            tree.start_transition(
3824                                NodeTransition::fade(
3825                                    drawer_portal,
3826                                    start_opacity,
3827                                    1.0,
3828                                    motion_duration(MOTION_EMPHASIZED_SECS),
3829                                    false,
3830                                )
3831                                .with_easing(MOTION_EASE_ENTER),
3832                            );
3833                            tree.start_transition(
3834                                NodeTransition::slide_fade(
3835                                    drawer_panel,
3836                                    Point::new(start_tx, 0.0),
3837                                    Point::new(0.0, 0.0),
3838                                    1.0,
3839                                    1.0,
3840                                    motion_duration(MOTION_EMPHASIZED_SECS),
3841                                    false,
3842                                )
3843                                .with_easing(MOTION_EASE_ENTER),
3844                            );
3845                        },
3846                        (),
3847                    );
3848                } else {
3849                    drawer_da_close.set(false);
3850                    drawer_dm_close.set(false);
3851                    handle.with_write(
3852                        |tree: &mut SceneTree| {
3853                            let is_visible: bool = tree.get_node(drawer_portal).is_some_and(
3854                                |scene_node_slot: &SceneNode| {
3855                                    scene_node_slot.style_ref().get_layout().get_display()
3856                                        != Display::None
3857                                },
3858                            );
3859                            let cur_opacity: f32 = tree
3860                                .get_node(drawer_portal)
3861                                .map(|scene_node_2: &SceneNode| {
3862                                    scene_node_2
3863                                        .style_ref()
3864                                        .get_paint()
3865                                        .get_opacity()
3866                                        .clamp(0.0, 1.0)
3867                                })
3868                                .unwrap_or(1.0);
3869                            let (cur_tx, panel_w): (f32, f32) = tree
3870                                .get_node(drawer_panel)
3871                                .map(|scene_node_3: &SceneNode| {
3872                                    let tx: f32 = scene_node_3
3873                                        .style_ref()
3874                                        .get_paint()
3875                                        .get_transform()
3876                                        .get_translate_x();
3877                                    let layout_w: f32 =
3878                                        scene_node_3.get_layout_box().get_bounds().get_width();
3879                                    let styled_w: f32 =
3880                                        match scene_node_3.style_ref().get_layout().get_width() {
3881                                            Length::Px(px) if px > 40.0 => px,
3882                                            _ => def_w,
3883                                        };
3884                                    let span_width: f32 =
3885                                        if layout_w > 40.0 { layout_w } else { styled_w };
3886                                    (tx, span_width)
3887                                })
3888                                .unwrap_or((0.0, def_w));
3889                            tree.cancel_subtree_transitions(drawer_portal);
3890                            tree.cancel_subtree_transitions(drawer_panel);
3891                            let mut hover_stack: Vec<NodeId> = vec![drawer_portal];
3892                            while let Some(cur_id) = hover_stack.pop() {
3893                                if let Some(cur_n) = tree.get_node_mut(cur_id) {
3894                                    cur_n.get_mut_interaction().set_hovered(false);
3895                                    hover_stack.extend(tree.children_iter(cur_id));
3896                                }
3897                            }
3898                            if let Some(item_count_60) = tree.get_node_mut(drawer_portal) {
3899                                item_count_60
3900                                    .get_mut_style()
3901                                    .get_mut_paint()
3902                                    .set_pointer_events(PointerEvents::None);
3903                            }
3904                            if !is_visible {
3905                                if let Some(item_count_61) = tree.get_node_mut(drawer_portal) {
3906                                    let computed_style_9: &mut Style =
3907                                        item_count_61.get_mut_style();
3908                                    computed_style_9.get_mut_layout().set_display(Display::None);
3909                                    computed_style_9
3910                                        .get_mut_paint()
3911                                        .set_opacity(1.0)
3912                                        .set_transform(Transform2D::default());
3913                                }
3914                                if let Some(item_count_62) = tree.get_node_mut(drawer_panel) {
3915                                    item_count_62
3916                                        .get_mut_style()
3917                                        .get_mut_paint()
3918                                        .set_opacity(1.0)
3919                                        .set_transform(Transform2D::default());
3920                                }
3921                                let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
3922                                tree.mark_dirty(drawer_portal, dirty_l | DIRTY_PAINT);
3923                                return;
3924                            }
3925                            tree.mark_dirty(drawer_portal, DIRTY_PAINT);
3926                            tree.start_transition(
3927                                NodeTransition::fade(
3928                                    drawer_portal,
3929                                    cur_opacity,
3930                                    0.0,
3931                                    motion_duration(MOTION_EMPHASIZED_SECS),
3932                                    true,
3933                                )
3934                                .with_easing(MOTION_EASE_EXIT),
3935                            );
3936                            tree.start_transition(
3937                                NodeTransition::slide_fade(
3938                                    drawer_panel,
3939                                    Point::new(cur_tx, 0.0),
3940                                    Point::new(-panel_w, 0.0),
3941                                    1.0,
3942                                    1.0,
3943                                    motion_duration(MOTION_EMPHASIZED_SECS),
3944                                    false,
3945                                )
3946                                .with_easing(MOTION_EASE_EXIT),
3947                            );
3948                        },
3949                        (),
3950                    );
3951                }
3952            })
3953        });
3954        ctx.get_scene().with_write(
3955            |tree: &mut SceneTree| {
3956                let mut owned_dots: Vec<NodeId> = Vec::with_capacity(2);
3957                if let Some(dot) = mobile_fps_dot {
3958                    owned_dots.push(dot);
3959                }
3960                if let Some(dot) = desktop_fps_dot {
3961                    owned_dots.push(dot);
3962                }
3963                if !owned_dots.is_empty() {
3964                    mark_theme_owned(tree, owned_dots.as_slice());
3965                }
3966                tree.attach_scope(root, scope);
3967            },
3968            (),
3969        );
3970        root
3971    }
3972}
3973
3974/// Construction and mounting for `EuvDivider`.
3975impl EuvDivider {
3976    /// Creates a horizontal divider.
3977    ///
3978    /// # Arguments
3979    ///
3980    /// - `ThemeTokens` - Active design tokens.
3981    ///
3982    /// # Returns
3983    ///
3984    /// - `Self` - Horizontal divider.
3985    #[must_use]
3986    pub fn horizontal(tokens: ThemeTokens) -> Self {
3987        Self {
3988            vertical: false,
3989            tokens,
3990        }
3991    }
3992
3993    /// Creates a vertical divider.
3994    ///
3995    /// # Arguments
3996    ///
3997    /// - `ThemeTokens` - Active design tokens.
3998    ///
3999    /// # Returns
4000    ///
4001    /// - `Self` - Vertical divider.
4002    #[must_use]
4003    pub fn vertical(tokens: ThemeTokens) -> Self {
4004        Self {
4005            vertical: true,
4006            tokens,
4007        }
4008    }
4009}
4010
4011/// Declarative `#[component]` implementation for `EuvDivider`.
4012#[component]
4013/// Inherent implementation of [`EuvDivider`].
4014impl EuvDivider {
4015    /// Renders `EuvDivider` into the ambient framework-managed `Context`.
4016    ///
4017    /// # Arguments
4018    ///
4019    /// - `&Self` - Component descriptor reference.
4020    ///
4021    /// # Returns
4022    ///
4023    /// - `NodeId` - Mounted root scene node handle.
4024    fn render(&self) -> NodeId {
4025        let tok: ThemeTokens = live_tokens_untracked(self.get_tokens());
4026        let border_color: Color = tok.get_palette().get_border();
4027        let line_w: f32 = tok.get_geometry().get_border_width().max(1.0);
4028        let is_vert: bool = self.get_vertical();
4029        let view_style: Style = style! {
4030            Width(if is_vert { Length::Px(line_w) } else { Length::Percent(100.0) })
4031            Height(if is_vert { Length::Percent(100.0) } else { Length::Px(line_w) })
4032            Background(border_color)
4033        };
4034        view! {
4035            view {
4036                style: view_style
4037            }
4038        }
4039    }
4040}
4041
4042/// Fluent section composition helpers for `EuvPage`.
4043impl EuvPage {
4044    /// Appends a section node below the page header.
4045    ///
4046    /// # Arguments
4047    ///
4048    /// - `Self` - Source page wrapper.
4049    /// - `NodeId` - Mounted section node.
4050    ///
4051    /// # Returns
4052    ///
4053    /// - `Self` - Updated page wrapper.
4054    #[must_use]
4055    pub fn section(mut self, node: NodeId) -> Self {
4056        self.get_mut_sections().push(node);
4057        self
4058    }
4059
4060    /// Sets optional style overrides merged onto the root page container (default is full fluid width).
4061    ///
4062    /// # Arguments
4063    ///
4064    /// - `Self` - Source page wrapper.
4065    /// - `impl Into<Option<Style>>` - Style override or `None` for fluid width.
4066    ///
4067    /// # Returns
4068    ///
4069    /// - `Self` - Updated page wrapper.
4070    #[must_use]
4071    pub fn style(mut self, style: impl Into<Option<Style>>) -> Self {
4072        self.set_style(style.into());
4073        self
4074    }
4075}
4076
4077/// Declarative `#[component]` implementation for `EuvPage`.
4078#[component]
4079/// Inherent implementation of [`EuvPage`].
4080impl EuvPage {
4081    /// Renders `EuvPage` into the ambient framework-managed `Context`.
4082    ///
4083    /// # Arguments
4084    ///
4085    /// - `&Self` - Component descriptor reference.
4086    ///
4087    /// # Returns
4088    ///
4089    /// - `NodeId` - Mounted root scene node handle.
4090    fn render(&self) -> NodeId {
4091        let mut ctx: Context = current_context();
4092        let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
4093        let opt_style: Option<Style> = self.get_style();
4094        let Self {
4095            title,
4096            subtitle,
4097            sections,
4098            ..
4099        } = self;
4100        let mut page_style: Style = Style::default();
4101        page_style
4102            .get_mut_layout()
4103            .set_flex_direction(FlexDirection::Column)
4104            .set_width(Length::Percent(100.0))
4105            .set_row_gap(SPACE_LG)
4106            .set_column_gap(SPACE_LG);
4107        if let Some(overflow_mode) = opt_style {
4108            let ov_lay: LayoutStyle = overflow_mode.get_layout();
4109            let def_lay: LayoutStyle = LayoutStyle::default();
4110            let dst_lay: &mut LayoutStyle = page_style.get_mut_layout();
4111            if ov_lay.get_width() != def_lay.get_width() {
4112                dst_lay.set_width(ov_lay.get_width());
4113            }
4114            if ov_lay.get_height() != def_lay.get_height() {
4115                dst_lay.set_height(ov_lay.get_height());
4116            }
4117            if ov_lay.get_min_width() != def_lay.get_min_width() {
4118                dst_lay.set_min_width(ov_lay.get_min_width());
4119            }
4120            if ov_lay.get_max_width() != def_lay.get_max_width() {
4121                dst_lay.set_max_width(ov_lay.get_max_width());
4122            }
4123            if ov_lay.get_min_height() != def_lay.get_min_height() {
4124                dst_lay.set_min_height(ov_lay.get_min_height());
4125            }
4126            if ov_lay.get_max_height() != def_lay.get_max_height() {
4127                dst_lay.set_max_height(ov_lay.get_max_height());
4128            }
4129            if ov_lay.get_padding() != def_lay.get_padding() {
4130                dst_lay.set_padding(ov_lay.get_padding());
4131            }
4132            if ov_lay.get_margin() != def_lay.get_margin() {
4133                dst_lay.set_margin(ov_lay.get_margin());
4134            }
4135            if ov_lay.get_row_gap() != def_lay.get_row_gap() {
4136                dst_lay.set_row_gap(ov_lay.get_row_gap());
4137            }
4138            if ov_lay.get_column_gap() != def_lay.get_column_gap() {
4139                dst_lay.set_column_gap(ov_lay.get_column_gap());
4140            }
4141            let ov_paint: PaintStyle = overflow_mode.get_paint();
4142            if let Some(bg) = ov_paint.background_color() {
4143                page_style.get_mut_paint().set_background(Some(bg));
4144            }
4145            let ov_text: TextStyle = overflow_mode.get_text();
4146            if ov_text.get_text_select() != TextStyle::default().get_text_select() {
4147                page_style
4148                    .get_mut_text()
4149                    .set_text_select(Some(ov_text.get_text_select()));
4150            }
4151        }
4152        let root: NodeId = view! {
4153            column {
4154                style: page_style
4155                EuvHeader {
4156                    title: title.clone()
4157                    subtitle: subtitle.clone()
4158                    tokens: tokens
4159                }
4160            }
4161        };
4162        if !sections.is_empty() {
4163            ctx.append_many(root, sections.as_slice());
4164        }
4165        root
4166    }
4167}
4168
4169/// Fluent child composition helpers for `EuvActionRow`.
4170impl EuvActionRow {
4171    /// Appends a control node to the wrapping horizontal action bar.
4172    ///
4173    /// # Arguments
4174    ///
4175    /// - `Self` - Source action row.
4176    /// - `NodeId` - Mounted control node.
4177    ///
4178    /// # Returns
4179    ///
4180    /// - `Self` - Updated action row.
4181    #[must_use]
4182    pub fn child(mut self, node: NodeId) -> Self {
4183        self.get_mut_children().push(node);
4184        self
4185    }
4186}
4187
4188/// Declarative `#[component]` implementation for `EuvActionRow`.
4189#[component]
4190/// Inherent implementation of [`EuvActionRow`].
4191impl EuvActionRow {
4192    /// Renders `EuvActionRow` into the ambient framework-managed `Context`.
4193    ///
4194    /// # Arguments
4195    ///
4196    /// - `&Self` - Component descriptor reference.
4197    ///
4198    /// # Returns
4199    ///
4200    /// - `NodeId` - Mounted root scene node handle.
4201    fn render(&self) -> NodeId {
4202        let mut ctx: Context = current_context();
4203        let Self { children } = self;
4204        let row_style: Style = style! {
4205            Width(Length::Percent(100.0))
4206            FlexWrap::Wrap
4207            AlignItems::Center
4208            Gap(SPACE_SM)
4209        };
4210        let root: NodeId = view! {
4211            row {
4212                style: row_style
4213            }
4214        };
4215        if !children.is_empty() {
4216            ctx.get_scene().with_write(
4217                |tree: &mut SceneTree| {
4218                    for child_node_id in children.iter().copied() {
4219                        let is_switch_like: bool = tree
4220                            .get_node(child_node_id)
4221                            .map(|node_ref: &SceneNode| {
4222                                tree.child_count(child_node_id) > 1
4223                                    || matches!(
4224                                        node_ref
4225                                            .a11y_props()
4226                                            .map(|a11y: A11yProps| a11y.get_role()),
4227                                        Some(A11yRole::Switch | A11yRole::Checkbox)
4228                                    )
4229                            })
4230                            .unwrap_or(false);
4231                        if let Some(node_mut) = tree.get_node_mut(child_node_id) {
4232                            let child_layout: &mut LayoutStyle =
4233                                node_mut.get_mut_style().get_mut_layout();
4234                            let has_explicit_width: bool =
4235                                !matches!(child_layout.get_width(), Length::Auto);
4236                            if !has_explicit_width {
4237                                let _: &mut LayoutStyle = child_layout
4238                                    .set_flex_grow(1.0)
4239                                    .set_flex_shrink(1.0)
4240                                    .set_flex_basis(Length::Px(0.0));
4241                                if matches!(child_layout.get_min_width(), Length::Auto) {
4242                                    let min_width_px: f32 = if is_switch_like {
4243                                        ACTION_ROW_SWITCH_MIN_WIDTH
4244                                    } else {
4245                                        ACTION_ROW_MIN_BUTTON_WIDTH.min(ACTION_ROW_MAX_BUTTON_WIDTH)
4246                                    };
4247                                    let _: &mut LayoutStyle =
4248                                        child_layout.set_min_width(Length::Px(min_width_px));
4249                                }
4250                            }
4251                        }
4252                    }
4253                },
4254                (),
4255            );
4256            ctx.append_many(root, children.as_slice());
4257        }
4258        root
4259    }
4260}
4261
4262/// Fluent card composition helpers for `EuvStatGrid`.
4263impl EuvStatGrid {
4264    /// Appends a KPI stat card node to the responsive grid.
4265    ///
4266    /// # Arguments
4267    ///
4268    /// - `Self` - Source stat grid.
4269    /// - `NodeId` - Mounted stat card node.
4270    ///
4271    /// # Returns
4272    ///
4273    /// - `Self` - Updated stat grid.
4274    #[must_use]
4275    pub fn card(mut self, node: NodeId) -> Self {
4276        self.get_mut_cards().push(node);
4277        self
4278    }
4279}
4280
4281/// Declarative `#[component]` implementation for `EuvStatGrid`.
4282#[component]
4283/// Inherent implementation of [`EuvStatGrid`].
4284impl EuvStatGrid {
4285    /// Renders `EuvStatGrid` into the ambient framework-managed `Context`.
4286    ///
4287    /// # Arguments
4288    ///
4289    /// - `&Self` - Component descriptor reference.
4290    ///
4291    /// # Returns
4292    ///
4293    /// - `NodeId` - Mounted root scene node handle.
4294    fn render(&self) -> NodeId {
4295        let mut ctx: Context = current_context();
4296        let bp_sig: Signal<Breakpoint> = ctx.get_breakpoint();
4297        let Self { cards } = self;
4298        let max_cols: u16 = (cards.len() as u16).clamp(1, 3);
4299        let init_cols: u16 = match bp_sig.get_untracked() {
4300            Breakpoint::Compact => 1,
4301            Breakpoint::Medium => max_cols.min(2),
4302            Breakpoint::Expanded => max_cols,
4303        };
4304        let grid_style: Style = style! {
4305            GridColumns(init_cols)
4306            Width(Length::Percent(100.0))
4307            Gap(SPACE_MD)
4308        };
4309        let root: NodeId = view! {
4310            grid {
4311                style: grid_style
4312            }
4313        };
4314        if !cards.is_empty() {
4315            ctx.append_many(root, cards.as_slice());
4316        }
4317        let handle: SceneHandle = ctx.get_scene().clone();
4318        let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
4319            Effect::new(move || {
4320                let cols: u16 = match bp_sig.get() {
4321                    Breakpoint::Compact => 1,
4322                    Breakpoint::Medium => max_cols.min(2),
4323                    Breakpoint::Expanded => max_cols,
4324                };
4325                handle.with_write(
4326                    |tree: &mut SceneTree| {
4327                        let changed: bool = if let Some(item_count) = tree.get_node_mut(root) {
4328                            if item_count.style_ref().get_layout().get_grid_columns() != cols {
4329                                item_count
4330                                    .get_mut_style()
4331                                    .get_mut_layout()
4332                                    .set_grid_columns(cols);
4333                                true
4334                            } else {
4335                                false
4336                            }
4337                        } else {
4338                            false
4339                        };
4340                        if changed {
4341                            let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
4342                            tree.mark_dirty(root, dirty_l | DIRTY_PAINT);
4343                        }
4344                    },
4345                    (),
4346                );
4347            })
4348        });
4349        ctx.get_scene().with_write(
4350            |tree: &mut SceneTree| {
4351                tree.attach_scope(root, scope);
4352            },
4353            (),
4354        );
4355        root
4356    }
4357}