tabs: add overflow scroll option for horizontal scrolling

This commit is contained in:
2026-11-14 18:31:18 +07:00
parent 648cbb9c52
commit 4b70df452a
2 changed files with 21 additions and 19 deletions
+19 -1
View File
@@ -108,6 +108,7 @@ pub struct Tabs {
id: ElementId,
selected: usize,
variant: TabsVariant,
overflow_scroll: bool,
a11y_label: Option<SharedString>,
on_change: Option<ChangeHandler>,
on_close: Option<CloseHandler>,
@@ -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<F>(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),
})
}
}
+2 -18
View File
@@ -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,