tabs: collapse same-kind tabs into group chips

This commit is contained in:
2026-11-15 14:50:48 +07:00
parent f6ba9c0d47
commit daca373f77
5 changed files with 668 additions and 90 deletions
+228 -44
View File
@@ -290,9 +290,21 @@ impl Gallery {
.selected(selected)
.tabs({
let tabs = self.tabs.clone();
let kinds: Vec<Option<SharedString>> = self
.tabs
.iter()
.map(|id| self.views.get(id).and_then(|panel| panel.kind(cx)))
.collect();
move |_, _| {
tabs.iter()
.map(|id| Tab::new(id.clone(), Self::label_of(id)).closeable(true))
.zip(kinds.iter())
.map(|(id, kind)| {
let tab = Tab::new(id.clone(), Self::label_of(id)).closeable(true);
match kind {
Some(kind) => tab.kind(kind.clone()),
None => tab,
}
})
.collect()
}
})
@@ -677,7 +689,11 @@ struct WelcomePanel {
gallery: WeakEntity<Gallery>,
}
impl Panel for WelcomePanel {}
impl Panel for WelcomePanel {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Layout".into())
}
}
impl Render for WelcomePanel {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -824,7 +840,11 @@ impl ButtonDemo {
}
}
impl Panel for ButtonDemo {}
impl Panel for ButtonDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Controls".into())
}
}
impl Render for ButtonDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -990,7 +1010,11 @@ impl InputDemo {
}
}
impl Panel for InputDemo {}
impl Panel for InputDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Controls".into())
}
}
impl Render for InputDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -1076,7 +1100,11 @@ impl FieldDemo {
}
}
impl Panel for FieldDemo {}
impl Panel for FieldDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Controls".into())
}
}
impl Render for FieldDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -1150,7 +1178,11 @@ impl Render for FieldDemo {
struct StatusDotDemo;
impl Panel for StatusDotDemo {}
impl Panel for StatusDotDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Controls".into())
}
}
impl Render for StatusDotDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -1320,7 +1352,11 @@ impl ComboboxDemo {
}
}
impl Panel for ComboboxDemo {}
impl Panel for ComboboxDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Controls".into())
}
}
impl Render for ComboboxDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -1391,7 +1427,11 @@ struct CheckboxDemo {
checked: bool,
}
impl Panel for CheckboxDemo {}
impl Panel for CheckboxDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Controls".into())
}
}
impl Render for CheckboxDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -1435,7 +1475,11 @@ struct RadioDemo {
plan: SharedString,
}
impl Panel for RadioDemo {}
impl Panel for RadioDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Controls".into())
}
}
impl Render for RadioDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -1473,7 +1517,11 @@ struct SwitchDemo {
checked: bool,
}
impl Panel for SwitchDemo {}
impl Panel for SwitchDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Controls".into())
}
}
impl Render for SwitchDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -1517,7 +1565,11 @@ struct ToggleDemo {
pressed: bool,
}
impl Panel for ToggleDemo {}
impl Panel for ToggleDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Controls".into())
}
}
impl Render for ToggleDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -1556,7 +1608,11 @@ struct SliderDemo {
volume: f32,
}
impl Panel for SliderDemo {}
impl Panel for SliderDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Controls".into())
}
}
impl Render for SliderDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -1595,7 +1651,11 @@ struct SegmentedDemo {
filter: ExploreFilter,
}
impl Panel for SegmentedDemo {}
impl Panel for SegmentedDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Controls".into())
}
}
impl Render for SegmentedDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -1679,7 +1739,11 @@ struct SelectDemo {
strategy: Option<Strategy>,
}
impl Panel for SelectDemo {}
impl Panel for SelectDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Controls".into())
}
}
impl Render for SelectDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -1729,7 +1793,11 @@ struct LinkDemo {
clicks: usize,
}
impl Panel for LinkDemo {}
impl Panel for LinkDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Controls".into())
}
}
impl Render for LinkDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -1779,7 +1847,11 @@ impl Render for LinkDemo {
struct ClipboardDemo;
impl Panel for ClipboardDemo {}
impl Panel for ClipboardDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Controls".into())
}
}
impl Render for ClipboardDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -1815,7 +1887,11 @@ impl Render for ClipboardDemo {
struct SeparatorDemo;
impl Panel for SeparatorDemo {}
impl Panel for SeparatorDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Layout".into())
}
}
impl Render for SeparatorDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -1869,7 +1945,11 @@ impl ResizableDemo {
}
}
impl Panel for ResizableDemo {}
impl Panel for ResizableDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Layout".into())
}
}
impl Render for ResizableDemo {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -1910,7 +1990,11 @@ impl Render for ResizableDemo {
struct BadgeDemo;
impl Panel for BadgeDemo {}
impl Panel for BadgeDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Data".into())
}
}
impl Render for BadgeDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -1949,7 +2033,11 @@ impl Render for BadgeDemo {
struct AvatarDemo;
impl Panel for AvatarDemo {}
impl Panel for AvatarDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Data".into())
}
}
impl Render for AvatarDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -1986,7 +2074,11 @@ impl Render for AvatarDemo {
struct ProgressDemo;
impl Panel for ProgressDemo {}
impl Panel for ProgressDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Data".into())
}
}
impl Render for ProgressDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -2013,7 +2105,11 @@ impl Render for ProgressDemo {
struct SpinnerDemo;
impl Panel for SpinnerDemo {}
impl Panel for SpinnerDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Data".into())
}
}
impl Render for SpinnerDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -2057,7 +2153,11 @@ struct ListDemo {
selected: Option<usize>,
}
impl Panel for ListDemo {}
impl Panel for ListDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Data".into())
}
}
impl Render for ListDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -2234,7 +2334,11 @@ impl TreeDemo {
}
}
impl Panel for TreeDemo {}
impl Panel for TreeDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Data".into())
}
}
impl Render for TreeDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -2279,7 +2383,11 @@ struct TabsDemo {
overflow_open: bool,
}
impl Panel for TabsDemo {}
impl Panel for TabsDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Data".into())
}
}
impl Render for TabsDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -2456,7 +2564,11 @@ struct AlertDemo {
dismissed: bool,
}
impl Panel for AlertDemo {}
impl Panel for AlertDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Feedback".into())
}
}
impl Render for AlertDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -2550,7 +2662,11 @@ struct ToastDemo {
toasts: Entity<Toasts>,
}
impl Panel for ToastDemo {}
impl Panel for ToastDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Feedback".into())
}
}
impl Render for ToastDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -2622,7 +2738,11 @@ struct DialogDemo {
gallery: WeakEntity<Gallery>,
}
impl Panel for DialogDemo {}
impl Panel for DialogDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Feedback".into())
}
}
impl Render for DialogDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -2690,7 +2810,11 @@ impl CommandPaletteDemo {
}
}
impl Panel for CommandPaletteDemo {}
impl Panel for CommandPaletteDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Feedback".into())
}
}
impl Render for CommandPaletteDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -2758,7 +2882,11 @@ struct MenuDemo {
open: bool,
}
impl Panel for MenuDemo {}
impl Panel for MenuDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Feedback".into())
}
}
impl Render for MenuDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -2831,7 +2959,11 @@ impl DropdownMenuDemo {
}
}
impl Panel for DropdownMenuDemo {}
impl Panel for DropdownMenuDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Feedback".into())
}
}
impl Render for DropdownMenuDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -2984,7 +3116,11 @@ struct ContextMenuDemo {
action: SharedString,
}
impl Panel for ContextMenuDemo {}
impl Panel for ContextMenuDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Feedback".into())
}
}
impl Render for ContextMenuDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -3041,7 +3177,11 @@ struct PopoverDemo {
open: bool,
}
impl Panel for PopoverDemo {}
impl Panel for PopoverDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Feedback".into())
}
}
impl Render for PopoverDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -3084,7 +3224,11 @@ impl Render for PopoverDemo {
struct TooltipDemo;
impl Panel for TooltipDemo {}
impl Panel for TooltipDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Feedback".into())
}
}
impl Render for TooltipDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -3131,7 +3275,11 @@ impl Render for TooltipDemo {
struct EmptyStateDemo;
impl Panel for EmptyStateDemo {}
impl Panel for EmptyStateDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Feedback".into())
}
}
impl Render for EmptyStateDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -3179,7 +3327,11 @@ impl Render for EmptyStateDemo {
struct ScrollAreaDemo;
impl Panel for ScrollAreaDemo {}
impl Panel for ScrollAreaDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Feedback".into())
}
}
impl Render for ScrollAreaDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -3263,7 +3415,11 @@ impl ScrollbarDemo {
}
}
impl Panel for ScrollbarDemo {}
impl Panel for ScrollbarDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Feedback".into())
}
}
impl Render for ScrollbarDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -3474,7 +3630,11 @@ impl CodeViewDemo {
}
}
impl Panel for CodeViewDemo {}
impl Panel for CodeViewDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Editor".into())
}
}
impl Render for CodeViewDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -3646,7 +3806,11 @@ impl DiffViewDemo {
}
}
impl Panel for DiffViewDemo {}
impl Panel for DiffViewDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Editor".into())
}
}
impl Render for DiffViewDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -3868,7 +4032,11 @@ impl MarkdownViewDemo {
}
}
impl Panel for MarkdownViewDemo {}
impl Panel for MarkdownViewDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Editor".into())
}
}
impl Render for MarkdownViewDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -3946,7 +4114,11 @@ impl TextViewDemo {
}
}
impl Panel for TextViewDemo {}
impl Panel for TextViewDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Editor".into())
}
}
impl Render for TextViewDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -3995,7 +4167,11 @@ struct SidebarDemo {
selected: Option<usize>,
}
impl Panel for SidebarDemo {}
impl Panel for SidebarDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Layout".into())
}
}
impl Render for SidebarDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -4165,7 +4341,11 @@ impl ResizeDemo {
const WIDTH_MAX_REMS: f32 = 20.;
}
impl Panel for ResizeDemo {}
impl Panel for ResizeDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Layout".into())
}
}
impl Render for ResizeDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
@@ -4245,7 +4425,11 @@ impl Render for ResizeDemo {
struct ThemeDemo;
impl Panel for ThemeDemo {}
impl Panel for ThemeDemo {
fn kind(&self, _: &App) -> Option<SharedString> {
Some("Theme".into())
}
}
impl Render for ThemeDemo {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {