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
+24 -11
View File
@@ -7,30 +7,51 @@ use std::sync::Arc;
use gpui::{
AnyElement, AnyView, App, Axis, Div, ElementId, Entity, IntoElement, ParentElement as _,
Render, RenderOnce, StyleRefinement, Styled as _, Window, div, rems,
Render, RenderOnce, SharedString, StyleRefinement, Styled as _, Window, div, rems,
};
use gpui_native_theme::ActiveTheme as _;
use crate::resizable::{Resizable, ResizableState};
pub trait Panel: Render + 'static {}
/// A user-defined panel the row can show.
#[allow(unused_variables)]
pub trait Panel: Render + 'static {
/// The kind the panel belongs to; same-kind panels group in the tab bar.
fn kind(&self, cx: &App) -> Option<SharedString> {
None
}
}
/// An object-safe handle to a panel, so apps can hold panels by kind.
#[allow(unused_variables)]
pub trait PanelView: 'static {
/// The panel's view.
fn view(&self) -> AnyView;
/// The panel's kind, read live from the panel.
fn kind(&self, cx: &App) -> Option<SharedString> {
None
}
}
impl<T: Panel> PanelView for Entity<T> {
fn view(&self) -> AnyView {
self.clone().into()
}
fn kind(&self, cx: &App) -> Option<SharedString> {
self.read(cx).kind(cx)
}
}
impl<P: PanelView + ?Sized> PanelView for Arc<P> {
fn view(&self) -> AnyView {
(**self).view()
}
fn kind(&self, cx: &App) -> Option<SharedString> {
(**self).kind(cx)
}
}
/// The layout the cached panel content lays out with.
@@ -131,14 +152,6 @@ impl RenderOnce for PanelRow {
None => div().w_full().h_full().child(main),
};
div()
.flex_1()
.min_w_0()
.h_full()
// the titlebar's centered tabs leave slack above the strip's
// bottom edge, so the top gutter is narrower to even out.
.p_2()
.pt_1()
.child(row)
div().flex_1().min_w_0().h_full().p_2().pt_1().child(row)
}
}