1use std::{ops::Range, time::Duration};
2
3use editor::{EditorSettings, ShowScrollbar, scroll::ScrollbarAutoHide};
4use gpui::{
5 AppContext, Axis, Context, Entity, FocusHandle, FontWeight, Length,
6 ListHorizontalSizingBehavior, ListSizingBehavior, MouseButton, Stateful, Task,
7 UniformListScrollHandle, WeakEntity, uniform_list,
8};
9use settings::Settings as _;
10use ui::{
11 ActiveTheme as _, AnyElement, App, Button, ButtonCommon as _, ButtonStyle, Color, Component,
12 ComponentScope, Div, ElementId, FixedWidth as _, FluentBuilder as _, Indicator,
13 InteractiveElement as _, IntoElement, ParentElement, Pixels, RegisterComponent, RenderOnce,
14 Scrollbar, ScrollbarState, StatefulInteractiveElement as _, Styled, StyledExt as _,
15 StyledTypography, Window, div, example_group_with_title, h_flex, px, single_example, v_flex,
16};
17
18struct UniformListData<const COLS: usize> {
19 render_item_fn: Box<dyn Fn(Range<usize>, &mut Window, &mut App) -> Vec<[AnyElement; COLS]>>,
20 element_id: ElementId,
21 row_count: usize,
22}
23
24enum TableContents<const COLS: usize> {
25 Vec(Vec<[AnyElement; COLS]>),
26 UniformList(UniformListData<COLS>),
27}
28
29impl<const COLS: usize> TableContents<COLS> {
30 fn rows_mut(&mut self) -> Option<&mut Vec<[AnyElement; COLS]>> {
31 match self {
32 TableContents::Vec(rows) => Some(rows),
33 TableContents::UniformList(_) => None,
34 }
35 }
36
37 fn len(&self) -> usize {
38 match self {
39 TableContents::Vec(rows) => rows.len(),
40 TableContents::UniformList(data) => data.row_count,
41 }
42 }
43}
44
45pub struct TableInteractionState {
46 pub focus_handle: FocusHandle,
47 pub scroll_handle: UniformListScrollHandle,
48 pub horizontal_scrollbar: ScrollbarProperties,
49 pub vertical_scrollbar: ScrollbarProperties,
50}
51
52impl TableInteractionState {
53 pub fn new(window: &mut Window, cx: &mut App) -> Entity<Self> {
54 cx.new(|cx| {
55 let focus_handle = cx.focus_handle();
56
57 cx.on_focus_out(&focus_handle, window, |this: &mut Self, _, window, cx| {
58 this.hide_scrollbars(window, cx);
59 })
60 .detach();
61
62 let scroll_handle = UniformListScrollHandle::new();
63 let vertical_scrollbar = ScrollbarProperties {
64 axis: Axis::Vertical,
65 state: ScrollbarState::new(scroll_handle.clone()).parent_entity(&cx.entity()),
66 show_scrollbar: false,
67 show_track: false,
68 auto_hide: false,
69 hide_task: None,
70 };
71
72 let horizontal_scrollbar = ScrollbarProperties {
73 axis: Axis::Horizontal,
74 state: ScrollbarState::new(scroll_handle.clone()).parent_entity(&cx.entity()),
75 show_scrollbar: false,
76 show_track: false,
77 auto_hide: false,
78 hide_task: None,
79 };
80
81 let mut this = Self {
82 focus_handle,
83 scroll_handle,
84 horizontal_scrollbar,
85 vertical_scrollbar,
86 };
87
88 this.update_scrollbar_visibility(cx);
89 this
90 })
91 }
92
93 fn update_scrollbar_visibility(&mut self, cx: &mut Context<Self>) {
94 let show_setting = EditorSettings::get_global(cx).scrollbar.show;
95
96 let scroll_handle = self.scroll_handle.0.borrow();
97
98 let autohide = |show: ShowScrollbar, cx: &mut Context<Self>| match show {
99 ShowScrollbar::Auto => true,
100 ShowScrollbar::System => cx
101 .try_global::<ScrollbarAutoHide>()
102 .map_or_else(|| cx.should_auto_hide_scrollbars(), |autohide| autohide.0),
103 ShowScrollbar::Always => false,
104 ShowScrollbar::Never => false,
105 };
106
107 let longest_item_width = scroll_handle.last_item_size.and_then(|size| {
108 (size.contents.width > size.item.width).then_some(size.contents.width)
109 });
110
111 // is there an item long enough that we should show a horizontal scrollbar?
112 let item_wider_than_container = if let Some(longest_item_width) = longest_item_width {
113 longest_item_width > px(scroll_handle.base_handle.bounds().size.width.0)
114 } else {
115 true
116 };
117
118 let show_scrollbar = match show_setting {
119 ShowScrollbar::Auto | ShowScrollbar::System | ShowScrollbar::Always => true,
120 ShowScrollbar::Never => false,
121 };
122 let show_vertical = show_scrollbar;
123
124 let show_horizontal = item_wider_than_container && show_scrollbar;
125
126 let show_horizontal_track =
127 show_horizontal && matches!(show_setting, ShowScrollbar::Always);
128
129 // TODO: we probably should hide the scroll track when the list doesn't need to scroll
130 let show_vertical_track = show_vertical && matches!(show_setting, ShowScrollbar::Always);
131
132 self.vertical_scrollbar = ScrollbarProperties {
133 axis: self.vertical_scrollbar.axis,
134 state: self.vertical_scrollbar.state.clone(),
135 show_scrollbar: show_vertical,
136 show_track: show_vertical_track,
137 auto_hide: autohide(show_setting, cx),
138 hide_task: None,
139 };
140
141 self.horizontal_scrollbar = ScrollbarProperties {
142 axis: self.horizontal_scrollbar.axis,
143 state: self.horizontal_scrollbar.state.clone(),
144 show_scrollbar: show_horizontal,
145 show_track: show_horizontal_track,
146 auto_hide: autohide(show_setting, cx),
147 hide_task: None,
148 };
149
150 cx.notify();
151 }
152
153 fn hide_scrollbars(&mut self, window: &mut Window, cx: &mut Context<Self>) {
154 self.horizontal_scrollbar.hide(window, cx);
155 self.vertical_scrollbar.hide(window, cx);
156 }
157
158 // fn listener(this: Entity<Self>, fn: F) ->
159
160 pub fn listener<E: ?Sized>(
161 this: &Entity<Self>,
162 f: impl Fn(&mut Self, &E, &mut Window, &mut Context<Self>) + 'static,
163 ) -> impl Fn(&E, &mut Window, &mut App) + 'static {
164 let view = this.downgrade();
165 move |e: &E, window: &mut Window, cx: &mut App| {
166 view.update(cx, |view, cx| f(view, e, window, cx)).ok();
167 }
168 }
169
170 fn render_vertical_scrollbar_track(
171 this: &Entity<Self>,
172 parent: Div,
173 scroll_track_size: Pixels,
174 cx: &mut App,
175 ) -> Div {
176 if !this.read(cx).vertical_scrollbar.show_track {
177 return parent;
178 }
179 let child = v_flex()
180 .h_full()
181 .flex_none()
182 .w(scroll_track_size)
183 .bg(cx.theme().colors().background)
184 .child(
185 div()
186 .size_full()
187 .flex_1()
188 .border_l_1()
189 .border_color(cx.theme().colors().border),
190 );
191 parent.child(child)
192 }
193
194 fn render_vertical_scrollbar(this: &Entity<Self>, parent: Div, cx: &mut App) -> Div {
195 if !this.read(cx).vertical_scrollbar.show_scrollbar {
196 return parent;
197 }
198 let child = div()
199 .id("keymap-editor-vertical-scroll")
200 .occlude()
201 .flex_none()
202 .h_full()
203 .cursor_default()
204 .absolute()
205 .right_0()
206 .top_0()
207 .bottom_0()
208 .w(px(12.))
209 .on_mouse_move(Self::listener(this, |_, _, _, cx| {
210 cx.notify();
211 cx.stop_propagation()
212 }))
213 .on_hover(|_, _, cx| {
214 cx.stop_propagation();
215 })
216 .on_mouse_up(
217 MouseButton::Left,
218 Self::listener(this, |this, _, window, cx| {
219 if !this.vertical_scrollbar.state.is_dragging()
220 && !this.focus_handle.contains_focused(window, cx)
221 {
222 this.vertical_scrollbar.hide(window, cx);
223 cx.notify();
224 }
225
226 cx.stop_propagation();
227 }),
228 )
229 .on_any_mouse_down(|_, _, cx| {
230 cx.stop_propagation();
231 })
232 .on_scroll_wheel(Self::listener(&this, |_, _, _, cx| {
233 cx.notify();
234 }))
235 .children(Scrollbar::vertical(
236 this.read(cx).vertical_scrollbar.state.clone(),
237 ));
238 parent.child(child)
239 }
240
241 /// Renders the horizontal scrollbar.
242 ///
243 /// The right offset is used to determine how far to the right the
244 /// scrollbar should extend to, useful for ensuring it doesn't collide
245 /// with the vertical scrollbar when visible.
246 fn render_horizontal_scrollbar(
247 this: &Entity<Self>,
248 parent: Stateful<Div>,
249 right_offset: Pixels,
250 cx: &mut App,
251 ) -> Stateful<Div> {
252 if !this.read(cx).horizontal_scrollbar.show_scrollbar {
253 return parent;
254 }
255 let child = div()
256 .id("keymap-editor-horizontal-scroll")
257 .occlude()
258 .flex_none()
259 .w_full()
260 .cursor_default()
261 .absolute()
262 .bottom_neg_px()
263 .left_0()
264 .right_0()
265 .pr(right_offset)
266 .on_mouse_move(Self::listener(this, |_, _, _, cx| {
267 cx.notify();
268 cx.stop_propagation()
269 }))
270 .on_hover(|_, _, cx| {
271 cx.stop_propagation();
272 })
273 .on_any_mouse_down(|_, _, cx| {
274 cx.stop_propagation();
275 })
276 .on_mouse_up(
277 MouseButton::Left,
278 Self::listener(this, |this, _, window, cx| {
279 if !this.horizontal_scrollbar.state.is_dragging()
280 && !this.focus_handle.contains_focused(window, cx)
281 {
282 this.horizontal_scrollbar.hide(window, cx);
283 cx.notify();
284 }
285
286 cx.stop_propagation();
287 }),
288 )
289 .on_scroll_wheel(Self::listener(this, |_, _, _, cx| {
290 cx.notify();
291 }))
292 .children(Scrollbar::horizontal(
293 // percentage as f32..end_offset as f32,
294 this.read(cx).horizontal_scrollbar.state.clone(),
295 ));
296 parent.child(child)
297 }
298
299 fn render_horizantal_scrollbar_track(
300 this: &Entity<Self>,
301 parent: Stateful<Div>,
302 scroll_track_size: Pixels,
303 cx: &mut App,
304 ) -> Stateful<Div> {
305 if !this.read(cx).horizontal_scrollbar.show_track {
306 return parent;
307 }
308 let child = h_flex()
309 .w_full()
310 .h(scroll_track_size)
311 .flex_none()
312 .relative()
313 .child(
314 div()
315 .w_full()
316 .flex_1()
317 // for some reason the horizontal scrollbar is 1px
318 // taller than the vertical scrollbar??
319 .h(scroll_track_size - px(1.))
320 .bg(cx.theme().colors().background)
321 .border_t_1()
322 .border_color(cx.theme().colors().border),
323 )
324 .when(this.read(cx).vertical_scrollbar.show_track, |parent| {
325 parent
326 .child(
327 div()
328 .flex_none()
329 // -1px prevents a missing pixel between the two container borders
330 .w(scroll_track_size - px(1.))
331 .h_full(),
332 )
333 .child(
334 // HACK: Fill the missing 1px 🥲
335 div()
336 .absolute()
337 .right(scroll_track_size - px(1.))
338 .bottom(scroll_track_size - px(1.))
339 .size_px()
340 .bg(cx.theme().colors().border),
341 )
342 });
343
344 parent.child(child)
345 }
346}
347
348/// A table component
349#[derive(RegisterComponent, IntoElement)]
350pub struct Table<const COLS: usize = 3> {
351 striped: bool,
352 width: Length,
353 headers: Option<[AnyElement; COLS]>,
354 rows: TableContents<COLS>,
355 interaction_state: Option<WeakEntity<TableInteractionState>>,
356 selected_item_index: Option<usize>,
357 column_widths: Option<[Length; COLS]>,
358}
359
360impl<const COLS: usize> Table<COLS> {
361 /// number of headers provided.
362 pub fn new() -> Self {
363 Table {
364 striped: false,
365 width: Length::Auto,
366 headers: None,
367 rows: TableContents::Vec(Vec::new()),
368 interaction_state: None,
369 selected_item_index: None,
370 column_widths: None,
371 }
372 }
373
374 /// Enables uniform list rendering.
375 /// The provided function will be passed directly to the `uniform_list` element.
376 /// Therefore, if this method is called, any calls to [`Table::row`] before or after
377 /// this method is called will be ignored.
378 pub fn uniform_list(
379 mut self,
380 id: impl Into<ElementId>,
381 row_count: usize,
382 render_item_fn: impl Fn(Range<usize>, &mut Window, &mut App) -> Vec<[AnyElement; COLS]>
383 + 'static,
384 ) -> Self {
385 self.rows = TableContents::UniformList(UniformListData {
386 element_id: id.into(),
387 row_count: row_count,
388 render_item_fn: Box::new(render_item_fn),
389 });
390 self
391 }
392
393 /// Enables row striping.
394 pub fn striped(mut self) -> Self {
395 self.striped = true;
396 self
397 }
398
399 /// Sets the width of the table.
400 pub fn width(mut self, width: impl Into<Length>) -> Self {
401 self.width = width.into();
402 self
403 }
404
405 pub fn interactable(mut self, interaction_state: &Entity<TableInteractionState>) -> Self {
406 self.interaction_state = Some(interaction_state.downgrade());
407 self
408 }
409
410 pub fn selected_item_index(mut self, selected_item_index: Option<usize>) -> Self {
411 self.selected_item_index = selected_item_index;
412 self
413 }
414
415 pub fn header(mut self, headers: [impl IntoElement; COLS]) -> Self {
416 self.headers = Some(headers.map(IntoElement::into_any_element));
417 self
418 }
419
420 pub fn row(mut self, items: [impl IntoElement; COLS]) -> Self {
421 if let Some(rows) = self.rows.rows_mut() {
422 rows.push(items.map(IntoElement::into_any_element));
423 }
424 self
425 }
426
427 pub fn column_widths(mut self, widths: [impl Into<Length>; COLS]) -> Self {
428 self.column_widths = Some(widths.map(Into::into));
429 self
430 }
431}
432
433fn base_cell_style(width: Option<Length>, cx: &App) -> Div {
434 div()
435 .px_1p5()
436 .when_some(width, |this, width| this.w(width))
437 .when(width.is_none(), |this| this.flex_1())
438 .justify_start()
439 .text_ui(cx)
440 .whitespace_nowrap()
441 .text_ellipsis()
442 .overflow_hidden()
443}
444
445pub fn render_row<const COLS: usize>(
446 row_index: usize,
447 items: [impl IntoElement; COLS],
448 table_context: TableRenderContext<COLS>,
449 cx: &App,
450) -> AnyElement {
451 let is_last = row_index == table_context.total_row_count - 1;
452 let bg = if row_index % 2 == 1 && table_context.striped {
453 Some(cx.theme().colors().text.opacity(0.05))
454 } else {
455 None
456 };
457 let column_widths = table_context
458 .column_widths
459 .map_or([None; COLS], |widths| widths.map(|width| Some(width)));
460 let is_selected = table_context.selected_item_index == Some(row_index);
461
462 div()
463 .w_full()
464 .flex()
465 .flex_row()
466 .items_center()
467 .justify_between()
468 .px_1p5()
469 .py_1()
470 .when_some(bg, |row, bg| row.bg(bg))
471 .when(!is_last, |row| {
472 row.border_b_1().border_color(cx.theme().colors().border)
473 })
474 .when(is_selected, |row| {
475 row.border_2()
476 .border_color(cx.theme().colors().panel_focused_border)
477 })
478 .children(
479 items
480 .map(IntoElement::into_any_element)
481 .into_iter()
482 .zip(column_widths)
483 .map(|(cell, width)| base_cell_style(width, cx).child(cell)),
484 )
485 .into_any_element()
486}
487
488pub fn render_header<const COLS: usize>(
489 headers: [impl IntoElement; COLS],
490 table_context: TableRenderContext<COLS>,
491 cx: &mut App,
492) -> impl IntoElement {
493 let column_widths = table_context
494 .column_widths
495 .map_or([None; COLS], |widths| widths.map(|width| Some(width)));
496 div()
497 .flex()
498 .flex_row()
499 .items_center()
500 .justify_between()
501 .w_full()
502 .p_2()
503 .border_b_1()
504 .border_color(cx.theme().colors().border)
505 .children(headers.into_iter().zip(column_widths).map(|(h, width)| {
506 base_cell_style(width, cx)
507 .font_weight(FontWeight::SEMIBOLD)
508 .child(h)
509 }))
510}
511
512#[derive(Clone, Copy)]
513pub struct TableRenderContext<const COLS: usize> {
514 pub striped: bool,
515 pub total_row_count: usize,
516 pub selected_item_index: Option<usize>,
517 pub column_widths: Option<[Length; COLS]>,
518}
519
520impl<const COLS: usize> TableRenderContext<COLS> {
521 fn new(table: &Table<COLS>) -> Self {
522 Self {
523 striped: table.striped,
524 total_row_count: table.rows.len(),
525 column_widths: table.column_widths,
526 selected_item_index: table.selected_item_index.clone(),
527 }
528 }
529}
530
531impl<const COLS: usize> RenderOnce for Table<COLS> {
532 fn render(mut self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
533 // match self.ro
534 let table_context = TableRenderContext::new(&self);
535 let interaction_state = self.interaction_state.and_then(|state| state.upgrade());
536
537 let scroll_track_size = px(16.);
538 let h_scroll_offset = if interaction_state
539 .as_ref()
540 .is_some_and(|state| state.read(cx).vertical_scrollbar.show_scrollbar)
541 {
542 // magic number
543 px(3.)
544 } else {
545 px(0.)
546 };
547
548 div()
549 .id("todo! how to have id")
550 .w(self.width)
551 .h_full()
552 .v_flex()
553 .when_some(interaction_state.as_ref(), |this, interaction_state| {
554 this.track_focus(&interaction_state.read(cx).focus_handle)
555 .on_hover({
556 let interaction_state = interaction_state.downgrade();
557 move |hovered, window, cx| {
558 interaction_state
559 .update(cx, |interaction_state, cx| {
560 if *hovered {
561 interaction_state.horizontal_scrollbar.show(cx);
562 interaction_state.vertical_scrollbar.show(cx);
563 cx.notify();
564 } else if !interaction_state
565 .focus_handle
566 .contains_focused(window, cx)
567 {
568 interaction_state.hide_scrollbars(window, cx);
569 }
570 })
571 .ok(); // todo! handle error?
572 }
573 })
574 })
575 .when_some(self.headers.take(), |this, headers| {
576 this.child(render_header(headers, table_context, cx))
577 })
578 .child(
579 div()
580 .flex_grow()
581 .w_full()
582 .relative()
583 .overflow_hidden()
584 .map(|parent| match self.rows {
585 TableContents::Vec(items) => parent.children(
586 items
587 .into_iter()
588 .enumerate()
589 .map(|(index, row)| render_row(index, row, table_context, cx)),
590 ),
591 TableContents::UniformList(uniform_list_data) => parent.child(
592 uniform_list(
593 uniform_list_data.element_id,
594 uniform_list_data.row_count,
595 {
596 let render_item_fn = uniform_list_data.render_item_fn;
597 move |range: Range<usize>, window, cx| {
598 let elements = render_item_fn(range.clone(), window, cx);
599 elements
600 .into_iter()
601 .zip(range)
602 .map(|(row, row_index)| {
603 render_row(row_index, row, table_context, cx)
604 })
605 .collect()
606 }
607 },
608 )
609 .size_full()
610 .flex_grow()
611 .with_sizing_behavior(ListSizingBehavior::Auto)
612 .with_horizontal_sizing_behavior(
613 ListHorizontalSizingBehavior::Unconstrained,
614 )
615 .when_some(
616 interaction_state.as_ref(),
617 |this, state| {
618 this.track_scroll(
619 state.read_with(cx, |s, _| s.scroll_handle.clone()),
620 )
621 },
622 ),
623 ),
624 })
625 .when_some(interaction_state.as_ref(), |this, interaction_state| {
626 this.map(|this| {
627 TableInteractionState::render_vertical_scrollbar_track(
628 interaction_state,
629 this,
630 scroll_track_size,
631 cx,
632 )
633 })
634 .map(|this| {
635 TableInteractionState::render_vertical_scrollbar(
636 interaction_state,
637 this,
638 cx,
639 )
640 })
641 }),
642 )
643 .when_some(interaction_state.as_ref(), |this, interaction_state| {
644 this.map(|this| {
645 TableInteractionState::render_horizantal_scrollbar_track(
646 interaction_state,
647 this,
648 scroll_track_size,
649 cx,
650 )
651 })
652 .map(|this| {
653 TableInteractionState::render_horizontal_scrollbar(
654 interaction_state,
655 this,
656 h_scroll_offset,
657 cx,
658 )
659 })
660 })
661 }
662}
663
664// computed state related to how to render scrollbars
665// one per axis
666// on render we just read this off the keymap editor
667// we update it when
668// - settings change
669// - on focus in, on focus out, on hover, etc.
670#[derive(Debug)]
671pub struct ScrollbarProperties {
672 axis: Axis,
673 show_scrollbar: bool,
674 show_track: bool,
675 auto_hide: bool,
676 hide_task: Option<Task<()>>,
677 state: ScrollbarState,
678}
679
680impl ScrollbarProperties {
681 // Shows the scrollbar and cancels any pending hide task
682 fn show(&mut self, cx: &mut Context<TableInteractionState>) {
683 if !self.auto_hide {
684 return;
685 }
686 self.show_scrollbar = true;
687 self.hide_task.take();
688 cx.notify();
689 }
690
691 fn hide(&mut self, window: &mut Window, cx: &mut Context<TableInteractionState>) {
692 const SCROLLBAR_SHOW_INTERVAL: Duration = Duration::from_secs(1);
693
694 if !self.auto_hide {
695 return;
696 }
697
698 let axis = self.axis;
699 self.hide_task = Some(cx.spawn_in(window, async move |keymap_editor, cx| {
700 cx.background_executor()
701 .timer(SCROLLBAR_SHOW_INTERVAL)
702 .await;
703
704 if let Some(keymap_editor) = keymap_editor.upgrade() {
705 keymap_editor
706 .update(cx, |keymap_editor, cx| {
707 match axis {
708 Axis::Vertical => {
709 keymap_editor.vertical_scrollbar.show_scrollbar = false
710 }
711 Axis::Horizontal => {
712 keymap_editor.horizontal_scrollbar.show_scrollbar = false
713 }
714 }
715 cx.notify();
716 })
717 .ok();
718 }
719 }));
720 }
721}
722
723impl Component for Table<3> {
724 fn scope() -> ComponentScope {
725 ComponentScope::Layout
726 }
727
728 fn description() -> Option<&'static str> {
729 Some("A table component for displaying data in rows and columns with optional styling.")
730 }
731
732 fn preview(_window: &mut Window, _cx: &mut App) -> Option<AnyElement> {
733 Some(
734 v_flex()
735 .gap_6()
736 .children(vec![
737 example_group_with_title(
738 "Basic Tables",
739 vec![
740 single_example(
741 "Simple Table",
742 Table::new()
743 .width(px(400.))
744 .header(["Name", "Age", "City"])
745 .row(["Alice", "28", "New York"])
746 .row(["Bob", "32", "San Francisco"])
747 .row(["Charlie", "25", "London"])
748 .into_any_element(),
749 ),
750 single_example(
751 "Two Column Table",
752 Table::new()
753 .header(["Category", "Value"])
754 .width(px(300.))
755 .row(["Revenue", "$100,000"])
756 .row(["Expenses", "$75,000"])
757 .row(["Profit", "$25,000"])
758 .into_any_element(),
759 ),
760 ],
761 ),
762 example_group_with_title(
763 "Styled Tables",
764 vec![
765 single_example(
766 "Default",
767 Table::new()
768 .width(px(400.))
769 .header(["Product", "Price", "Stock"])
770 .row(["Laptop", "$999", "In Stock"])
771 .row(["Phone", "$599", "Low Stock"])
772 .row(["Tablet", "$399", "Out of Stock"])
773 .into_any_element(),
774 ),
775 single_example(
776 "Striped",
777 Table::new()
778 .width(px(400.))
779 .striped()
780 .header(["Product", "Price", "Stock"])
781 .row(["Laptop", "$999", "In Stock"])
782 .row(["Phone", "$599", "Low Stock"])
783 .row(["Tablet", "$399", "Out of Stock"])
784 .row(["Headphones", "$199", "In Stock"])
785 .into_any_element(),
786 ),
787 ],
788 ),
789 example_group_with_title(
790 "Mixed Content Table",
791 vec![single_example(
792 "Table with Elements",
793 Table::new()
794 .width(px(840.))
795 .header(["Status", "Name", "Priority", "Deadline", "Action"])
796 .row([
797 Indicator::dot().color(Color::Success).into_any_element(),
798 "Project A".into_any_element(),
799 "High".into_any_element(),
800 "2023-12-31".into_any_element(),
801 Button::new("view_a", "View")
802 .style(ButtonStyle::Filled)
803 .full_width()
804 .into_any_element(),
805 ])
806 .row([
807 Indicator::dot().color(Color::Warning).into_any_element(),
808 "Project B".into_any_element(),
809 "Medium".into_any_element(),
810 "2024-03-15".into_any_element(),
811 Button::new("view_b", "View")
812 .style(ButtonStyle::Filled)
813 .full_width()
814 .into_any_element(),
815 ])
816 .row([
817 Indicator::dot().color(Color::Error).into_any_element(),
818 "Project C".into_any_element(),
819 "Low".into_any_element(),
820 "2024-06-30".into_any_element(),
821 Button::new("view_c", "View")
822 .style(ButtonStyle::Filled)
823 .full_width()
824 .into_any_element(),
825 ])
826 .into_any_element(),
827 )],
828 ),
829 ])
830 .into_any_element(),
831 )
832 }
833}