Tabs: the tabs after the leading tab are drawn whole

With a leading tab, the tabs after it fit whole by construction, but
each one's room was the strip's width less a running sum of the widths
before it. That sum can come out a fraction of a point short of a tab's
width, which shortened the active tab's title though it fits. The tabs
after the leading tab now take their whole widths. `leading_tab` and
the new `tab_room` have unit tests, and the frame test's doc comment
now says that the strip used to end short of the » button.
This commit is contained in:
dotCooCoo
2026-11-18 19:30:33 -08:00
parent ce5c4c230c
commit 35d2cb680a
4 changed files with 39 additions and 7 deletions
+1 -1
View File
@@ -32,7 +32,7 @@ pub use status_bar::{StatusBarShow, deserialize_status_bar_show, set_status_bar_
#[cfg(test)]
use status_bar::{StatusReadoutWidths, color_profile_name, date_time_label, status_readouts};
#[cfg(test)]
use tabs::{CLOSE_BEFORE_TITLE, first_tab_shown, tab_drop, tab_groups, tab_title};
use tabs::{CLOSE_BEFORE_TITLE, first_tab_shown, leading_tab, tab_drop, tab_groups, tab_room, tab_title};
pub use tabs::{doc_tabs, isolation_bar, step_document};
pub(crate) use tabs::{document_window_title, show_document, window_tab};
+14 -3
View File
@@ -131,11 +131,21 @@ pub(super) fn first_tab_shown(widths: &[f32], active: Option<usize>, room: f32)
/// When the tabs `widths` wide from `first` to the last one leave at least `least` of `room` before
/// the » button, the tab before `first` fills that room with its title shortened (#8584). → the
/// first tab the strip shows and, when it is that tab, the width it gets.
fn leading_tab(widths: &[f32], first: usize, room: f32, least: f32) -> (usize, Option<f32>) {
pub(super) fn leading_tab(widths: &[f32], first: usize, room: f32, least: f32) -> (usize, Option<f32>) {
let rest: f32 = widths.get(first..).map_or(0.0, |w| w.iter().sum());
if first > 0 && room - rest >= least { (first - 1, Some(room - rest)) } else { (first, None) }
}
/// The room a tab `w` wide has: `left` of the strip, or with a leading tab `lead` wide
/// ([`leading_tab`]), `lead` for it (`leading`) and its whole width for each tab after it.
pub(super) fn tab_room(lead: Option<f32>, leading: bool, w: f32, left: f32) -> f32 {
match lead {
Some(l) if leading => l,
Some(_) => w,
None => left,
}
}
/// The × of a document tab `w` wide, drawn in `xr` and clicked within 3 pt of it, or `None` for a
/// tab shortened narrower than the × and its click area.
fn tab_close_box(ui: &Ui, t: &Tokens, xr: egui::Rect, w: f32, id: egui::Id) -> Option<egui::Response> {
@@ -206,8 +216,9 @@ pub fn doc_tabs(app: &mut VectorcraftApp, ui: &mut Ui) {
// A tab that doesn't fit whole takes the rest of the strip with its title shortened, as
// long as some of the title fits (#8584); its tooltip shows the whole title. The active
// tab always shows, shortened to the strip when it is wider than the whole strip. The
// leading tab before the ones that fit whole takes only the room they leave.
let left = lead.filter(|_| k == first).unwrap_or(strip.left() + room - x);
// leading tab before the ones that fit whole takes only the room they leave, and the tabs
// after it are drawn whole.
let left = tab_room(lead, k == first, *w, strip.left() + room - x);
let is_active = Some(k) == active;
// A shortened title too wide for its room even as "…" is not drawn, so it stays clear of
// the ×.
+21
View File
@@ -8,6 +8,27 @@ fn the_active_tab_stays_in_view() {
assert_eq!(super::first_tab_shown(&widths, Some(4), 50.0), 4, "a tab wider than the room still shows");
}
/// When the tabs shown from a later one to the end leave room, the tab before them takes that room
/// (#8584).
#[test]
fn the_tab_before_the_shown_ones_takes_the_room_they_leave() {
let widths = [100.0; 10];
assert_eq!(super::leading_tab(&widths, 7, 350.0, 90.0), (7, None), "50 left is less than the least room");
assert_eq!(super::leading_tab(&widths, 7, 390.0, 90.0), (6, Some(90.0)), "exactly the least room");
assert_eq!(super::leading_tab(&widths, 7, 389.0, 90.0), (7, None), "just under the least room");
assert_eq!(super::leading_tab(&widths, 0, 2000.0, 90.0), (0, None), "no tab before the first");
assert_eq!(super::leading_tab(&widths, 9, 50.0, 90.0), (9, None), "the tabs shown are wider than the room");
}
/// After a leading tab, the tabs are drawn whole, even when the strip's running sum leaves a hair
/// less than a tab's width; without one, a tab has the rest of the strip (#8584).
#[test]
fn the_tabs_after_the_leading_one_are_drawn_whole() {
assert_eq!(super::tab_room(Some(90.0), true, 200.0, 500.0), 90.0, "the leading tab");
assert_eq!(super::tab_room(Some(90.0), false, 120.0, 119.99), 120.0, "a tab after it");
assert_eq!(super::tab_room(None, false, 120.0, 119.99), 119.99, "no leading tab");
}
/// Tabs 100 wide at 0, 100, 200…, for documents `docs` (a document listed twice has two views).
fn slots(docs: &[usize]) -> Vec<(usize, egui::Rect)> {
docs.iter().enumerate().map(|(k, &d)| (d, egui::Rect::from_min_size(egui::pos2(k as f32 * 100.0, 0.0), egui::vec2(100.0, 30.0)))).collect()
+3 -3
View File
@@ -85,9 +85,9 @@ fn the_tab_that_does_not_fit_whole_fills_the_rest_of_the_strip() {
);
}
/// With the last document active, the tabs that end the strip leave room before the » button, and
/// the tab before them fills it with its title shortened instead of the strip starting with that
/// room empty (#8584).
/// With the last document active, the tabs from it to the end leave room before the » button, and
/// the tab before them fills that room with its title shortened instead of the strip ending short
/// of the » button (#8584).
#[test]
fn with_the_last_document_active_the_tab_before_the_shown_ones_fills_the_room() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());