From 0a8c2468ba60e7dd7a5024bce7cbd5520e04230c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 13:00:56 -0800 Subject: [PATCH 1/4] Fix #8584: the document tab that doesn't fit whole fills the rest of the strip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the open documents' tabs don't all fit, the strip stopped at the last tab that fit whole and left the room before the » button empty, even where it could hold most of the next tab. That tab now fills the room with its title shortened and ending in "…", as long as at least 40 pt of the title fits, and its tooltip shows the whole title, wrapped to fit inside the window. An active tab wider than the whole strip is shortened the same way, so its × no longer runs under the » button. --- crates/ui-egui/src/chrome/status_bar.rs | 2 +- crates/ui-egui/src/chrome/tabs.rs | 65 ++++++++++--- crates/ui-egui/src/tests/tab_overflow.rs | 112 ++++++++++++++++++++++- docs/ui-parity.md | 1 + 4 files changed, 163 insertions(+), 17 deletions(-) diff --git a/crates/ui-egui/src/chrome/status_bar.rs b/crates/ui-egui/src/chrome/status_bar.rs index 7c39666f78..57b1b2a457 100644 --- a/crates/ui-egui/src/chrome/status_bar.rs +++ b/crates/ui-egui/src/chrome/status_bar.rs @@ -277,7 +277,7 @@ pub(super) fn clipped_label(ui: &mut Ui, text: impl Into) -> e } /// Show `text` on hover in a tooltip that wraps to fit inside the window. -fn full_text_tooltip(response: egui::Response, text: impl Into) -> egui::Response { +pub(super) fn full_text_tooltip(response: egui::Response, text: impl Into) -> egui::Response { let text = text.into(); response.on_hover_ui(|ui| { let margins = ui.spacing().menu_margin.sum().x + 2.0 * ui.spacing().item_spacing.x; diff --git a/crates/ui-egui/src/chrome/tabs.rs b/crates/ui-egui/src/chrome/tabs.rs index f88372e75b..3392ad905c 100644 --- a/crates/ui-egui/src/chrome/tabs.rs +++ b/crates/ui-egui/src/chrome/tabs.rs @@ -128,9 +128,25 @@ pub(super) fn first_tab_shown(widths: &[f32], active: Option, room: f32) first } +/// 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 { + /// The least width of a tab that holds its × and the ×'s click area. + const CLOSE_ROOM: f32 = 25.0; + if w < CLOSE_ROOM { + return None; + } + let xresp = ui.interact(xr.expand(3.0), id, Sense::click()); + icons::paint(ui, "x", xr, if xresp.hovered() { t.text_strong } else { t.text }); + Some(xresp) +} + /// Document tab strip: "Name* @ 66.67% (RGB/Preview)". User Interface › Large Tabs makes the tabs /// taller, with larger titles. Tabs that don't fit are reached from a » button at the strip's -/// right end, which lists every open document, and the active tab is always in view (#746). +/// right end, which lists every open document, and the active tab is always in view (#746). The +/// first tab that doesn't fit whole fills the room left before the » button with its title +/// shortened, when that room holds some of the title (#8584), and an active tab wider than the +/// whole strip is shortened to it. /// Each view Window › New Window opened has a tab of its own. Windows floating have no tab /// ([`crate::doc_windows`]); while the current window is a floating one, the tab of the window the /// strip shows is the highlighted one. A tab dragged more than [`crate::doc_windows::TEAR_OFF`] @@ -140,6 +156,10 @@ pub(super) fn first_tab_shown(widths: &[f32], active: Option, room: f32) pub fn doc_tabs(app: &mut VectorcraftApp, ui: &mut Ui) { /// The width of the » button. const MORE: f32 = 30.0; + /// A tab's width beyond its title's: the margins and the ×. + const TAB_PADDING: f32 = 50.0; + /// The least width of title a tab shortened to fit the strip shows. + const MIN_TITLE: f32 = 40.0; let t = Tokens::get(ui.ctx()); let (height, title_size) = tab_size(app); let (strip, _) = ui.allocate_exact_size(vec2(ui.available_width(), height), Sense::hover()); @@ -160,7 +180,7 @@ pub fn doc_tabs(app: &mut VectorcraftApp, ui: &mut Ui) { (title.clone(), ui.painter().layout_no_wrap(title, theme::semibold(title_size), color)) }) .collect(); - let widths: Vec = tabs.iter().map(|(_, g)| g.size().x + 50.0).collect(); + let widths: Vec = tabs.iter().map(|(_, g)| g.size().x + TAB_PADDING).collect(); let overflow = widths.iter().sum::() > strip.width(); let room = strip.width() - if overflow { MORE } else { 0.0 }; let first = if overflow { first_tab_shown(&widths, active, room) } else { 0 }; @@ -173,15 +193,33 @@ pub fn doc_tabs(app: &mut VectorcraftApp, ui: &mut Ui) { // the drag just ended), for moving it along the strip. let mut slots: Vec<(usize, egui::Rect)> = vec![]; let mut dragged = None; - for (k, ((_, galley), w)) in tabs.iter().zip(&widths).enumerate().skip(first) { - if x + w > strip.left() + room && Some(k) != active { - break; - } + for (k, ((title, galley), w)) in tabs.iter().zip(&widths).enumerate().skip(first) { + // 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. + let left = strip.left() + room - x; + // A shortened title too wide for its room even as "…" is not drawn, so it stays clear of + // the ×. + let (galley, w, shortened, title_fits) = if *w > left { + if left < TAB_PADDING + MIN_TITLE && Some(k) != active { + break; + } + let color = if Some(k) == active { t.text_strong } else { t.text_dim }; + let mut job = egui::text::LayoutJob::simple_singleline(title.clone(), theme::semibold(title_size), color); + let max_width = (left - TAB_PADDING).max(0.0); + job.wrap = egui::text::TextWrapping { max_width, max_rows: 1, break_anywhere: true, overflow_character: Some('…') }; + let galley = ui.painter().layout_job(job); + let fits = galley.size().x <= max_width; + (galley, left.max(0.0), true, fits) + } else { + (galley.clone(), *w, false, true) + }; let Some(&win) = docked.get(k) else { break }; let i = win.0; let is_active = Some(k) == active; - let r = egui::Rect::from_min_size(egui::pos2(x, strip.top()), vec2(*w, strip.height() - 1.0)); + let r = egui::Rect::from_min_size(egui::pos2(x, strip.top()), vec2(w, strip.height() - 1.0)); let resp = ui.interact(r, ui.scope_id().with(("tab", i, win.1)), Sense::click_and_drag()); + let resp = if shortened { super::status_bar::full_text_tooltip(resp, title.as_str()) } else { resp }; slots.push((i, r)); if resp.dragged() || resp.drag_stopped() { dragged = Some((i, resp.drag_stopped())); @@ -196,13 +234,16 @@ pub fn doc_tabs(app: &mut VectorcraftApp, ui: &mut Ui) { // (#673). let (x_center, title_left) = if CLOSE_BEFORE_TITLE { (r.left() + 16.0, r.left() + 32.0) } else { (r.right() - 16.0, r.left() + 14.0) }; let xr = egui::Rect::from_center_size(egui::pos2(x_center, r.center().y), vec2(12.0, 12.0)); - let xresp = ui.interact(xr.expand(3.0), ui.scope_id().with(("tabx", i, win.1)), Sense::click()); - icons::paint(ui, "x", xr, if xresp.hovered() { t.text_strong } else { t.text }); - ui.painter().galley(egui::pos2(title_left, r.center().y - galley.size().y / 2.0), galley.clone(), t.text); - hovering_art |= crate::document_drag::hover_tab(app, &resp, win, xr.expand(3.0)); + let xresp = tab_close_box(ui, &t, xr, w, ui.scope_id().with(("tabx", i, win.1))); + if title_fits { + ui.painter().galley(egui::pos2(title_left, r.center().y - galley.size().y / 2.0), galley, t.text); + } + let x_area = if xresp.is_some() { xr.expand(3.0) } else { egui::Rect::NOTHING }; + hovering_art |= crate::document_drag::hover_tab(app, &resp, win, x_area); // A middle-click anywhere on the tab closes it as the × does (#6506), so closing a // modified document's last view still asks to save first. - if xresp.clicked() || resp.middle_clicked() || xresp.middle_clicked() { + let x_clicked = xresp.as_ref().is_some_and(|x| x.clicked() || x.middle_clicked()); + if x_clicked || resp.middle_clicked() { close = Some(win); } else if resp.clicked() { activate = Some(win); diff --git a/crates/ui-egui/src/tests/tab_overflow.rs b/crates/ui-egui/src/tests/tab_overflow.rs index 2ed4f866c1..7c7594bde4 100644 --- a/crates/ui-egui/src/tests/tab_overflow.rs +++ b/crates/ui-egui/src/tests/tab_overflow.rs @@ -10,21 +10,27 @@ const SIZE: egui::Vec2 = egui::vec2(1000.0, 700.0); /// Run a tab-strip frame and return the visible texts with their screen rects. fn frame(app: &mut VectorcraftApp, ctx: &egui::Context, time: f64, events: Vec) -> Vec<(String, egui::Rect)> { + frame_sized(app, ctx, SIZE, time, events) +} + +/// [`frame`] in a window `size` large. +fn frame_sized(app: &mut VectorcraftApp, ctx: &egui::Context, size: egui::Vec2, time: f64, events: Vec) -> Vec<(String, egui::Rect)> { let mut out = ctx.run_ui( - egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, SIZE)), time: Some(time), events, ..Default::default() }, + egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, size)), time: Some(time), events, ..Default::default() }, |ui| { egui::CentralPanel::default().show(ui, |ui| chrome::doc_tabs(app, ui)); }, ); out.textures_delta.clear(); - let screen = egui::Rect::from_min_size(Pos2::ZERO, SIZE); - // Texts nested in shape lists too, kept only where their clip rect shows them whole. + let screen = egui::Rect::from_min_size(Pos2::ZERO, size); + // Texts nested in shape lists too, kept only where their clip rect shows them whole, as their + // glyphs draw them (a title shortened to fit ends with its …). fn walk(s: &egui::Shape, clip: egui::Rect, v: &mut Vec<(String, egui::Rect)>) { match s { egui::Shape::Text(t) => { let r = egui::Rect::from_min_size(t.pos, t.galley.size()); if clip.contains_rect(r) { - v.push((t.galley.text().to_owned(), r)); + v.push((t.galley.rows.iter().flat_map(|row| row.glyphs.iter().map(|g| g.chr)).collect(), r)); } } egui::Shape::Vec(list) => list.iter().for_each(|s| walk(s, clip, v)), @@ -42,6 +48,104 @@ fn click(at: Pos2, pressed: bool) -> Event { Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers: Default::default() } } +/// The tab that doesn't fit whole fills the room left before the » button with its title shortened, +/// instead of the strip leaving that room empty (#8584), and its tooltip shows the whole title. +#[test] +fn the_tab_that_does_not_fit_whole_fills_the_rest_of_the_strip() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + // Three tabs about 240 pt wide fit whole; the fourth, with a longer name, doesn't. + for i in 0..8 { + let name = if i == 3 { format!("Tab test {i} with a much longer name") } else { format!("Tab test {i}") }; + app.run("file.new", json!({"width": 100, "height": 100, "name": name})).unwrap(); + } + app.session.set_active(0); + app.sync_views(); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + let texts = frame(&mut app, &ctx, 0.0, vec![]); + let mut tabs: Vec<(String, egui::Rect)> = texts.into_iter().filter(|(t, _)| t.starts_with("Tab test")).collect(); + tabs.sort_by(|a, b| a.1.left().total_cmp(&b.1.left())); + let whole = tabs.iter().filter(|(t, _)| !t.ends_with('…')).count(); + let (short, r) = tabs.last().cloned().unwrap_or_else(|| panic!("tabs are drawn: {tabs:?}")); + assert!((2..8).contains(&whole), "some tabs fit whole and some don't: {tabs:?}"); + assert!(short.ends_with('…'), "a tab with a shortened title follows the whole ones: {tabs:?}"); + assert_eq!(tabs.len(), whole + 1, "one tab is shortened: {tabs:?}"); + // The strip ends 8 pt from the window's edge, and the » button takes its last 30 pt; the tab's + // padding (50 pt with the ×) and less than one character are left over. + let more_left = SIZE.x - 8.0 - 30.0; + assert!(r.right() > more_left - 50.0 - 16.0 && r.right() <= more_left, "the shortened title reaches the » button: {r:?}"); + // The whole title shows in the shortened tab's tooltip. + let name = short.trim_end_matches('…'); + let mut texts = frame(&mut app, &ctx, 1.0, vec![Event::PointerMoved(r.center())]); + for i in 1..20 { + texts = frame(&mut app, &ctx, 1.0 + f64::from(i) * 0.1, vec![]); + } + assert!( + texts.iter().any(|(t, _)| t.starts_with(name) && !t.ends_with('…') && t.contains("(RGB/Preview)")), + "the tooltip shows the whole title: {texts:?}" + ); +} + +/// The active tab with a title wider than the whole strip is shortened to end before the » button, +/// so its × stays on screen, and its tooltip shows the whole title. +#[test] +fn an_active_tab_wider_than_the_strip_is_shortened_to_it() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 100, "height": 100, "name": "Tab test short"})).unwrap(); + let long = format!("Tab test {}", "long name ".repeat(20)); + app.run("file.new", json!({"width": 100, "height": 100, "name": long})).unwrap(); + app.session.set_active(1); + app.sync_views(); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + let texts = frame(&mut app, &ctx, 0.0, vec![]); + let tabs: Vec<(String, egui::Rect)> = texts.into_iter().filter(|(t, _)| t.starts_with("Tab test")).collect(); + let [(short, r)] = tabs.as_slice() else { panic!("only the active tab shows: {tabs:?}") }; + assert!(short.starts_with("Tab test long") && short.ends_with('…'), "{tabs:?}"); + let more_left = SIZE.x - 8.0 - 30.0; + assert!(r.right() <= more_left, "the title ends before the » button: {r:?}"); + let name = short.trim_end_matches('…'); + let mut texts = frame(&mut app, &ctx, 1.0, vec![Event::PointerMoved(r.center())]); + for i in 1..20 { + texts = frame(&mut app, &ctx, 1.0 + f64::from(i) * 0.1, vec![]); + } + assert!(texts.iter().any(|(t, _)| t.starts_with(name) && t.contains("(RGB/Preview)")), "the tooltip shows the whole title: {texts:?}"); + // In a window narrower than a tooltip's usual width, the tooltip wraps the title to fit. + let narrow = egui::vec2(300.0, 400.0); + let texts = frame_sized(&mut app, &ctx, narrow, 3.0, vec![]); + let r = texts.iter().find(|(t, _)| t.starts_with("Tab test long")).map(|(_, r)| *r).unwrap_or_else(|| panic!("{texts:?}")); + let mut texts = frame_sized(&mut app, &ctx, narrow, 4.0, vec![Event::PointerMoved(r.center())]); + for i in 1..20 { + texts = frame_sized(&mut app, &ctx, narrow, 4.0 + f64::from(i) * 0.1, vec![]); + } + let tip = texts.iter().find(|(t, _)| t.contains("(RGB/Preview)")).unwrap_or_else(|| panic!("the tooltip shows in the window: {texts:?}")); + assert!(tip.1.right() <= narrow.x, "{tip:?}"); +} + +/// In a strip too narrow for any of the active tab's title, the title, "…" included, is not drawn +/// over the ×; in one too narrow for the × as well, a click on the tab does not close it. +#[test] +fn an_active_tab_in_a_very_narrow_strip_keeps_clear_of_its_close_box() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 100, "height": 100, "name": "Tab test short"})).unwrap(); + app.run("file.new", json!({"width": 100, "height": 100, "name": "Tab test active"})).unwrap(); + app.session.set_active(1); + app.sync_views(); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + // The strip is 70 pt wide: the » button takes 30 pt and the active tab the other 40 pt. + let texts = frame_sized(&mut app, &ctx, egui::vec2(86.0, 400.0), 0.0, vec![]); + assert!(!texts.iter().any(|(t, r)| r.left() < 48.0 && (t.starts_with("Tab test") || t.contains('…'))), "no title is drawn: {texts:?}"); + // The strip is 50 pt wide, leaving the tab 20 pt: a click on it makes no × close it. + let narrow = egui::vec2(66.0, 400.0); + let at = Pos2::new(18.0, 18.0); + frame_sized(&mut app, &ctx, narrow, 1.0, vec![Event::PointerMoved(at)]); + frame_sized(&mut app, &ctx, narrow, 1.1, vec![click(at, true)]); + frame_sized(&mut app, &ctx, narrow, 1.2, vec![click(at, false)]); + frame_sized(&mut app, &ctx, narrow, 1.3, vec![]); + assert_eq!(app.session.documents().len(), 2, "the click does not close the tab's document"); +} + /// Every document of a large session can be picked from the » list: it scrolls instead of running /// off the bottom of the window. #[test] diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 64e6be0b94..b8f7e6f841 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -415,6 +415,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po | Selection artwork drag hovers a visible document tab to activate it, then drops editable artwork on its canvas | done | `tests_document_drag`, `edit.dropSelection`, lossless resource and one-step Undo regressions; a release over another document's tiled pane copies it there too (`canvas::panes` tests), and so does a release over a floating window drawn inside the main window (`doc_windows` tests); overflow-menu drag and floating OS windows remain separate | | A document tab dragged along the tab strip moves its document; a line marks where it goes, the current document and every document's view stay as they were, and a drag off the strip still floats it | done | #5663, [public source](https://helpx.adobe.com/illustrator/using/customizing-workspace.html); `document.move`; `tests::tab_reorder`, `chrome::tests` (drop index with floating and view tabs), `engine` `tests::document_move` | | A middle-click on a document tab or its × closes it as the × does; closing a modified document's last view asks to save first (VectorCraft addition, as in PhotoCraft) | done | #6506; `chrome::tests::a_middle_click_on_a_tab_closes_it_as_the_close_box_does`; not scored | +| When the document tabs don't all fit, the first tab that doesn't fit whole fills the room before the » button with its title shortened and ending in "…", once at least 40 pt of the title fits; an active tab wider than the strip is shortened to it; the tooltip of a shortened tab shows the whole title, wrapped to the window (VectorCraft's own rule) | done | #8584; `tests::tab_overflow`; not scored | | Panels hidden by Tab or Shift+Tab show for a while when the pointer rests on the left or right edge of the window, over the canvas, and hide again when it moves away; Tab shows them for good | done | Part of #5661; `window.panels.peek` ([Workspace basics](https://web.archive.org/web/2014/https://helpx.adobe.com/illustrator/using/workspace-basics.html), "Hide or show all panels"); VectorCraft's own choices: the 6 pt band and the 0.3 s delays, only the docked panels on that side show (floating panels, Tools and the Control bar stay hidden), and nothing shows in Presentation Mode; `panel_docking::tests::resting_on_the_right_edge_shows_the_hidden_panels_over_the_canvas_until_the_pointer_leaves` and the tests after it | | Behaviour | Status | Notes | From 0f6be1ba6de1f025519d6920e79a0cd4949f5083 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 18:42:52 -0800 Subject: [PATCH 2/4] Tabs: with the last document active, the tab before the shown ones fills the room When the active tab was one of the last documents, the strip showed the tabs from it to the end and left the room before them empty. The tab before them now fills that room with its title shortened, as the tab after the whole ones does. The tab strip takes each tab's window and title from one list, so a docked window without a document no longer shifts which tab is drawn as the active one. The tests check that 3 tabs fit whole and a fourth is shortened in a window 1000 pt wide. --- crates/ui-egui/src/chrome/tabs.rs | 44 +++++++++++++++--------- crates/ui-egui/src/tests/tab_overflow.rs | 29 ++++++++++++++-- docs/ui-parity.md | 2 +- 3 files changed, 55 insertions(+), 20 deletions(-) diff --git a/crates/ui-egui/src/chrome/tabs.rs b/crates/ui-egui/src/chrome/tabs.rs index 3392ad905c..fb99338cda 100644 --- a/crates/ui-egui/src/chrome/tabs.rs +++ b/crates/ui-egui/src/chrome/tabs.rs @@ -128,6 +128,14 @@ pub(super) fn first_tab_shown(widths: &[f32], active: Option, room: f32) first } +/// 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) { + 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 × 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 { @@ -145,8 +153,9 @@ fn tab_close_box(ui: &Ui, t: &Tokens, xr: egui::Rect, w: f32, id: egui::Id) -> O /// taller, with larger titles. Tabs that don't fit are reached from a » button at the strip's /// right end, which lists every open document, and the active tab is always in view (#746). The /// first tab that doesn't fit whole fills the room left before the » button with its title -/// shortened, when that room holds some of the title (#8584), and an active tab wider than the -/// whole strip is shortened to it. +/// shortened, when that room holds some of the title (#8584). When the active tab is among the last +/// ones and the tabs from it to the end leave room, the tab before them fills that room instead. An +/// active tab wider than the whole strip is shortened to it. /// Each view Window › New Window opened has a tab of its own. Windows floating have no tab /// ([`crate::doc_windows`]); while the current window is a floating one, the tab of the window the /// strip shows is the highlighted one. A tab dragged more than [`crate::doc_windows::TEAR_OFF`] @@ -168,22 +177,22 @@ pub fn doc_tabs(app: &mut VectorcraftApp, ui: &mut Ui) { ui.painter().line_segment([strip.left_bottom(), strip.right_bottom()], Stroke::new(1.0, t.border)); // On the Home screen no tab is the current one. let shown = crate::doc_windows::tab_window(app).filter(|_| app.ui.home.is_none()); - // The windows under the tabs; `active` is the position of the highlighted one. - let docked = crate::doc_windows::docked_windows(app); - let active = docked.iter().position(|w| Some(*w) == shown); - let tabs: Vec<(String, std::sync::Arc)> = docked - .iter() - .filter_map(|w| Some((*w, app.session.documents().get(w.0)?))) + // The windows under the tabs, with their titles; `active` is the position of the highlighted one. + let tabs: Vec<(crate::doc_windows::Win, String, std::sync::Arc)> = crate::doc_windows::docked_windows(app) + .into_iter() + .filter_map(|w| Some((w, app.session.documents().get(w.0)?))) .map(|(w, d)| { let title = window_tab_title(app, w, d); let color = if Some(w) == shown { t.text_strong } else { t.text_dim }; - (title.clone(), ui.painter().layout_no_wrap(title, theme::semibold(title_size), color)) + (w, title.clone(), ui.painter().layout_no_wrap(title, theme::semibold(title_size), color)) }) .collect(); - let widths: Vec = tabs.iter().map(|(_, g)| g.size().x + TAB_PADDING).collect(); + let active = tabs.iter().position(|(w, _, _)| Some(*w) == shown); + let widths: Vec = tabs.iter().map(|(_, _, g)| g.size().x + TAB_PADDING).collect(); let overflow = widths.iter().sum::() > strip.width(); let room = strip.width() - if overflow { MORE } else { 0.0 }; let first = if overflow { first_tab_shown(&widths, active, room) } else { 0 }; + let (first, lead) = leading_tab(&widths, first, room, TAB_PADDING + MIN_TITLE); let mut x = strip.left(); let mut activate = None; let mut close = None; @@ -193,18 +202,20 @@ pub fn doc_tabs(app: &mut VectorcraftApp, ui: &mut Ui) { // the drag just ended), for moving it along the strip. let mut slots: Vec<(usize, egui::Rect)> = vec![]; let mut dragged = None; - for (k, ((title, galley), w)) in tabs.iter().zip(&widths).enumerate().skip(first) { + for (k, ((win, title, galley), w)) in tabs.iter().zip(&widths).enumerate().skip(first) { // 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. - let left = strip.left() + room - x; + // 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); + 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 ×. let (galley, w, shortened, title_fits) = if *w > left { - if left < TAB_PADDING + MIN_TITLE && Some(k) != active { + if left < TAB_PADDING + MIN_TITLE && !is_active { break; } - let color = if Some(k) == active { t.text_strong } else { t.text_dim }; + let color = if Some(*win) == shown { t.text_strong } else { t.text_dim }; let mut job = egui::text::LayoutJob::simple_singleline(title.clone(), theme::semibold(title_size), color); let max_width = (left - TAB_PADDING).max(0.0); job.wrap = egui::text::TextWrapping { max_width, max_rows: 1, break_anywhere: true, overflow_character: Some('…') }; @@ -214,9 +225,8 @@ pub fn doc_tabs(app: &mut VectorcraftApp, ui: &mut Ui) { } else { (galley.clone(), *w, false, true) }; - let Some(&win) = docked.get(k) else { break }; + let win = *win; let i = win.0; - let is_active = Some(k) == active; let r = egui::Rect::from_min_size(egui::pos2(x, strip.top()), vec2(w, strip.height() - 1.0)); let resp = ui.interact(r, ui.scope_id().with(("tab", i, win.1)), Sense::click_and_drag()); let resp = if shortened { super::status_bar::full_text_tooltip(resp, title.as_str()) } else { resp }; diff --git a/crates/ui-egui/src/tests/tab_overflow.rs b/crates/ui-egui/src/tests/tab_overflow.rs index 7c7594bde4..186a3f3a21 100644 --- a/crates/ui-egui/src/tests/tab_overflow.rs +++ b/crates/ui-egui/src/tests/tab_overflow.rs @@ -67,9 +67,8 @@ fn the_tab_that_does_not_fit_whole_fills_the_rest_of_the_strip() { tabs.sort_by(|a, b| a.1.left().total_cmp(&b.1.left())); let whole = tabs.iter().filter(|(t, _)| !t.ends_with('…')).count(); let (short, r) = tabs.last().cloned().unwrap_or_else(|| panic!("tabs are drawn: {tabs:?}")); - assert!((2..8).contains(&whole), "some tabs fit whole and some don't: {tabs:?}"); + assert_eq!((whole, tabs.len()), (3, 4), "3 tabs fit whole and one more is shortened: {tabs:?}"); assert!(short.ends_with('…'), "a tab with a shortened title follows the whole ones: {tabs:?}"); - assert_eq!(tabs.len(), whole + 1, "one tab is shortened: {tabs:?}"); // The strip ends 8 pt from the window's edge, and the » button takes its last 30 pt; the tab's // padding (50 pt with the ×) and less than one character are left over. let more_left = SIZE.x - 8.0 - 30.0; @@ -86,6 +85,32 @@ 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). +#[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()); + for i in 0..8 { + app.run("file.new", json!({"width": 100, "height": 100, "name": format!("Tab test {i}")})).unwrap(); + } + app.session.set_active(7); + app.sync_views(); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + let texts = frame(&mut app, &ctx, 0.0, vec![]); + let mut tabs: Vec<(String, egui::Rect)> = texts.into_iter().filter(|(t, _)| t.starts_with("Tab test")).collect(); + tabs.sort_by(|a, b| a.1.left().total_cmp(&b.1.left())); + let whole = tabs.iter().filter(|(t, _)| !t.ends_with('…')).count(); + assert_eq!((whole, tabs.len()), (3, 4), "3 tabs fit whole and one more is shortened: {tabs:?}"); + let (lead, r) = tabs.first().cloned().unwrap_or_else(|| panic!("tabs are drawn: {tabs:?}")); + assert!(lead.starts_with("Tab test 4") && lead.ends_with('…'), "the tab before the shown ones comes first, shortened: {tabs:?}"); + // The strip starts 8 pt from the window's edge, and the title 14 pt into the tab (32 pt on + // macOS, after the ×). + assert!(r.left() <= 8.0 + 32.0 + 1.0, "the shortened tab starts the strip: {r:?}"); + assert!(tabs.last().is_some_and(|(t, _)| t.starts_with("Tab test 7")), "the active tab ends the strip: {tabs:?}"); +} + /// The active tab with a title wider than the whole strip is shortened to end before the » button, /// so its × stays on screen, and its tooltip shows the whole title. #[test] diff --git a/docs/ui-parity.md b/docs/ui-parity.md index b8f7e6f841..1c2475a2da 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -415,7 +415,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po | Selection artwork drag hovers a visible document tab to activate it, then drops editable artwork on its canvas | done | `tests_document_drag`, `edit.dropSelection`, lossless resource and one-step Undo regressions; a release over another document's tiled pane copies it there too (`canvas::panes` tests), and so does a release over a floating window drawn inside the main window (`doc_windows` tests); overflow-menu drag and floating OS windows remain separate | | A document tab dragged along the tab strip moves its document; a line marks where it goes, the current document and every document's view stay as they were, and a drag off the strip still floats it | done | #5663, [public source](https://helpx.adobe.com/illustrator/using/customizing-workspace.html); `document.move`; `tests::tab_reorder`, `chrome::tests` (drop index with floating and view tabs), `engine` `tests::document_move` | | A middle-click on a document tab or its × closes it as the × does; closing a modified document's last view asks to save first (VectorCraft addition, as in PhotoCraft) | done | #6506; `chrome::tests::a_middle_click_on_a_tab_closes_it_as_the_close_box_does`; not scored | -| When the document tabs don't all fit, the first tab that doesn't fit whole fills the room before the » button with its title shortened and ending in "…", once at least 40 pt of the title fits; an active tab wider than the strip is shortened to it; the tooltip of a shortened tab shows the whole title, wrapped to the window (VectorCraft's own rule) | done | #8584; `tests::tab_overflow`; not scored | +| When the document tabs don't all fit, the first tab that doesn't fit whole fills the room before the » button with its title shortened and ending in "…", once that room leaves at least 40 pt for the title; with the active tab among the last ones, the tab before the ones shown fills the room left at the start instead; an active tab wider than the strip is shortened to it, and a tab narrower than 25 pt shows no ×; the tooltip of a shortened tab shows the whole title, wrapped to the window (VectorCraft's own rule) | done | #8584; `tests::tab_overflow`; not scored | | Panels hidden by Tab or Shift+Tab show for a while when the pointer rests on the left or right edge of the window, over the canvas, and hide again when it moves away; Tab shows them for good | done | Part of #5661; `window.panels.peek` ([Workspace basics](https://web.archive.org/web/2014/https://helpx.adobe.com/illustrator/using/workspace-basics.html), "Hide or show all panels"); VectorCraft's own choices: the 6 pt band and the 0.3 s delays, only the docked panels on that side show (floating panels, Tools and the Control bar stay hidden), and nothing shows in Presentation Mode; `panel_docking::tests::resting_on_the_right_edge_shows_the_hidden_panels_over_the_canvas_until_the_pointer_leaves` and the tests after it | | Behaviour | Status | Notes | From 35d2cb680a1cdd197c8e32cb580a785f5183a559 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 19:30:33 -0800 Subject: [PATCH 3/4] Tabs: the tabs after the leading tab are drawn whole MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- crates/ui-egui/src/chrome.rs | 2 +- crates/ui-egui/src/chrome/tabs.rs | 17 ++++++++++++++--- crates/ui-egui/src/chrome/tests.rs | 21 +++++++++++++++++++++ crates/ui-egui/src/tests/tab_overflow.rs | 6 +++--- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index 43b9f5b69c..254a5a0c8b 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -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}; diff --git a/crates/ui-egui/src/chrome/tabs.rs b/crates/ui-egui/src/chrome/tabs.rs index fb99338cda..d23fb775ad 100644 --- a/crates/ui-egui/src/chrome/tabs.rs +++ b/crates/ui-egui/src/chrome/tabs.rs @@ -131,11 +131,21 @@ pub(super) fn first_tab_shown(widths: &[f32], active: Option, 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) { +pub(super) fn leading_tab(widths: &[f32], first: usize, room: f32, least: f32) -> (usize, Option) { 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, 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 { @@ -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 ×. diff --git a/crates/ui-egui/src/chrome/tests.rs b/crates/ui-egui/src/chrome/tests.rs index 4c9506b13c..1fd8245365 100644 --- a/crates/ui-egui/src/chrome/tests.rs +++ b/crates/ui-egui/src/chrome/tests.rs @@ -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() diff --git a/crates/ui-egui/src/tests/tab_overflow.rs b/crates/ui-egui/src/tests/tab_overflow.rs index 186a3f3a21..11d7d273db 100644 --- a/crates/ui-egui/src/tests/tab_overflow.rs +++ b/crates/ui-egui/src/tests/tab_overflow.rs @@ -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()); From 3ed0218033a157fab6dc832e318b14a45e05e184 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 19:49:24 -0800 Subject: [PATCH 4/4] Tabs: a shortened title shows at fractional tab widths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit egui rounds a wrap width to the nearest point, so a shortened title laid out for 66.5 pt could come out 67 pt wide, and the tab then hid it as too wide for its room. The width is now rounded down before the title is laid out. A new test lays the title out at every quarter point from the width of "…" to 200 pt and checks that each one fits. --- crates/ui-egui/src/chrome.rs | 2 +- crates/ui-egui/src/chrome/tabs.rs | 24 +++++++++++++++++++----- crates/ui-egui/src/chrome/tests.rs | 23 +++++++++++++++++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index 254a5a0c8b..e0338b5253 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -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, leading_tab, tab_drop, tab_groups, tab_room, tab_title}; +use tabs::{CLOSE_BEFORE_TITLE, first_tab_shown, leading_tab, shortened_title, 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}; diff --git a/crates/ui-egui/src/chrome/tabs.rs b/crates/ui-egui/src/chrome/tabs.rs index d23fb775ad..4f7666e171 100644 --- a/crates/ui-egui/src/chrome/tabs.rs +++ b/crates/ui-egui/src/chrome/tabs.rs @@ -146,6 +146,24 @@ pub(super) fn tab_room(lead: Option, leading: bool, w: f32, left: f32) -> f } } +/// `title` in one line at most `max_width` wide, ending in "…" when it is cut short, and whether +/// it fits in `max_width`. egui rounds a wrap width to the nearest point, so the width is rounded +/// down first. +pub(super) fn shortened_title( + ctx: &egui::Context, + title: &str, + font: egui::FontId, + color: egui::Color32, + max_width: f32, +) -> (std::sync::Arc, bool) { + let max_width = max_width.max(0.0); + let mut job = egui::text::LayoutJob::simple_singleline(title.to_owned(), font, color); + job.wrap = egui::text::TextWrapping { max_width: max_width.floor(), max_rows: 1, break_anywhere: true, overflow_character: Some('…') }; + let galley = ctx.fonts_mut(|f| f.layout_job(job)); + let fits = galley.size().x <= max_width; + (galley, fits) +} + /// 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 { @@ -227,11 +245,7 @@ pub fn doc_tabs(app: &mut VectorcraftApp, ui: &mut Ui) { break; } let color = if Some(*win) == shown { t.text_strong } else { t.text_dim }; - let mut job = egui::text::LayoutJob::simple_singleline(title.clone(), theme::semibold(title_size), color); - let max_width = (left - TAB_PADDING).max(0.0); - job.wrap = egui::text::TextWrapping { max_width, max_rows: 1, break_anywhere: true, overflow_character: Some('…') }; - let galley = ui.painter().layout_job(job); - let fits = galley.size().x <= max_width; + let (galley, fits) = shortened_title(ui.ctx(), title, theme::semibold(title_size), color, left - TAB_PADDING); (galley, left.max(0.0), true, fits) } else { (galley.clone(), *w, false, true) diff --git a/crates/ui-egui/src/chrome/tests.rs b/crates/ui-egui/src/chrome/tests.rs index 1fd8245365..cfe22456a4 100644 --- a/crates/ui-egui/src/chrome/tests.rs +++ b/crates/ui-egui/src/chrome/tests.rs @@ -29,6 +29,29 @@ fn the_tabs_after_the_leading_one_are_drawn_whole() { assert_eq!(super::tab_room(None, false, 120.0, 119.99), 119.99, "no leading tab"); } +/// A shortened title shows at every width that holds "…", fractional ones included (#8584). +#[test] +fn a_shortened_title_fits_at_fractional_widths() { + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + let font = crate::theme::semibold(13.0); + let title = "Untitled-12 @ 66.67 % (RGB/Preview)"; + let mut too_wide = vec![]; + let mut output = ctx.run_ui(egui::RawInput::default(), |ui| { + let (ellipsis, _) = super::shortened_title(ui.ctx(), "…", font.clone(), egui::Color32::WHITE, 1000.0); + let mut width = ellipsis.size().x.ceil() + 1.0; + while width < 200.0 { + let (galley, fits) = super::shortened_title(ui.ctx(), title, font.clone(), egui::Color32::WHITE, width); + if !fits { + too_wide.push((width, galley.size().x)); + } + width += 0.25; + } + }); + output.textures_delta.clear(); + assert!(too_wide.is_empty(), "shortened titles wider than their room (room, width): {too_wide:?}"); +} + /// 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()