mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 12:38:18 +00:00
Merge pull request #8637 from dotCooCoo/fix/issue-8584
Fix #8584: the document tab that doesn't fit whole fills the rest of the strip
This commit is contained in:
@@ -33,7 +33,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, 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};
|
||||
|
||||
|
||||
@@ -277,7 +277,7 @@ pub(super) fn clipped_label(ui: &mut Ui, text: impl Into<egui::WidgetText>) -> 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::WidgetText>) -> egui::Response {
|
||||
pub(super) fn full_text_tooltip(response: egui::Response, text: impl Into<egui::WidgetText>) -> 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;
|
||||
|
||||
@@ -128,9 +128,62 @@ 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.
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
/// `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<egui::Galley>, 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<egui::Response> {
|
||||
/// 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). 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`]
|
||||
@@ -140,6 +193,10 @@ pub(super) fn first_tab_shown(widths: &[f32], active: Option<usize>, 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());
|
||||
@@ -148,22 +205,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 + 50.0).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;
|
||||
@@ -173,15 +230,31 @@ 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;
|
||||
}
|
||||
let Some(&win) = docked.get(k) else { break };
|
||||
let i = win.0;
|
||||
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. The
|
||||
// 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;
|
||||
let r = egui::Rect::from_min_size(egui::pos2(x, strip.top()), vec2(*w, strip.height() - 1.0));
|
||||
// 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 && !is_active {
|
||||
break;
|
||||
}
|
||||
let color = if Some(*win) == shown { t.text_strong } else { t.text_dim };
|
||||
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)
|
||||
};
|
||||
let win = *win;
|
||||
let i = win.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 +269,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);
|
||||
|
||||
@@ -8,6 +8,50 @@ 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");
|
||||
}
|
||||
|
||||
/// 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()
|
||||
|
||||
@@ -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<Event>) -> 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<Event>) -> 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,129 @@ 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_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:?}");
|
||||
// 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:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// 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());
|
||||
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]
|
||||
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]
|
||||
|
||||
@@ -423,6 +423,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 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