From aa3ec09edd8d76af39bddcb04c0ead80004d9a1b Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 21 Nov 2026 17:53:59 -0500 Subject: [PATCH] Keep trailing tab controls visible in narrow rows --- .../ui-contract/src/contract/items/hooks.rs | 2 +- crates/ui-widgets/src/tabs/document.rs | 4 ---- crates/ui-widgets/tests/it/tabs.rs | 19 ------------------- 3 files changed, 1 insertion(+), 24 deletions(-) diff --git a/crates/ui-contract/src/contract/items/hooks.rs b/crates/ui-contract/src/contract/items/hooks.rs index a980a34cf..176974164 100644 --- a/crates/ui-contract/src/contract/items/hooks.rs +++ b/crates/ui-contract/src/contract/items/hooks.rs @@ -227,7 +227,7 @@ impl ShapeHooks for ItemsHooks<'_, '_, C> { let mut layout = comp.item_layout_from(previous, &*self.source, width, item, scx); // An auto-width layout sets its items side by side: where its width comes from its rows, it takes their run at // their ideal widths, not the widest one (a tab strip in a bar's unbounded row). - let run = (layout.auto_widths() && (asked.is_some() || !bounded || self.content_sized(comp)) && !self.source.is_empty()) + let run = (layout.auto_widths() && (asked.is_some() || !bounded) && !self.source.is_empty()) .then(|| self.run_in(ui, id, room).min(room.x)) .filter(|run| *run > width); let (width, asked) = match run { diff --git a/crates/ui-widgets/src/tabs/document.rs b/crates/ui-widgets/src/tabs/document.rs index fc6df751b..0951fe9fd 100644 --- a/crates/ui-widgets/src/tabs/document.rs +++ b/crates/ui-widgets/src/tabs/document.rs @@ -269,14 +269,10 @@ impl<'a, D: Clone + Eq + Hash + Send + Sync + std::fmt::Debug + 'static> Documen pub fn show(self, ui: &mut Ui) -> DocumentTabsOutput { let DocumentTabs { label, tabs, selected, reorderable, tear_off, leading, trailing, large, takes_files } = self; let source = keyed(tabs, |tab: &DocumentTab| tab.id.clone()).with_text(|tab| Cow::Borrowed(tab.label.as_str())); - let has_trailing = trailing.is_some(); let make_strip = || { let mut strip = TabStrip::new(label.clone()) .takes_drop(DropKind::new(DropPlace::Between, |_: &ListDrag, _| true)) .can_close(move |key: &D| tabs.iter().any(|tab| &tab.id == key && tab.closable)); - if has_trailing { - strip = strip.sizing(Sizing::Content); - } if takes_files { strip = strip.takes_drop(DropKind::new(DropPlace::Between, |_: &OsFiles, _| true)); } diff --git a/crates/ui-widgets/tests/it/tabs.rs b/crates/ui-widgets/tests/it/tabs.rs index 057d7d78a..4472d41da 100644 --- a/crates/ui-widgets/tests/it/tabs.rs +++ b/crates/ui-widgets/tests/it/tabs.rs @@ -91,25 +91,6 @@ fn document_tabs_with_trailing_control_fill_their_parent_row() { assert!(visible > 1, "the strip uses the available width: {visible} tab visible"); } -#[trial] -fn trailing_control_follows_short_document_tabs() { - use craft_ui::buttons::Button; - use craft_ui::contract::Show as _; - use craft_ui::tabs::{DocumentTab, DocumentTabs}; - let mut fixture = Fixture::new(|ui| { - let tabs = [DocumentTab::new(1, "One document")]; - let _ = DocumentTabs::new("Documents", &tabs) - .trailing(|ui| { - Button::new("Open").show(ui); - }) - .show(ui); - }); - fixture.room(egui::vec2(1000.0, 100.0)).settle(); - let tab = fixture.by_label("One document").expect("document tab").rect; - let open = fixture.by_label("Open").expect("trailing control").rect; - assert!(open.left() - tab.right() < tab.width(), "trailing control follows the tab: {tab:?}, {open:?}"); -} - #[trial] fn document_tabs_reserve_space_for_the_trailing_control() { use craft_ui::buttons::Button;