mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 12:38:18 +00:00
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.
This commit is contained in:
@@ -128,6 +128,14 @@ pub(super) fn first_tab_shown(widths: &[f32], active: Option<usize>, 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<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 × 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> {
|
||||
@@ -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<egui::Galley>)> = 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<egui::Galley>)> = 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<f32> = tabs.iter().map(|(_, g)| g.size().x + TAB_PADDING).collect();
|
||||
let active = tabs.iter().position(|(w, _, _)| Some(*w) == shown);
|
||||
let widths: Vec<f32> = tabs.iter().map(|(_, _, g)| g.size().x + TAB_PADDING).collect();
|
||||
let overflow = widths.iter().sum::<f32>() > 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 };
|
||||
|
||||
@@ -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]
|
||||
|
||||
+1
-1
@@ -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 |
|
||||
|
||||
Reference in New Issue
Block a user