From cac8725f59b46fddfe06de085bd747a219b961f5 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Wed, 25 Nov 2026 17:56:05 +0100 Subject: [PATCH] Panel tabs clip and overflow: drop the ellipsis shrink Panel tabs keep the framework's clip and overflow: they shrink to their first letters with the label clipped at the tab's edge, the shown tab whole, and the tabs that do not fit go to the strip's overflow menu. PanelTabShrink::Ellipsis goes with the option that chose it: DockConfig::tab_shrink, the group's tab_shrink, TabStrip::panel_shrink, Tab::panel_shrink, FitMode::ShrinkToLeast, TabKind::fit_mode_for and clips_label_in, and craft_behavior::fit::fit_to_least with its docs. Trials: the two ellipsis trials and the helpers they alone used are removed with the option. --- crates/behavior/src/fit.rs | 52 +------ crates/ui-panels/src/docking/config.rs | 14 +- crates/ui-panels/src/docking/group.rs | 9 +- crates/ui-patterns/src/patterns/dock/area.rs | 1 - crates/ui-widgets/src/tabs/mod.rs | 2 +- crates/ui-widgets/src/tabs/rules.rs | 43 +----- crates/ui-widgets/src/tabs/strip.rs | 34 +--- crates/ui-widgets/src/tabs/tab.rs | 24 +-- crates/ui-widgets/tests/it/tabs.rs | 154 +------------------ docs/contract-api.md | 1 - docs/ui-docking.md | 1 - 11 files changed, 22 insertions(+), 313 deletions(-) diff --git a/crates/behavior/src/fit.rs b/crates/behavior/src/fit.rs index 3712ca15e2..4e767cb6b0 100644 --- a/crates/behavior/src/fit.rs +++ b/crates/behavior/src/fit.rs @@ -1,7 +1,6 @@ -//! The fit rules: which tabs, bar items or titles stay in a strip and which go to an overflow menu. [`fit`], -//! [`fit_to_least`] and [`fit_whole`] assign tab widths (tabs shrink before they overflow, or keep their width); -//! [`fit_items`] shortens items that have a short form, then drops command items and titles from the end. All of them -//! read no egui types. +//! The fit rules: which tabs, bar items or titles stay in a strip and which go to an overflow menu. [`fit`] and +//! [`fit_whole`] assign tab widths (tabs shrink before they overflow, or keep their width); [`fit_items`] shortens +//! items that have a short form, then drops command items and titles from the end. All of them read no egui types. /// Tabs visible on a strip and tabs that need an overflow menu, all in original order. #[derive(Clone, Debug, Default, PartialEq)] @@ -176,51 +175,6 @@ pub fn fit_whole(natural: &[f32], selected: usize, kept: &[bool], available: f32 TabFit { shown, overflow, overflow_width } } -/// Fit tab widths into `available` points, each tab shrinking to its own `least` before any tab overflows. -/// Every tab shrinks, the selected one too: the widest tabs shrink first to a common cap, and each keeps at least -/// `min(natural, least)` of its own. Only when the tabs do not all fit at their least is an overflow button -/// `overflow_width` wide reserved; the selected tab stays, the others follow in order while their least widths fit -/// beside it, and the rest overflow, the last ones first. A selected tab whose least alone is wider than the strip -/// less the button takes the room left. A tab past the end of `least` keeps its natural width as its least. -/// -/// Dimensions are sanitized as in [`fit`], and the shown widths plus `overflow_width` never exceed the sanitized -/// available width. Work and storage are linear in the input count (with at most 32 fitting passes). -pub fn fit_to_least(natural: &[f32], least: &[f32], selected: usize, available: f32, overflow_width: f32) -> TabFit { - let available = tab_extent(available); - let natural: Vec = natural.iter().map(|&w| tab_extent(w)).collect(); - let floors: Vec = natural.iter().enumerate().map(|(i, &w)| least.get(i).map_or(w, |&least| w.min(tab_extent(least)))).collect(); - let all: Vec = (0..natural.len()).collect(); - let total = |widths: &[f32]| widths.iter().map(|&w| f64::from(w)).sum::(); - if total(natural.as_slice()) <= f64::from(available) { - return TabFit { shown: all.into_iter().zip(natural).collect(), ..Default::default() }; - } - // One tab has nowhere to overflow; all available space belongs to it. - if natural.len() == 1 { - return TabFit { shown: vec![(0, available)], ..Default::default() }; - } - let floor = |i: usize| floors.get(i).copied().unwrap_or(0.0); - if total(floors.as_slice()) <= f64::from(available) { - return TabFit { shown: squeeze_floored(&natural, &all, available, 0.0, floor), ..Default::default() }; - } - let overflow_width = tab_extent(overflow_width).min(available); - let budget = available - overflow_width; - let selected = selected.min(natural.len().saturating_sub(1)); - let mut used = f64::from(floor(selected)); - let mut open = true; - let (shown, overflow): (Vec, Vec) = all.into_iter().partition(|&i| { - if i == selected { - return true; - } - open = open && used + f64::from(floor(i)) <= f64::from(budget); - if open { - used += f64::from(floor(i)); - } - open - }); - let shown = squeeze_floored(&natural, &shown, budget, 0.0, floor); - TabFit { shown, overflow, overflow_width } -} - fn squeeze(natural: &[f32], indices: &[usize], total: f32, minimum: f32) -> Vec<(usize, f32)> { squeeze_floored(natural, indices, total, minimum, |i| natural.get(i).copied().unwrap_or(0.0).min(minimum)) } diff --git a/crates/ui-panels/src/docking/config.rs b/crates/ui-panels/src/docking/config.rs index 7d35042691..90cdca42d9 100644 --- a/crates/ui-panels/src/docking/config.rs +++ b/crates/ui-panels/src/docking/config.rs @@ -3,7 +3,7 @@ use super::targets::ZoneRule; use super::{ColumnCards, IconicMode}; -use crate::tabs::{PanelTabLook, PanelTabShrink}; +use crate::tabs::PanelTabLook; use craft_behavior::{DockSide, IconId}; /// A set of the sides of the layout's outer edge or of a group. @@ -109,10 +109,6 @@ pub struct DockConfig { /// filled rounded pill ([`PanelTabLook::Pill`]), or a square filled block on a canvas strip /// ([`PanelTabLook::Block`]). pub tab_look: PanelTabLook, - /// How far the groups' panel tabs shrink before they overflow: to their first letters, clipped - /// ([`PanelTabShrink::FirstLetters`]), or each to a readable prefix ending in "…", the shown tab too - /// ([`PanelTabShrink::Ellipsis`]), the tabs that do not fit at that width going to the strip's overflow menu. - pub tab_shrink: PanelTabShrink, /// A floating window opens in an OS window of its own where the window host opens OS windows and reports where /// they are on the desktop (not on Wayland) and its panels allow it (`PanelSpec::allow_native`). Elsewhere, and /// with this off, it shows in the app window. A window that takes over a held press (`DockArea::continue_move`) @@ -150,7 +146,6 @@ impl Default for DockConfig { titled_headers: false, wheel_selects_tabs: false, tab_look: PanelTabLook::Plain, - tab_shrink: PanelTabShrink::FirstLetters, native_windows: true, group_order_items: false, panel_menu_always: false, @@ -280,13 +275,6 @@ impl DockConfig { self } - /// How far the groups' panel tabs shrink ([`tab_shrink`](Self::tab_shrink)). - #[must_use] - pub fn tab_shrink(mut self, shrink: PanelTabShrink) -> Self { - self.tab_shrink = shrink; - self - } - /// Flush docks on or off ([`flush_docks`](Self::flush_docks)). #[must_use] pub fn flush_docks(mut self, on: bool) -> Self { diff --git a/crates/ui-panels/src/docking/group.rs b/crates/ui-panels/src/docking/group.rs index 4b277b8b48..29c277e8ac 100644 --- a/crates/ui-panels/src/docking/group.rs +++ b/crates/ui-panels/src/docking/group.rs @@ -22,7 +22,7 @@ use crate::runtime::focus::{self, FocusRequest, FocusTarget}; use crate::runtime::memory::sub; use crate::sections::FooterBar; use crate::style::{ComponentStyle, Corners, RuleLook, RuleWidth, StyleColor, StyleCx, SurfaceKind, TypeRole}; -use crate::tabs::{PanelTabLook, PanelTabShrink, Tab, TabKind, TabStrip, TornOff}; +use crate::tabs::{PanelTabLook, Tab, TabKind, TabStrip, TornOff}; use craft_behavior::{CursorIcon, CursorPriority, DockSide, IconId, Metrics, PartKey, PressPhase, Sense, keyed}; use craft_theme::{ControlSize, GripMark, GripShape, Tokens}; use egui::{Id, Pos2, Rect, Response, Ui, Vec2}; @@ -374,9 +374,6 @@ pub struct DockGroup<'a, P: Clone + Hash + Send + Sync + 'static> { wheel_selects_tabs: bool, /// The look of the tabs: [`tab_look`](DockGroup::tab_look). tab_look: PanelTabLook, - /// How far the tabs shrink ([`DockConfig::tab_shrink`](super::DockConfig::tab_shrink)). - #[prop] - tab_shrink: PanelTabShrink, /// The header shows the shown panel's title (with its count) and a close button in place of the tab strip, as a /// single titled panel does: the panels are shown from a rail, not by tabs. #[prop(flag)] @@ -441,7 +438,6 @@ impl<'a, P: Clone + Hash + Send + Sync + PartialEq + Debug + 'static> DockGroup< closable: false, wheel_selects_tabs: false, tab_look: PanelTabLook::Plain, - tab_shrink: PanelTabShrink::FirstLetters, titled: false, take_focus: false, dock: None, @@ -766,7 +762,6 @@ impl Container for closable: self.closable, wheel_selects: self.wheel_selects_tabs, look: self.tab_look, - shrink: self.tab_shrink, take_focus: self.take_focus, dock: self.dock, sent: Outbox::new(&mut sent), @@ -861,7 +856,6 @@ struct TabRow<'a, P> { closable: bool, wheel_selects: bool, look: PanelTabLook, - shrink: PanelTabShrink, /// The strip takes key focus in this pass (`DockGroup::take_focus`): in the key, so the row runs and the strip /// takes it while it runs. take_focus: bool, @@ -950,7 +944,6 @@ fn tab_row(row: &mu .kind(TabKind::Panel) .keeps_focus() .panel_look(row.look) - .panel_shrink(row.shrink) .shown(shown_tab(panels, active)) .tear_off() .natural_height(true) diff --git a/crates/ui-patterns/src/patterns/dock/area.rs b/crates/ui-patterns/src/patterns/dock/area.rs index b05261bbc5..7a70fe737a 100644 --- a/crates/ui-patterns/src/patterns/dock/area.rs +++ b/crates/ui-patterns/src/patterns/dock/area.rs @@ -1246,7 +1246,6 @@ impl Pass<'_, P> { .panel_menu_shown(*hosted || scene.config.panel_menu_always) .panel_menu_icon(scene.config.panel_menu_icon.clone()) .tab_look(scene.config.tab_look) - .tab_shrink(scene.config.tab_shrink) .command_states(states.clone()); if look.in_window { group = group.in_window(); diff --git a/crates/ui-widgets/src/tabs/mod.rs b/crates/ui-widgets/src/tabs/mod.rs index 554d1946d6..7a68e3be2e 100644 --- a/crates/ui-widgets/src/tabs/mod.rs +++ b/crates/ui-widgets/src/tabs/mod.rs @@ -6,7 +6,7 @@ mod words; mod rules; pub(crate) mod tab; -pub use rules::{CloseSide, DocumentTabLook, FitMode, OverflowMenu, OverflowPlace, PanelTabLook, PanelTabShrink, TabCloseLook, TabKind, close_side}; +pub use rules::{CloseSide, DocumentTabLook, FitMode, OverflowMenu, OverflowPlace, PanelTabLook, TabCloseLook, TabKind, close_side}; pub use tab::{Tab, TabOutput, TabPartEvent, TabRole, TabStyle}; pub use words::TabWords; diff --git a/crates/ui-widgets/src/tabs/rules.rs b/crates/ui-widgets/src/tabs/rules.rs index 5cc4de1bdb..e3fb27b917 100644 --- a/crates/ui-widgets/src/tabs/rules.rs +++ b/crates/ui-widgets/src/tabs/rules.rs @@ -1,6 +1,6 @@ //! The pure rules of a tab strip: what each kind of strip does, and which side a tab's close button is on. -use craft_behavior::fit::{TabFit, fit, fit_to_least, fit_whole}; +use craft_behavior::fit::{TabFit, fit, fit_whole}; use craft_host::target::Os; /// The look of document tabs ([`TabKind::Document`]) app-wide. An app sets it once at its root (`RootEnv::values`); @@ -51,22 +51,6 @@ pub enum PanelTabLook { Block, } -/// How far panel tabs ([`TabKind::Panel`]) shrink before they overflow, and how a label too long for its tab ends: a -/// strip's choice ([`TabStrip::panel_shrink`](super::TabStrip)), which a dock makes for its groups' tabs. -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, crate::contract::MemoProps)] -#[non_exhaustive] -pub enum PanelTabShrink { - /// Tabs shrink to their title's first letters, the label clipped at the tab's edge with no ellipsis. - #[default] - FirstLetters, - /// Tabs shrink no further than their label's readable least, its first - /// [`TextRun::READABLE_CHARACTERS`](crate::primitives::TextRun::READABLE_CHARACTERS) characters and an ellipsis (a - /// title at most one character longer stays whole), and a cut label ends in "…". Every tab shrinks, the shown one - /// too, the widest first; only the tabs that do not fit at their least go to the overflow menu, the last ones - /// first ([`FitMode::ShrinkToLeast`]). - Ellipsis, -} - /// The kind of a strip. It sets the defaults below; the host picks one per strip. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[non_exhaustive] @@ -99,22 +83,16 @@ pub enum FitMode { /// Whether the selected tab keeps its natural width. keep_selected: bool, }, - /// Every tab shrinks towards its own least width, the selected one too, the widest first; only the tabs that do - /// not fit at their least overflow, the last ones first (`fit_to_least`). Panel tabs under - /// [`PanelTabShrink::Ellipsis`]. - ShrinkToLeast, } impl FitMode { /// Fits tabs of the `natural` widths into `available`, keeping the `selected` tab. Whole widths give the tabs /// marked in `kept` the room before the other tabs (`fit_whole`); shrinking tabs have no kept tabs. `minimum` is - /// the narrowest a shrinking tab becomes and `overflow` the width of the overflow button; [`FitMode::ShrinkToLeast`] - /// takes it as every tab's least (a strip passes each tab's own to `fit_to_least`). + /// the narrowest a shrinking tab becomes and `overflow` the width of the overflow button. pub fn fit(self, natural: &[f32], selected: usize, kept: &[bool], available: f32, minimum: f32, overflow: f32) -> TabFit { match self { FitMode::Whole => fit_whole(natural, selected, kept, available, overflow), FitMode::Shrink { keep_selected } => fit(natural, selected, available, minimum, overflow, keep_selected), - FitMode::ShrinkToLeast => fit_to_least(natural, &vec![minimum; natural.len()], selected, available, overflow), } } } @@ -154,20 +132,12 @@ impl TabKind { if self.shrinks_in(look) { FitMode::Shrink { keep_selected: self.keeps_active_width() } } else { self.fit_mode() } } - /// How tab widths are fitted under the app's document tab look and the strip's panel shrink: panel tabs under - /// [`PanelTabShrink::Ellipsis`] all shrink to their own readable least, the shown tab too, before any overflows - /// ([`FitMode::ShrinkToLeast`]); every other kind and shrink is [`TabKind::fit_mode_in`]. - pub fn fit_mode_for(self, look: DocumentTabLook, shrink: PanelTabShrink) -> FitMode { - if self == Self::Panel && shrink == PanelTabShrink::Ellipsis { FitMode::ShrinkToLeast } else { self.fit_mode_in(look) } - } - /// Whether these are document tabs under [`DocumentTabLook::Shrinking`]. pub fn shrinks_in(self, look: DocumentTabLook) -> bool { self == Self::Document && look == DocumentTabLook::Shrinking } - /// Whether the shown tab keeps its whole title while the other tabs shrink: panel tabs that shrink to their first - /// letters (under [`PanelTabShrink::Ellipsis`] the shown tab shrinks with the others, [`TabKind::fit_mode_for`]). + /// Whether the shown tab keeps its whole title while the other tabs shrink: panel tabs. pub fn keeps_active_width(self) -> bool { self == Self::Panel } @@ -178,13 +148,6 @@ impl TabKind { self == Self::Panel } - /// Whether a label too long for its tab is clipped at the tab's edge under the strip's `shrink`: panel tabs that - /// shrink to their first letters ([`PanelTabShrink::FirstLetters`]); under [`PanelTabShrink::Ellipsis`] they end - /// in an ellipsis as the other kinds do. - pub fn clips_label_in(self, shrink: PanelTabShrink) -> bool { - self.clips_label() && shrink == PanelTabShrink::FirstLetters - } - /// Where the overflow button sits: at the strip's end for document and text tabs, after the last tab for panel /// tabs. pub fn overflow_place(self) -> OverflowPlace { diff --git a/crates/ui-widgets/src/tabs/strip.rs b/crates/ui-widgets/src/tabs/strip.rs index 23bb277528..52f4604363 100644 --- a/crates/ui-widgets/src/tabs/strip.rs +++ b/crates/ui-widgets/src/tabs/strip.rs @@ -30,7 +30,7 @@ use crate::primitives::{PaintShape, StrokeWidth}; use crate::runtime::commands::FireSource; use crate::runtime::env::Label; use crate::style::{ComponentStyle, StyleColor, StyleCx}; -use craft_behavior::fit::{FitItem, fit_items, fit_to_least}; +use craft_behavior::fit::{FitItem, fit_items}; use craft_behavior::{ Flow, HitLevel, HitPriority, IconId, Insets, ItemLayout, ItemSource, Metrics, NavShape, PartKey, PressPhase, ScrollPos, Selection, SelectionChange, Sense, @@ -332,21 +332,8 @@ impl StripLayout { .collect(); let selected = lane.iter().position(|place| matches!(*place, Lane::Tab(at) if at == *selected)).unwrap_or(usize::MAX); let available = (*width - ends_room).max(0.0) + tab_gap; - let fit = if *mode == FitMode::ShrinkToLeast { - // Each tab shrinks no further than its own least; a tab fading out keeps its width. - let least: Vec = lane - .iter() - .map(|place| match *place { - Lane::Tab(at) => min.get(at).copied().unwrap_or(0.0), - Lane::Ghost(k) => ghosts.get(k).map_or(0.0, |ghost| ghost.width), - }) - .map(|width| width + tab_gap) - .collect(); - fit_to_least(&padded, &least, selected, available, *height) - } else { - let minimum = min.iter().copied().fold(0.0, f32::max); - mode.fit(&padded, selected, &held, available, minimum + tab_gap, *height) - }; + let minimum = min.iter().copied().fold(0.0, f32::max); + let fit = mode.fit(&padded, selected, &held, available, minimum + tab_gap, *height); *shown = vec![false; count]; *left = vec![*width; count]; *wide = vec![0.0; count]; @@ -528,9 +515,8 @@ impl TabRoles<'_, K> { /// asks for the tab's context menu. /// /// The `kind` picks the rules: document and text tabs keep whole titles and send the rest to an overflow menu of -/// every tab; panel tabs shrink before they overflow and the menu lists the hidden ones. Panel tabs shrink to their -/// first letters, clipped, beside the shown tab whole, or with `panel_shrink(PanelTabShrink::Ellipsis)` each to a -/// readable prefix ending in "…", the shown tab too, before any overflows. The shown tab is always visible. A tab +/// every tab; panel tabs shrink to their first letters, clipped, beside the shown tab whole, before they overflow, +/// and the menu lists the hidden ones. The shown tab is always visible. A tab /// dragged out of the strip and released where no other strip, dock or drop target takes it is reported as /// `torn_off`. #[derive(crate::contract::Component, crate::contract::Props)] @@ -551,11 +537,6 @@ pub struct TabStrip<'a, K: Clone + Eq + Hash + Send + Sync + std::fmt::Debug + ' /// The look of a panel strip's tabs ([`TabKind::Panel`]). #[prop] panel_look: super::PanelTabLook, - /// How far a panel strip's tabs ([`TabKind::Panel`]) shrink before they overflow: to their first letters, clipped - /// (the default), or each to a readable prefix ending in an ellipsis, the shown tab too - /// ([`PanelTabShrink::Ellipsis`](super::PanelTabShrink)). - #[prop] - panel_shrink: super::PanelTabShrink, /// The tab the host shows. A click, Space, Enter or a drop reports the new one in the output. #[prop] shown: Option, @@ -628,7 +609,6 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + std::fmt::Debug + 'static> TabStri kind: TabKind::Document, large: false, panel_look: super::PanelTabLook::Plain, - panel_shrink: super::PanelTabShrink::FirstLetters, shown: None, tear_off: false, wheel_selects: false, @@ -1085,7 +1065,7 @@ impl Collection // Each end item is measured in this pass, with its label and icon only. let ends = self.trailing.iter().map(|end| end.fit_item(cx)).collect(); let look = cx.env::(); - let mode = self.kind.fit_mode_for(look, self.panel_shrink); + let mode = self.kind.fit_mode_in(look); let fitting = Fitting { selected, mode, kept, ends, gap: cx.tokens.space.gap.inline, ghosts, departed }; // Shrinking document tabs stand apart by the inline gap; the other kinds and looks touch. let tab_gap = if self.kind.shrinks_in(look) { cx.tokens.space.gap.inline } else { 0.0 }; @@ -1094,7 +1074,7 @@ impl Collection /// Every tab takes the strip's kind, panel look, panel shrink and size. fn dress<'r>(&self, tab: Self::Item<'r>, _: &RowState) -> Self::Item<'r> { - let tab = tab.kind(self.kind).panel_look(self.panel_look).panel_shrink(self.panel_shrink); + let tab = tab.kind(self.kind).panel_look(self.panel_look); if self.large { tab.large() } else { tab } } diff --git a/crates/ui-widgets/src/tabs/tab.rs b/crates/ui-widgets/src/tabs/tab.rs index 4da01bba8e..875f513371 100644 --- a/crates/ui-widgets/src/tabs/tab.rs +++ b/crates/ui-widgets/src/tabs/tab.rs @@ -3,10 +3,9 @@ //! Selection, the lead, the focus ring and the drag ghost belong to the collection that shows the tab; the tab draws //! the look the item step gives it and reports what its own parts do. The strip gives the tab a rect: the tab's //! measure is its natural width (`Proposal::Min` the room for the first letters of its title beside its icon and close -//! button, or for a panel tab under `PanelTabShrink::Ellipsis` its label's readable least), and a narrower rect cuts the -//! label first, then the detail, and shows the whole text as a tooltip. +//! button), and a narrower rect cuts the label first, then the detail, and shows the whole text as a tooltip. -use super::rules::{CloseSide, PanelTabLook, PanelTabShrink, TabCloseLook, TabKind, close_side}; +use super::rules::{CloseSide, PanelTabLook, TabCloseLook, TabKind, close_side}; use super::words::TabWords; use std::borrow::Cow; @@ -208,9 +207,6 @@ pub struct Tab<'a> { #[style_key] #[prop] panel_look: PanelTabLook, - /// How far a panel tab ([`TabKind::Panel`]) shrinks and how its cut label ends; the other kinds have their own. - #[prop] - panel_shrink: PanelTabShrink, /// Secondary text after the label (a colour mode, a zoom). #[prop(into)] detail: Option