Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Studio: the floating Properties card has the Adjustments tab (#7265)

heojunfo64e7ed1583a4
diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rs
index 0412c4fc6..517462bbe 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),
@@ -690,21 +708,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 f0a64562c..ae6ef9aa6 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 9a1b07f2b..e4f73f727 100644
--- a/crates/ui-egui/src/panels.rs
+++ b/crates/ui-egui/src/panels.rs
@@ -3547,8 +3547,9 @@ fn snapshot_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, selected: Option<u6
// ----------------------------------------------------------------------------- properties
-/// Floating Properties card anchored to the canvas' top-right corner. It shows the same content as
-/// the docked panel (`properties_body`): document, layer, adjustment and mask properties.
+/// Floating Properties card anchored to the canvas' top-right corner. It has the docked group's
+/// tabs: Properties (`properties_body`: document, layer, adjustment and mask properties) and
+/// Adjustments (`adjustments_grid`).
pub fn properties_window(app: &mut PhotocraftApp, ctx: &egui::Context) {
if app.ui.docking.is_some() {
return;
@@ -3578,24 +3579,44 @@ pub fn properties_window(app: &mut PhotocraftApp, ctx: &egui::Context) {
let shown = egui::Area::new(card_id).order(egui::Order::Middle).fixed_pos(pos + offset).show(ctx, |ui| {
frame.show(ui, |ui| {
ui.set_width(width - 28.0);
- let title = ui.horizontal(|ui| {
- ui.label(RichText::new(tl!("Properties")).font(theme::semibold(13.5)).color(t.text));
- ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
- if icons::button(ui, "minus", 22.0, false, tl!("Hide Properties")).clicked() {
- app.ui.panels.properties = false;
- }
- });
- });
- let bar = title.response.rect.with_max_x(title.response.rect.right() - 28.0);
+ // Properties | Adjustments, as on the docked group (#7265).
+ let group = crate::dock::Group::Properties;
+ let visible = app.ui.dock.visible_tabs(group, false);
+ let indices: Vec<usize> = 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() {