Skip to main content

euv_ui/component/display/
impl.rs

1use super::*;
2
3/// Tone color resolution helper for `EuvTone`.
4impl EuvTone {
5    /// Resolves `(background, foreground)` colors for this tone under `palette`.
6    ///
7    /// # Arguments
8    ///
9    /// - `&Self` - Semantic tone.
10    /// - `ThemePalette` - Active theme palette.
11    ///
12    /// # Returns
13    ///
14    /// - `(Color, Color)` - Background and foreground colors.
15    #[inline(always)]
16    #[must_use]
17    pub fn colors(&self, palette: ThemePalette) -> (Color, Color) {
18        let role: SurfaceRole = match *self {
19            Self::Neutral => SurfaceRole::Secondary,
20            Self::Primary => SurfaceRole::Primary,
21            Self::Success => SurfaceRole::Success,
22            Self::Warning => SurfaceRole::Warning,
23            Self::Destructive => SurfaceRole::Destructive,
24        };
25        let surface: SurfaceColors = palette.surface(role);
26        (surface.get_bg(), surface.get_fg())
27    }
28}
29
30/// Fluent tone builder for `EuvBadge`.
31impl EuvBadge {
32    /// Overrides the semantic tone fluently.
33    ///
34    /// # Arguments
35    ///
36    /// - `Self` - Source badge.
37    /// - `EuvTone` - Target semantic tone.
38    ///
39    /// # Returns
40    ///
41    /// - `Self` - Updated badge.
42    #[must_use]
43    pub fn tone(mut self, tone: EuvTone) -> Self {
44        self.set_tone(tone);
45        self
46    }
47}
48
49/// Declarative `#[component]` implementation for `EuvBadge`.
50#[component]
51/// Inherent implementation of [`EuvBadge`].
52impl EuvBadge {
53    /// Renders `EuvBadge` into the ambient framework-managed `Context`.
54    ///
55    /// # Arguments
56    ///
57    /// - `&Self` - Component descriptor reference.
58    ///
59    /// # Returns
60    ///
61    /// - `NodeId` - Mounted root scene node handle.
62    fn render(&self) -> NodeId {
63        let ctx: Context = current_context();
64        let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
65        let theme_palette: ThemePalette = tokens.get_palette();
66        let geometry: ThemeGeometry = tokens.get_geometry();
67        let (bg, fg): (Color, Color) = self.get_tone().colors(theme_palette);
68        let Self { label, .. } = self;
69        let mut row_st: Style = Style::default();
70        row_st
71            .get_mut_layout()
72            .set_flex_direction(FlexDirection::Row)
73            .set_align_self(AlignSelf::Start)
74            .set_height(Length::Px(24.0))
75            .set_justify_content(JustifyContent::Center)
76            .set_align_items(AlignItems::Center)
77            .set_padding(Edges::symmetric(0.0, SPACE_SM))
78            .set_overflow(Overflow::Hidden);
79        row_st
80            .get_mut_paint()
81            .set_background(Some(bg))
82            .set_border(Border::new(
83                geometry.get_border_width(),
84                theme_palette.get_border().with_alpha(72),
85            ))
86            .set_radius(CornerRadius::all(RADIUS_PILL));
87        let mut txt_st: Style = Style::default();
88        txt_st
89            .get_mut_text()
90            .set_font_size(11.0)
91            .set_weight(FontWeight::SemiBold)
92            .set_color(fg)
93            .set_align(TextAlign::Center)
94            .set_overflow(TextOverflow::Ellipsis);
95        ctx.get_scene().with_write(
96            |tree: &mut SceneTree| {
97                let root: NodeId = tree.create_view(row_st);
98                let txt_id: NodeId = tree.create_text(label.clone(), txt_st);
99                tree.append_child(root, txt_id);
100                root
101            },
102            NodeId::default(),
103        )
104    }
105}
106
107/// Declarative `#[component]` implementation for `EuvAlert`.
108#[component]
109/// Inherent implementation of [`EuvAlert`].
110impl EuvAlert {
111    /// Renders `EuvAlert` into the ambient framework-managed `Context`.
112    ///
113    /// # Arguments
114    ///
115    /// - `&Self` - Component descriptor reference.
116    ///
117    /// # Returns
118    ///
119    /// - `NodeId` - Mounted root scene node handle.
120    fn render(&self) -> NodeId {
121        let ctx: Context = current_context();
122        let tokens: ThemeTokens = live_tokens_untracked(self.get_tokens());
123        let theme_palette: ThemePalette = tokens.get_palette();
124        let geometry: ThemeGeometry = tokens.get_geometry();
125        let (accent, _): (Color, Color) = self.get_tone().colors(theme_palette);
126        let muted_surface: SurfaceColors = theme_palette.surface(SurfaceRole::Muted);
127        let border_col: Color = match self.get_tone() {
128            EuvTone::Primary | EuvTone::Neutral => theme_palette.get_border(),
129            _ => accent.with_alpha(152),
130        };
131        let Self {
132            title,
133            description,
134            style,
135            ..
136        } = self;
137        let mut col_st: Style = Style::default();
138        col_st
139            .get_mut_layout()
140            .set_flex_direction(FlexDirection::Column)
141            .set_width(Length::Percent(100.0))
142            .set_padding(Edges::all(SPACE_MD))
143            .set_row_gap(SPACE_XS)
144            .set_column_gap(SPACE_XS)
145            .set_overflow(Overflow::Hidden);
146        col_st
147            .get_mut_paint()
148            .set_background(Some(muted_surface.get_bg()))
149            .set_border(Border::new(
150                geometry.get_border_width().max(0.0),
151                border_col,
152            ))
153            .set_radius(CornerRadius::all(geometry.get_radius_md().max(0.0)));
154        col_st = col_st.with_overrides(*style);
155        let mut title_st: Style = Style::default();
156        title_st.get_mut_layout().set_width(Length::Percent(100.0));
157        title_st
158            .get_mut_text()
159            .set_font_size(14.0)
160            .set_weight(FontWeight::SemiBold)
161            .set_color(muted_surface.get_fg());
162        let mut desc_st: Style = Style::default();
163        desc_st.get_mut_layout().set_width(Length::Percent(100.0));
164        desc_st
165            .get_mut_text()
166            .set_font_size(13.0)
167            .set_color(theme_palette.get_muted_foreground());
168        ctx.get_scene().with_write(
169            |tree: &mut SceneTree| {
170                let root: NodeId = tree.create_view(col_st);
171                let title_id: NodeId = tree.create_text(title.clone(), title_st);
172                let desc_id: NodeId = tree.create_text(description.clone(), desc_st);
173                tree.append_children(root, &[title_id, desc_id]);
174                root
175            },
176            NodeId::default(),
177        )
178    }
179}
180
181/// Declarative `#[component]` implementation for `EuvProgress`.
182#[component]
183/// Inherent implementation of [`EuvProgress`].
184impl EuvProgress {
185    /// Renders `EuvProgress` into the ambient framework-managed `Context`.
186    ///
187    /// Track and fill share `RADIUS_PILL` with crisp, fringe-free end caps: `pct <= 0.001` renders track only,
188    /// `pct >= 0.999` renders fill only, and intermediate percentages paint non-overlapping clipped pill halves
189    /// while always reading live theme tokens.
190    ///
191    /// # Arguments
192    ///
193    /// - `&Self` - Component descriptor reference.
194    ///
195    /// # Returns
196    ///
197    /// - `NodeId` - Mounted root scene node handle.
198    fn render(&self) -> NodeId {
199        let base_tokens: ThemeTokens = self.get_tokens();
200        let mut track_st: Style = style! {
201            Width(Length::Percent(100.0))
202            Height(Length::Px(8.0))
203            Radius(RADIUS_PILL)
204            Overflow::Hidden
205        };
206        track_st = track_st.with_overrides(self.get_style());
207        if let Length::Px(px) = track_st.get_layout().get_height() {
208            let clamped: f32 = if px > 0.0 { px.max(4.0) } else { 8.0 };
209            let _: &mut LayoutStyle = track_st.get_mut_layout().set_height(Length::Px(clamped));
210        }
211        let frac: f32 = self.get_value().clamp(0.0, 1.0);
212        let paint_progress = move |bounds: Rect, display_list: &mut DisplayList| {
213            let theme_palette: ThemePalette = live_tokens_untracked(base_tokens).get_palette();
214            let pill: CornerRadius = CornerRadius::all(RADIUS_PILL);
215            if frac <= 0.001 {
216                display_list.push(DrawCommand::FillRoundedRect {
217                    rect: bounds,
218                    color: theme_palette.get_secondary(),
219                    radius: pill,
220                    border: Border::default(),
221                });
222                return;
223            }
224            if frac >= 0.999 {
225                display_list.push(DrawCommand::FillRoundedRect {
226                    rect: bounds,
227                    color: theme_palette.get_primary(),
228                    radius: pill,
229                    border: Border::default(),
230                });
231                return;
232            }
233            let total_w: f32 = bounds.get_width();
234            let split_w: f32 = (total_w * frac).round().clamp(0.0, total_w);
235            if split_w <= 0.0 {
236                display_list.push(DrawCommand::FillRoundedRect {
237                    rect: bounds,
238                    color: theme_palette.get_secondary(),
239                    radius: pill,
240                    border: Border::default(),
241                });
242                return;
243            }
244            if split_w >= total_w {
245                display_list.push(DrawCommand::FillRoundedRect {
246                    rect: bounds,
247                    color: theme_palette.get_primary(),
248                    radius: pill,
249                    border: Border::default(),
250                });
251                return;
252            }
253            let pos_x: f32 = bounds.get_x();
254            let pos_y: f32 = bounds.get_y();
255            let track_h: f32 = bounds.get_height();
256            display_list.push(DrawCommand::PushClip(Rect::new(
257                pos_x, pos_y, split_w, track_h,
258            )));
259            display_list.push(DrawCommand::FillRoundedRect {
260                rect: bounds,
261                color: theme_palette.get_primary(),
262                radius: pill,
263                border: Border::default(),
264            });
265            display_list.push(DrawCommand::PopClip);
266            display_list.push(DrawCommand::PushClip(Rect::new(
267                pos_x + split_w,
268                pos_y,
269                (total_w - split_w).max(0.0),
270                track_h,
271            )));
272            display_list.push(DrawCommand::FillRoundedRect {
273                rect: bounds,
274                color: theme_palette.get_secondary(),
275                radius: pill,
276                border: Border::default(),
277            });
278            display_list.push(DrawCommand::PopClip);
279        };
280        view! {
281            canvas {
282                style: track_st
283                painter: paint_progress
284            }
285        }
286    }
287}
288
289/// Window calculation, clamped scrolling, and reactive mounting for `EuvVirtualList`.
290impl EuvVirtualList {
291    /// Sets the visible scroll viewport height in logical pixels fluently.
292    ///
293    /// # Arguments
294    ///
295    /// - `Self` - Source virtual list.
296    /// - `f32` - Viewport height in logical pixels.
297    ///
298    /// # Returns
299    ///
300    /// - `Self` - Updated virtual list.
301    #[must_use]
302    pub fn viewport_height(mut self, height: f32) -> Self {
303        self.set_viewport_height(height);
304        self
305    }
306
307    /// Sets the overscan row count mounted above and below the viewport fluently.
308    ///
309    /// # Arguments
310    ///
311    /// - `Self` - Source virtual list.
312    /// - `usize` - Number of extra rows to mount per edge.
313    ///
314    /// # Returns
315    ///
316    /// - `Self` - Updated virtual list.
317    #[must_use]
318    pub fn overscan(mut self, overscan: usize) -> Self {
319        self.set_overscan(overscan);
320        self
321    }
322
323    /// Resolves effective viewport height (defaulting to `320.0` when unset).
324    ///
325    /// # Arguments
326    ///
327    /// - `&Self` - Virtual list configuration.
328    ///
329    /// # Returns
330    ///
331    /// - `f32` - Resolved viewport height in logical pixels.
332    #[must_use]
333    fn resolved_viewport_height(&self) -> f32 {
334        let height_val: f32 = self.get_viewport_height();
335        if height_val > 0.0 { height_val } else { 320.0 }
336    }
337
338    /// Returns the maximum valid scroll Y offset in logical pixels.
339    ///
340    /// # Arguments
341    ///
342    /// - `&Self` - Virtual list configuration.
343    ///
344    /// # Returns
345    ///
346    /// - `f32` - Upper scroll bound `>= 0.0`.
347    #[must_use]
348    pub fn max_scroll_y(&self) -> f32 {
349        let total_h: f32 = (self.get_total_items() as f32) * self.get_item_height().max(1.0);
350        (total_h - self.resolved_viewport_height().max(1.0)).max(0.0)
351    }
352
353    /// Advances the reactive scroll offset by `delta_y`, clamped to `[0.0, max_scroll_y()]`.
354    ///
355    /// # Arguments
356    ///
357    /// - `&Self` - Virtual list configuration.
358    /// - `f32` - Incremental vertical scroll delta in logical pixels.
359    pub fn scroll_by(&self, delta_y: f32) {
360        let max_y: f32 = self.max_scroll_y();
361        let next: f32 = (self.get_scroll_y().get_untracked() + delta_y).clamp(0.0, max_y);
362        let _: bool = self.get_scroll_y().set_if_changed(next);
363    }
364
365    /// Computes the `(start_index, end_index_exclusive)` window of rows visible in the viewport.
366    ///
367    /// # Arguments
368    ///
369    /// - `&Self` - Virtual list configuration.
370    ///
371    /// # Returns
372    ///
373    /// - `(usize, usize)` - Half-open range of indices to materialize.
374    #[must_use]
375    pub fn visible_range(&self) -> (usize, usize) {
376        let total: usize = self.get_total_items();
377        if total == 0 {
378            return (0, 0);
379        }
380        let item_h: f32 = self.get_item_height().max(1.0);
381        let view_h: f32 = self.resolved_viewport_height().max(1.0);
382        let scroll_y: f32 = self
383            .get_scroll_y()
384            .get_untracked()
385            .clamp(0.0, self.max_scroll_y());
386        let overscan: usize = if self.get_overscan() == 0 {
387            3
388        } else {
389            self.get_overscan()
390        };
391        let first_vis: usize = (scroll_y / item_h).floor() as usize;
392        let vis_count: usize = (view_h / item_h).ceil() as usize;
393        let start: usize = first_vis.saturating_sub(overscan);
394        let end: usize = (first_vis + vis_count + overscan).min(total);
395        (start, end)
396    }
397
398    /// Mounts a reactive clipped scrollable list returning a controller handle for O(1) stable-ID single-row patches and refreshes.
399    ///
400    /// # Arguments
401    ///
402    /// - `&Self` - Virtual list configuration.
403    /// - `CallbackFn` - Zero-context row builder closure taking `usize` row index and returning `NodeId`.
404    ///
405    /// # Returns
406    ///
407    /// - `EuvVirtualListHandle` - Mounted viewport root and targeted single-row update controller.
408    #[must_use]
409    pub fn mount_with_handle<CallbackFn>(&self, row_builder: CallbackFn) -> EuvVirtualListHandle
410    where
411        CallbackFn: FnMut(usize) -> NodeId + 'static,
412    {
413        let mut ctx: Context = current_context();
414        let live_tok: ThemeTokens = live_tokens_untracked(self.get_tokens());
415        let theme_palette: ThemePalette = live_tok.get_palette();
416        let geometry: ThemeGeometry = live_tok.get_geometry();
417        let scroll_sig: Signal<f32> = self.get_scroll_y();
418        let total_items: usize = self.get_total_items();
419        let overscan: usize = if self.get_overscan() == 0 {
420            3
421        } else {
422            self.get_overscan()
423        };
424        let view_h: f32 = self.resolved_viewport_height().max(1.0);
425        let builder_cell: Rc<RefCell<dyn FnMut(usize) -> NodeId + 'static>> =
426            Rc::new(RefCell::new(row_builder));
427        let builder_for_effect: Rc<RefCell<dyn FnMut(usize) -> NodeId + 'static>> =
428            Rc::clone(&builder_cell);
429        let border_w: f32 = geometry.get_border_width();
430        let inner_view_h: f32 = (view_h - border_w * 2.0).max(1.0);
431        let item_h: f32 = self.get_item_height().max(1.0);
432        let vis_count: usize = (view_h / item_h).ceil() as usize;
433        let total_h: f32 = (total_items as f32) * item_h;
434        let max_scroll: f32 = (total_h - inner_view_h).max(0.0);
435        let max_scroll_range: f32 = self.max_scroll_y();
436        let on_vlist_scroll = move |ui_event: &UiEvent| {
437            if let UiEventKind::Scroll(delta) = ui_event.get_kind() {
438                let next: f32 = (scroll_sig.get_untracked() + delta.get_y()).clamp(0.0, max_scroll);
439                let _: bool = scroll_sig.set_if_changed(next);
440            }
441        };
442        let scroll_tertiary_style: Style = style! {
443            FlexDirection::Column
444            Width(Length::Percent(100.0))
445            Height(Length::Px(view_h))
446            Background(theme_palette.get_card())
447            Border::new(border_w, theme_palette.get_border())
448            Radius(geometry.get_radius_md())
449        };
450        let container: NodeId = view! {
451            scroll {
452                style: scroll_tertiary_style
453                on_scroll: on_vlist_scroll
454            }
455        };
456        let mut rows_host_style: Style = Style::default();
457        rows_host_style
458            .get_mut_layout()
459            .set_flex_direction(FlexDirection::Column)
460            .set_width(Length::Percent(100.0));
461        let rows_host: NodeId = ctx.view(rows_host_style);
462        ctx.append(container, rows_host);
463        let init_scroll: f32 = scroll_sig.get_untracked().clamp(0.0, max_scroll);
464        ctx.set_virtual_scroll(container, init_scroll, total_h);
465        let scene_for_rows: SceneHandle = ctx.get_scene().clone();
466        let scene_for_handle: SceneHandle = scene_for_rows.clone();
467        let ctx_for_rows: Context = ctx.clone();
468        let ctx_for_handle: Context = ctx.clone();
469        let window: Rc<RefCell<VecDeque<(usize, Scope, NodeId)>>> =
470            Rc::new(RefCell::new(VecDeque::new()));
471        let window_effect: Rc<RefCell<VecDeque<(usize, Scope, NodeId)>>> = Rc::clone(&window);
472        let window_handle: Rc<RefCell<VecDeque<(usize, Scope, NodeId)>>> = Rc::clone(&window);
473        let (vlist_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
474            let window_cleanup: Rc<RefCell<VecDeque<(usize, Scope, NodeId)>>> = Rc::clone(&window);
475            on_cleanup(move || {
476                if let Ok(mut guard) = window_cleanup.try_borrow_mut() {
477                    while let Some((_, row_scope, _)) = guard.pop_front() {
478                        row_scope.dispose();
479                    }
480                }
481            });
482            let mut current_range: (usize, usize) = (0, 0);
483            let mut initialized: bool = false;
484            let mut retired_scopes: Vec<Scope> = Vec::new();
485            let mut retired_nodes: Vec<NodeId> = Vec::new();
486            let mut built_prefix: Vec<(usize, Scope, NodeId)> = Vec::new();
487            let mut built_suffix: Vec<(usize, Scope, NodeId)> = Vec::new();
488            let mut next_children: Vec<NodeId> = Vec::new();
489            Effect::new(move || {
490                let raw_scroll: f32 = scroll_sig.get();
491                let cur_scroll: f32 = raw_scroll.clamp(0.0, max_scroll);
492                let (new_start, new_end): (usize, usize) = if total_items == 0 {
493                    (0, 0)
494                } else {
495                    let clamped_for_range: f32 = raw_scroll.clamp(0.0, max_scroll_range);
496                    let first_vis: usize = (clamped_for_range / item_h).floor() as usize;
497                    let start: usize = first_vis.saturating_sub(overscan);
498                    let end: usize = (first_vis + vis_count + overscan).min(total_items);
499                    (start, end)
500                };
501                let local_scroll_y: f32 = (cur_scroll - (new_start as f32) * item_h).max(0.0);
502                if initialized && (new_start, new_end) == current_range {
503                    scene_for_rows.with_write(
504                        |tree: &mut SceneTree| {
505                            tree.set_virtual_scroll(container, cur_scroll, total_h);
506                            tree.set_scroll_offset(container, Point::new(0.0, local_scroll_y));
507                        },
508                        (),
509                    );
510                    return;
511                }
512                let (old_start, old_end): (usize, usize) = current_range;
513                let has_overlap: bool = initialized
514                    && old_start < old_end
515                    && new_start < new_end
516                    && new_start < old_end
517                    && old_start < new_end;
518                retired_scopes.clear();
519                retired_nodes.clear();
520                let (prefix_start, prefix_end, suffix_start, suffix_end): (
521                    usize,
522                    usize,
523                    usize,
524                    usize,
525                ) = if has_overlap {
526                    if let Ok(mut guard) = window_effect.try_borrow_mut() {
527                        while let Some(&(idx, _, _)) = guard.front() {
528                            if idx < new_start {
529                                if let Some((_, scope, node_id)) = guard.pop_front() {
530                                    retired_scopes.push(scope);
531                                    retired_nodes.push(node_id);
532                                }
533                            } else {
534                                break;
535                            }
536                        }
537                        while let Some(&(idx, _, _)) = guard.back() {
538                            if idx >= new_end {
539                                if let Some((_, scope, node_id)) = guard.pop_back() {
540                                    retired_scopes.push(scope);
541                                    retired_nodes.push(node_id);
542                                }
543                            } else {
544                                break;
545                            }
546                        }
547                    }
548                    let keep_start: usize = old_start.max(new_start);
549                    let keep_end: usize = old_end.min(new_end);
550                    (new_start, keep_start, keep_end, new_end)
551                } else {
552                    if let Ok(mut guard) = window_effect.try_borrow_mut() {
553                        retired_scopes.reserve(guard.len());
554                        retired_nodes.reserve(guard.len());
555                        while let Some((_, scope, node_id)) = guard.pop_front() {
556                            retired_scopes.push(scope);
557                            retired_nodes.push(node_id);
558                        }
559                    }
560                    (new_start, new_end, new_end, new_end)
561                };
562                for retired in retired_scopes.drain(..) {
563                    retired.dispose();
564                }
565                let prefix_len: usize = prefix_end.saturating_sub(prefix_start);
566                let suffix_len: usize = suffix_end.saturating_sub(suffix_start);
567                built_prefix.clear();
568                built_suffix.clear();
569                if prefix_len > 0 || suffix_len > 0 {
570                    built_prefix.reserve(prefix_len);
571                    built_suffix.reserve(suffix_len);
572                    untracked(|| {
573                        with_context(ctx_for_rows.clone(), || {
574                            if let Ok(mut build_row) = builder_for_effect.try_borrow_mut() {
575                                for idx in prefix_start..prefix_end {
576                                    let (row_scope, row_node): (Scope, NodeId) =
577                                        Scope::run(|_: Scope| build_row(idx));
578                                    built_prefix.push((idx, row_scope, row_node));
579                                }
580                                for idx in suffix_start..suffix_end {
581                                    let (row_scope, row_node): (Scope, NodeId) =
582                                        Scope::run(|_: Scope| build_row(idx));
583                                    built_suffix.push((idx, row_scope, row_node));
584                                }
585                            }
586                        });
587                    });
588                }
589                next_children.clear();
590                next_children.reserve(new_end.saturating_sub(new_start));
591                if let Ok(mut guard) = window_effect.try_borrow_mut() {
592                    for entry in built_prefix.drain(..).rev() {
593                        guard.push_front(entry);
594                    }
595                    for entry in built_suffix.drain(..) {
596                        guard.push_back(entry);
597                    }
598                    for &(_, _, node_id) in guard.iter() {
599                        next_children.push(node_id);
600                    }
601                }
602                current_range = (new_start, new_end);
603                initialized = true;
604                scene_for_rows.with_write(
605                    |tree: &mut SceneTree| {
606                        for old_node in retired_nodes.drain(..) {
607                            tree.dispose_subtree(old_node);
608                        }
609                        let _: bool =
610                            tree.set_children_detached(rows_host, next_children.as_slice());
611                        let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
612                        let dirty_c: u16 = DIRTY_CHILDREN | DIRTY_PAINT;
613                        tree.mark_dirty(rows_host, dirty_l | dirty_c);
614                        tree.set_virtual_scroll(container, cur_scroll, total_h);
615                        tree.set_scroll_offset(container, Point::new(0.0, local_scroll_y));
616                    },
617                    (),
618                );
619            })
620        });
621        ctx.get_scene().with_write(
622            |tree: &mut SceneTree| {
623                tree.attach_scope(container, vlist_scope);
624            },
625            (),
626        );
627        EuvVirtualListHandle {
628            container,
629            rows_host,
630            scene: scene_for_handle,
631            ctx: ctx_for_handle,
632            window: window_handle,
633            builder: builder_cell,
634        }
635    }
636
637    /// Mounts a reactive clipped scrollable list materializing only the visible row window as `scroll_y` changes.
638    ///
639    /// # Arguments
640    ///
641    /// - `&Self` - Virtual list configuration.
642    /// - `CallbackFn` - Zero-context row builder closure taking `usize` row index and returning `NodeId`.
643    ///
644    /// # Returns
645    ///
646    /// - `NodeId` - Mounted reactive scroll viewport handle.
647    pub fn mount_with<CallbackFn>(&self, row_builder: CallbackFn) -> NodeId
648    where
649        CallbackFn: FnMut(usize) -> NodeId + 'static,
650    {
651        self.mount_with_handle(row_builder).root()
652    }
653
654    /// Mounts a zero-allocation pooled virtual list that recycles mounted row subtrees and rebinds them in place on scroll.
655    ///
656    /// # Arguments
657    ///
658    /// - `&Self` - Virtual list configuration.
659    /// - `Init` - Factory constructing one reusable row subtree `(row_root, row_state)` per pool slot.
660    /// - `Bind` - In-place binder updating a recycled row's `row_state` for a new item index inside `SceneTree`.
661    ///
662    /// # Returns
663    ///
664    /// - `NodeId` - Mounted reactive scroll viewport handle.
665    pub fn mount_pooled<TextValue, Init, Bind>(
666        &self,
667        mut create_row: Init,
668        mut bind_row: Bind,
669    ) -> NodeId
670    where
671        TextValue: 'static,
672        Init: FnMut() -> (NodeId, TextValue) + 'static,
673        Bind: FnMut(&mut TextValue, usize, &mut SceneTree) + 'static,
674    {
675        let mut ctx: Context = current_context();
676        let live_tok: ThemeTokens = live_tokens_untracked(self.get_tokens());
677        let theme_palette: ThemePalette = live_tok.get_palette();
678        let geometry: ThemeGeometry = live_tok.get_geometry();
679        let scroll_sig: Signal<f32> = self.get_scroll_y();
680        let total_items: usize = self.get_total_items();
681        let overscan: usize = if self.get_overscan() == 0 {
682            3
683        } else {
684            self.get_overscan()
685        };
686        let view_h: f32 = self.resolved_viewport_height().max(1.0);
687        let border_w: f32 = geometry.get_border_width();
688        let inner_view_h: f32 = (view_h - border_w * 2.0).max(1.0);
689        let item_h: f32 = self.get_item_height().max(1.0);
690        let vis_count: usize = (view_h / item_h).ceil() as usize;
691        let total_h: f32 = (total_items as f32) * item_h;
692        let max_scroll: f32 = (total_h - inner_view_h).max(0.0);
693        let max_scroll_range: f32 = self.max_scroll_y();
694        let on_vlist_scroll = move |ui_event: &UiEvent| {
695            if let UiEventKind::Scroll(delta) = ui_event.get_kind() {
696                let next: f32 = (scroll_sig.get_untracked() + delta.get_y()).clamp(0.0, max_scroll);
697                let _: bool = scroll_sig.set_if_changed(next);
698            }
699        };
700        let scroll_secondary_style: Style = style! {
701            FlexDirection::Column
702            Width(Length::Percent(100.0))
703            Height(Length::Px(view_h))
704            Background(theme_palette.get_card())
705            Border::new(border_w, theme_palette.get_border())
706            Radius(geometry.get_radius_md())
707        };
708        let container: NodeId = view! {
709            scroll {
710                style: scroll_secondary_style
711                on_scroll: on_vlist_scroll
712            }
713        };
714        let mut rows_host_style: Style = Style::default();
715        rows_host_style
716            .get_mut_layout()
717            .set_flex_direction(FlexDirection::Column)
718            .set_width(Length::Percent(100.0));
719        let rows_host: NodeId = ctx.view(rows_host_style);
720        ctx.append(container, rows_host);
721        let init_scroll: f32 = scroll_sig.get_untracked().clamp(0.0, max_scroll);
722        ctx.set_virtual_scroll(container, init_scroll, total_h);
723        let _: usize = overscan;
724        let max_pool_slots: usize = vis_count.saturating_add(1).min(total_items);
725        let spare_pool_rc: Rc<RefCell<Vec<(NodeId, TextValue)>>> =
726            Rc::new(RefCell::new(Vec::with_capacity(max_pool_slots)));
727        untracked(|| {
728            with_context(ctx.clone(), || {
729                let mut pool_guard: RefMut<'_, Vec<(NodeId, TextValue)>> =
730                    spare_pool_rc.borrow_mut();
731                for _ in 0..max_pool_slots {
732                    pool_guard.push(create_row());
733                }
734            });
735        });
736        let scene_for_rows: SceneHandle = ctx.get_scene().clone();
737        let scene_for_cleanup: SceneHandle = ctx.get_scene().clone();
738        let spare_for_cleanup: Rc<RefCell<Vec<(NodeId, TextValue)>>> = Rc::clone(&spare_pool_rc);
739        let (vlist_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
740            on_cleanup(move || {
741                let detached: Vec<(NodeId, TextValue)> = take(&mut *spare_for_cleanup.borrow_mut());
742                if !detached.is_empty() {
743                    scene_for_cleanup.with_write(
744                        |tree: &mut SceneTree| {
745                            for (node_id, _) in detached.into_iter() {
746                                tree.dispose_subtree(node_id);
747                            }
748                        },
749                        (),
750                    );
751                }
752            });
753            let mut active_window: VecDeque<(usize, NodeId, TextValue)> =
754                VecDeque::with_capacity(max_pool_slots);
755            let mut next_children: Vec<NodeId> = Vec::with_capacity(max_pool_slots);
756            let mut current_range: (usize, usize) = (0, 0);
757            let mut initialized: bool = false;
758            Effect::new(move || {
759                let raw_scroll: f32 = scroll_sig.get();
760                let cur_scroll: f32 = raw_scroll.clamp(0.0, max_scroll);
761                let (new_start, new_end): (usize, usize) = if total_items == 0 {
762                    (0, 0)
763                } else {
764                    let clamped_for_range: f32 = raw_scroll.clamp(0.0, max_scroll_range);
765                    let first_vis: usize = (clamped_for_range / item_h).floor() as usize;
766                    let start: usize = first_vis.min(total_items.saturating_sub(max_pool_slots));
767                    let end: usize = start.saturating_add(max_pool_slots).min(total_items);
768                    (start, end)
769                };
770                let local_scroll_y: f32 = (cur_scroll - (new_start as f32) * item_h).max(0.0);
771                if initialized && (new_start, new_end) == current_range {
772                    scene_for_rows.with_write(
773                        |tree: &mut SceneTree| {
774                            tree.set_virtual_scroll(container, cur_scroll, total_h);
775                            tree.set_scroll_offset(container, Point::new(0.0, local_scroll_y));
776                        },
777                        (),
778                    );
779                    return;
780                }
781                let (old_start, old_end): (usize, usize) = current_range;
782                let new_len: usize = new_end.saturating_sub(new_start);
783                if initialized && new_len == active_window.len() {
784                    current_range = (new_start, new_end);
785                    scene_for_rows.with_write(
786                        |tree: &mut SceneTree| {
787                            for (entry, idx) in active_window.iter_mut().zip(new_start..new_end) {
788                                if entry.0 != idx {
789                                    entry.0 = idx;
790                                    bind_row(&mut entry.2, idx, tree);
791                                }
792                            }
793                            tree.set_virtual_scroll(container, cur_scroll, total_h);
794                            tree.set_scroll_offset(container, Point::new(0.0, local_scroll_y));
795                        },
796                        (),
797                    );
798                    return;
799                }
800                let has_overlap: bool = initialized
801                    && old_start < old_end
802                    && new_start < new_end
803                    && new_start < old_end
804                    && old_start < new_end;
805                let (prefix_start, prefix_end, suffix_start, suffix_end): (
806                    usize,
807                    usize,
808                    usize,
809                    usize,
810                ) = {
811                    let Ok(mut spare_pool) = spare_pool_rc.try_borrow_mut() else {
812                        return;
813                    };
814                    if has_overlap {
815                        while let Some(&(idx, _, _)) = active_window.front() {
816                            if idx < new_start {
817                                if let Some((_, node_id, state)) = active_window.pop_front() {
818                                    spare_pool.push((node_id, state));
819                                }
820                            } else {
821                                break;
822                            }
823                        }
824                        while let Some(&(idx, _, _)) = active_window.back() {
825                            if idx >= new_end {
826                                if let Some((_, node_id, state)) = active_window.pop_back() {
827                                    spare_pool.push((node_id, state));
828                                }
829                            } else {
830                                break;
831                            }
832                        }
833                        let keep_start: usize = old_start.max(new_start);
834                        let keep_end: usize = old_end.min(new_end);
835                        (new_start, keep_start, keep_end, new_end)
836                    } else {
837                        while let Some((_, node_id, state)) = active_window.pop_front() {
838                            spare_pool.push((node_id, state));
839                        }
840                        (new_start, new_end, new_end, new_end)
841                    }
842                };
843                current_range = (new_start, new_end);
844                initialized = true;
845                scene_for_rows.with_write(
846                    |tree: &mut SceneTree| {
847                        if let Ok(mut spare_pool) = spare_pool_rc.try_borrow_mut() {
848                            for idx in (prefix_start..prefix_end).rev() {
849                                if let Some((node_id, mut state)) = spare_pool.pop() {
850                                    bind_row(&mut state, idx, tree);
851                                    active_window.push_front((idx, node_id, state));
852                                }
853                            }
854                            for idx in suffix_start..suffix_end {
855                                if let Some((node_id, mut state)) = spare_pool.pop() {
856                                    bind_row(&mut state, idx, tree);
857                                    active_window.push_back((idx, node_id, state));
858                                }
859                            }
860                        }
861                        next_children.clear();
862                        for &(_, node_id, _) in active_window.iter() {
863                            next_children.push(node_id);
864                        }
865                        let _: bool =
866                            tree.set_children_detached(rows_host, next_children.as_slice());
867                        let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
868                        let dirty_c: u16 = DIRTY_CHILDREN | DIRTY_PAINT;
869                        tree.mark_dirty(rows_host, dirty_l | dirty_c);
870                        tree.set_virtual_scroll(container, cur_scroll, total_h);
871                        tree.set_scroll_offset(container, Point::new(0.0, local_scroll_y));
872                    },
873                    (),
874                );
875            })
876        });
877        ctx.get_scene().with_write(
878            |tree: &mut SceneTree| {
879                tree.attach_scope(container, vlist_scope);
880            },
881            (),
882        );
883        container
884    }
885}
886
887/// Stable-ID O(1) single-row lookup, surgical patching, and isolated refresh operations for `EuvVirtualListHandle`.
888impl EuvVirtualListHandle {
889    /// Returns the mounted scrollable container `NodeId`.
890    ///
891    /// # Arguments
892    ///
893    /// - `&Self` - Virtual list controller reference.
894    ///
895    /// # Returns
896    ///
897    /// - `NodeId` - Mounted container root handle.
898    #[must_use]
899    pub fn root(&self) -> NodeId {
900        let Self { container, .. } = self;
901        *container
902    }
903
904    /// Resolves the mounted `NodeId` for logical row `index` in O(1) when currently materialized in the viewport window.
905    ///
906    /// # Arguments
907    ///
908    /// - `&Self` - Virtual list controller reference.
909    /// - `usize` - Stable logical row index.
910    ///
911    /// # Returns
912    ///
913    /// - `Option<NodeId>` - Active row node handle if currently visible, or `None` when off-screen.
914    #[must_use]
915    pub fn row_node(&self, index: usize) -> Option<NodeId> {
916        let Self { window, .. } = self;
917        let guard: Ref<'_, VecDeque<(usize, Scope, NodeId)>> = window.try_borrow().ok()?;
918        let &(start_idx, _, _) = guard.front()?;
919        let slot: usize = index.checked_sub(start_idx)?;
920        let &(found_idx, _, node_id) = guard.get(slot)?;
921        if found_idx == index {
922            Some(node_id)
923        } else {
924            None
925        }
926    }
927
928    /// Mutates a single materialized row in place inside one `SceneTree` write lock without rebuilding sibling rows or invalidating `rows_host` children.
929    ///
930    /// # Arguments
931    ///
932    /// - `&Self` - Virtual list controller reference.
933    /// - `usize` - Stable logical row index to patch.
934    /// - `CallbackFn` - Mutation closure receiving `(&mut SceneTree, NodeId)` for the target row.
935    ///
936    /// # Returns
937    ///
938    /// - `bool` - `true` when `index` was materialized and patched, or `false` when off-screen.
939    pub fn patch_row<CallbackFn>(&self, index: usize, patch: CallbackFn) -> bool
940    where
941        CallbackFn: FnOnce(&mut SceneTree, NodeId),
942    {
943        let Some(target_node) = self.row_node(index) else {
944            return false;
945        };
946        let Self { scene, .. } = self;
947        scene.with_write(
948            |tree: &mut SceneTree| {
949                if tree.get_node(target_node).is_some() {
950                    patch(tree, target_node);
951                    true
952                } else {
953                    false
954                }
955            },
956            false,
957        )
958    }
959
960    /// Rebuilds and swaps only the single materialized row at logical `index` in O(1), leaving all sibling rows and their layout caches untouched.
961    ///
962    /// # Arguments
963    ///
964    /// - `&Self` - Virtual list controller reference.
965    /// - `usize` - Stable logical row index to refresh.
966    ///
967    /// # Returns
968    ///
969    /// - `bool` - `true` when `index` was visible and refreshed, or `false` when off-screen.
970    pub fn update_row(&self, index: usize) -> bool {
971        let Self {
972            rows_host,
973            scene,
974            ctx,
975            window,
976            builder,
977            ..
978        } = self;
979        let slot_opt: Option<usize> = window.try_borrow().ok().and_then(
980            |guard: Ref<'_, VecDeque<(usize, Scope, NodeId)>>| {
981                let &(start_idx, _, _) = guard.front()?;
982                let slot: usize = index.checked_sub(start_idx)?;
983                let &(found_idx, _, _) = guard.get(slot)?;
984                if found_idx == index { Some(slot) } else { None }
985            },
986        );
987        let Some(slot) = slot_opt else {
988            return false;
989        };
990        let built_opt: Option<(Scope, NodeId)> = untracked(|| {
991            with_context(ctx.clone(), || {
992                builder.try_borrow_mut().ok().map(
993                    |mut build_row: RefMut<'_, dyn FnMut(usize) -> NodeId + 'static>| {
994                        Scope::run(|_: Scope| build_row(index))
995                    },
996                )
997            })
998        });
999        let Some((new_scope, new_node)) = built_opt else {
1000            return false;
1001        };
1002        let replaced: Option<(Scope, NodeId)> = window.try_borrow_mut().ok().and_then(
1003            |mut guard: RefMut<'_, VecDeque<(usize, Scope, NodeId)>>| {
1004                let entry: &mut (usize, Scope, NodeId) = guard.get_mut(slot)?;
1005                if entry.0 != index {
1006                    return None;
1007                }
1008                let old_entry: (usize, Scope, NodeId) =
1009                    replace(entry, (index, new_scope, new_node));
1010                Some((old_entry.1, old_entry.2))
1011            },
1012        );
1013        let Some((old_scope, old_node)) = replaced else {
1014            new_scope.dispose();
1015            scene.with_write(
1016                |tree: &mut SceneTree| {
1017                    tree.dispose_subtree(new_node);
1018                },
1019                (),
1020            );
1021            return false;
1022        };
1023        old_scope.dispose();
1024        let host_id: NodeId = *rows_host;
1025        scene.with_write(
1026            |tree: &mut SceneTree| {
1027                let _: bool = tree.replace_child(host_id, old_node, new_node);
1028                tree.dispose_subtree(old_node);
1029                let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
1030                let dirty_c: u16 = DIRTY_CHILDREN | DIRTY_PAINT;
1031                tree.mark_dirty(host_id, dirty_l | dirty_c);
1032            },
1033            (),
1034        );
1035        true
1036    }
1037}
1038
1039/// Internal table grid and fullscreen modal builders for `EuvTable`.
1040impl EuvTable {
1041    /// Builds the dynamically sized unclipped table grid node tree directly inside `tree`.
1042    ///
1043    /// # Arguments
1044    ///
1045    /// - `&mut SceneTree` - Mutable retained scene tree.
1046    /// - `&[String]` - Ordered column header labels.
1047    /// - `&[Vec<String>]` - Matrix of row cell strings.
1048    /// - `&[f32]` - Precomputed per-column natural widths in logical pixels.
1049    /// - `(f32, Option<TextSelectMode>)` - Total natural width and optional text selection mode.
1050    /// - `ThemeTokens` - Active design tokens.
1051    ///
1052    /// # Returns
1053    ///
1054    /// - `NodeId` - Mounted table inner column root handle.
1055    fn mount_table_grid_in_tree(
1056        tree: &mut SceneTree,
1057        headers: &[String],
1058        rows: &[Vec<String>],
1059        col_widths: &[f32],
1060        grid_opts: (f32, Option<TextSelectMode>),
1061        tokens: ThemeTokens,
1062    ) -> NodeId {
1063        let (total_w, text_select): (f32, Option<TextSelectMode>) = grid_opts;
1064        let theme_palette: ThemePalette = tokens.get_palette();
1065        let geometry: ThemeGeometry = tokens.get_geometry();
1066        let col_count: usize = col_widths.len();
1067        let safe_total_w: f32 = total_w.max(1.0);
1068        let border_h: f32 = geometry.get_border_width().max(1.0);
1069        let mut inner_col_st: Style = Style::default();
1070        if let Some(mode) = text_select {
1071            inner_col_st = inner_col_st.text_select(mode);
1072        }
1073        inner_col_st
1074            .get_mut_layout()
1075            .set_flex_direction(FlexDirection::Column)
1076            .set_min_width(Length::Px(safe_total_w))
1077            .set_width(Length::Percent(100.0))
1078            .set_flex_shrink(0.0);
1079        let inner_col: NodeId = tree.create_view(inner_col_st);
1080        let mut head_row_st: Style = Style::default();
1081        head_row_st
1082            .get_mut_layout()
1083            .set_flex_direction(FlexDirection::Row)
1084            .set_width(Length::Percent(100.0))
1085            .set_align_items(AlignItems::Stretch)
1086            .set_overflow(Overflow::Hidden);
1087        head_row_st
1088            .get_mut_paint()
1089            .set_background(Some(theme_palette.get_muted()));
1090        let head_row: NodeId = tree.create_view(head_row_st);
1091        let mut hdr_txt_st: Style = Style::default();
1092        hdr_txt_st
1093            .get_mut_layout()
1094            .set_width(Length::Percent(100.0));
1095        hdr_txt_st
1096            .get_mut_text()
1097            .set_font_size(TABLE_HEADER_FONT_SIZE)
1098            .set_weight(FontWeight::SemiBold)
1099            .set_color(theme_palette.get_muted_foreground())
1100            .set_overflow(TextOverflow::Wrap);
1101        let mut body_txt_st: Style = Style::default();
1102        body_txt_st
1103            .get_mut_layout()
1104            .set_width(Length::Percent(100.0));
1105        body_txt_st
1106            .get_mut_text()
1107            .set_font_size(TABLE_BODY_FONT_SIZE)
1108            .set_color(theme_palette.get_foreground())
1109            .set_overflow(TextOverflow::Wrap);
1110        let mut cell_styles: Vec<Style> = Vec::with_capacity(col_count);
1111        for &cw in col_widths.iter() {
1112            let pct: f32 = (cw / safe_total_w) * 100.0;
1113            let mut computed_style: Style = Style::default();
1114            computed_style
1115                .get_mut_layout()
1116                .set_flex_direction(FlexDirection::Row)
1117                .set_width(Length::Percent(pct))
1118                .set_min_width(Length::Px(cw))
1119                .set_flex_shrink(0.0)
1120                .set_align_items(AlignItems::Center)
1121                .set_padding(Edges::symmetric(SPACE_SM, SPACE_MD))
1122                .set_overflow(Overflow::Hidden);
1123            cell_styles.push(computed_style);
1124        }
1125        let mut cell_buf: Vec<NodeId> = Vec::with_capacity(col_count);
1126        for (ci, &cell_style) in cell_styles.iter().enumerate() {
1127            let label: &str = headers.get(ci).map(String::as_str).unwrap_or("");
1128            let cell_node: NodeId = tree.create_view(cell_style);
1129            let txt_node: NodeId = tree.create_text(label.to_string(), hdr_txt_st);
1130            tree.append_child(cell_node, txt_node);
1131            cell_buf.push(cell_node);
1132        }
1133        if !cell_buf.is_empty() {
1134            tree.append_children(head_row, &cell_buf);
1135        }
1136        let mut div_st: Style = Style::default();
1137        div_st
1138            .get_mut_layout()
1139            .set_width(Length::Percent(100.0))
1140            .set_height(Length::Px(border_h));
1141        div_st
1142            .get_mut_paint()
1143            .set_background(Some(theme_palette.get_border()));
1144        let mut data_row_st: Style = Style::default();
1145        data_row_st
1146            .get_mut_layout()
1147            .set_flex_direction(FlexDirection::Row)
1148            .set_width(Length::Percent(100.0))
1149            .set_align_items(AlignItems::Stretch)
1150            .set_overflow(Overflow::Hidden);
1151        let even_bg: Color = theme_palette.get_card();
1152        let odd_bg: Color = theme_palette.get_muted().with_alpha(96);
1153        let mut all_rows: Vec<NodeId> = Vec::with_capacity(rows.len() * 2 + 1);
1154        all_rows.push(head_row);
1155        for (ri, row_cells) in rows.iter().enumerate() {
1156            let div_node: NodeId = tree.create_view(div_st);
1157            let mut row_st: Style = data_row_st;
1158            row_st
1159                .get_mut_paint()
1160                .set_background(Some(if ri % 2 == 1 { odd_bg } else { even_bg }));
1161            let row_node: NodeId = tree.create_view(row_st);
1162            cell_buf.clear();
1163            for (ci, &cell_style) in cell_styles.iter().enumerate() {
1164                let cell_str: &str = row_cells.get(ci).map(String::as_str).unwrap_or("");
1165                let cell_node: NodeId = tree.create_view(cell_style);
1166                let txt_node: NodeId = tree.create_text(cell_str.to_string(), body_txt_st);
1167                tree.append_child(cell_node, txt_node);
1168                cell_buf.push(cell_node);
1169            }
1170            if !cell_buf.is_empty() {
1171                tree.append_children(row_node, &cell_buf);
1172            }
1173            all_rows.push(div_node);
1174            all_rows.push(row_node);
1175        }
1176        tree.append_children(inner_col, &all_rows);
1177        inner_col
1178    }
1179
1180    /// Mounts the full-viewport 2D scrollable fullscreen modal card for `EuvTable` on demand.
1181    ///
1182    /// # Arguments
1183    ///
1184    /// - `&Context` - Active build context.
1185    /// - `ThemeTokens` - Fallback design tokens resolved against live ambient theme.
1186    /// - `&[String]` - Ordered column header labels.
1187    /// - `&[Vec<String>]` - Matrix of row cell strings.
1188    /// - `&[f32]` - Precomputed per-column natural widths in logical pixels.
1189    /// - `(f32, Option<TextSelectMode>, Signal<bool>)` - Tuple of `(total_w, text_select, fs_open)`.
1190    ///
1191    /// # Returns
1192    ///
1193    /// - `NodeId` - Mounted fullscreen modal card root handle.
1194    fn mount_fullscreen_modal_card(
1195        ctx: &Context,
1196        tokens: ThemeTokens,
1197        headers: &[String],
1198        rows: &[Vec<String>],
1199        col_widths: &[f32],
1200        modal_opts: (f32, Option<TextSelectMode>, Signal<bool>),
1201    ) -> NodeId {
1202        let (total_w, text_select, fs_open): (f32, Option<TextSelectMode>, Signal<bool>) =
1203            modal_opts;
1204        let live_tok: ThemeTokens = live_tokens_untracked(tokens);
1205        let live_p: ThemePalette = live_tok.get_palette();
1206        let live_g: ThemeGeometry = live_tok.get_geometry();
1207        let safe_sig: Signal<SafeAreaInsets> = ctx.get_safe_area();
1208        let vp_sig: Signal<Size> = ctx.get_viewport_size();
1209        let init_fs: FullscreenSafeLayout =
1210            resolve_fullscreen_safe_layout(vp_sig.get_untracked(), safe_sig.get_untracked());
1211        let init_body: Edges = init_fs.get_body_padding();
1212        let summary_text: String = format!(
1213            "{TABLE_HEADER_TITLE} · {} cols × {} rows",
1214            col_widths.len(),
1215            rows.len()
1216        );
1217        let grid_node: NodeId = ctx.get_scene().with_write(
1218            |tree: &mut SceneTree| {
1219                Self::mount_table_grid_in_tree(
1220                    tree,
1221                    headers,
1222                    rows,
1223                    col_widths,
1224                    (total_w, text_select),
1225                    live_tok,
1226                )
1227            },
1228            NodeId::default(),
1229        );
1230        let on_close_click = move |_: &UiEvent| {
1231            let _: bool = fs_open.set_if_changed(false);
1232        };
1233        let paint_close_icon = move |bounds: Rect, display_list: &mut DisplayList| {
1234            let cur_p: ThemePalette = live_tokens_untracked(tokens).get_palette();
1235            let close_fg: Color = cur_p.surface(SurfaceRole::Card).get_fg();
1236            draw_euv_icon(EuvIconName::Close, bounds, display_list, close_fg);
1237        };
1238        let close_btn_sz: f32 = live_g.get_control_sm();
1239        let mut top_bar_node: NodeId = NodeId::default();
1240        let mut body_scroll_node: NodeId = NodeId::default();
1241        let column_style: Style = style! {
1242            Width(Length::Percent(100.0))
1243            Height(Length::Percent(100.0))
1244            Margin(Edges::all(0.0))
1245            Padding(Edges::all(0.0))
1246            Background(live_p.get_card())
1247            Radius(0.0)
1248            Overflow::Hidden
1249            StopScrollPropagation(true)
1250            StopEventPropagation(true)
1251        };
1252        let row_style: Style = style! {
1253            Width(Length::Percent(100.0))
1254            Padding(init_fs.get_header_padding())
1255            JustifyContent::SpaceBetween
1256            AlignItems::Center
1257            Gap(SPACE_SM)
1258            Background(live_p.get_muted())
1259            Overflow::Hidden
1260            TextSelectMode::None
1261        };
1262        let text_style: Style = style! {
1263            FlexGrow(1.0)
1264            FlexShrink(1.0)
1265            MinWidth(Length::Px(0.0))
1266            FontSize(13.0)
1267            FontWeight::SemiBold
1268            TextColor(live_p.get_foreground())
1269            TextOverflow::Ellipsis
1270        };
1271        let row_secondary_style: Style = style! {
1272            Width(Length::Px(close_btn_sz))
1273            Height(Length::Px(close_btn_sz))
1274            FlexShrink(0.0)
1275            JustifyContent::Center
1276            AlignItems::Center
1277            Background(live_p.get_card())
1278            Border::new(live_g.get_border_width(), live_p.get_border())
1279            Radius(live_g.get_radius_sm())
1280            Overflow::Hidden
1281            CursorIcon::Pointer
1282        };
1283        let canvas_style: Style = style! {
1284            Width(Length::Px(14.0))
1285            Height(Length::Px(14.0))
1286        };
1287        let view_style: Style = style! {
1288            Width(Length::Percent(100.0))
1289            Height(Length::Px(live_g.get_border_width().max(1.0)))
1290            Background(live_p.get_border())
1291        };
1292        let scroll_style: Style = style! {
1293            FlexDirection::Column
1294            FlexGrow(1.0)
1295            FlexShrink(1.0)
1296            MinHeight(Length::Px(0.0))
1297            Width(Length::Percent(100.0))
1298            AlignItems::Start
1299            Padding(Edges::new(
1300                SPACE_MD,
1301                SPACE_MD + init_body.get_right(),
1302                SPACE_MD + init_body.get_bottom(),
1303                SPACE_MD + init_body.get_left()
1304            ))
1305            StopScrollPropagation(true)
1306        };
1307        let card: NodeId = view! {
1308            column {
1309                style: column_style
1310                row {
1311                    node_ref: top_bar_node
1312                    style: row_style
1313                    text {
1314                        style: text_style
1315                        { summary_text }
1316                    }
1317                    row {
1318                        style: row_secondary_style
1319                        role: A11yRole::Button
1320                        a11y_label: TABLE_BUTTON_CLOSE.to_string()
1321                        on_click: on_close_click
1322                        canvas {
1323                            style: canvas_style
1324                            painter: paint_close_icon
1325                        }
1326                    }
1327                }
1328                view {
1329                    style: view_style
1330                }
1331                scroll {
1332                    node_ref: body_scroll_node
1333                    style: scroll_style
1334                    { grid_node }
1335                }
1336            }
1337        };
1338        let handle_safe: SceneHandle = ctx.get_scene().clone();
1339        let (safe_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
1340            Effect::new(move || {
1341                let fs_lay: FullscreenSafeLayout =
1342                    resolve_fullscreen_safe_layout(vp_sig.get(), safe_sig.get());
1343                let fs_body: Edges = fs_lay.get_body_padding();
1344                handle_safe.with_write(
1345                    |tree: &mut SceneTree| {
1346                        let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
1347                        if let Some(item_count) = tree.get_node_mut(top_bar_node) {
1348                            item_count
1349                                .get_mut_style()
1350                                .get_mut_layout()
1351                                .set_padding(fs_lay.get_header_padding());
1352                            tree.mark_dirty(top_bar_node, dirty_l | DIRTY_PAINT);
1353                        }
1354                        if let Some(node_entry) = tree.get_node_mut(body_scroll_node) {
1355                            node_entry
1356                                .get_mut_style()
1357                                .get_mut_layout()
1358                                .set_padding(Edges::new(
1359                                    SPACE_MD,
1360                                    SPACE_MD + fs_body.get_right(),
1361                                    SPACE_MD + fs_body.get_bottom(),
1362                                    SPACE_MD + fs_body.get_left(),
1363                                ));
1364                            tree.mark_dirty(body_scroll_node, dirty_l | DIRTY_PAINT);
1365                        }
1366                    },
1367                    (),
1368                );
1369            })
1370        });
1371        ctx.get_scene().with_write(
1372            |tree: &mut SceneTree| {
1373                tree.attach_scope(card, safe_scope);
1374            },
1375            (),
1376        );
1377        card
1378    }
1379}
1380
1381/// Declarative `#[component]` implementation for `EuvTable`.
1382#[component]
1383/// Inherent implementation of [`EuvTable`].
1384impl EuvTable {
1385    /// Renders `EuvTable` into the ambient framework-managed `Context` with dynamic unclipped column widths, 2D scrolling, and a fullscreen modal view.
1386    ///
1387    /// # Arguments
1388    ///
1389    /// - `&Self` - Component descriptor reference.
1390    ///
1391    /// # Returns
1392    ///
1393    /// - `NodeId` - Mounted root scene node handle.
1394    fn render(&self) -> NodeId {
1395        let ctx: Context = current_context();
1396        let base_tokens: ThemeTokens = self.get_tokens();
1397        let tokens: ThemeTokens = live_tokens_untracked(base_tokens);
1398        let theme_palette: ThemePalette = tokens.get_palette();
1399        let geometry: ThemeGeometry = tokens.get_geometry();
1400        let Self {
1401            headers,
1402            rows,
1403            style,
1404            ..
1405        } = self;
1406        let table_style: Option<Style> = *style;
1407        let table_text_select: Option<TextSelectMode> = table_style
1408            .and_then(|computed_style: Style| computed_style.get_text().text_select_mode());
1409        let (col_widths, total_w): (Vec<f32>, f32) = compute_table_column_widths(
1410            headers,
1411            rows,
1412            TABLE_HEADER_FONT_SIZE,
1413            TABLE_BODY_FONT_SIZE,
1414        );
1415        let summary_text: String = format!(
1416            "{TABLE_HEADER_TITLE} · {} cols × {} rows",
1417            col_widths.len(),
1418            rows.len()
1419        );
1420        let headers_rc: Rc<[String]> = Rc::from(headers.as_slice());
1421        let rows_rc: Rc<[Vec<String>]> = Rc::from(rows.as_slice());
1422        let col_widths_rc: Rc<[f32]> = Rc::from(col_widths.as_slice());
1423        let fs_open_slot: Rc<Cell<Option<Signal<bool>>>> = Rc::new(Cell::new(None));
1424        let radius_md: CornerRadius = CornerRadius::all(geometry.get_radius_md().max(0.0));
1425        let radius_sm: CornerRadius = CornerRadius::all(geometry.get_radius_sm().max(0.0));
1426        let border_w: f32 = geometry.get_border_width().max(1.0);
1427        let ctrl_sm: f32 = geometry.get_control_sm();
1428        ctx.get_scene().with_write(
1429            |tree: &mut SceneTree| {
1430                let mut root_st: Style = Style::default();
1431                root_st
1432                    .get_mut_layout()
1433                    .set_flex_direction(FlexDirection::Column)
1434                    .set_width(Length::Percent(100.0))
1435                    .set_overflow(Overflow::Hidden);
1436                root_st
1437                    .get_mut_paint()
1438                    .set_background(Some(theme_palette.get_card()))
1439                    .set_border(Border::new(
1440                        geometry.get_border_width(),
1441                        theme_palette.get_border(),
1442                    ))
1443                    .set_radius(radius_md);
1444                root_st = root_st.with_overrides(table_style);
1445                let root: NodeId = tree.create_view(root_st);
1446                let mut toolbar_st: Style = style! {
1447                    TextSelectMode::None
1448                };
1449                toolbar_st
1450                    .get_mut_layout()
1451                    .set_flex_direction(FlexDirection::Row)
1452                    .set_width(Length::Percent(100.0))
1453                    .set_padding(Edges::symmetric(SPACE_XS, SPACE_MD))
1454                    .set_justify_content(JustifyContent::SpaceBetween)
1455                    .set_align_items(AlignItems::Center)
1456                    .set_row_gap(SPACE_SM)
1457                    .set_column_gap(SPACE_SM)
1458                    .set_overflow(Overflow::Hidden);
1459                toolbar_st
1460                    .get_mut_paint()
1461                    .set_background(Some(theme_palette.get_muted()));
1462                let toolbar_row: NodeId = tree.create_view(toolbar_st);
1463                let mut title_st: Style = Style::default();
1464                title_st
1465                    .get_mut_layout()
1466                    .set_flex_grow(1.0)
1467                    .set_flex_shrink(1.0)
1468                    .set_min_width(Length::Px(0.0));
1469                title_st
1470                    .get_mut_text()
1471                    .set_font_size(11.5)
1472                    .set_weight(FontWeight::SemiBold)
1473                    .set_color(theme_palette.get_muted_foreground())
1474                    .set_overflow(TextOverflow::Ellipsis);
1475                let title_node: NodeId = tree.create_text(summary_text, title_st);
1476                let mut fs_btn_st: Style = Style::default();
1477                fs_btn_st
1478                    .get_mut_layout()
1479                    .set_flex_direction(FlexDirection::Row)
1480                    .set_width(Length::Px(ctrl_sm))
1481                    .set_height(Length::Px(ctrl_sm))
1482                    .set_flex_shrink(0.0)
1483                    .set_justify_content(JustifyContent::Center)
1484                    .set_align_items(AlignItems::Center)
1485                    .set_overflow(Overflow::Hidden);
1486                fs_btn_st
1487                    .get_mut_paint()
1488                    .set_background(Some(theme_palette.get_card()))
1489                    .set_border(Border::new(
1490                        geometry.get_border_width(),
1491                        theme_palette.get_border(),
1492                    ))
1493                    .set_radius(radius_sm)
1494                    .set_cursor(CursorIcon::Pointer);
1495                let fs_btn: NodeId = tree.create_view(fs_btn_st);
1496                let mut icon_st: Style = Style::default();
1497                icon_st
1498                    .get_mut_layout()
1499                    .set_width(Length::Px(13.0))
1500                    .set_height(Length::Px(13.0));
1501                let paint_fs_icon: CanvasDrawCallback = Rc::new(RefCell::new(
1502                    move |bounds: Rect, display_list: &mut DisplayList| {
1503                        let cur_p: ThemePalette = live_tokens_untracked(base_tokens).get_palette();
1504                        let fg: Color = cur_p.surface(SurfaceRole::Card).get_fg();
1505                        draw_euv_icon(EuvIconName::Maximize, bounds, display_list, fg);
1506                    },
1507                ));
1508                let fs_icon: NodeId = tree.create_canvas(icon_st, paint_fs_icon);
1509                tree.append_child(fs_btn, fs_icon);
1510                tree.append_children(toolbar_row, &[title_node, fs_btn]);
1511                let mut div_st: Style = Style::default();
1512                div_st
1513                    .get_mut_layout()
1514                    .set_width(Length::Percent(100.0))
1515                    .set_height(Length::Px(border_w));
1516                div_st
1517                    .get_mut_paint()
1518                    .set_background(Some(theme_palette.get_border()));
1519                let div_node: NodeId = tree.create_view(div_st);
1520                let mut scroll_st: Style = Style::default();
1521                scroll_st
1522                    .get_mut_layout()
1523                    .set_flex_direction(FlexDirection::Column)
1524                    .set_align_items(AlignItems::Start)
1525                    .set_width(Length::Percent(100.0))
1526                    .set_max_height(Length::Px(TABLE_INLINE_MAX_HEIGHT));
1527                let scroll_node: NodeId = tree.create_scroll_view(scroll_st);
1528                let grid_node: NodeId = Self::mount_table_grid_in_tree(
1529                    tree,
1530                    headers,
1531                    rows,
1532                    &col_widths,
1533                    (total_w, table_text_select),
1534                    tokens,
1535                );
1536                tree.append_child(scroll_node, grid_node);
1537                let mut portal_st: Style = Style::default();
1538                portal_st
1539                    .get_mut_layout()
1540                    .set_display(Display::None)
1541                    .set_flex_direction(FlexDirection::Column)
1542                    .set_position(Position::Fixed)
1543                    .set_top(Some(0.0))
1544                    .set_right(Some(0.0))
1545                    .set_bottom(Some(0.0))
1546                    .set_left(Some(0.0))
1547                    .set_width(Length::Percent(100.0))
1548                    .set_height(Length::Percent(100.0))
1549                    .set_padding(Edges::all(0.0))
1550                    .set_margin(Edges::all(0.0))
1551                    .set_justify_content(JustifyContent::Start)
1552                    .set_align_items(AlignItems::Stretch)
1553                    .set_overflow(Overflow::Hidden)
1554                    .set_z_index(Z_INDEX_FULLSCREEN);
1555                portal_st
1556                    .get_mut_paint()
1557                    .set_background(Some(theme_palette.get_card()))
1558                    .set_border(Border::default())
1559                    .set_radius(CornerRadius::all(0.0))
1560                    .set_pointer_events(PointerEvents::None)
1561                    .set_stop_scroll_propagation(true)
1562                    .set_stop_event_propagation(true);
1563                let fs_portal: NodeId = tree.create_portal(portal_st);
1564                let ctx_fs: Context = ctx.clone();
1565                let headers_fs: Rc<[String]> = Rc::clone(&headers_rc);
1566                let rows_fs: Rc<[Vec<String>]> = Rc::clone(&rows_rc);
1567                let widths_fs: Rc<[f32]> = Rc::clone(&col_widths_rc);
1568                let on_open_fs: UiEventHandler = Rc::new(RefCell::new(move |_: &UiEvent| {
1569                    bind_fullscreen_context(&ctx_fs);
1570                    if let Some(sig) = fs_open_slot.get() {
1571                        if sig.get_untracked() {
1572                            let _: bool = sig.set_if_changed(false);
1573                        }
1574                        let _: bool = sig.set_if_changed(true);
1575                        return;
1576                    }
1577                    let fs_open: Signal<bool> = Signal::new(true);
1578                    fs_open_slot.set(Some(fs_open));
1579                    let handle_ov: SceneHandle = ctx_fs.get_scene().clone();
1580                    let handle_vp: SceneHandle = ctx_fs.get_scene().clone();
1581                    let prev_open: Rc<Cell<bool>> = Rc::new(Cell::new(false));
1582                    let fs_acquired: Rc<Cell<bool>> = Rc::new(Cell::new(false));
1583                    let in_enter_guard: Rc<Cell<bool>> = Rc::new(Cell::new(false));
1584                    let fs_cleanup: Rc<Cell<bool>> = Rc::clone(&fs_acquired);
1585                    let ctx_build: Context = ctx_fs.clone();
1586                    let headers_build: Rc<[String]> = Rc::clone(&headers_fs);
1587                    let rows_build: Rc<[Vec<String>]> = Rc::clone(&rows_fs);
1588                    let widths_build: Rc<[f32]> = Rc::clone(&widths_fs);
1589                    let on_fs_key: UiEventHandler =
1590                        Rc::new(RefCell::new(move |ui_event: &UiEvent| {
1591                            if matches!(
1592                                ui_event.get_kind(),
1593                                UiEventKind::KeyDown(KeyCode::Escape | KeyCode::Back, _)
1594                            ) && fs_open.get_untracked()
1595                            {
1596                                let _: bool = fs_open.set_if_changed(false);
1597                            }
1598                        }));
1599                    ctx_fs.get_scene().with_write(
1600                        |scene_tree: &mut SceneTree| {
1601                            if let Some(node) = scene_tree.get_node_mut(fs_portal) {
1602                                node.get_mut_handlers().set_on_key_down(Some(on_fs_key));
1603                            }
1604                        },
1605                        (),
1606                    );
1607                    let (ov_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
1608                        on_cleanup(move || {
1609                            if fs_cleanup.replace(false) {
1610                                exit_fullscreen();
1611                            }
1612                        });
1613                        let _: Effect = EuvOverlayStack::bind_signal(
1614                            fs_open,
1615                            TABLE_FULLSCREEN_OVERLAY_NAME,
1616                            Z_INDEX_FULLSCREEN,
1617                        );
1618                        let vp_sig: Signal<Size> = ctx_build.get_viewport_size();
1619                        let _: Effect = Effect::new(move || {
1620                            let box_size: Size = vp_sig.get();
1621                            if !fs_open.get() {
1622                                return;
1623                            }
1624                            let vw: f32 = box_size.get_width().max(1.0);
1625                            let vh: f32 = box_size.get_height().max(1.0);
1626                            handle_vp.with_write(
1627                                |tree_ref: &mut SceneTree| {
1628                                    if let Some(item_count) = tree_ref.get_node_mut(fs_portal) {
1629                                        item_count
1630                                            .get_mut_style()
1631                                            .get_mut_layout()
1632                                            .set_width(Length::Px(vw))
1633                                            .set_height(Length::Px(vh));
1634                                        let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
1635                                        tree_ref.mark_dirty(fs_portal, dirty_l | DIRTY_PAINT);
1636                                        notify_frame_needed();
1637                                    }
1638                                },
1639                                (),
1640                            );
1641                        });
1642                        let global_fs_sig: Signal<bool> = use_fullscreen_active();
1643                        let ctx_fs_sig: Signal<bool> = ctx_build.immersive_fullscreen_signal();
1644                        let saw_global_fs: Rc<Cell<bool>> = Rc::new(Cell::new(false));
1645                        let saw_ctx_fs: Rc<Cell<bool>> = Rc::new(Cell::new(false));
1646                        let saw_global_reset: Rc<Cell<bool>> = Rc::clone(&saw_global_fs);
1647                        let saw_ctx_reset: Rc<Cell<bool>> = Rc::clone(&saw_ctx_fs);
1648                        let fs_acquired_sync: Rc<Cell<bool>> = Rc::clone(&fs_acquired);
1649                        let enter_guard_sync: Rc<Cell<bool>> = Rc::clone(&in_enter_guard);
1650                        let _: Effect = Effect::new(move || {
1651                            let g_active: bool = global_fs_sig.get();
1652                            let c_active: bool = ctx_fs_sig.get();
1653                            if enter_guard_sync.get() {
1654                                if g_active {
1655                                    saw_global_fs.set(true);
1656                                }
1657                                if c_active {
1658                                    saw_ctx_fs.set(true);
1659                                }
1660                                return;
1661                            }
1662                            if !fs_acquired_sync.get() {
1663                                saw_global_fs.set(false);
1664                                saw_ctx_fs.set(false);
1665                                return;
1666                            }
1667                            if g_active {
1668                                saw_global_fs.set(true);
1669                            }
1670                            if c_active {
1671                                saw_ctx_fs.set(true);
1672                            }
1673                            let external_exit: bool = (saw_global_fs.get() && !g_active)
1674                                || (saw_ctx_fs.get() && !c_active);
1675                            if external_exit {
1676                                let _: bool = fs_open.set_if_changed(false);
1677                            }
1678                        });
1679                        Effect::new(move || {
1680                            let is_open: bool = fs_open.get();
1681                            if is_open == prev_open.replace(is_open) {
1682                                return;
1683                            }
1684                            if is_open {
1685                                in_enter_guard.set(true);
1686                                saw_global_reset.set(false);
1687                                saw_ctx_reset.set(false);
1688                                let live_bg: Color =
1689                                    live_tokens_untracked(base_tokens).get_palette().get_card();
1690                                let vp_now: Size = vp_sig.get_untracked();
1691                                let vw: f32 = vp_now.get_width().max(1.0);
1692                                let vh: f32 = vp_now.get_height().max(1.0);
1693                                let modal_card: NodeId = with_context(ctx_build.clone(), || {
1694                                    Self::mount_fullscreen_modal_card(
1695                                        &ctx_build,
1696                                        base_tokens,
1697                                        &headers_build,
1698                                        &rows_build,
1699                                        &widths_build,
1700                                        (total_w, table_text_select, fs_open),
1701                                    )
1702                                });
1703                                let portal_shown: bool = modal_card != NodeId::default()
1704                                    && handle_ov.with_write(
1705                                        |blend_factor: &mut SceneTree| {
1706                                            if blend_factor.get_node(fs_portal).is_none()
1707                                                || blend_factor.get_node(modal_card).is_none()
1708                                            {
1709                                                return false;
1710                                            }
1711                                            blend_factor.cancel_subtree_transitions(fs_portal);
1712                                            blend_factor
1713                                                .replace_children(fs_portal, vec![modal_card]);
1714                                            if let Some(node_entry) =
1715                                                blend_factor.get_node_mut(fs_portal)
1716                                            {
1717                                                let element_style: &mut Style =
1718                                                    node_entry.get_mut_style();
1719                                                element_style
1720                                                    .get_mut_layout()
1721                                                    .set_display(Display::Flex)
1722                                                    .set_width(Length::Px(vw))
1723                                                    .set_height(Length::Px(vh));
1724                                                element_style
1725                                                    .get_mut_paint()
1726                                                    .set_background(Some(live_bg))
1727                                                    .set_pointer_events(PointerEvents::Auto)
1728                                                    .set_opacity(1.0)
1729                                                    .set_transform(Transform2D::default());
1730                                            }
1731                                            let _: Vec<(UiEventHandler, UiEvent)> =
1732                                                blend_factor.update_focus(Some(fs_portal));
1733                                            let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
1734                                            blend_factor
1735                                                .mark_dirty(fs_portal, dirty_l | DIRTY_PAINT);
1736                                            notify_frame_needed();
1737                                            true
1738                                        },
1739                                        false,
1740                                    );
1741                                let entered: bool = portal_shown
1742                                    && (fs_acquired.get()
1743                                        || enter_fullscreen_for_portal(&ctx_build, fs_portal));
1744                                if entered {
1745                                    fs_acquired.set(true);
1746                                } else {
1747                                    handle_ov.dismiss_portal_immediate(fs_portal);
1748                                    if fs_acquired.replace(false) {
1749                                        exit_fullscreen();
1750                                    }
1751                                    prev_open.set(false);
1752                                    let _: bool = fs_open.set_if_changed(false);
1753                                }
1754                                in_enter_guard.set(false);
1755                                notify_frame_needed();
1756                            } else {
1757                                in_enter_guard.set(false);
1758                                if fs_acquired.replace(false) {
1759                                    exit_fullscreen();
1760                                }
1761                                handle_ov.dismiss_portal_immediate(fs_portal);
1762                            }
1763                        })
1764                    });
1765                    ctx_fs.get_scene().with_write(
1766                        |time_step: &mut SceneTree| {
1767                            time_step.attach_scope(root, ov_scope);
1768                        },
1769                        (),
1770                    );
1771                }));
1772                if let Some(node) = tree.get_node_mut(fs_btn) {
1773                    node.get_mut_handlers().set_on_click(Some(on_open_fs));
1774                    node.get_mut_interaction().set_focusable(true);
1775                    *node.get_mut_a11y() = Some(A11yProps::new(
1776                        A11yRole::Button,
1777                        TABLE_BUTTON_FULLSCREEN.to_string(),
1778                    ));
1779                }
1780                tree.append_children(root, &[toolbar_row, div_node, scroll_node, fs_portal]);
1781                root
1782            },
1783            NodeId::default(),
1784        )
1785    }
1786}