diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rs index 5f0a95e915..40a74bbf25 100644 --- a/crates/ui-egui/src/dock.rs +++ b/crates/ui-egui/src/dock.rs @@ -417,6 +417,24 @@ pub fn rail_click(app: &mut PhotocraftApp, g: Group, docked: bool) { } } +/// A tab strip's Close: hide `tab` of `g`, and the group with its last tab. When the selected +/// tab closes, the next one on the strip (or the previous one, for the last) is selected. +pub(crate) fn close_tab(app: &mut PhotocraftApp, g: Group, tab: usize, pro: bool) { + let shown_before = app.ui.dock.visible_tabs(g, pro); + app.ui.dock.hide_tab(g, tab, pro); + let remaining = app.ui.dock.visible_tabs(g, pro); + if remaining.is_empty() { + *g.shown_mut(&mut app.ui.panels) = false; + } else if *g.tab_mut(&mut app.ui.dock_tabs) == tab { + // Prefer the next tab on the strip, or the previous one when closing the last. + let at = shown_before.iter().position(|(i, _)| *i == tab).unwrap_or(0); + let next = shown_before.iter().skip(at + 1).find(|x| remaining.contains(x)).or_else(|| remaining.last()); + if let Some(&(next, _)) = next { + *g.tab_mut(&mut app.ui.dock_tabs) = next; + } + } +} + /// Per-group interactions collected while drawing, applied afterwards. enum Action { ToggleCollapse(Group), @@ -694,21 +712,7 @@ pub fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui, shown: &[Group], mut bod app.ui.dock.set_collapsed(g, on); } Action::Close(g) => *g.shown_mut(&mut app.ui.panels) = false, - Action::CloseTab(g, tab) => { - let shown_before = app.ui.dock.visible_tabs(g, t.pro); - app.ui.dock.hide_tab(g, tab, t.pro); - let remaining = app.ui.dock.visible_tabs(g, t.pro); - if remaining.is_empty() { - *g.shown_mut(&mut app.ui.panels) = false; - } else if *g.tab_mut(&mut app.ui.dock_tabs) == tab { - // Prefer the next tab on the strip, or the previous one when closing the last. - let at = shown_before.iter().position(|(i, _)| *i == tab).unwrap_or(0); - let next = shown_before.iter().skip(at + 1).find(|x| remaining.contains(x)).or_else(|| remaining.last()); - if let Some(&(next, _)) = next { - *g.tab_mut(&mut app.ui.dock_tabs) = next; - } - } - } + Action::CloseTab(g, tab) => close_tab(app, g, tab, t.pro), Action::MoveTab(g, tab, before) => app.ui.dock.move_tab(g, tab, before, t.pro), Action::Move(g, before) => { if before != Some(g) { diff --git a/crates/ui-egui/src/dock_tests.rs b/crates/ui-egui/src/dock_tests.rs index f0a64562c4..ae6ef9aa61 100644 --- a/crates/ui-egui/src/dock_tests.rs +++ b/crates/ui-egui/src/dock_tests.rs @@ -672,6 +672,53 @@ fn panel_tab_context_menu_closes_one_tab_or_its_group() { } } +/// #7265: Studio's floating Properties card has the docked group's Adjustments tab, so Window › +/// Adjustments shows the grid of adjustment layers instead of Properties. +#[test] +fn studio_properties_card_shows_the_adjustments_tab() { + use egui_kittest::kittest::Queryable; + + let (mut app, _, _) = app_with_layers(); + app.last_canvas_rect = Rect::from_min_size(Pos2::ZERO, vec2(900.0, 700.0)); + let mut h = Harness::builder().with_size(vec2(900.0, 700.0)).build_ui_state( + |ui, app: &mut PhotocraftApp| { + let ctx = ui.ctx().clone(); + if ctx.fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) { + crate::panels::properties_window(app, &ctx); + } + }, + app, + ); + PhotocraftApp::setup_context(&h.ctx, ThemeKind::Studio); + h.state_mut().ui.theme = ThemeKind::Studio; + h.run_steps(3); + let ctx = h.ctx.clone(); + crate::menus::invoke(h.state_mut(), &ctx, "window.panel.adjustments", json!({})).unwrap(); + h.run_steps(3); + assert!(h.state().ui.panels.properties && h.state().ui.dock_tabs.properties == 1); + assert!(h.query_by_label("Add an adjustment").is_some(), "Window › Adjustments shows the Adjustments grid"); + // The Properties tab switches back to the layer's properties. + h.get_by_label("Properties").click(); + h.run_steps(3); + assert_eq!(h.state().ui.dock_tabs.properties, 0); + assert!(h.query_by_label("Add an adjustment").is_none()); + assert!(h.query_by_label("Reset to defaults").is_some(), "the Curves layer's properties"); + // Closing the Adjustments tab leaves Properties alone on the card. + h.get_by_label("Adjustments").click(); + h.run_steps(3); + let p = h.get_by_label("Adjustments").rect().center(); + h.hover_at(p); + h.run_steps(1); + h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Secondary, pressed: true, modifiers: Modifiers::NONE }); + h.step(); + h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Secondary, pressed: false, modifiers: Modifiers::NONE }); + h.run_steps(2); + h.get_by_label("Close").click(); + h.run_steps(3); + assert!(h.state().ui.panels.properties && h.state().ui.dock_tabs.properties == 0); + assert!(h.query_by_label("Adjustments").is_none() && h.query_by_label("Reset to defaults").is_some()); +} + fn is_pro(theme: ThemeKind) -> bool { theme.is_pro() } diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index e2286b446a..33933c40fc 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -3675,8 +3675,9 @@ fn snapshot_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, selected: Option = visible.iter().map(|(i, _)| *i).collect(); + let tabs: Vec<&str> = visible.iter().map(|(_, name)| *name).collect(); + let mut sel = indices.iter().position(|i| *i == app.ui.dock_tabs.properties).unwrap_or(0); + let (row, _) = ui.allocate_exact_size(vec2(ui.available_width(), 24.0), Sense::hover()); + let hide = Rect::from_min_max(pos2(row.right() - 22.0, row.top() + 1.0), pos2(row.right(), row.bottom() - 1.0)); + if icons::button(&mut ui.new_child(egui::UiBuilder::new().max_rect(hide)), "minus", 22.0, false, tl!("Hide Properties")).clicked() { + app.ui.panels.properties = false; + } + // The title bar drags the card; registered before the tabs so they keep their clicks. + let bar = Rect::from_min_max(row.min, pos2((hide.left() - 6.0).max(row.left()), row.bottom())); let grip = ui.interact(bar, card_id.with("title"), Sense::drag()); if grip.hovered() || grip.dragged() { ui.ctx().set_cursor_icon(egui::CursorIcon::Grab); } drag = grip.drag_delta(); + let strip = crate::tab_strip::pill_tabs(ui, card_id.with("tabs"), bar, &tabs, &mut sel, false); + if let Some(&picked) = indices.get(sel) { + app.ui.dock_tabs.properties = picked; + } + match strip.context { + Some(crate::tab_strip::TabContextAction::Close(i)) => { + if let Some(&tab) = indices.get(i) { + crate::dock::close_tab(app, group, tab, false); + } + } + Some(crate::tab_strip::TabContextAction::CloseGroup) => app.ui.panels.properties = false, + None => {} + } ui.add_space(6.0); widgets::hairline(ui); ui.add_space(8.0); - properties_body(app, ui); + match indices.get(sel) { + Some(0) | None => properties_body(app, ui), + Some(_) => adjustments_grid(app, ui), + } }); }); if drag != egui::Vec2::ZERO && canvas.is_positive() {