PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Document tabs: elide and overflow into a » menu when they are too many (#1276) (#1293)
Fahad Faruqib44133c8b3e3
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rsindex 248a3a7e4..a2196eef5 100644--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@ -1133,88 +1133,140 @@ fn tabs(app: &mut PhotocraftApp, ui: &mut egui::Ui) -> TabStrip {return pro_tabs(app, ui);}let active = app.session.active_index();+ let tab_count = app.session.documents().len();+ let mut doc_tabs = Vec::with_capacity(tab_count);let mut activate = None;let mut close = None;let mut tab_action = None;- let tab_count = app.session.documents().len();let (mut focus_open, mut cancel_open) = (None, None);let focused_open = app.jobs.focus.is_some();// Layers dragged over a tab show its document (`layer_transfer`).let dragging = crate::layer_transfer::pointer_if_armed(app, ui.ctx());let mut drag_over = None;- let mut doc_tabs = Vec::with_capacity(tab_count);+ let font = crate::theme::medium(12.5);+ let meta_font = egui::FontId::proportional(10.5);+ // Files opening in the background (#210) are tabs too; they share the fit's index space,+ // after the documents.+ let opening = crate::jobs_ui::open_tabs(app);+ // Every tab's natural width, whether or not it stays on the strip.+ let natural: Vec<f32> = app+ .session+ .documents()+ .iter()+ .map(|st| {+ let name = format!("{}{}", st.doc.name, if st.is_dirty() { " *" } else { "" });+ ui.painter().layout_no_wrap(name, font.clone(), t.text).size().x+ + ui.painter().layout_no_wrap(format!("{}/{}", mode_label(&st.doc), st.doc.depth.bits()), meta_font.clone(), t.text_faint).size().x+ + STUDIO_TAB_PAD+ })+ .chain(opening.iter().map(|(_, name, frac)| {+ ui.painter().layout_no_wrap(name.clone(), font.clone(), t.text).size().x+ + ui.painter().layout_no_wrap(format!("{:.0}%", frac * 100.0), meta_font.clone(), t.text_faint).size().x+ + STUDIO_TAB_PAD+ }))+ .collect();+ let selected = app+ .jobs+ .focus+ .and_then(|job| opening.iter().position(|(open, _, _)| *open == job))+ .map_or_else(|| app.session.active_index().unwrap_or(0), |p| tab_count + p);let frame = egui::Frame::NONE.fill(t.canvas).inner_margin(egui::Margin { left: 8, right: 8, top: 6, bottom: 4 }).show(ui, |ui| {- ui.horizontal(|ui| {- ui.spacing_mut().item_spacing.x = 4.0;- for (i, st) in app.session.documents().iter().enumerate() {- let sel = Some(i) == active && !focused_open;- let name = format!("{}{}", st.doc.name, if st.is_dirty() { " *" } else { "" });- let meta = format!("{}/{}", mode_label(&st.doc), st.doc.depth.bits());- let name_g = ui.painter().layout_no_wrap(name, crate::theme::medium(12.5), t.text);- let meta_g = ui.painter().layout_no_wrap(meta, egui::FontId::proportional(10.5), t.text_faint);- let w = name_g.size().x + meta_g.size().x + 44.0;- let (r, resp) = ui.allocate_exact_size(egui::vec2(w, 26.0), Sense::click());- resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::SelectableLabel, true, sel, &st.doc.name));- doc_tabs.push(r);- if sel {- ui.painter().rect_filled(r, t.radius_sm, t.card);- ui.painter().rect_stroke(r, t.radius_sm, Stroke::new(1.0, t.card_border), egui::StrokeKind::Inside);- } else if resp.hovered() {- ui.painter().rect_filled(r, t.radius_sm, t.hover.gamma_multiply(0.5));- }- if dragging.is_some_and(|p| r.contains(p)) {- drag_over = Some(i);- ui.painter().rect_stroke(r, t.radius_sm, Stroke::new(1.5, t.accent), egui::StrokeKind::Inside);- }- let color = if sel { t.text } else { t.text_dim };- let ny = r.center().y - name_g.size().y / 2.0;- ui.painter().galley_with_override_text_color(egui::pos2(r.left() + 10.0, ny), name_g.clone(), color);- ui.painter().galley(egui::pos2(r.left() + 16.0 + name_g.size().x, r.center().y - meta_g.size().y / 2.0), meta_g, t.text_faint);- let xr = Rect::from_center_size(egui::pos2(r.right() - 12.0, r.center().y), egui::vec2(16.0, 16.0));- let xresp = ui.interact(xr, ui.id().with(("tabx", i)), Sense::click());- if xresp.hovered() {- ui.painter().rect_filled(xr, 4.0, t.hover);- }- crate::icons::paint(ui, xr, "x", 11.0, if xresp.hovered() { t.text } else { t.text_faint });- if xresp.clicked() {- close = Some(i);- } else if resp.clicked() {- activate = Some(i);- }- resp.context_menu(|ui| {- tab_action = tab_context_menu(ui, i, tab_count);- });- }- // Files opening in the background: a tab with a progress underline; × cancels.- for (job, name, frac) in crate::jobs_ui::open_tabs(app) {- let sel = app.jobs.focus == Some(job);- let name_g = ui.painter().layout_no_wrap(name, crate::theme::medium(12.5), t.text);- let meta_g = ui.painter().layout_no_wrap(format!("{:.0}%", frac * 100.0), egui::FontId::proportional(10.5), t.text_faint);- let w = name_g.size().x + meta_g.size().x + 44.0;- let (r, resp) = ui.allocate_exact_size(egui::vec2(w, 26.0), Sense::click());- if sel {- ui.painter().rect_filled(r, t.radius_sm, t.card);- ui.painter().rect_stroke(r, t.radius_sm, Stroke::new(1.0, t.card_border), egui::StrokeKind::Inside);- } else if resp.hovered() {- ui.painter().rect_filled(r, t.radius_sm, t.hover.gamma_multiply(0.5));- }- let ny = r.center().y - name_g.size().y / 2.0;- ui.painter().galley_with_override_text_color(egui::pos2(r.left() + 10.0, ny), name_g.clone(), if sel { t.text } else { t.text_dim });- ui.painter().galley(egui::pos2(r.left() + 16.0 + name_g.size().x, r.center().y - meta_g.size().y / 2.0), meta_g, t.text_faint);- crate::jobs_ui::tab_underline(ui, r, frac, &t);- let xr = Rect::from_center_size(egui::pos2(r.right() - 12.0, r.center().y), egui::vec2(16.0, 16.0));- let xresp = ui.interact(xr, ui.id().with(("tabjobx", job.0)), Sense::click());- if xresp.hovered() {- ui.painter().rect_filled(xr, 4.0, t.hover);- }- crate::icons::paint(ui, xr, "x", 11.0, if xresp.hovered() { t.text } else { t.text_faint });- if xresp.on_hover_text(tl!("Cancel opening")).clicked() {- cancel_open = Some(job);- } else if resp.clicked() {- focus_open = Some(job);- }+ let (row, _) = ui.allocate_exact_size(egui::vec2(ui.available_width(), 26.0), Sense::hover());+ let f = crate::tab_strip::fit(&natural, selected, row.width(), DOC_TAB_MIN_W, crate::tab_strip::CHEVRON_W);+ let mut x = row.left();+ let mut placed: Vec<(usize, Rect)> = Vec::with_capacity(f.shown.len());+ for &(i, w) in &f.shown {+ // The old horizontal layout put 4 pt between tabs; `w` carries it, the tab doesn't.+ let r = Rect::from_min_size(egui::pos2(x, row.top()), egui::vec2((w - STUDIO_TAB_GAP).max(8.0), row.height()));+ placed.push((i, r));+ x = r.right() + STUDIO_TAB_GAP;+ }+ for &(i, r) in placed.iter().filter(|(i, _)| *i < tab_count) {+ let Some(st) = app.session.documents().get(i) else { continue };+ let sel = Some(i) == active && !focused_open;+ let name = format!("{}{}", st.doc.name, if st.is_dirty() { " *" } else { "" });+ let meta = format!("{}/{}", mode_label(&st.doc), st.doc.depth.bits());+ let natural_w = natural.get(i).copied().unwrap_or(0.0);+ let meta_g = ui.painter().layout_no_wrap(meta, meta_font.clone(), t.text_faint);+ let name_max = (r.width() - STUDIO_TAB_PAD + STUDIO_TAB_GAP - meta_g.size().x).max(1.0);+ let name_g = crate::tab_strip::elided(ui, &name, font.clone(), t.text, name_max);+ // The title was cut: the tooltip has the rest of it.+ let cut = name_g.size().x + 0.5 < natural_w - STUDIO_TAB_PAD + STUDIO_TAB_GAP - meta_g.size().x;+ let resp = ui.interact(r, ui.id().with(("dtab", i)), Sense::click());+ resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::SelectableLabel, true, sel, &st.doc.name));+ doc_tabs.push(r);+ if sel {+ ui.painter().rect_filled(r, t.radius_sm, t.card);+ ui.painter().rect_stroke(r, t.radius_sm, Stroke::new(1.0, t.card_border), egui::StrokeKind::Inside);+ } else if resp.hovered() {+ ui.painter().rect_filled(r, t.radius_sm, t.hover.gamma_multiply(0.5));}- });+ if dragging.is_some_and(|p| r.contains(p)) {+ drag_over = Some(i);+ ui.painter().rect_stroke(r, t.radius_sm, Stroke::new(1.5, t.accent), egui::StrokeKind::Inside);+ }+ let color = if sel { t.text } else { t.text_dim };+ let ny = r.center().y - name_g.size().y / 2.0;+ ui.painter().galley_with_override_text_color(egui::pos2(r.left() + 10.0, ny), name_g.clone(), color);+ ui.painter().galley(egui::pos2(r.left() + 16.0 + name_g.size().x, r.center().y - meta_g.size().y / 2.0), meta_g, t.text_faint);+ let xr = Rect::from_center_size(egui::pos2(r.right() - 12.0, r.center().y), egui::vec2(16.0, 16.0));+ let xresp = ui.interact(xr, ui.id().with(("dtabx", i)), Sense::click());+ if xresp.hovered() {+ ui.painter().rect_filled(xr, 4.0, t.hover);+ }+ crate::icons::paint(ui, xr, "x", 11.0, if xresp.hovered() { t.text } else { t.text_faint });+ let resp = if cut { resp.on_hover_text(name) } else { resp };+ if xresp.clicked() {+ close = Some(i);+ } else if resp.clicked() {+ activate = Some(i);+ }+ resp.context_menu(|ui| {+ tab_action = tab_context_menu(ui, i, tab_count);+ });+ }+ // Files opening in the background: a tab with a progress underline; × cancels.+ for &(i, r) in placed.iter().filter(|(i, _)| *i >= tab_count) {+ let Some((job, name, frac)) = opening.get(i - tab_count) else { continue };+ let sel = app.jobs.focus == Some(*job);+ let meta_g = ui.painter().layout_no_wrap(format!("{:.0}%", frac * 100.0), meta_font.clone(), t.text_faint);+ let name_g = crate::tab_strip::elided(ui, name, font.clone(), t.text, (r.width() - STUDIO_TAB_PAD + STUDIO_TAB_GAP - meta_g.size().x).max(1.0));+ let resp = ui.interact(r, ui.id().with(("dtabjob", job.0)), Sense::click());+ if sel {+ ui.painter().rect_filled(r, t.radius_sm, t.card);+ ui.painter().rect_stroke(r, t.radius_sm, Stroke::new(1.0, t.card_border), egui::StrokeKind::Inside);+ } else if resp.hovered() {+ ui.painter().rect_filled(r, t.radius_sm, t.hover.gamma_multiply(0.5));+ }+ let ny = r.center().y - name_g.size().y / 2.0;+ ui.painter().galley_with_override_text_color(egui::pos2(r.left() + 10.0, ny), name_g.clone(), if sel { t.text } else { t.text_dim });+ ui.painter().galley(egui::pos2(r.left() + 16.0 + name_g.size().x, r.center().y - meta_g.size().y / 2.0), meta_g, t.text_faint);+ crate::jobs_ui::tab_underline(ui, r, *frac, &t);+ let xr = Rect::from_center_size(egui::pos2(r.right() - 12.0, r.center().y), egui::vec2(16.0, 16.0));+ let xresp = ui.interact(xr, ui.id().with(("dtabjobx", job.0)), Sense::click());+ if xresp.hovered() {+ ui.painter().rect_filled(xr, 4.0, t.hover);+ }+ crate::icons::paint(ui, xr, "x", 11.0, if xresp.hovered() { t.text } else { t.text_faint });+ if xresp.on_hover_text(tl!("Cancel opening")).clicked() {+ cancel_open = Some(*job);+ } else if resp.clicked() {+ focus_open = Some(*job);+ }+ }+ if !f.overflow.is_empty() {+ let left = x.min((row.right() - crate::tab_strip::CHEVRON_W).max(row.left()));+ let r = Rect::from_min_size(egui::pos2(left, row.top()), egui::vec2(crate::tab_strip::CHEVRON_W, row.height()));+ let labels: Vec<&str> =+ app.session.documents().iter().map(|st| st.doc.name.as_str()).chain(opening.iter().map(|(_, name, _)| name.as_str())).collect();+ let mut picked = None;+ crate::tab_strip::overflow_button(ui, ui.id().with("dtab-overflow"), r, tl!("More documents"), &labels, &f.overflow, &mut picked);+ match picked {+ Some(i) if i < tab_count => activate = Some(i),+ Some(i) => focus_open = opening.get(i - tab_count).map(|(job, _, _)| *job).or(focus_open),+ None => {}+ }+ }});open_tab_clicks(app, activate, focus_open, cancel_open);if let Some(i) = drag_over {@@ -1275,7 +1327,30 @@ fn open_tab_clicks(}}+/// Document tabs: the chrome around a title (the × and its gaps), and the width a tab shrinks to+/// before it moves into the » overflow menu.+const DOC_TAB_PAD: f32 = 42.0;+const DOC_TAB_MIN_W: f32 = 72.0;+/// The Studio strip's tabs carried 4 pt of spacing between them and 44 pt of chrome; `fit` sees+/// one number per tab, so the gap rides in the natural width and comes back out when painted.+const STUDIO_TAB_PAD: f32 = 48.0;+const STUDIO_TAB_GAP: f32 = 4.0;++/// Photoshop's tab title: "name @ 50% (Layer 1, RGB/8)", "(Layer 1, Layer Mask/8)" when the mask+/// is targeted; the Background layer's name is omitted.+fn pro_tab_title(app: &PhotocraftApp, i: usize) -> String {+ let Some(st) = app.session.documents().get(i) else { return String::new() };+ let zoom = app.ui.views.get(i).map_or(100.0, |v| v.zoom * 100.0);+ let active_layer = st.active_layer.and_then(|id| st.doc.layer(id)).filter(|l| !(l.name == "Background" && l.locks.transparency));+ let mask = app.session.active_index() == Some(i) && app.ui.mask_target && active_layer.is_some_and(|l| l.mask.is_some());+ let model = if mask { tl!("Layer Mask").to_string() } else { mode_label(&st.doc).to_string() };+ let layer = active_layer.map(|l| format!("{}, ", l.name)).unwrap_or_default();+ format!("{} @ {}% ({layer}{model}/{}){}", st.doc.name, fmt_zoom(zoom), st.doc.depth.bits(), if st.is_dirty() { "*" } else { "" })+}+/// Photoshop document tabs: "name @ 33.3% (RGB/8)" on a dark strip; active tab matches panels.+/// Tabs that don't fit shrink and elide, and the ones that still don't fit move into a » menu at+/// the end of the strip; the active document's tab always stays on the strip (#1276).fn pro_tabs(app: &mut PhotocraftApp, ui: &mut egui::Ui) -> TabStrip {let t = crate::theme::Tokens::get(ui.ctx());let active = app.session.active_index().filter(|_| app.jobs.focus.is_none());@@ -1285,23 +1360,34 @@ fn pro_tabs(app: &mut PhotocraftApp, ui: &mut egui::Ui) -> TabStrip {let dragging = crate::layer_transfer::pointer_if_armed(app, ui.ctx());let mut drag_over = None;let mac = ui.ctx().os() == egui::os::OperatingSystem::Mac;+ let font = egui::FontId::proportional(11.5);let (strip, _) = ui.allocate_exact_size(egui::vec2(ui.available_width(), 26.0), Sense::hover());ui.painter().rect_filled(strip, 0.0, t.tab_strip);+ // Files opening in the background (#210) are tabs too ("name (Opening… 45%)" with a progress+ // underline); they share the fit's index space, after the documents.+ let opening = crate::jobs_ui::open_tabs(app);+ let mut titles: Vec<String> = (0..tab_count).map(|i| pro_tab_title(app, i)).collect();+ titles.extend(opening.iter().map(|(_, name, frac)| format!("{name} ({} {:.0}%)", tl!("Opening…"), frac * 100.0)));+ // Every tab's natural width, whether or not it stays on the strip.+ let natural: Vec<f32> = titles.iter().map(|title| ui.painter().layout_no_wrap(title.clone(), font.clone(), t.text).size().x + DOC_TAB_PAD).collect();+ let selected = app+ .jobs+ .focus+ .and_then(|job| opening.iter().position(|(open, _, _)| *open == job))+ .map_or_else(|| app.session.active_index().unwrap_or(0), |p| tab_count + p);+ let f = crate::tab_strip::fit(&natural, selected, strip.width(), DOC_TAB_MIN_W, crate::tab_strip::CHEVRON_W);let mut x = strip.left();+ let mut placed: Vec<(usize, Rect)> = Vec::with_capacity(f.shown.len());+ for &(i, w) in &f.shown {+ let r = Rect::from_min_size(egui::pos2(x, strip.top()), egui::vec2(w, strip.height()));+ placed.push((i, r));+ x = r.right();+ }let mut doc_tabs = Vec::with_capacity(tab_count);- for (i, st) in app.session.documents().iter().enumerate() {- let zoom = app.ui.views.get(i).map_or(100.0, |v| v.zoom * 100.0);- // Photoshop: "name @ 50% (Layer 1, RGB/8)", "(Layer 1, Layer Mask/8)" when the mask is targeted;- // the Background layer's name is omitted.- let active_layer = st.active_layer.and_then(|id| st.doc.layer(id)).filter(|l| !(l.name == "Background" && l.locks.transparency));- let is_active_doc = app.session.active_index() == Some(i);- let mask = is_active_doc && app.ui.mask_target && active_layer.is_some_and(|l| l.mask.is_some());- let model = if mask { tl!("Layer Mask").to_string() } else { mode_label(&st.doc).to_string() };- let layer = active_layer.map(|l| format!("{}, ", l.name)).unwrap_or_default();- let title = format!("{} @ {}% ({layer}{model}/{}){}", st.doc.name, fmt_zoom(zoom), st.doc.depth.bits(), if st.is_dirty() { "*" } else { "" });- let g = ui.painter().layout_no_wrap(title, egui::FontId::proportional(11.5), t.text);- let r = Rect::from_min_size(egui::pos2(x, strip.top()), egui::vec2(g.size().x + 42.0, strip.height()));- doc_tabs.push(r);+ let (mut focus_open, mut cancel_open) = (None, None);+ for &(i, r) in placed.iter().filter(|(i, _)| *i < tab_count) {+ let Some(title) = titles.get(i) else { continue };+ let g = crate::tab_strip::elided(ui, title, font.clone(), t.text, (r.width() - DOC_TAB_PAD).max(1.0));let resp = ui.interact(r, ui.id().with(("ptab", i)), Sense::click());let sel = Some(i) == active;if sel {@@ -1321,6 +1407,8 @@ fn pro_tabs(app: &mut PhotocraftApp, ui: &mut egui::Ui) -> TabStrip {xresp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, tl!("Close")));crate::icons::paint(ui, xr, "x", 10.0, if xresp.hovered() { t.text } else { t.text_faint });ui.painter().galley_with_override_text_color(at, g, if sel { t.text } else { t.text_faint });+ let cut = natural.get(i).copied().unwrap_or(0.0) > r.width() + 0.5;+ let resp = if cut { resp.on_hover_text(title.as_str()) } else { resp };if xresp.clicked() {close = Some(i);} else if resp.clicked() {@@ -1329,33 +1417,43 @@ fn pro_tabs(app: &mut PhotocraftApp, ui: &mut egui::Ui) -> TabStrip {resp.context_menu(|ui| {tab_action = tab_context_menu(ui, i, tab_count);});- x = r.right();+ doc_tabs.push(r);}- // Files opening in the background (#210): "name (Opening… 45%)" with a progress underline.- let (mut focus_open, mut cancel_open) = (None, None);- for (job, name, frac) in crate::jobs_ui::open_tabs(app) {- let title = format!("{name} ({} {:.0}%)", tl!("Opening…"), frac * 100.0);- let g = ui.painter().layout_no_wrap(title, egui::FontId::proportional(11.5), t.text);- let r = Rect::from_min_size(egui::pos2(x, strip.top()), egui::vec2(g.size().x + 42.0, strip.height()));+ for &(i, r) in placed.iter().filter(|(i, _)| *i >= tab_count) {+ let Some((job, _, frac)) = opening.get(i - tab_count) else { continue };+ let Some(title) = titles.get(i) else { continue };+ let g = crate::tab_strip::elided(ui, title, font.clone(), t.text, (r.width() - DOC_TAB_PAD).max(1.0));let resp = ui.interact(r, ui.id().with(("ptabjob", job.0)), Sense::click());- let sel = app.jobs.focus == Some(job);+ let sel = app.jobs.focus == Some(*job);if sel {ui.painter().rect_filled(r, 0.0, t.chrome);} else if resp.hovered() {ui.painter().rect_filled(r, 0.0, t.hover.gamma_multiply(0.35));}ui.painter().line_segment([r.right_top(), r.right_bottom()], Stroke::new(1.0, t.separator));- crate::jobs_ui::tab_underline(ui, r, frac, &t);+ crate::jobs_ui::tab_underline(ui, r, *frac, &t);let (xr, at) = pro_tab_layout(r, g.size().y, mac);let xresp = ui.interact(xr, ui.id().with(("ptabjobx", job.0)), Sense::click());+ xresp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, tl!("Close")));crate::icons::paint(ui, xr, "x", 10.0, if xresp.hovered() { t.text } else { t.text_faint });ui.painter().galley_with_override_text_color(at, g, if sel { t.text } else { t.text_faint });if xresp.on_hover_text(tl!("Cancel opening")).clicked() {- cancel_open = Some(job);+ cancel_open = Some(*job);} else if resp.clicked() {- focus_open = Some(job);+ focus_open = Some(*job);+ }+ }+ if !f.overflow.is_empty() {+ let left = x.min((strip.right() - crate::tab_strip::CHEVRON_W).max(strip.left()));+ let r = Rect::from_min_size(egui::pos2(left, strip.top()), egui::vec2(crate::tab_strip::CHEVRON_W, strip.height()));+ let labels: Vec<&str> = titles.iter().map(String::as_str).collect();+ let mut picked = None;+ crate::tab_strip::overflow_button(ui, ui.id().with("ptab-overflow"), r, tl!("More documents"), &labels, &f.overflow, &mut picked);+ match picked {+ Some(i) if i < tab_count => activate = Some(i),+ Some(i) => focus_open = opening.get(i - tab_count).map(|(job, _, _)| *job).or(focus_open),+ None => {}}- x = r.right();}open_tab_clicks(app, activate, focus_open, cancel_open);if let Some(i) = drag_over {@@ -3099,6 +3197,9 @@ fn hex(c: [f32; 4]) -> String {format!("#{:02x}{:02x}{:02x}", b(c[0]), b(c[1]), b(c[2]))}+#[cfg(test)]+mod tabs_tests;+#[cfg(test)]mod tests {#[test]diff --git a/crates/ui-egui/src/canvas/tabs_tests.rs b/crates/ui-egui/src/canvas/tabs_tests.rsnew file mode 100644index 000000000..94e7cb9b1--- /dev/null+++ b/crates/ui-egui/src/canvas/tabs_tests.rs@@ -0,0 +1,88 @@+//! #1276: a document tab strip with more tabs than fit keeps the active document's tab on the+//! strip, shrinks and elides the others, and moves the rest into a » menu (whole app, real tree).++use egui::vec2;+use egui_kittest::Harness;+use egui_kittest::kittest::Queryable;+use serde_json::json;++use crate::PhotocraftApp;+use crate::theme::ThemeKind;++use super::{TabStrip, pro_tab_title};++/// A real app window with `docs` documents named "ch1-pNN.png".+fn harness(docs: usize, theme: ThemeKind) -> Harness<'static, PhotocraftApp> {+ let mut h = Harness::builder().with_size(vec2(1000.0, 700.0)).with_max_steps(64).build_eframe(move |cc| {+ PhotocraftApp::setup_context(&cc.egui_ctx, theme);+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());+ // The theme is an interface preference, applied on the first frame: set the preference.+ app.run("prefs.set", json!({"values": {"interface.theme": theme.id()}})).unwrap();+ for n in 1..=docs {+ app.run("file.new", json!({"width": 400, "height": 300, "name": format!("ch1-p{n:02}.png")})).unwrap();+ }+ app+ });+ h.run_steps(4);+ h+}++fn strip(h: &Harness<'_, PhotocraftApp>) -> TabStrip {+ h.state().tab_strip.clone().expect("the strip is drawn")+}++fn has_menu(h: &Harness<'_, PhotocraftApp>) -> bool {+ h.query_by_label("More documents").is_some()+}++#[test]+fn overflowing_tabs_stay_on_the_strip_and_the_rest_move_to_the_menu() {+ let h = harness(14, ThemeKind::Pro);+ assert_eq!(h.state().session.documents().len(), 14);+ let s = strip(&h);+ assert!(s.tabs.len() < 14, "some tabs must overflow into the menu: {} shown", s.tabs.len());+ for r in &s.tabs {+ assert!(s.rect.contains_rect(*r), "a tab runs past the strip: {r:?} in {:?}", s.rect);+ }+ assert!(has_menu(&h), "the strip carries a » menu while tabs are hidden");+ // The active document is the first thing the fit keeps: its tab is on the strip, not behind+ // the menu, however many tabs are open (#1276).+ let title = pro_tab_title(h.state(), h.state().session.active_index().unwrap());+ assert!(h.query_by_label(&title).is_some(), "the active tab is on the strip: {title}");+}++#[test]+fn the_active_document_brings_its_tab_onto_the_strip() {+ let mut h = harness(14, ThemeKind::Pro);+ for pick in [0, 13, 7] {+ h.state_mut().session.set_active(pick);+ h.run_steps(2);+ let title = pro_tab_title(h.state(), pick);+ assert!(h.query_by_label(&title).is_some(), "tab {pick} is focused on the strip: {title}");+ }+}++#[test]+fn tabs_that_fit_keep_their_natural_widths_and_no_menu() {+ let h = harness(3, ThemeKind::Pro);+ let s = strip(&h);+ assert_eq!(s.tabs.len(), 3, "every tab stays on the strip when they fit");+ assert!(h.query_by_label("More documents").is_none(), "no overflow menu when the tabs fit");+ for i in 0..3 {+ assert!(h.query_by_label(&pro_tab_title(h.state(), i)).is_some(), "tab {i} is on the strip");+ }+}++#[test]+fn studio_tabs_overflow_into_the_same_menu() {+ let h = harness(14, ThemeKind::Studio);+ let s = strip(&h);+ assert!(s.tabs.len() < 14, "{} shown", s.tabs.len());+ for r in &s.tabs {+ assert!(s.rect.contains_rect(*r), "a tab runs past the strip: {r:?} in {:?}", s.rect);+ }+ assert!(has_menu(&h), "the Studio strip carries a » menu too");+ let active = h.state().session.active_index().unwrap();+ let name = h.state().session.documents()[active].doc.name.clone();+ assert!(h.query_by_label(&name).is_some(), "the active tab is on the strip: {name}");+}diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsvindex b46ebcc3b..a00901707 100644--- a/crates/ui-egui/src/i18n/cs.tsv+++ b/crates/ui-egui/src/i18n/cs.tsv@@ -1945,6 +1945,7 @@System Info… Informace o systému…System Info Informace o systémuMore panels Další panely+ More documents Další dokumentyThese settings aren't available in PhotoCraft yet. Tato nastavení zatím v aplikaci PhotoCraft nejsou k dispozici.Graphics GrafikaReset GPU Backend Obnovit grafický backenddiff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsvindex 3c9cb4b0c..c2e1853dc 100644--- a/crates/ui-egui/src/i18n/de.tsv+++ b/crates/ui-egui/src/i18n/de.tsv@@ -1918,6 +1918,7 @@System Info… Systeminformationen…System Info SysteminformationenMore panels Weitere Bedienfelder+ More documents Weitere DokumenteThese settings aren't available in PhotoCraft yet. Diese Einstellungen gibt es in PhotoCraft noch nicht.Graphics GrafikReset GPU Backend GPU-Backend zurücksetzendiff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsvindex c7f3d1f48..deae655ec 100644--- a/crates/ui-egui/src/i18n/es.tsv+++ b/crates/ui-egui/src/i18n/es.tsv@@ -1931,6 +1931,7 @@System Info… Información del sistema…System Info Información del sistemaMore panels Más paneles+ More documents Más documentosThese settings aren't available in PhotoCraft yet. Estos ajustes aún no están disponibles en PhotoCraft.Graphics GráficosReset GPU Backend Restablecer el backend de GPUdiff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsvindex 58c8e6e66..730a187c8 100644--- a/crates/ui-egui/src/i18n/fr.tsv+++ b/crates/ui-egui/src/i18n/fr.tsv@@ -1903,6 +1903,7 @@System Info… Informations système…System Info Informations systèmeMore panels Autres panneaux+ More documents Autres documentsThese settings aren't available in PhotoCraft yet. Ces paramètres ne sont pas encore disponibles dans PhotoCraft.Graphics GraphismesReset GPU Backend Réinitialiser le moteur GPUdiff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsvindex 6e08d361b..1d78b390a 100644--- a/crates/ui-egui/src/i18n/id.tsv+++ b/crates/ui-egui/src/i18n/id.tsv@@ -1897,6 +1897,7 @@System Info… Info Sistem…System Info Info SistemMore panels Panel lainnya+ More documents Dokumen lainnyaThese settings aren't available in PhotoCraft yet. Pengaturan ini belum tersedia di PhotoCraft.Graphics GrafisReset GPU Backend Reset Backend GPUdiff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsvindex d9d0d7917..dd066daf0 100644--- a/crates/ui-egui/src/i18n/it.tsv+++ b/crates/ui-egui/src/i18n/it.tsv@@ -1928,6 +1928,7 @@System Info… Info sistema…System Info Info sistemaMore panels Altri pannelli+ More documents Altri documentiThese settings aren't available in PhotoCraft yet. Queste impostazioni non sono ancora disponibili in PhotoCraft.Graphics GraficaReset GPU Backend Reimposta backend GPUdiff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsvindex 3dff04a9e..5d53e789b 100644--- a/crates/ui-egui/src/i18n/ja.tsv+++ b/crates/ui-egui/src/i18n/ja.tsv@@ -1936,6 +1936,7 @@System Info… システム情報…System Info システム情報More panels その他のパネル+ More documents その他のドキュメントThese settings aren't available in PhotoCraft yet. これらの設定は PhotoCraft ではまだ使用できません。Graphics グラフィックスReset GPU Backend GPU バックエンドをリセットdiff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsvindex d04471c61..bc38c1798 100644--- a/crates/ui-egui/src/i18n/ko.tsv+++ b/crates/ui-egui/src/i18n/ko.tsv@@ -1898,6 +1898,7 @@System Info… 시스템 정보…System Info 시스템 정보More panels 추가 패널+ More documents 추가 문서These settings aren't available in PhotoCraft yet. 이 설정은 아직 PhotoCraft에서 사용할 수 없습니다.Graphics 그래픽Reset GPU Backend GPU 백엔드 초기화diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsvindex f13ecedc6..52600b036 100644--- a/crates/ui-egui/src/i18n/pt-br.tsv+++ b/crates/ui-egui/src/i18n/pt-br.tsv@@ -1902,6 +1902,7 @@System Info… Informações do sistema…System Info Informações do sistemaMore panels Mais painéis+ More documents Mais documentosThese settings aren't available in PhotoCraft yet. Estas configurações ainda não estão disponíveis no PhotoCraft.Graphics GráficosReset GPU Backend Redefinir backend da GPUdiff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsvindex ca2e5b34d..f369bf23d 100644--- a/crates/ui-egui/src/i18n/ru.tsv+++ b/crates/ui-egui/src/i18n/ru.tsv@@ -1368,6 +1368,7 @@Keyboard Shortcuts and Menus Комбинации клавиш и менюMenus МенюMore panels Ещё панели+ More documents Ещё документыCollapse All Groups Свернуть все группыExpand All Groups Развернуть все группыCollapse Свернутьdiff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsvindex e93e49048..badc5798a 100644--- a/crates/ui-egui/src/i18n/zh-hans.tsv+++ b/crates/ui-egui/src/i18n/zh-hans.tsv@@ -1987,6 +1987,7 @@ cameraRaw Blending 混合System Info… 系统信息…System Info 系统信息More panels 更多面板+ More documents 更多文档These settings aren't available in PhotoCraft yet. PhotoCraft 暂不支持这些设置。Graphics 图形Reset GPU Backend 重置 GPU 后端diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsvindex 94dc73777..0585d0dbe 100644--- a/crates/ui-egui/src/i18n/zh-hant.tsv+++ b/crates/ui-egui/src/i18n/zh-hant.tsv@@ -1927,6 +1927,7 @@System Info… 系統資訊…System Info 系統資訊More panels 更多面板+ More documents 更多文件These settings aren't available in PhotoCraft yet. 這些設定在 PhotoCraft 中尚未提供。Graphics 圖形Reset GPU Backend 重設 GPU 後端diff --git a/crates/ui-egui/src/tab_strip.rs b/crates/ui-egui/src/tab_strip.rsindex b1bce70e8..2bd646c15 100644--- a/crates/ui-egui/src/tab_strip.rs+++ b/crates/ui-egui/src/tab_strip.rs@@ -94,7 +94,31 @@ pub struct StripOut {}/// Width of the » overflow button.-const CHEVRON_W: f32 = 18.0;+pub const CHEVRON_W: f32 = 18.0;++/// Draw the » overflow button at `r`: hover tip `tip`, listing the tabs named by `labels` at the+/// indices in `overflow`. A picked index is left in `picked`.+pub fn overflow_button(ui: &mut Ui, id: egui::Id, r: Rect, tip: &str, labels: &[&str], overflow: &[usize], picked: &mut Option<usize>) {+ let t = Tokens::get(ui.ctx());+ let resp = ui.interact(r, id, Sense::click());+ if resp.hovered() {+ ui.painter().rect_filled(r.shrink2(vec2(1.0, 3.0)), t.radius_sm, t.hover.gamma_multiply(0.6));+ }+ crate::icons::paint(ui, r, "chevrons-right", 12.0, if resp.hovered() { t.text } else { t.text_dim });+ resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, tip));+ let resp = resp.on_hover_text(tip);+ egui::Popup::menu(&resp).show(|ui| {+ ui.set_min_width(140.0);+ for &i in overflow {+ if let Some(name) = labels.get(i)+ && ui.button(*name).clicked()+ {+ *picked = Some(i);+ ui.close();+ }+ }+ });+}/// Draw the tabs of a strip in `area` (the strip minus the menu button). `paint_tab` draws one/// tab: (ui, rect, index, label galley, response, active).@@ -137,24 +161,11 @@ fn tabs_in(}if !f.overflow.is_empty() {let r = Rect::from_min_size(pos2(x, area.top()), vec2(CHEVRON_W, area.height()));- let resp = ui.interact(r, id.with("tab-overflow"), Sense::click());- if resp.hovered() {- ui.painter().rect_filled(r.shrink2(vec2(1.0, 3.0)), t.radius_sm, t.hover.gamma_multiply(0.6));+ let mut picked = None;+ overflow_button(ui, id.with("tab-overflow"), r, tl!("More panels"), tabs, &f.overflow, &mut picked);+ if let Some(i) = picked {+ *selected = i;}- crate::icons::paint(ui, r, "chevrons-right", 12.0, if resp.hovered() { t.text } else { t.text_dim });- resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, tl!("More panels")));- let resp = resp.on_hover_text(tl!("More panels"));- egui::Popup::menu(&resp).show(|ui| {- ui.set_min_width(140.0);- for &i in &f.overflow {- if let Some(name) = tabs.get(i)- && ui.button(*name).clicked()- {- *selected = i;- ui.close();- }- }- });out.chevron = Some(r);}out