Keep trailing tab controls visible in narrow rows

This commit is contained in:
Dylan M. Taylor committed 2026-11-21 17:53:59 -05:00
1 parent cedf9e01b6
commit aa3ec09edd
3 files changed
+1 -24

No files matched your search

@@ -227,7 +227,7 @@ impl<C: Collection> ShapeHooks<C> 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 {
-4
View File
@@ -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<D> {
let DocumentTabs { label, tabs, selected, reorderable, tear_off, leading, trailing, large, takes_files } = self;
let source = keyed(tabs, |tab: &DocumentTab<D>| 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<D>, _| 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));
}
-19
View File
@@ -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;