Skip to content

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

fix(toolbar): port drag-release flyout selection onto upstream toolbar

Nigel Ihza Firdausyf9795681b204
diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs
index b2bb91c73..4b7e58588 100644
--- a/crates/ui-egui/src/panels.rs
+++ b/crates/ui-egui/src/panels.rs
@@ -24,7 +24,7 @@ const TOOL_SECTIONS: &[&[&[Tool]]] = &[
&[Tool::Eyedropper, Tool::Ruler, Tool::Note, Tool::Count],
],
&[
- &[Tool::SpotHealing, Tool::Healing, Tool::Patch, Tool::ContentAwareMove, Tool::RedEye],
+ &[Tool::Remove, Tool::SpotHealing, Tool::Healing, Tool::Patch, Tool::ContentAwareMove, Tool::RedEye],
&[Tool::Brush, Tool::Pencil, Tool::MixerBrush],
&[Tool::CloneStamp, Tool::PatternStamp],
&[Tool::HistoryBrush],
@@ -92,10 +92,8 @@ pub fn toolbar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
let t = Tokens::get(ui.ctx());
let (w1, bx, m) = if t.pro { (40.0, 30.0, 5i8) } else { (50.0, 36.0, 7i8) };
let sections = visible_sections(&app.session.prefs().toolbar.hidden);
- // Two columns when the header chevron asks for them, or when one column doesn't fit.
- let slots: usize = sections.iter().map(Vec::len).sum();
- let double =
- app.ui.panels.toolbar_double || toolbar_needs_double(slots, sections.len(), bx, t.pro, t.round_chips, ui.available_rect_before_wrap().height());
+ // Two columns when the header chevron asks for them; a column that doesn't fit scrolls.
+ let double = app.ui.panels.toolbar_double;
let w = if double { w1 + bx + 2.0 } else { w1 };
egui::Panel::left("toolbar").resizable(false).exact_size(w).frame(egui::Frame::NONE.fill(t.chrome).inner_margin(egui::Margin::symmetric(m, 8))).show(
ui,
@@ -131,189 +129,199 @@ pub fn toolbar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
if ui.input(|i| i.pointer.any_pressed()) {
ui.data_mut(|d| d.remove::<egui::Id>(held_id));
}
- // Pro has no group dividers, so its two columns fill every row across groups.
- let sections: Vec<Vec<(usize, Vec<Tool>)>> = if t.pro { vec![sections.into_iter().flatten().collect()] } else { sections };
- for (si, section) in sections.iter().enumerate() {
- // Photoshop 2026 draws one uninterrupted column (no group dividers).
- if si > 0 && !t.pro {
- ui.add_space(4.0);
- let (r, _) = ui.allocate_exact_size(vec2(if double { bx * 2.0 + 2.0 } else { bx }, 1.0), Sense::hover());
- ui.painter().line_segment([r.left_center() + vec2(8.0, 0.0), r.right_center() - vec2(8.0, 0.0)], Stroke::new(1.0, t.separator));
- ui.add_space(4.0);
- }
- let rows: Vec<&[(usize, Vec<Tool>)]> = if double { section.chunks(2).collect() } else { section.chunks(1).collect() };
- for row in rows {
- ui.horizontal(|ui| {
- for (slot_index, slot) in row.iter() {
- let key = egui::Id::new(("tool-slot", *slot_index));
- let tool = slot_tool(ui, app.ui.tool, slot, key);
- let sel = slot.contains(&app.ui.tool);
- let tip = if tool.key() == '\0' { tl!(tool.label()).to_string() } else { format!("{} ({})", tl!(tool.label()), tool.key()) };
- let resp = icons::button(ui, icons::tool_icon(tool), bx, sel, &tip);
- if slot.len() > 1 {
- let r = resp.rect;
- let tri = vec![r.right_bottom() + vec2(-2.0, -2.0), r.right_bottom() + vec2(-6.0, -2.0), r.right_bottom() + vec2(-2.0, -6.0)];
- ui.painter().add(egui::Shape::convex_polygon(tri, t.text_faint, Stroke::NONE));
- }
- if resp.clicked() && ui.data(|d| d.get_temp::<egui::Id>(held_id)) != Some(key) {
- app.ui.tool = tool;
- }
- // Double-clicking the Hand tool fits the image on screen (Photoshop).
- if resp.double_clicked() && tool == Tool::Hand {
- app.ui.tool = tool;
- // With no document open there is nothing to fit.
- let _ = app.run("view.fitOnScreen", json!({}));
- }
- // Right-click, long-press, or drag off the tool button opens its flyout (Photoshop).
- let held_for = resp.is_pointer_button_down_on().then(|| ui.input(|i| i.pointer.press_start_time().map(|t0| i.time - t0))).flatten();
- if slot.len() > 1
- && let Some(seconds) = held_for
- && seconds < 0.35
- {
- ui.ctx().request_repaint_after(std::time::Duration::from_secs_f64(0.35 - seconds));
- }
- let long_press = held_for.is_some_and(|seconds| seconds >= 0.35);
- let drag_open = tool_flyout_drag_open(resp.dragged(), resp.hovered());
- if slot.len() > 1 && (resp.secondary_clicked() || long_press || drag_open) {
- ui.data_mut(|d| {
- d.insert_temp(flyout_id, (key, resp.rect));
- if long_press || drag_open {
- // Suppress the origin button's click when released after opening.
- d.insert_temp(held_id, key);
- }
- });
- }
- if slot.len() > 1 && long_press {
- ui.ctx().request_repaint();
- }
- if let Some((open_key, anchor)) = ui.data(|d| d.get_temp::<(egui::Id, Rect)>(flyout_id))
- && open_key == key
- {
- let area = egui::Area::new(key.with("flyout"))
- .order(egui::Order::Foreground)
- .fixed_pos(anchor.right_top() + vec2(6.0, 0.0))
- .show(ui.ctx(), |ui| {
- egui::Frame::popup(ui.style()).show(ui, |ui| {
- let label_w = slot
- .iter()
- .map(|it| {
- ui.painter().layout_no_wrap(tl!(it.label()).to_string(), egui::FontId::proportional(12.5), t.text).size().x
- })
- .fold(0.0f32, f32::max);
- let fw = (label_w + 42.0 + 40.0).max(180.0);
- for &item in slot.iter() {
- let (r, ir) = ui.allocate_exact_size(vec2(fw, 26.0), Sense::click());
- if ir.hovered() {
- ui.painter().rect_filled(r, 3.0, t.hover);
- }
- if item == tool {
- ui.painter().rect_filled(
- Rect::from_center_size(pos2(r.left() + 8.0, r.center().y), vec2(4.0, 4.0)),
- 0.0,
- t.text,
+ egui::ScrollArea::vertical().id_salt("toolbar-columns").show(ui, |ui| {
+ // Pro has no group dividers, so its two columns fill every row across groups.
+ let sections: Vec<Vec<(usize, Vec<Tool>)>> = if t.pro { vec![sections.into_iter().flatten().collect()] } else { sections };
+ for (si, section) in sections.iter().enumerate() {
+ // Photoshop 2026 draws one uninterrupted column (no group dividers).
+ if si > 0 && !t.pro {
+ ui.add_space(4.0);
+ let (r, _) = ui.allocate_exact_size(vec2(if double { bx * 2.0 + 2.0 } else { bx }, 1.0), Sense::hover());
+ ui.painter().line_segment([r.left_center() + vec2(8.0, 0.0), r.right_center() - vec2(8.0, 0.0)], Stroke::new(1.0, t.separator));
+ ui.add_space(4.0);
+ }
+ let rows: Vec<&[(usize, Vec<Tool>)]> = if double { section.chunks(2).collect() } else { section.chunks(1).collect() };
+ for row in rows {
+ ui.horizontal(|ui| {
+ for (slot_index, slot) in row.iter() {
+ let key = egui::Id::new(("tool-slot", *slot_index));
+ let tool = slot_tool(ui, app.ui.tool, slot, key);
+ let sel = slot.contains(&app.ui.tool);
+ let tip = if tool.key() == '\0' { tl!(tool.label()).to_string() } else { format!("{} ({})", tl!(tool.label()), tool.key()) };
+ let resp = icons::button(ui, icons::tool_icon(tool), bx, sel, &tip);
+ if slot.len() > 1 {
+ paint_toolbar_flyout_indicator(ui, &t, &resp);
+ }
+ if resp.clicked() && ui.data(|d| d.get_temp::<egui::Id>(held_id)) != Some(key) {
+ app.ui.tool = tool;
+ }
+ // Double-clicking the Hand tool fits the image on screen (Photoshop).
+ if resp.double_clicked() && tool == Tool::Hand {
+ app.ui.tool = tool;
+ // With no document open there is nothing to fit.
+ let _ = app.run("view.fitOnScreen", json!({}));
+ }
+ // Double-clicking the Zoom tool zooms to 100% (Photoshop).
+ if resp.double_clicked() && tool == Tool::Zoom {
+ app.ui.tool = tool;
+ // With no document open there is nothing to zoom.
+ let _ = app.run("view.actualPixels", json!({}));
+ }
+ // Right-click, long-press, or drag off the tool button opens its flyout (Photoshop).
+ let held_for =
+ resp.is_pointer_button_down_on().then(|| ui.input(|i| i.pointer.press_start_time().map(|t0| i.time - t0))).flatten();
+ if slot.len() > 1
+ && let Some(seconds) = held_for
+ && seconds < 0.35
+ {
+ ui.ctx().request_repaint_after(std::time::Duration::from_secs_f64(0.35 - seconds));
+ }
+ let long_press = held_for.is_some_and(|seconds| seconds >= 0.35);
+ let drag_open = tool_flyout_drag_open(resp.dragged(), resp.hovered());
+ if slot.len() > 1 && (resp.secondary_clicked() || long_press || drag_open) {
+ ui.data_mut(|d| {
+ d.insert_temp(flyout_id, (key, resp.rect));
+ if long_press || drag_open {
+ d.insert_temp(held_id, key);
+ }
+ });
+ }
+ if slot.len() > 1 && long_press {
+ ui.ctx().request_repaint();
+ }
+ if let Some((open_key, anchor)) = ui.data(|d| d.get_temp::<(egui::Id, Rect)>(flyout_id))
+ && open_key == key
+ {
+ let area = egui::Area::new(key.with("flyout"))
+ .order(egui::Order::Foreground)
+ .fixed_pos(anchor.right_top() + vec2(6.0, 0.0))
+ .show(ui.ctx(), |ui| {
+ egui::Frame::popup(ui.style()).show(ui, |ui| {
+ let label_w = slot
+ .iter()
+ .map(|it| {
+ ui.painter()
+ .layout_no_wrap(tl!(it.label()).to_string(), egui::FontId::proportional(12.5), t.text)
+ .size()
+ .x
+ })
+ .fold(0.0f32, f32::max);
+ let fw = (label_w + 42.0 + 40.0).max(180.0);
+ for &item in slot.iter() {
+ let (r, ir) = ui.allocate_exact_size(vec2(fw, 26.0), Sense::click());
+ if ir.hovered() {
+ ui.painter().rect_filled(r, 3.0, t.hover);
+ }
+ if item == tool {
+ ui.painter().rect_filled(
+ Rect::from_center_size(pos2(r.left() + 8.0, r.center().y), vec2(4.0, 4.0)),
+ 0.0,
+ t.text,
+ );
+ }
+ icons::paint(
+ ui,
+ Rect::from_center_size(pos2(r.left() + 26.0, r.center().y), vec2(18.0, 18.0)),
+ icons::tool_icon(item),
+ 14.0,
+ t.icon,
);
- }
- icons::paint(
- ui,
- Rect::from_center_size(pos2(r.left() + 26.0, r.center().y), vec2(18.0, 18.0)),
- icons::tool_icon(item),
- 14.0,
- t.icon,
- );
- ui.painter().text(
- pos2(r.left() + 42.0, r.center().y),
- Align2::LEFT_CENTER,
- tl!(item.label()),
- egui::FontId::proportional(12.5),
- t.text,
- );
- if item.key() != '\0' {
ui.painter().text(
- pos2(r.right() - 8.0, r.center().y),
- Align2::RIGHT_CENTER,
- item.key().to_string(),
- egui::FontId::proportional(12.0),
- t.text_dim,
+ pos2(r.left() + 42.0, r.center().y),
+ Align2::LEFT_CENTER,
+ tl!(item.label()),
+ egui::FontId::proportional(12.5),
+ t.text,
);
+ if item.key() != '\0' {
+ ui.painter().text(
+ pos2(r.right() - 8.0, r.center().y),
+ Align2::RIGHT_CENTER,
+ item.key().to_string(),
+ egui::FontId::proportional(12.0),
+ t.text_dim,
+ );
+ }
+ let release_from_origin = tool_flyout_release(
+ r,
+ ui.input(|i| i.pointer.hover_pos()),
+ ui.input(|i| i.pointer.primary_released()),
+ ui.data(|d| d.get_temp::<egui::Id>(held_id)) == Some(key),
+ );
+ if ir.clicked() || release_from_origin {
+ app.ui.tool = item;
+ ui.data_mut(|d| d.remove::<(egui::Id, Rect)>(flyout_id));
+ }
}
- let release_from_origin = tool_flyout_release(
- r,
- ui.input(|i| i.pointer.hover_pos()),
- ui.input(|i| i.pointer.primary_released()),
- ui.data(|d| d.get_temp::<egui::Id>(held_id)) == Some(key),
- );
- if ir.clicked() || release_from_origin {
- app.ui.tool = item;
- ui.data_mut(|d| d.remove::<(egui::Id, Rect)>(flyout_id));
- }
- }
+ });
});
- });
- let held_release = resp.clicked() && ui.data(|d| d.get_temp::<egui::Id>(held_id)) == Some(key);
- let clicked_outside = ui.input(|i| i.pointer.any_click()) && !held_release && !area.response.hovered() && !resp.hovered();
- if clicked_outside || ui.input(|i| i.key_pressed(egui::Key::Escape)) {
- ui.data_mut(|d| d.remove::<(egui::Id, Rect)>(flyout_id));
+ let held_release = resp.clicked() && ui.data(|d| d.get_temp::<egui::Id>(held_id)) == Some(key);
+ let clicked_outside = ui.input(|i| i.pointer.any_click()) && !held_release && !area.response.hovered() && !resp.hovered();
+ if clicked_outside || ui.input(|i| i.key_pressed(egui::Key::Escape)) {
+ ui.data_mut(|d| d.remove::<(egui::Id, Rect)>(flyout_id));
+ }
}
}
- }
- });
- }
- }
- let ctx = ui.ctx().clone();
- if t.pro && icons::button(ui, "ellipsis", bx, false, tl!("Edit Toolbar…")).clicked() {
- let _ = crate::menus::invoke(app, &ctx, "edit.toolbar", json!({}));
- }
- ui.add_space(if t.pro { 8.0 } else { 14.0 });
- color_chips(app, ui, double);
- if t.pro {
- ui.add_space(8.0);
- let quick_mask = app.session.active().is_some_and(|s| s.doc.quick_mask.is_some());
- if icons::button(
- ui,
- "square-dashed",
- bx,
- quick_mask,
- if quick_mask { tl!("Edit in Standard Mode (Q)") } else { tl!("Edit in Quick Mask Mode (Q)") },
- )
- .clicked()
- {
- let _ = crate::menus::invoke(app, &ctx, "select.editInQuickMaskMode", json!({}));
+ });
+ }
}
- let sm = icons::button(ui, "app-window", bx, false, tl!("Change Screen Mode (F)"));
- if sm.clicked() {
- let _ = crate::menus::invoke(app, &ctx, "view.screenMode.cycle", json!({}));
+ let ctx = ui.ctx().clone();
+ if t.pro && icons::button(ui, "ellipsis", bx, false, tl!("Edit Toolbar…")).clicked() {
+ let _ = crate::menus::invoke(app, &ctx, "edit.toolbar", json!({}));
}
- // Right-click (or long-press) lists the modes, like Photoshop's flyout.
- egui::Popup::context_menu(&sm).show(|ui| {
- ui.set_min_width(220.0);
- for (id, label) in [
- ("view.screenMode.standard", tl!("Standard Screen Mode")),
- ("view.screenMode.fullScreenWithMenuBar", tl!("Full Screen Mode With Menu Bar")),
- ("view.screenMode.fullScreen", tl!("Full Screen Mode")),
- ] {
- let on = crate::view_cmds::checked(app, id).unwrap_or(false);
- if ui.add(egui::Button::selectable(on, label)).clicked() {
- let _ = crate::menus::invoke(app, &ctx, id, json!({}));
- ui.close();
+ ui.add_space(if t.pro { 8.0 } else { 14.0 });
+ color_chips(app, ui, double);
+ if t.pro {
+ ui.add_space(8.0);
+
+ let layout = if double { egui::Layout::left_to_right(egui::Align::Min) } else { egui::Layout::top_down(egui::Align::Min) };
+
+ ui.with_layout(layout, |ui| {
+ let quick_mask = app.session.active().is_some_and(|s| s.doc.quick_mask.is_some());
+ if icons::button(
+ ui,
+ "square-dashed",
+ bx,
+ quick_mask,
+ if quick_mask { tl!("Edit in Standard Mode (Q)") } else { tl!("Edit in Quick Mask Mode (Q)") },
+ )
+ .clicked()
+ {
+ let _ = crate::menus::invoke(app, &ctx, "select.editInQuickMaskMode", json!({}));
}
- }
- });
- }
+ let sm = icons::button(ui, "app-window", bx, false, tl!("Change Screen Mode (F)"));
+ paint_toolbar_flyout_indicator(ui, &t, &sm);
+
+ if sm.clicked() {
+ let _ = crate::menus::invoke(app, &ctx, "view.screenMode.cycle", json!({}));
+ }
+ // Right-click (or long-press) lists the modes, like Photoshop's flyout.
+ egui::Popup::context_menu(&sm).show(|ui| {
+ ui.set_min_width(220.0);
+ for (id, label) in [
+ ("view.screenMode.standard", tl!("Standard Screen Mode")),
+ ("view.screenMode.fullScreenWithMenuBar", tl!("Full Screen Mode With Menu Bar")),
+ ("view.screenMode.fullScreen", tl!("Full Screen Mode")),
+ ] {
+ let on = crate::view_cmds::checked(app, id).unwrap_or(false);
+ if ui.add(egui::Button::selectable(on, label)).clicked() {
+ let _ = crate::menus::invoke(app, &ctx, id, json!({}));
+ ui.close();
+ }
+ }
+ });
+ });
+ }
+ });
},
);
}
-/// Does the toolbar need two columns? Height of one column (header, tool slots, Edit Toolbar,
-/// colour chips, Quick Mask and Screen Mode) against the height the toolbar gets.
-pub fn toolbar_needs_double(slots: usize, sections: usize, bx: f32, pro: bool, studio: bool, avail_h: f32) -> bool {
- let pitch = bx + 3.0;
- let needed = if pro {
- // margins + header + slots + "…" + gap + colour chips + gap + 2 buttons
- 16.0 + 21.0 + (slots + 1) as f32 * pitch + 8.0 + chips_height(true, false, false) + 8.0 + 2.0 * pitch
- } else {
- 16.0 + slots as f32 * pitch + sections.saturating_sub(1) as f32 * 12.0 + 14.0 + chips_height(false, studio, false)
- };
- needed > avail_h
+/// Paints a triangle on the bottom right corner of an icon button to indicate that a toolbar item has a submenu.
+pub fn paint_toolbar_flyout_indicator(ui: &mut egui::Ui, tokens: &Tokens, resp: &egui::Response) {
+ let r = resp.rect;
+ let tri = vec![r.right_bottom() + vec2(-2.0, -2.0), r.right_bottom() + vec2(-6.0, -2.0), r.right_bottom() + vec2(-2.0, -6.0)];
+ ui.painter().add(egui::Shape::convex_polygon(tri, tokens.text_faint, Stroke::NONE));
}
fn c32(c: [f32; 4]) -> Color32 {
@@ -823,6 +831,15 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
crate::brush_picker::settings_toggle(app, ui);
widgets::vline(ui, 22.0);
}
+ if tool == Tool::CloneStamp {
+ let before = app.session.tools.brush.clone();
+ let mut brush = before.clone();
+ let width = if t.pro { 62.0 } else { 66.0 };
+ percent_field(ui, tl!("Opacity"), &mut brush.opacity, 1.0..=100.0, width);
+ percent_field(ui, tl!("Flow"), &mut brush.flow, 1.0..=100.0, width);
+ crate::brush_panel::commit_gesture(app, ui.ctx(), &before, &brush);
+ widgets::vline(ui, 22.0);
+ }
if crate::eraser_ui::options_bar(app, ui, tool)
|| crate::retouch_ui::options_bar(app, ui, tool)
|| crate::vector_ui::options_bar(app, ui, tool)
@@ -836,24 +853,38 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
let b = &mut brush;
match app.ui.tool {
Tool::Brush | Tool::Eraser if t.pro => {
- brush_preset_chip(ui, b, &mut app.ui);
- crate::brush_picker::settings_toggle(app, ui);
+ // A Block-mode Eraser has a fixed size, opacity and flow (Photoshop, #2770).
+ let block = crate::eraser_ui::block_mode(app, app.ui.tool);
+ ui.add_enabled_ui(!block, |ui| {
+ brush_preset_chip(ui, b, &mut app.ui);
+ crate::brush_picker::settings_toggle(app, ui);
+ });
widgets::vline(ui, 22.0);
- opt_label(ui, tl!("Mode"));
- let mut mode = b.mode;
- let opts: Vec<(BlendMode, &str)> = BlendMode::LAYER_MODES.iter().map(|m| (*m, m.label())).collect();
- if widgets::dropdown(ui, "brush-mode", &mut mode, &opts, 96.0) {
- b.mode = mode;
- }
- percent_field(ui, tl!("Opacity"), &mut b.opacity, 0.0..=100.0, 62.0);
- if icons::button(ui, "circle-dot", 24.0, b.pressure_opacity, tl!("Always use pressure for opacity")).clicked() {
- b.pressure_opacity = !b.pressure_opacity;
- }
- percent_field(ui, tl!("Flow"), &mut b.flow, 1.0..=100.0, 62.0);
- let airbrush = icons::button(ui, "sparkles", 24.0, b.build_up, tl!("Enable airbrush-style build-up effects"));
- if crate::brush_picker::named(airbrush, tl!("Enable airbrush-style build-up effects")).clicked() {
- b.build_up = !b.build_up;
+ // The Eraser has no blend mode: its Mode is Brush, Pencil or Block (#2662).
+ if app.ui.tool == Tool::Eraser {
+ crate::eraser_ui::mode_dropdown(ui, &mut app.ui.tool_options.eraser_mode);
+ } else {
+ opt_label(ui, tl!("Mode"));
+ let mut mode = b.mode;
+ let opts: Vec<(BlendMode, &str)> = BlendMode::LAYER_MODES.iter().map(|m| (*m, m.label())).collect();
+ if widgets::dropdown(ui, "brush-mode", &mut mode, &opts, 96.0) {
+ b.mode = mode;
+ }
}
+ ui.add_enabled_ui(!block, |ui| {
+ percent_field(ui, tl!("Opacity"), &mut b.opacity, 0.0..=100.0, 62.0);
+ if icons::button(ui, "circle-dot", 24.0, b.pressure_opacity, tl!("Always use pressure for opacity")).clicked() {
+ b.pressure_opacity = !b.pressure_opacity;
+ }
+ });
+ // A Pencil- or Block-mode Eraser is always full flow, without build-up (Photoshop).
+ ui.add_enabled_ui(!block && !crate::eraser_ui::pencil_mode(app, app.ui.tool), |ui| {
+ percent_field(ui, tl!("Flow"), &mut b.flow, 1.0..=100.0, 62.0);
+ let airbrush = icons::button(ui, "sparkles", 24.0, b.build_up, tl!("Enable airbrush-style build-up effects"));
+ if crate::brush_picker::named(airbrush, tl!("Enable airbrush-style build-up effects")).clicked() {
+ b.build_up = !b.build_up;
+ }
+ });
opt_label(ui, tl!("Smoothing"));
smoothing_field(ui, b, 58.0);
smoothing_options(ui, b);
@@ -861,7 +892,6 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
if icons::button(ui, "circle-dot", 24.0, b.pressure_size, tl!("Always use pressure for size")).clicked() {
b.pressure_size = !b.pressure_size;
}
- crate::symmetry_ui::menu(app, ui);
}
// Pencil: Photoshop's options (no hardness or flow: the pencil is always hard).
Tool::Pencil => {
@@ -889,12 +919,21 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
brush_preset_chip(ui, b, &mut app.ui);
crate::brush_picker::settings_toggle(app, ui);
widgets::vline(ui, 22.0);
- opt_label(ui, tl!("Size"));
- widgets::value_field(ui, &mut b.size, 1.0..=2500.0, "px", 76.0);
+ // A Block-mode Eraser has a fixed size, opacity and flow (Photoshop, #2770).
+ let block = crate::eraser_ui::block_mode(app, app.ui.tool);
+ ui.add_enabled_ui(!block, |ui| {
+ opt_label(ui, tl!("Size"));
+ widgets::value_field(ui, &mut b.size, 1.0..=2500.0, "px", 76.0);
+ });
widgets::vline(ui, 22.0);
- percent_field(ui, tl!("Hardness"), &mut b.hardness, 0.0..=100.0, 66.0);
- percent_field(ui, tl!("Opacity"), &mut b.opacity, 0.0..=100.0, 66.0);
- percent_field(ui, tl!("Flow"), &mut b.flow, 1.0..=100.0, 66.0);
+ if app.ui.tool == Tool::Eraser {
+ crate::eraser_ui::mode_dropdown(ui, &mut app.ui.tool_options.eraser_mode);
+ }
+ // A Pencil-mode Eraser is always hard and at full flow (Photoshop).
+ let fixed = block || crate::eraser_ui::pencil_mode(app, app.ui.tool);
+ ui.add_enabled_ui(!fixed, |ui| percent_field(ui, tl!("Hardness"), &mut b.hardness, 0.0..=100.0, 66.0));
+ ui.add_enabled_ui(!block, |ui| percent_field(ui, tl!("Opacity"), &mut b.opacity, 0.0..=100.0, 66.0));
+ ui.add_enabled_ui(!fixed, |ui| percent_field(ui, tl!("Flow"), &mut b.flow, 1.0..=100.0, 66.0));
opt_label(ui, tl!("Smoothing"));
smoothing_field(ui, b, 66.0);
widgets::vline(ui, 22.0);
@@ -1084,23 +1123,34 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
crate::gradient_ui::options_changed(app, &before);
}
Tool::Crop if t.pro => {
- let o = &mut app.ui.tool_options;
- let ratios: Vec<(String, &str)> = crate::chrome_ui::CROP_RATIOS.iter().map(|(k, l)| (k.to_string(), *l)).collect();
- widgets::dropdown(ui, "crop-ratio", &mut o.crop_ratio, &ratios, 120.0);
- // Custom ratio fields (Photoshop shows the preset's numbers here).
- let (mut rw, mut rh) = crate::chrome_ui::crop_ratio(&o.crop_ratio, 0.0, 0.0).map_or((0.0, 0.0), |(w, h)| (w as f32, h as f32));
- let cw = widgets::value_field(ui, &mut rw, 0.0..=99_999.0, "", 54.0).changed();
- let swap = icons::button(ui, "arrow-left-right", 22.0, false, tl!("Swaps height and width")).clicked();
- let ch = widgets::value_field(ui, &mut rh, 0.0..=99_999.0, "", 54.0).changed();
- if swap {
- std::mem::swap(&mut rw, &mut rh);
+ let presets = crate::crop_size::dropdown_options();
+ if widgets::dropdown(ui, "crop-ratio", &mut app.ui.tool_options.crop_ratio, &presets, 140.0) {
+ // A size preset or Front Image fills W x H x Resolution (#2443).
+ crate::crop_size::chosen(app);
}
- if (cw || ch || swap) && rw > 0.0 && rh > 0.0 {
- o.crop_ratio = format!("{}:{}", widgets::fmt_num(rw as f64), widgets::fmt_num(rh as f64));
+ let o = &mut app.ui.tool_options;
+ if o.crop_ratio == crate::crop_size::WHR {
+ crate::crop_size::fields(o, ui);
+ } else {
+ // Custom ratio fields (Photoshop shows the preset's numbers here).
+ let (mut rw, mut rh) = crate::chrome_ui::crop_ratio(&o.crop_ratio, 0.0, 0.0).map_or((0.0, 0.0), |(w, h)| (w as f32, h as f32));
+ let cw = widgets::value_field(ui, &mut rw, 0.0..=99_999.0, "", 54.0).changed();
+ let swap = icons::button(ui, "arrow-left-right", 22.0, false, tl!("Swaps height and width")).clicked();
+ let ch = widgets::value_field(ui, &mut rh, 0.0..=99_999.0, "", 54.0).changed();
+ if swap {
+ std::mem::swap(&mut rw, &mut rh);
+ }
+ if (cw || ch || swap) && rw > 0.0 && rh > 0.0 {
+ o.crop_ratio = format!("{}:{}", widgets::fmt_num(rw as f64), widgets::fmt_num(rh as f64));
+ }
}
widgets::vline(ui, 22.0);
if widgets::secondary_button(ui, tl!("Clear"), 0.0).clicked() {
- o.crop_ratio.clear();
+ if o.crop_ratio == crate::crop_size::WHR {
+ crate::crop_size::clear(o);
+ } else {
+ o.crop_ratio.clear();
+ }
}
crate::crop_straighten::options_button(&mut app.crop.straighten, ui);
crate::crop_overlay::options_button(o, ui);
@@ -1274,6 +1324,11 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
// Retouching and smart-selection tools draw their bar in `retouch_ui::options_bar`.
_ => {}
}
+ // Painting symmetry is independent of visual theme. Keep the options-bar
+ // action available for Brush, Pencil and Eraser in every palette (#2659).
+ if matches!(tool, Tool::Brush | Tool::Pencil | Tool::Eraser) {
+ crate::symmetry_ui::menu(app, ui);
+ }
crate::brush_panel::commit_gesture(app, ui.ctx(), &brush_before, &brush);
});
});
@@ -1297,6 +1352,36 @@ fn label(ui: &mut egui::Ui, s: &str) {
ui.label(RichText::new(s).color(t.text_dim));
}
+/// Photoshop's scrubby Opacity/Fill labels: drag horizontally to change the percentage without
+/// hitting the small number field. The unique drag ID coalesces every frame into one undo step.
+fn scrub_pct_label(ui: &mut egui::Ui, text: &str, percent: &mut f32) -> widgets::PopupFieldResponse {
+ let t = Tokens::get(ui.ctx());
+ let resp =
+ ui.add(egui::Label::new(RichText::new(text).color(t.text_dim)).sense(Sense::click_and_drag())).on_hover_cursor(egui::CursorIcon::ResizeHorizontal);
+ let key = resp.id.with("percent-label-drag");
+ if resp.drag_started() {
+ let stamp = ui.ctx().cumulative_pass_nr();
+ ui.data_mut(|d| d.insert_temp(key, (*percent, stamp)));
+ }
+ let mut out = widgets::PopupFieldResponse::default();
+ if resp.dragged()
+ && let Some((start, stamp)) = ui.data(|d| d.get_temp::<(f32, u64)>(key))
+ && let (Some(origin), Some(pos)) = (ui.input(|i| i.pointer.press_origin()), resp.interact_pointer_pos())
+ {
+ // Match DragValue's 0.5 percentage-point per screen point; do not jump on press.
+ let next = (start + (pos.x - origin.x) * 0.5).clamp(0.0, 100.0);
+ if next.is_finite() && next != *percent {
+ *percent = next;
+ out.changed = true;
+ out.drag = Some(stamp);
+ }
+ }
+ if resp.drag_stopped() {
+ ui.data_mut(|d| d.remove::<(f32, u64)>(key));
+ }
+ out
+}
+
/// Width of `s` as [`label`] draws it (body text).
fn body_text_width(ui: &egui::Ui, s: &str) -> f32 {
let font = egui::TextStyle::Body.resolve(ui.style());
@@ -1584,11 +1669,26 @@ fn navigator(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
app.ui.views[idx].center = [d.x.clamp(0.0, size.width as f32), d.y.clamp(0.0, size.height as f32)];
app.ui.views[idx].fit_pending = false;
}
+ // The Navigator has its own zoom target: an unmodified wheel over the preview
+ // should zoom even when the document canvas is configured to scroll on wheel.
+ // Use the canvas wheel classifier to honour one ×1.1 step per notch without
+ // applying egui's smoothed wheel tail a second time.
+ if resp.hovered()
+ && let Some(crate::wheel_nav::Wheel::Zoom(factor)) = crate::wheel_nav::read(&ctx, true)
+ {
+ let view = &mut app.ui.views[idx];
+ let next = crate::zoom_levels::clamp(view.zoom * factor, view.doc_size);
+ if next != view.zoom {
+ view.zoom = next;
+ view.fit_pending = false;
+ }
+ }
// Visible-area rectangle.
let v = app.ui.views[idx].clone();
let canvas = app.last_canvas_rect;
let point_zoom = (v.zoom / app.canvas_ppp()).max(1e-6);
- let vw = canvas.width() / point_zoom * s;
+ // Pixel aspect correction shows fewer document columns across the same canvas width.
+ let vw = canvas.width() / point_zoom / app.ui.view.display_aspect() * s;
let vh = canvas.height() / point_zoom * s;
let c = pos2(rect.min.x + v.center[0] * s, rect.min.y + v.center[1] * s);
let vr = Rect::from_center_size(c, vec2(vw, vh)).intersect(frame.shrink(1.0));
@@ -1617,6 +1717,43 @@ fn navigator(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
}
}
+#[cfg(test)]
+mod navigator_wheel_tests {
+ use super::*;
+ use egui::{Event, Modifiers, MouseWheelUnit, RawInput, TouchPhase};
+
+ fn frame(app: &mut PhotocraftApp, ctx: &egui::Context, pointer: Pos2, wheel: f32) {
+ let mut events = vec![Event::PointerMoved(pointer)];
+ if wheel != 0.0 {
+ events.push(Event::MouseWheel { unit: MouseWheelUnit::Line, delta: vec2(0.0, wheel), phase: TouchPhase::Move, modifiers: Modifiers::NONE });
+ }
+ let mut out = ctx
+ .run_ui(RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(430.0, 460.0))), events, ..Default::default() }, |ui| navigator(app, ui));
+ out.textures_delta.clear();
+ }
+
+ #[test]
+ fn navigator_wheel_changes_zoom_only_when_over_preview() {
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({"width": 200, "height": 100})).unwrap();
+ app.sync_views();
+ app.ui.views[0].zoom = 1.0;
+ app.ui.views[0].fit_pending = false;
+ let ctx = egui::Context::default();
+ PhotocraftApp::setup_context(&ctx, crate::theme::ThemeKind::ALL[0]);
+ crate::wheel_nav::configure(&ctx);
+ frame(&mut app, &ctx, pos2(50.0, 55.0), 0.0);
+ let center = app.ui.views[0].center;
+ frame(&mut app, &ctx, pos2(50.0, 55.0), 1.0);
+ assert!((app.ui.views[0].zoom - 1.1).abs() < 1e-4, "one wheel notch zooms once");
+ assert_eq!(app.ui.views[0].center, center, "Navigator wheel must not pan");
+ frame(&mut app, &ctx, pos2(50.0, 55.0), -1.0);
+ assert!((app.ui.views[0].zoom - 1.0).abs() < 1e-4);
+ frame(&mut app, &ctx, pos2(50.0, 400.0), 1.0);
+ assert!((app.ui.views[0].zoom - 1.0).abs() < 1e-4, "wheel outside preview leaves zoom unchanged");
+ }
+}
+
fn empty(ui: &mut egui::Ui, s: &str) {
let t = Tokens::get(ui.ctx());
ui.add_space(6.0);
@@ -1635,12 +1772,14 @@ fn color_picker(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
let mut s = hsva0.s * 100.0;
let mut v = hsva0.v * 100.0;
let hue = widgets::hue_stops();
- let mut changed = widgets::slider_row(ui, tl!("Hue"), &mut h, 0.0..=360.0, "°", Some(&hue)).changed();
+ // Preferences ▸ Interface ▸ Dynamic Color Sliders: off, the tracks are the plain ones.
+ let dynamic = app.session.prefs().interface.dynamic_color_sliders;
+ let mut changed = widgets::slider_row(ui, tl!("Hue"), &mut h, 0.0..=360.0, "°", dynamic.then_some(&hue)).changed();
let sat_stops =
[egui::ecolor::Hsva::new(hsva0.h, 0.0, hsva0.v.max(0.2), 1.0), egui::ecolor::Hsva::new(hsva0.h, 1.0, hsva0.v.max(0.2), 1.0)].map(Color32::from);
- changed |= widgets::slider_row(ui, tl!("Saturation"), &mut s, 0.0..=100.0, "%", Some(&sat_stops)).changed();
+ changed |= widgets::slider_row(ui, tl!("Saturation"), &mut s, 0.0..=100.0, "%", dynamic.then_some(&sat_stops)).changed();
let val_stops = [Color32::BLACK, Color32::from(egui::ecolor::Hsva::new(hsva0.h, hsva0.s, 1.0, 1.0))];
- changed |= widgets::slider_row(ui, tl!("Brightness"), &mut v, 0.0..=100.0, "%", Some(&val_stops)).changed();
+ changed |= widgets::slider_row(ui, tl!("Brightness"), &mut v, 0.0..=100.0, "%", dynamic.then_some(&val_stops)).changed();
let hsva = egui::ecolor::Hsva::new(h / 360.0, s / 100.0, v / 100.0, 1.0);
// Only an edit counts: the h/s/v round trip isn't exact, so comparing values would rewrite
// the foreground (and recolour selected type) every frame.
@@ -1710,6 +1849,18 @@ fn layer_drag_edge_scroll(pointer: Option<Pos2>, viewport: Rect, dragging: bool,
direction.signum() * velocity * dt.clamp(0.0, 0.05)
}
+/// Fit blend mode + Opacity into the available Layers-panel width (#2309).
+/// Preserve the normal translated label when there is room; on a narrow dock,
+/// keep the field interactive and give the dropdown the remaining width.
+fn opacity_row_layout(available: f32, label_width: f32, gap: f32) -> (f32, bool) {
+ let full_right = label_width + LAYER_PCT_W + 2.0 * gap + 16.0;
+ // The label shows while the blend dropdown keeps a usable width (at the default dock width
+ // with an English label it does; a long translated label on a narrow dock gives way).
+ let show_label = available >= full_right + 80.0;
+ let reserved = LAYER_PCT_W + gap + if show_label { label_width + gap + 16.0 } else { 0.0 };
+ ((available - reserved).max(40.0), show_label)
+}
+
fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
// A new active layer opens its parent groups and is scrolled into view (#152).
let reveal = crate::layer_reveal::track(app, ui.ctx());
@@ -1759,12 +1910,13 @@ fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
ui.horizontal(|ui| {
ui.add_enabled_ui(!bg, |ui| {
let mut m = l.blend;
- // Leave room for the Opacity label and field: a translated label ("Непрозрачность:")
- // can be much wider than the English one, and must not slide under the dropdown.
+ // Reserve space for the numeric field first. On a narrow dock, hide the
+ // redundant visible Opacity label rather than force the dropdown beyond
+ // the panel's right edge (#2309). The numeric field keeps its name.
let opacity_label = if t.pro { tl!("Opacity:") } else { tl!("Opacity") };
- let right = (body_text_width(ui, opacity_label) + LAYER_PCT_W + 2.0 * ui.spacing().item_spacing.x + 16.0).max(150.0);
- let w = ui.available_width() - right;
- let (chosen, hovered) = widgets::dropdown_wheel_hovered(ui, "blend", &mut m, &blend_options(l.is_group(), l.blend), w.max(100.0));
+ let (blend_width, show_opacity_label) =
+ opacity_row_layout(ui.available_width(), body_text_width(ui, opacity_label), ui.spacing().item_spacing.x);
+ let (chosen, hovered) = widgets::dropdown_wheel_hovered(ui, "blend", &mut m, &blend_options(l.is_group(), l.blend), blend_width);
// One step per choice: a click, an arrow key or each wheel notch (#1747).
for m in &chosen {
actions.push(("layer.setProps".into(), json!({"layer": l.id.0, "blend": m.label()})));
@@ -1773,11 +1925,12 @@ fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
crate::blend_preview::hover(app, l.id, hovered.filter(|_| chosen.is_empty()));
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let mut o = l.opacity * 100.0;
- let r = widgets::popup_value_field(ui, opacity_label, &mut o, 0.0..=100.0, "%", LAYER_PCT_W);
- if r.changed {
- actions.push(pct_action(l, "opacity", o, r.drag));
+ let field = widgets::popup_value_field(ui, opacity_label, &mut o, 0.0..=100.0, "%", LAYER_PCT_W);
+ // On a narrow dock the (scrubby) label yields its room to the controls (#2309).
+ let scrub = if show_opacity_label { scrub_pct_label(ui, opacity_label, &mut o) } else { widgets::PopupFieldResponse::default() };
+ if field.changed || scrub.changed {
+ actions.push(pct_action(l, "opacity", o, scrub.drag.or(field.drag)));
}
- label(ui, opacity_label);
});
});
});
@@ -1822,11 +1975,11 @@ fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
ui.add_enabled_ui(!bg, |ui| {
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let mut f = l.fill_opacity * 100.0;
- let r = widgets::popup_value_field(ui, fill_label, &mut f, 0.0..=100.0, "%", LAYER_PCT_W);
- if r.changed {
- actions.push(pct_action(l, "fill", f, r.drag));
+ let field = widgets::popup_value_field(ui, fill_label, &mut f, 0.0..=100.0, "%", LAYER_PCT_W);
+ let scrub = scrub_pct_label(ui, fill_label, &mut f);
+ if field.changed || scrub.changed {
+ actions.push(pct_action(l, "fill", f, scrub.drag.or(field.drag)));
}
- label(ui, fill_label);
})
});
});
@@ -1862,6 +2015,9 @@ fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
let filter = app.ui.layer_filter.clone();
let fx_collapsed = app.session.active().map(|d| d.fx_collapsed.clone()).unwrap_or_default();
crate::layer_row_ui::begin(ui.ctx());
+ // The drawn rows, top to bottom (#1721): the space between them and below the last
+ // one is a drop zone too.
+ let mut drawn: Vec<(LayerId, Rect)> = Vec::new();
for &(depth, l) in &rows {
// Select › Isolate Layers.
if !photocraft_engine::select_extra_cmds::isolation_shows(&doc, &isolated, l.id) {
@@ -1882,7 +2038,7 @@ fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
}
let row = RowSel { selected: selection.contains(&l.id), primary: active == Some(l.id), multi: selection.len() > 1 };
let top = ui.cursor().top();
- layer_row(app, &ctx, ui, &doc, l, depth, row, &mut actions);
+ drawn.push((l.id, layer_row(app, &ctx, ui, &doc, l, depth, row, &mut actions)));
if reveal == Some(l.id) {
crate::layer_reveal::scroll_to_row(ui, top);
}
@@ -1891,6 +2047,17 @@ fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
}
crate::smart_ui::filter_rows(app, ui, l, depth, &mut actions);
}
+ // #1721: the list takes drops everywhere, not only on a row (Photoshop): the space
+ // between two rows lands above the lower one, the empty space below the bottom-most
+ // row below it. Both copy with ⌥ held, move without.
+ for w in drawn.windows(2) {
+ let gap = Rect::from_min_max(pos2(w[0].1.left(), w[0].1.bottom()), pos2(w[0].1.right(), w[1].1.top()));
+ layer_drop_zone(app, &ctx, ui, gap, (w[1].0, w[1].1), "above", &mut actions);
+ }
+ if let Some(&(last, last_rect)) = drawn.last() {
+ let below = Rect::from_min_max(pos2(last_rect.left(), last_rect.bottom()), pos2(last_rect.right(), ui.clip_rect().bottom()));
+ layer_drop_zone(app, &ctx, ui, below, (last, last_rect), "below", &mut actions);
+ }
// ⌥-click the line between two layers: clip / release the upper one (#967).
crate::clip_line_ui::show(ui, &doc, &mut actions);
// A rename whose row is gone (deleted, filtered out, inside a closed group) ends,
@@ -1925,7 +2092,10 @@ fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
};
let trash = icons::button(ui, "trash", 26.0, false, tl!(label));
if trash.clicked() {
- actions.push((delete.into(), json!({})));
+ // Like Photoshop, ⌥/Alt-click deletes without asking.
+ let confirm = delete == "layer.delete" && !ui.input(|i| i.modifiers.alt);
+ let params = if confirm { json!({"__trash": true}) } else { json!({}) };
+ actions.push((delete.into(), params));
}
actions.extend(footer_drop(ui, &trash, footer_drag, "layer.delete"));
// A click follows the selected thumbnail; name that action for screen readers even
@@ -1938,7 +2108,11 @@ fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
actions.extend(footer_drop(ui, &new_layer, footer_drag, "layer.duplicate"));
let group = icons::button(ui, "folder", 26.0, false, tl!("Create a new group"));
if group.clicked() {
- actions.push(("layer.new.group".into(), json!({})));
+ // Like Photoshop a plain click adds an empty group; Shift-click groups the selected
+ // layers, the same as Layer › Group Layers (#2561).
+ let shift = ui.input(|i| i.modifiers.shift);
+ let cmd = if shift && active_layer.is_some() { "layer.groupLayers" } else { "layer.new.group" };
+ actions.push((cmd.into(), json!({})));
}
actions.extend(footer_drop(ui, &group, footer_drag, "layer.groupLayers"));
let adj = footer_menu_button(ui, "adjustment-layer", 26.0, tl!("Create new fill or adjustment layer"));
@@ -1997,11 +2171,13 @@ fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
if id == "ui.maskTarget" {
app.ui.mask_target = p.as_bool().unwrap_or(false);
app.ui.vector_mask_target = false;
+ app.sync_mask_targets();
continue;
}
if id == "ui.vectorMaskTarget" {
app.ui.vector_mask_target = p.as_bool().unwrap_or(false);
app.ui.mask_target = false;
+ app.sync_mask_targets();
continue;
}
if p.is_null() {
@@ -2147,7 +2323,7 @@ fn layer_row(
depth: usize,
row: RowSel,
actions: &mut Vec<(String, Value)>,
-) {
+) -> Rect {
let selected = row.selected;
let t = Tokens::get(ctx);
// Photoshop's default (medium) thumbnails: 32 pt rows.
@@ -2164,7 +2340,7 @@ fn layer_row(
// otherwise lay out names, icons and thumbnails every frame. Group rows stay whole: their
// disclosure triangle is a widget (accessibility, scroll-to).
if !ui.is_rect_visible(rect) && !l.is_group() && !resp.context_menu_opened() && crate::layer_row_ui::renaming(ctx) != Some(l.id.0) {
- return;
+ return rect;
}
let painter = ui.painter_at(rect.expand(1.0));
if t.pro {
@@ -2333,6 +2509,13 @@ fn layer_row(
// One rename at a time: starting this one commits any other (#314).
actions.push(done);
}
+ } else if let Some(kind) = pos.and_then(|p| masks.hit(p)) {
+ if kind == crate::mask_thumbs_ui::MaskKind::Pixel {
+ actions.push(("ui.maskTarget".into(), json!(true)));
+ }
+ if let Some((cmd, val)) = crate::mask_thumbs_ui::double_click_command(app, kind) {
+ actions.push((cmd.into(), val));
+ }
} else if pos.and_then(|p| masks.hit(p)).is_none() {
let id = match &l.content {
LayerContent::Adjustment(_) | LayerContent::Fill(_) if on(thumb) => "layer.layerContentOptions",
@@ -2352,6 +2535,7 @@ fn layer_row(
}
// Right-click context menu.
resp.context_menu(|ui| {
+ crate::widgets::style_spectrum_popup_menu(ui);
// Right-clicking inside a multi-selection keeps it and acts on every selected layer.
let on_set = row.multi && selected;
if crate::layer_menu_ui::show(app, ui, l, on_set, actions)
@@ -2360,6 +2544,7 @@ fn layer_row(
actions.push(done);
}
});
+ rect
}
/// Screen rect and UVs for a layer thumbnail: the document-shaped part of the square cell and of
@@ -2519,12 +2704,13 @@ pub fn properties_window(app: &mut PhotocraftApp, ctx: &egui::Context) {
}
let Some(st) = app.session.active() else { return };
let Some(id) = st.active_layer else { return };
- let Some(layer) = st.doc.layer(id) else { return };
- // The floating card appears for adjustment and fill layers (their controls live here).
- if !matches!(layer.content, LayerContent::Adjustment(_) | LayerContent::Fill(_)) {
+ let doc = st.doc.clone();
+ let Some(layer) = doc.layer(id) else { return };
+ // Pixel-mask controls also belong here when their thumbnail is targeted.
+ let mask_target = crate::mask_props_ui::targeted(app, layer);
+ if !mask_target && !matches!(layer.content, LayerContent::Adjustment(_) | LayerContent::Fill(_)) {
return;
}
- let layer = layer.clone();
let t = Tokens::get(ctx);
let canvas = app.last_canvas_rect;
let width = 320.0;
@@ -2583,10 +2769,12 @@ pub fn properties_window(app: &mut PhotocraftApp, ctx: &egui::Context) {
ui.add_space(8.0);
// Per-layer ids, so text still being typed for one layer can't commit to the next.
ui.push_id(id, |ui| {
- if let LayerContent::Adjustment(adj) = &layer.content {
+ if mask_target {
+ crate::mask_props_ui::properties(app, ui, layer);
+ } else if let LayerContent::Adjustment(adj) = &layer.content {
adjustment_controls(app, ui, id, adj);
} else {
- layer_controls(app, ui, &layer);
+ layer_controls(app, ui, layer);
}
});
});
@@ -2658,6 +2846,14 @@ fn properties_body(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
empty(ui, tl!("No properties"));
return;
};
+ let doc = st.doc.clone();
+ if let Some(layer) = st.active_layer.and_then(|id| doc.layer(id))
+ && crate::mask_props_ui::targeted(app, layer)
+ {
+ crate::props_layout::header(ui, layer);
+ crate::mask_props_ui::properties(app, ui, layer);
+ return;
+ }
// Photoshop shows the Document properties when nothing or the Background layer is selected.
if crate::doc_props_ui::shows_document(&st.doc, st.active_layer) {
crate::doc_props_ui::properties(app, ui);
@@ -2665,7 +2861,6 @@ fn properties_body(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
}
let Some(id) = st.active_layer else { return };
// Borrowed from the document snapshot: cloning the layer every frame copied whole groups.
- let doc = st.doc.clone();
let Some(layer) = doc.layer(id) else { return };
// Header: kind icon, layer name and kind (#155); sections below draw their own separators.
crate::props_layout::header(ui, layer);
@@ -2764,6 +2959,18 @@ fn field_chips(app: &mut PhotocraftApp, ui: &mut egui::Ui, chips: Rect) {
}
}
+/// Where the dock tells the Color field how tall its group body is.
+pub(crate) fn color_field_fill_id() -> egui::Id {
+ egui::Id::new("color-field-fill-height")
+}
+
+/// Height of the Color field: the group body's height (when docked) less the hex/RGB readout,
+/// which folds onto a second line in a narrow dock. 120 pt when nothing sets a height.
+fn color_field_height(avail: Option<f32>, width: f32) -> f32 {
+ let reserve = 32.0 + if width < 280.0 { 26.0 } else { 0.0 };
+ avail.filter(|a| a.is_finite()).map_or(120.0, |a| (a - reserve).clamp(120.0, 2000.0))
+}
+
/// Photoshop Color panel: saturation/brightness field + hue strip, drawn as shaded meshes.
fn color_field(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
let t = Tokens::get(ui.ctx());
@@ -2777,7 +2984,9 @@ fn color_field(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
}
let w = ui.available_width();
let strip_w = 14.0;
- let h = 120.0;
+ // Photoshop's Color panel field fills the panel: take the height the dock offers, less the
+ // hex/RGB readout (which folds onto a second line in a narrow dock). Without a dock, 120 pt.
+ let h = color_field_height(ui.data(|d| d.get_temp::<f32>(color_field_fill_id())), w);
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 8.0;
let (chips, _) = ui.allocate_exact_size(vec2(38.0, h), Sense::hover());
@@ -3042,6 +3251,31 @@ fn layer_drag_and_drop(
if copy {
ctx.set_cursor_icon(egui::CursorIcon::Copy);
}
+ // #1721: with ⌥ held the row also takes the drop onto itself — the only drop target a
+ // single-layer document has. The copy lands above or below it (never into a group's own
+ // centre). A multi-selection is left alone: the engine copies it beside each of its own
+ // layers, not onto one of them.
+ let selected = app.session.active().map(|st| st.selected_layers()).unwrap_or_default();
+ let in_multi = selected.len() > 1 && selected.contains(&l.id);
+ if copy
+ && !in_multi
+ && let Some(p) = pointer.filter(|p| rect.contains(*p))
+ {
+ let position = if (p.y - rect.top()) / rect.height() < 0.5 { "above" } else { "below" };
+ let painter = ui.painter();
+ if position == "above" {
+ painter.line_segment([rect.left_top(), rect.right_top()], Stroke::new(2.0, t.accent));
+ } else {
+ painter.line_segment([rect.left_bottom(), rect.right_bottom()], Stroke::new(2.0, t.accent));
+ }
+ if released {
+ let mut payload = layer_drop_payload(dragged, l.id, position, &selected);
+ if let Some(o) = payload.as_object_mut() {
+ o.insert("copy".into(), json!(true));
+ }
+ actions.push(("layer.moveTo".into(), payload));
+ }
+ }
return;
}
let Some(p) = pointer else { return };
@@ -3078,6 +3312,42 @@ fn layer_drag_and_drop(
}
}
+/// #1721: the drop zones no row owns — the space between two rows and the empty space below the
+/// bottom-most one. The drop lands on `target` at `position` (`above` or `below` its row): a copy
+/// with ⌥ held on release (Photoshop), a move without. A multi-selection dropped on the row it
+/// was grabbed from is left alone: the engine can only copy it beside each of its own layers.
+fn layer_drop_zone(
+ app: &PhotocraftApp,
+ ctx: &egui::Context,
+ ui: &egui::Ui,
+ zone: Rect,
+ target: (LayerId, Rect),
+ position: &'static str,
+ actions: &mut Vec<(String, Value)>,
+) {
+ let Some(dragged) = ctx.data(|d| d.get_temp::<u64>(egui::Id::new("layer-drag"))) else { return };
+ let selected = app.session.active().map(|st| st.selected_layers()).unwrap_or_default();
+ if target.0 == LayerId(dragged) && selected.len() > 1 && selected.contains(&target.0) {
+ return;
+ }
+ let Some(p) = ctx.input(|i| i.pointer.interact_pos()) else { return };
+ if !zone.contains(p) {
+ return;
+ }
+ let t = Tokens::get(ctx);
+ let line = if position == "above" { [target.1.left_top(), target.1.right_top()] } else { [target.1.left_bottom(), target.1.right_bottom()] };
+ ui.painter().line_segment(line, Stroke::new(2.0, t.accent));
+ if ctx.input(|i| i.pointer.any_released()) {
+ let mut payload = layer_drop_payload(dragged, target.0, position, &selected);
+ if ctx.input(|i| i.modifiers.alt)
+ && let Some(o) = payload.as_object_mut()
+ {
+ o.insert("copy".into(), json!(true));
+ }
+ actions.push(("layer.moveTo".into(), payload));
+ }
+}
+
/// An fx row being dragged: the layer it belongs to and the effect index (`None` = the "Effects"
/// row, all of them).
type FxDrag = (u64, Option<usize>);
@@ -3211,6 +3481,27 @@ fn selection_mode_buttons(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
ui.spacing_mut().item_spacing.x = 8.0;
}
+#[cfg(test)]
+mod symmetry_theme_tests {
+ use super::*;
+ use egui_kittest::{Harness, kittest::Queryable};
+
+ #[test]
+ fn brush_pencil_and_eraser_expose_symmetry_menu_in_every_theme() {
+ for kind in crate::theme::ThemeKind::ALL {
+ for tool in [Tool::Brush, Tool::Pencil, Tool::Eraser] {
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({"width": 80, "height": 80})).unwrap();
+ app.ui.tool = tool;
+ let mut h = Harness::builder().with_size(vec2(1600.0, 300.0)).build_ui_state(|ui, app| options_bar(app, ui), app);
+ PhotocraftApp::setup_context(&h.ctx, kind);
+ h.run_steps(4);
+ assert!(h.query_by_label("Set painting symmetry options").is_some(), "missing symmetry menu in {:?} for {:?}", kind, tool);
+ }
+ }
+ }
+}
+
#[cfg(test)]
mod color_tests {
use super::*;
@@ -3396,6 +3687,17 @@ mod color_tests {
assert_eq!(srgb_bytes(h.state().session.tools.foreground), [0, 255, 0]);
}
+ /// The Color field fills the dock group, never shrinks below 120 pt, and ignores a bad height.
+ #[test]
+ fn color_field_height_fills_the_group() {
+ assert_eq!(color_field_height(None, 300.0), 120.0);
+ assert_eq!(color_field_height(Some(500.0), 300.0), 468.0);
+ assert_eq!(color_field_height(Some(500.0), 200.0), 442.0);
+ assert_eq!(color_field_height(Some(60.0), 300.0), 120.0);
+ assert_eq!(color_field_height(Some(f32::NAN), 300.0), 120.0);
+ assert_eq!(color_field_height(Some(1.0e9), 300.0), 2000.0);
+ }
+
fn field_harness(app: PhotocraftApp) -> egui_kittest::Harness<'static, PhotocraftApp> {
// 60 fps steps, so two clicks a frame apart are a double-click.
let mut h = egui_kittest::Harness::builder().with_size(vec2(300.0, 200.0)).with_step_dt(1.0 / 60.0).build_ui_state(
@@ -3698,6 +4000,8 @@ mod type_flyout_tests {
let j = TOOL_SECTIONS.iter().flat_map(|section| section.iter()).find(|slot| slot.contains(&Tool::SpotHealing)).expect("J group");
assert!(j.contains(&Tool::RedEye), "{j:?}");
assert_eq!(j.last(), Some(&Tool::RedEye));
+ // Remove leads the flyout, so the slot shows it until another J tool is picked.
+ assert_eq!(j.first(), Some(&Tool::Remove));
}
#[test]
@@ -3884,16 +4188,20 @@ mod toolbar_tests {
}
}
- /// The Hand tool's toolbar button: tool buttons have no label, so find it by slot order.
- fn hand_button(h: &egui_kittest::Harness<'_, PhotocraftApp>) -> egui::Pos2 {
+ /// A tool's toolbar button: tool buttons have no label, so find it by slot order.
+ fn tool_button(h: &egui_kittest::Harness<'_, PhotocraftApp>, tool: Tool) -> egui::Pos2 {
let size = egui::Vec2::splat(if Tokens::get(&h.ctx).pro { 30.0 } else { 36.0 });
let buttons: Vec<Rect> = h.ctx.viewport(|v| {
v.prev_pass.widgets.layers().flat_map(|(_, w)| w.iter()).filter(|w| w.rect.size() == size && w.sense.senses_click()).map(|w| w.rect).collect()
});
- let index = TOOL_SECTIONS.iter().flat_map(|section| section.iter()).position(|slot| slot.contains(&Tool::Hand)).unwrap();
+ let index = TOOL_SECTIONS.iter().flat_map(|section| section.iter()).position(|slot| slot.contains(&tool)).unwrap();
buttons[index].center()
}
+ fn hand_button(h: &egui_kittest::Harness<'_, PhotocraftApp>) -> egui::Pos2 {
+ tool_button(h, Tool::Hand)
+ }
+
fn toolbar_harness(app: PhotocraftApp) -> egui_kittest::Harness<'static, PhotocraftApp> {
// 60 fps steps, so two clicks a few frames apart are a double-click.
let mut h = egui_kittest::Harness::builder().with_size(vec2(800.0, 1400.0)).with_step_dt(1.0 / 60.0).build_ui_state(
@@ -3942,6 +4250,41 @@ mod toolbar_tests {
assert_eq!(h.state().ui.tool, Tool::Hand);
assert!(h.state().session.active().is_none());
}
+
+ /// Double-clicking the Zoom tool zooms to 100% (Photoshop); a single click only picks the tool.
+ #[test]
+ fn double_clicking_the_zoom_tool_zooms_to_actual_pixels() {
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({"width": 64, "height": 64})).unwrap();
+ app.ui.tool = Tool::Move;
+ app.ui.views[0].fit_pending = true;
+ app.ui.views[0].zoom = 0.25;
+ let mut h = toolbar_harness(app);
+ let p = tool_button(&h, Tool::Zoom);
+ click(&mut h, p);
+ assert_eq!(h.state().ui.tool, Tool::Zoom);
+ assert_eq!(h.state().ui.views[0].zoom, 0.25, "a single click doesn't zoom");
+ // Past the double-click window, so the next two clicks are a fresh double-click.
+ h.run_steps(40);
+ click(&mut h, p);
+ click(&mut h, p);
+ assert_eq!(h.state().ui.tool, Tool::Zoom);
+ assert_eq!(h.state().ui.views[0].zoom, 1.0, "a double-click zooms to 100%");
+ assert!(!h.state().ui.views[0].fit_pending, "100% replaces a pending fit");
+ }
+
+ /// With no document open the double-click still picks the tool and doesn't panic.
+ #[test]
+ fn double_clicking_the_zoom_tool_without_a_document_is_harmless() {
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+ app.ui.tool = Tool::Move;
+ let mut h = toolbar_harness(app);
+ let p = tool_button(&h, Tool::Zoom);
+ click(&mut h, p);
+ click(&mut h, p);
+ assert_eq!(h.state().ui.tool, Tool::Zoom);
+ assert!(h.state().session.active().is_none());
+ }
}
#[cfg(test)]
@@ -4101,6 +4444,33 @@ mod group_drag_selection_tests {
}
}
+#[cfg(test)]
+mod opacity_row_layout_tests {
+ use super::*;
+
+ #[test]
+ fn opacity_label_yields_to_controls_in_narrow_layers_panel() {
+ let gap = 2.0;
+ let label = 62.0;
+ let (wide, visible) = opacity_row_layout(360.0, label, gap);
+ assert!(visible);
+ assert!(wide >= 100.0);
+ // The default dock width keeps the English label (the Layers dock at its 250 px minimum).
+ assert!(opacity_row_layout(255.0, 46.0, 8.0).1);
+ let (medium, visible) = opacity_row_layout(180.0, label, gap);
+ assert!(!visible, "the long label must not overlap the blend field");
+ assert!(medium + LAYER_PCT_W + gap <= 180.0);
+ let (narrow, visible) = opacity_row_layout(135.0, label, gap);
+ assert!(!visible);
+ assert!(narrow >= 40.0);
+ assert!(narrow + LAYER_PCT_W + gap <= 135.0);
+ }
+}
+
+#[cfg(test)]
+#[path = "mask_props_ui_tests.rs"]
+mod mask_properties_tests;
+
#[cfg(test)]
mod tool_flyout_gesture_tests {
use super::*;