diff --git a/crates/data/src/tabs.rs b/crates/data/src/tabs.rs index a2c9740..e44c5cb 100644 --- a/crates/data/src/tabs.rs +++ b/crates/data/src/tabs.rs @@ -108,6 +108,7 @@ pub struct Tabs { id: ElementId, selected: usize, variant: TabsVariant, + overflow_scroll: bool, a11y_label: Option, on_change: Option, on_close: Option, @@ -124,6 +125,7 @@ impl Tabs { id: id.into(), selected: 0, variant: TabsVariant::default(), + overflow_scroll: false, a11y_label: None, on_change: None, on_close: None, @@ -143,6 +145,12 @@ impl Tabs { self } + /// Scrolls the strip horizontally when the tabs overflow. + pub fn overflow_scroll(mut self, overflow_scroll: bool) -> Self { + self.overflow_scroll = overflow_scroll; + self + } + /// Reports the next selected tab, as an index into the `tabs` vec — not a tab key; indices shift on reorder. pub fn on_change(mut self, handler: F) -> Self where @@ -254,7 +262,17 @@ impl RenderOnce for Tabs { } TabsVariant::Pill => root.items_center().gap_1(), }) - .children(strip) + .map(|root| match self.overflow_scroll { + true => root.min_w_0().overflow_x_scroll().child( + div() + .flex_none() + .flex() + .gap_1() + .when(self.variant == TabsVariant::Pill, |row| row.items_center()) + .children(strip), + ), + false => root.children(strip), + }) } } diff --git a/crates/layout/src/dock.rs b/crates/layout/src/dock.rs index e39e564..0d0b25d 100644 --- a/crates/layout/src/dock.rs +++ b/crates/layout/src/dock.rs @@ -1064,6 +1064,7 @@ fn render_pane( pane.key ))) .variant(TabsVariant::Pill) + .overflow_scroll(true) .selected(selected) .tabs({ let tabs = pane.tabs.clone(); @@ -1119,9 +1120,6 @@ fn render_pane( let bar_id = SharedString::from(format!("{dock_id}-pane-{}-bar", pane.key)); let strip_id = SharedString::from(format!("{dock_id}-pane-{}-strip", pane.key)); - let tabs_scroll_id = - SharedString::from(format!("{dock_id}-pane-{}-tabs-scroll", pane.key)); - let tabs_fit_id = SharedString::from(format!("{dock_id}-pane-{}-tabs-fit", pane.key)); let prefix = titlebar.prefix.as_ref().map(|prefix| prefix()); let suffix = titlebar.suffix.as_ref().map(|suffix| suffix()); @@ -1142,21 +1140,7 @@ fn render_pane( .when_some(prefix, |bar, element| { bar.child(div().flex_none().mr_1().child(element)) }) - .child( - div() - .id(tabs_scroll_id.clone()) - .debug_selector(move || tabs_scroll_id.to_string()) - .flex() - .min_w_0() - .overflow_x_scroll() - .child( - div() - .id(tabs_fit_id.clone()) - .debug_selector(move || tabs_fit_id.to_string()) - .flex_none() - .child(tabs), - ), - ) + .child(tabs) .child(titlebar_strip( div().id(strip_id.clone()).flex_1().self_stretch(), strip_id,