diff --git a/crates/ui-egui/src/panels/actions.rs b/crates/ui-egui/src/panels/actions.rs index a4a5969544..004d152185 100644 --- a/crates/ui-egui/src/panels/actions.rs +++ b/crates/ui-egui/src/panels/actions.rs @@ -11,6 +11,7 @@ use serde_json::{Value, json}; use photocraft_engine::actions_cmds::{self, Action}; use crate::PhotocraftApp; +use crate::icons; use crate::theme::Tokens; /// Which row is selected and which rows are expanded. The action list itself is @@ -821,6 +822,86 @@ fn display_order(rows: &[Row]) -> Vec { order } +struct SetHeaderResult { + toggled: bool, + save: bool, +} + +fn draw_set_header(ui: &mut egui::Ui, set: &str, count: u64, collapsed: bool, tokens: &Tokens) -> SetHeaderResult { + let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), 24.0), Sense::click()); + response.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, true, !collapsed, set)); + if response.hovered() { + ui.painter().rect_filled(rect, 0.0, tokens.hover.gamma_multiply(0.5)); + } + let triangle = Rect::from_center_size(pos2(rect.left() + 12.0, rect.center().y), vec2(8.0, 8.0)); + let points = if collapsed { + vec![triangle.left_top(), triangle.right_center(), triangle.left_bottom()] + } else { + vec![triangle.left_top(), triangle.right_top(), triangle.center_bottom()] + }; + ui.painter().add(egui::Shape::convex_polygon(points, tokens.text_dim, Stroke::NONE)); + icons::paint( + ui, + Rect::from_center_size(pos2(rect.left() + 30.0, rect.center().y), vec2(16.0, 16.0)), + if collapsed { "folder" } else { "folder-open" }, + 12.0, + tokens.icon, + ); + ui.painter().text(pos2(rect.left() + 44.0, rect.center().y), Align2::LEFT_CENTER, set, egui::FontId::proportional(12.0), tokens.text); + let summary = crate::i18n::trn(crate::i18n::current(), count, "{n} action", "{n} actions"); + ui.painter().text(pos2(rect.right() - 8.0, rect.center().y), Align2::RIGHT_CENTER, summary, egui::FontId::proportional(11.0), tokens.text_faint); + let toggled = response.clicked(); + let mut save = false; + response.context_menu(|ui| { + if ui.button(tl!("Save Set…")).clicked() { + save = true; + ui.close(); + } + }); + SetHeaderResult { toggled, save } +} + +fn action_context_menu(app: &mut PhotocraftApp, response: &egui::Response, index: usize, name: &str, swatch: &str) { + egui::Popup::context_menu(response).close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside).show(|ui| { + ui.label(tl!("Keyboard Shortcuts")); + let current = app.session.prefs().shortcuts.get(&shortcut_id(name)).cloned().unwrap_or_default(); + let (key, mut shift, mut command) = photocraft_engine::atn_cmds::parse_function_key(¤t).unwrap_or((0, false, false)); + for number in std::iter::once(0).chain(1..=12) { + let label = if number == 0 { tl!("None").to_string() } else { format!("F{number}") }; + if ui.selectable_label(key == number, label).clicked() { + let chosen = if number == 0 { String::new() } else { photocraft_engine::atn_cmds::function_key_name(number, shift, command) }; + let _ = assign_shortcut(app, name, &chosen); + ui.close(); + } + } + ui.add_enabled_ui(key > 0, |ui| { + let command_label = if cfg!(target_os = "macos") { tl!("Command") } else { tl!("Ctrl") }; + let toggled = ui.checkbox(&mut shift, tl!("Shift")).changed() | ui.checkbox(&mut command, command_label).changed(); + if toggled { + let _ = assign_shortcut(app, name, &photocraft_engine::atn_cmds::function_key_name(key, shift, command)); + } + }); + ui.separator(); + ui.menu_button(tl!("Color"), |ui| { + for (id, label) in [ + ("", tl!("None")), + ("red", tl!("Red")), + ("orange", tl!("Orange")), + ("yellow", tl!("Yellow")), + ("green", tl!("Green")), + ("blue", tl!("Blue")), + ("violet", tl!("Violet")), + ("gray", tl!("Gray")), + ] { + if ui.selectable_label(swatch == id, label).clicked() { + let _ = app.run("actions.setColor", json!({"action": index, "color": id})); + ui.close(); + } + } + }); + }); +} + pub fn panel(app: &mut PhotocraftApp, ui: &mut egui::Ui) { let t = Tokens::get(ui.ctx()); let recording = app.session.actions.recording; @@ -900,38 +981,14 @@ pub fn panel(app: &mut PhotocraftApp, ui: &mut egui::Ui) { { shown_set = Some(set); let collapsed = app.ui.actions.collapsed_sets.iter().any(|c| c == set); - let (hr, hresp) = ui.allocate_exact_size(vec2(ui.available_width(), 24.0), Sense::click()); - hresp.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, true, !collapsed, set)); - if hresp.hovered() { - ui.painter().rect_filled(hr, 0.0, t.hover.gamma_multiply(0.5)); - } - let tri = Rect::from_center_size(pos2(hr.left() + 12.0, hr.center().y), vec2(8.0, 8.0)); - let pts = if collapsed { - vec![tri.left_top(), tri.right_center(), tri.left_bottom()] - } else { - vec![tri.left_top(), tri.right_top(), tri.center_bottom()] - }; - ui.painter().add(egui::Shape::convex_polygon(pts, t.text_dim, Stroke::NONE)); - crate::icons::paint( - ui, - Rect::from_center_size(pos2(hr.left() + 30.0, hr.center().y), vec2(16.0, 16.0)), - if collapsed { "folder" } else { "folder-open" }, - 12.0, - t.icon, - ); - ui.painter().text(pos2(hr.left() + 44.0, hr.center().y), Align2::LEFT_CENTER, set, egui::FontId::proportional(12.0), t.text); let count = rows.iter().filter(|r| r.set.as_deref() == Some(set)).count() as u64; - let summary = crate::i18n::trn(crate::i18n::current(), count, "{n} action", "{n} actions"); - ui.painter().text(pos2(hr.right() - 8.0, hr.center().y), Align2::RIGHT_CENTER, summary, egui::FontId::proportional(11.0), t.text_faint); - if hresp.clicked() { + let result = draw_set_header(ui, set, count, collapsed, &t); + if result.toggled { set_toggled = Some(set.to_string()); } - hresp.context_menu(|ui| { - if ui.button(tl!("Save Set…")).clicked() { - save_set = Some(set.to_string()); - ui.close(); - } - }); + if result.save { + save_set = Some(set.to_string()); + } } if set.as_deref().is_some_and(|set| app.ui.actions.collapsed_sets.iter().any(|c| c == set)) { continue; @@ -1012,45 +1069,7 @@ pub fn panel(app: &mut PhotocraftApp, ui: &mut egui::Ui) { } // Clicks inside stay open, so Shift and Command can both be ticked; every item that // finishes closes the menu itself. - egui::Popup::context_menu(&resp).close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside).show(|ui| { - ui.label(tl!("Keyboard Shortcuts")); - let current = app.session.prefs().shortcuts.get(&shortcut_id(name)).cloned().unwrap_or_default(); - // Photoshop's Action Options: a function key, with Shift and Command (#7646). - let (key, mut shift, mut command) = photocraft_engine::atn_cmds::parse_function_key(¤t).unwrap_or((0, false, false)); - for n in std::iter::once(0).chain(1..=12) { - let label = if n == 0 { tl!("None").to_string() } else { format!("F{n}") }; - if ui.selectable_label(key == n, label).clicked() { - let chosen = if n == 0 { String::new() } else { photocraft_engine::atn_cmds::function_key_name(n, shift, command) }; - let _ = assign_shortcut(app, name, &chosen); - ui.close(); - } - } - ui.add_enabled_ui(key > 0, |ui| { - let command_label = if cfg!(target_os = "macos") { tl!("Command") } else { tl!("Ctrl") }; - let toggled = ui.checkbox(&mut shift, tl!("Shift")).changed() | ui.checkbox(&mut command, command_label).changed(); - if toggled { - let _ = assign_shortcut(app, name, &photocraft_engine::atn_cmds::function_key_name(key, shift, command)); - } - }); - ui.separator(); - ui.menu_button(tl!("Color"), |ui| { - for (id, label) in [ - ("", tl!("None")), - ("red", tl!("Red")), - ("orange", tl!("Orange")), - ("yellow", tl!("Yellow")), - ("green", tl!("Green")), - ("blue", tl!("Blue")), - ("violet", tl!("Violet")), - ("gray", tl!("Gray")), - ] { - if ui.selectable_label(swatch == id, label).clicked() { - let _ = app.run("actions.setColor", json!({"action": i, "color": id})); - ui.close(); - } - } - }); - }); + action_context_menu(app, &resp, i, name, swatch); if resp.double_clicked() && !button_mode { // Photoshop renames in place when the name itself is double-clicked. if resp.interact_pointer_pos().is_some_and(|p| name_rect.expand2(vec2(4.0, 13.0)).contains(p)) { @@ -1060,56 +1079,11 @@ pub fn panel(app: &mut PhotocraftApp, ui: &mut egui::Ui) { } } if expanded { - for (step, (id, params)) in steps.iter().enumerate() { - let (r, response) = ui.allocate_exact_size(vec2(ui.available_width(), 20.0), Sense::click_and_drag()); - if reveal == Some((i, step + 1)) { - ui.scroll_to_rect(r, Some(egui::Align::BOTTOM)); - } - let label = step_label(id, params); - let selected = app.ui.actions.selected == Some(i) && app.ui.actions.selected_step == Some(step); - response.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, true, selected, &label)); - if selected { - ui.painter().rect_filled(r, 0.0, t.row_selected); - } else if response.hovered() { - ui.painter().rect_filled(r, 0.0, t.hover.gamma_multiply(0.5)); - } - if let Some(change) = drag_row(ui, &response, DragRow { action: i, step: Some(step) }, &t) { - moved = Some(change); - } - let on = !disabled.contains(&step); - let color = if on { t.text_dim } else { t.text_faint }; - ui.painter().text(pos2(x0 + 62.0, r.center().y), Align2::LEFT_CENTER, &label, egui::FontId::proportional(11.5), color); - // Photoshop's check column: unchecked steps are skipped by playback, Batch and droplets. - let check = ui.interact( - Rect::from_center_size(pos2(x0 + 30.0, r.center().y), vec2(16.0, 16.0)), - ui.scope_id().with(("action-step-check", i, step)), - Sense::click(), - ); - check.widget_info(|| egui::WidgetInfo::selected(egui::Role::CheckBox, true, on, format!("{}: {label}", tl!("Include in playback")))); - paint_check(ui, check.rect, on, &t); - // Photoshop's dialog column: playback shows the step's dialog, seeded with its - // recorded values, and continues when it is confirmed. - let with_dialog = dialogs.contains(&step); - let dialog = ui.interact( - Rect::from_center_size(pos2(x0 + 46.0, r.center().y), vec2(16.0, 16.0)), - ui.scope_id().with(("action-step-dialog", i, step)), - Sense::click(), - ); - // A toggle button, not a check box, so the check column stays the only CheckBox role. - dialog.widget_info(|| { - egui::WidgetInfo::selected(egui::Role::Button, true, with_dialog, format!("{}: {label}", tl!("Show dialog during playback"))) - }); - crate::icons::paint(ui, dialog.rect, "message-square", 11.0, if with_dialog { t.icon } else { t.text_faint.gamma_multiply(0.45) }); - let dialog = dialog.on_hover_text(tl!("Show dialog during playback")); - if check.on_hover_text(tl!("Include in playback")).clicked() { - toggled = Some((i, step)); - } else if dialog.clicked() { - dialog_toggled = Some((i, step)); - } else if response.clicked() { - app.ui.actions.selected = Some(i); - app.ui.actions.selected_step = Some(step); - } - } + let context = StepRowsContext { action: i, x0, steps, disabled, dialogs, reveal, tokens: &t }; + let events = draw_step_rows(app, ui, &context); + moved = moved.or(events.moved); + toggled = toggled.or(events.toggled); + dialog_toggled = dialog_toggled.or(events.dialog_toggled); } } }); @@ -1190,5 +1164,83 @@ pub fn panel(app: &mut PhotocraftApp, ui: &mut egui::Ui) { } } +struct StepRowsContext<'a> { + action: usize, + x0: f32, + steps: &'a [(String, Value)], + disabled: &'a std::collections::BTreeSet, + dialogs: &'a std::collections::BTreeSet, + reveal: Option<(usize, usize)>, + tokens: &'a Tokens, +} + +#[derive(Default)] +struct StepRowEvents { + moved: Option<(DragRow, usize)>, + toggled: Option<(usize, usize)>, + dialog_toggled: Option<(usize, usize)>, +} + +fn draw_step_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, context: &StepRowsContext<'_>) -> StepRowEvents { + let mut events = StepRowEvents::default(); + for (step, (id, params)) in context.steps.iter().enumerate() { + let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), 20.0), Sense::click_and_drag()); + if context.reveal == Some((context.action, step + 1)) { + ui.scroll_to_rect(rect, Some(egui::Align::BOTTOM)); + } + let label = step_label(id, params); + draw_step_label(app, ui, rect, &response, step, &label, context); + events.moved = drag_row(ui, &response, DragRow { action: context.action, step: Some(step) }, context.tokens).or(events.moved); + let (check, dialog) = draw_step_controls(ui, rect, step, &label, context); + if check.clicked() { + events.toggled = Some((context.action, step)); + } else if dialog.clicked() { + events.dialog_toggled = Some((context.action, step)); + } else if response.clicked() { + app.ui.actions.selected = Some(context.action); + app.ui.actions.selected_step = Some(step); + } + } + events +} + +fn draw_step_label(app: &PhotocraftApp, ui: &egui::Ui, rect: Rect, response: &egui::Response, step: usize, label: &str, context: &StepRowsContext<'_>) { + let selected = app.ui.actions.selected == Some(context.action) && app.ui.actions.selected_step == Some(step); + response.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, true, selected, label)); + if selected { + ui.painter().rect_filled(rect, 0.0, context.tokens.row_selected); + } else if response.hovered() { + ui.painter().rect_filled(response.rect, 0.0, context.tokens.hover.gamma_multiply(0.5)); + } + let color = if context.disabled.contains(&step) { context.tokens.text_faint } else { context.tokens.text_dim }; + ui.painter().text(pos2(context.x0 + 62.0, rect.center().y), Align2::LEFT_CENTER, label, egui::FontId::proportional(11.5), color); +} + +fn draw_step_controls(ui: &mut egui::Ui, rect: Rect, step: usize, label: &str, context: &StepRowsContext<'_>) -> (egui::Response, egui::Response) { + let on = !context.disabled.contains(&step); + let check = ui.interact( + Rect::from_center_size(pos2(context.x0 + 30.0, rect.center().y), vec2(16.0, 16.0)), + ui.scope_id().with(("action-step-check", context.action, step)), + Sense::click(), + ); + check.widget_info(|| egui::WidgetInfo::selected(egui::Role::CheckBox, true, on, format!("{}: {label}", tl!("Include in playback")))); + paint_check(ui, check.rect, on, context.tokens); + let with_dialog = context.dialogs.contains(&step); + let dialog = ui.interact( + Rect::from_center_size(pos2(context.x0 + 46.0, rect.center().y), vec2(16.0, 16.0)), + ui.scope_id().with(("action-step-dialog", context.action, step)), + Sense::click(), + ); + dialog.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, true, with_dialog, format!("{}: {label}", tl!("Show dialog during playback")))); + crate::icons::paint( + ui, + dialog.rect, + "message-square", + 11.0, + if with_dialog { context.tokens.icon } else { context.tokens.text_faint.gamma_multiply(0.45) }, + ); + (check.on_hover_text(tl!("Include in playback")), dialog.on_hover_text(tl!("Show dialog during playback"))) +} + #[cfg(test)] mod tests; diff --git a/crates/ui-egui/src/panels/brush_controls.rs b/crates/ui-egui/src/panels/brush_controls.rs index eb5bcc7374..d6a96112a7 100644 --- a/crates/ui-egui/src/panels/brush_controls.rs +++ b/crates/ui-egui/src/panels/brush_controls.rs @@ -1,4 +1,4 @@ -use super::*; +use super::{Align2, BlendMode, Color32, PhotocraftApp, Rect, Sense, Stroke, StrokeKind, Tokens, c32, icons, json, pos2, vec2, widgets}; /// Photoshop's brush preset picker chip: a soft/hard round tip preview with the size underneath. /// Draw a round brush tip preview (hard core fading to a soft edge). diff --git a/crates/ui-egui/src/panels/color.rs b/crates/ui-egui/src/panels/color.rs index 273893ae5a..90cfa9d8e6 100644 --- a/crates/ui-egui/src/panels/color.rs +++ b/crates/ui-egui/src/panels/color.rs @@ -1,4 +1,4 @@ -use super::*; +use super::{Color32, PhotocraftApp, Rect, RichText, Sense, Stroke, StrokeKind, Tokens, c32, pos2, theme, vec2, widgets}; /// The Color panel's foreground and background chips. A click picks the colour the field edits, /// framed; a double-click opens the Color Picker on it. diff --git a/crates/ui-egui/src/panels/dock.rs b/crates/ui-egui/src/panels/dock.rs index 99f2afc7a8..4bc72ab57b 100644 --- a/crates/ui-egui/src/panels/dock.rs +++ b/crates/ui-egui/src/panels/dock.rs @@ -3,7 +3,7 @@ use super::info::info_panel; use super::layers::{channels, layers}; use super::navigator::navigator; use super::properties::{adjustments_grid, properties_body}; -use super::*; +use super::{PhotocraftApp, Stroke, Tokens, icons, pos2}; // ----------------------------------------------------------------------------- dock diff --git a/crates/ui-egui/src/panels/history.rs b/crates/ui-egui/src/panels/history.rs index 7af5b3e3c1..939ef07e6b 100644 --- a/crates/ui-egui/src/panels/history.rs +++ b/crates/ui-egui/src/panels/history.rs @@ -1,5 +1,5 @@ use super::layer_drag::dropped_on; -use super::*; +use super::{Align2, Color32, HistorySource, PhotocraftApp, Rect, Sense, Stroke, StrokeKind, Tokens, Tool, Value, empty, icons, json, pos2, vec2, widgets}; pub(super) fn history(app: &mut PhotocraftApp, ui: &mut egui::Ui) { let t = Tokens::get(ui.ctx()); diff --git a/crates/ui-egui/src/panels/info.rs b/crates/ui-egui/src/panels/info.rs index 41a16d9f97..56a60e82d0 100644 --- a/crates/ui-egui/src/panels/info.rs +++ b/crates/ui-egui/src/panels/info.rs @@ -1,4 +1,4 @@ -use super::*; +use super::{PhotocraftApp, RichText, Tokens, Value, empty, json, theme, widgets}; /// The active document's pixel under the pointer, if the pointer is over the image. pub(crate) fn hover_pixel(app: &PhotocraftApp) -> Option<(i32, i32)> { diff --git a/crates/ui-egui/src/panels/layer_drag.rs b/crates/ui-egui/src/panels/layer_drag.rs index fd9a5d9b47..f778ccec75 100644 --- a/crates/ui-egui/src/panels/layer_drag.rs +++ b/crates/ui-egui/src/panels/layer_drag.rs @@ -1,5 +1,5 @@ use super::layers::footer_label; -use super::*; +use super::{Layer, LayerId, MaskKind, PhotocraftApp, Pos2, Rect, Sense, Stroke, StrokeKind, Tokens, Value, icons, json, pos2, vec2}; /// Scroll the Layers panel while holding a layer drag over its top/bottom edge or past them. /// diff --git a/crates/ui-egui/src/panels/layer_row.rs b/crates/ui-egui/src/panels/layer_row.rs index 959ca07da8..5f182c13a5 100644 --- a/crates/ui-egui/src/panels/layer_row.rs +++ b/crates/ui-egui/src/panels/layer_row.rs @@ -1,6 +1,8 @@ use super::layer_drag::{MaskDrag, fx_drop, layer_drag_and_drop, mask_drag_key, start_fx_drag, starts_mask_drag}; use super::layers::simple_lock_toggle; -use super::*; +use super::{ + Color32, CornerRadius, Layer, LayerContent, PhotocraftApp, Pos2, Rect, Sense, Stroke, StrokeKind, Tokens, Value, icons, json, pos2, theme, vec2, widgets, +}; /// How a Layers panel row is selected: in the (multi-)selection, the primary/active layer, and /// whether several layers are selected. @@ -55,28 +57,51 @@ fn eye_sweep(ctx: &egui::Context, l: &Layer, row: Rect, eye: &egui::Response, ac let set = |visible: bool, key: u64| ("layer.setProps".to_string(), json!({"layer": l.id.0, "visible": visible, "coalesce": format!("layer-eye-sweep:{key}")})); if eye.drag_started() { - let sweep = EyeSweep { visible: !l.visible, key: ctx.cumulative_pass_nr(), swept: vec![l.id.0] }; - actions.push(set(sweep.visible, sweep.key)); - ctx.data_mut(|d| d.insert_temp(id, sweep)); + start_eye_sweep(ctx, l, id, actions, &set); + } else { + continue_eye_sweep(ctx, l, row, id, actions, &set); + } +} + +fn start_eye_sweep(ctx: &egui::Context, layer: &Layer, id: egui::Id, actions: &mut Vec<(String, Value)>, set: &impl Fn(bool, u64) -> (String, Value)) { + let sweep = EyeSweep { visible: !layer.visible, key: ctx.cumulative_pass_nr(), swept: vec![layer.id.0] }; + actions.push(set(sweep.visible, sweep.key)); + ctx.data_mut(|data| data.insert_temp(id, sweep)); +} + +fn continue_eye_sweep( + ctx: &egui::Context, + layer: &Layer, + row: Rect, + id: egui::Id, + actions: &mut Vec<(String, Value)>, + set: &impl Fn(bool, u64) -> (String, Value), +) { + let Some(mut sweep) = ctx.data(|data| data.get_temp::(id)) else { return }; + if !sweep_pointer_down(ctx) { + ctx.data_mut(|data| data.remove::(id)); return; } - let Some(mut sweep) = ctx.data(|d| d.get_temp::(id)) else { return }; - let (down, pos, delta) = ctx.input(|i| (i.pointer.primary_down(), i.pointer.interact_pos(), i.pointer.delta())); - if !down { - ctx.data_mut(|d| d.remove::(id)); + let Some((y0, y1)) = swept_pointer_range(ctx) else { return }; + if y1 < row.top() || y0 >= row.bottom() || sweep.swept.contains(&layer.id.0) { return; } - // Everything the pointer passed since the last frame, so a fast drag skips no row. - let Some(p) = pos else { return }; - let (y0, y1) = ((p.y - delta.y).min(p.y), (p.y - delta.y).max(p.y)); - if y1 < row.top() || y0 >= row.bottom() || sweep.swept.contains(&l.id.0) { - return; - } - if l.visible != sweep.visible { + if layer.visible != sweep.visible { actions.push(set(sweep.visible, sweep.key)); } - sweep.swept.push(l.id.0); - ctx.data_mut(|d| d.insert_temp(id, sweep)); + sweep.swept.push(layer.id.0); + ctx.data_mut(|data| data.insert_temp(id, sweep)); +} + +fn sweep_pointer_down(ctx: &egui::Context) -> bool { + ctx.input(|input| input.pointer.primary_down()) +} + +/// The pointer segment between frames catches rows even when a fast drag skips them visually. +fn swept_pointer_range(ctx: &egui::Context) -> Option<(f32, f32)> { + let (position, delta) = ctx.input(|input| (input.pointer.interact_pos(), input.pointer.delta())); + let p = position?; + Some(((p.y - delta.y).min(p.y), (p.y - delta.y).max(p.y))) } /// Marker in the clipped row's existing 12-point slot, beside its thumbnail. diff --git a/crates/ui-egui/src/panels/layers.rs b/crates/ui-egui/src/panels/layers.rs index 1d548ce270..fe0f8c9577 100644 --- a/crates/ui-egui/src/panels/layers.rs +++ b/crates/ui-egui/src/panels/layers.rs @@ -4,7 +4,7 @@ use super::layer_drag::{ }; use super::layer_row::{RowSel, layer_row}; use super::options_bar::{LAYER_PCT_W, body_text_width, pct_action, scrub_pct_label}; -use super::*; +use super::{BlendMode, Layer, LayerId, MaskKind, PhotocraftApp, Rect, Sense, Tokens, Value, empty, icons, json, label, pos2, theme, vec2, widgets}; // ----------------------------------------------------------------------------- layers diff --git a/crates/ui-egui/src/panels/navigator.rs b/crates/ui-egui/src/panels/navigator.rs index a6bfbf00c8..b588288c47 100644 --- a/crates/ui-egui/src/panels/navigator.rs +++ b/crates/ui-egui/src/panels/navigator.rs @@ -1,4 +1,4 @@ -use super::*; +use super::{Color32, PhotocraftApp, Pos2, Rect, Sense, Stroke, StrokeKind, Tokens, empty, icons, pos2, vec2, widgets}; pub(super) fn navigator(app: &mut PhotocraftApp, ui: &mut egui::Ui) { let t = Tokens::get(ui.ctx()); diff --git a/crates/ui-egui/src/panels/options_bar.rs b/crates/ui-egui/src/panels/options_bar.rs index e24c3b4e6b..48f1ba9962 100644 --- a/crates/ui-egui/src/panels/options_bar.rs +++ b/crates/ui-egui/src/panels/options_bar.rs @@ -1,6 +1,7 @@ use super::brush_controls::{brush_preset_chip, mixer_load_swatch, paint_mode_dropdown, smoothing_field, smoothing_options, tool_mode_dropdown}; use super::properties::{select_and_mask_button, selection_mode_buttons}; -use super::*; +use super::{BlendMode, Color32, PhotocraftApp, RichText, Sense, Tokens, Tool, Value, icons, json, vec2, widgets}; +use photocraft_paint::BrushSettings; // Custom controls also need to bring keyboard focus into a scroll viewport. pub(super) fn reveal_focused_control(ui: &egui::Ui) { @@ -130,511 +131,7 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) { let brush_before = app.session.tools.brush.clone(); let mut brush = brush_before.clone(); let b = &mut brush; - match app.ui.tool { - Tool::Brush | Tool::Eraser if t.pro => { - // 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); - // 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 held = app.held_erase; - paint_mode_dropdown(ui, "brush-mode", b, &mut app.ui.tool_options.brush_clear, held); - } - 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, "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); - widgets::vline(ui, 22.0); - if icons::button(ui, "circle-dot", 24.0, b.pressure_size, tl!("Always use pressure for size")).clicked() { - b.pressure_size = !b.pressure_size; - } - } - // Pencil: Photoshop's options (no hardness or flow: the pencil is always hard). - Tool::Pencil => { - brush_preset_chip(ui, b, &mut app.ui); - crate::brush_picker::settings_toggle(app, ui); - widgets::vline(ui, 22.0); - if !t.pro { - opt_label(ui, tl!("Size")); - widgets::value_field(ui, &mut b.size, 1.0..=photocraft_engine::paint::MAX_BRUSH_SIZE, "px", 76.0); - widgets::vline(ui, 22.0); - } - opt_label(ui, tl!("Mode")); - let held = app.held_erase; - paint_mode_dropdown(ui, "pencil-mode", b, &mut app.ui.tool_options.pencil_clear, held); - percent_field(ui, tl!("Opacity"), &mut b.opacity, 0.0..=100.0, if t.pro { 62.0 } else { 66.0 }); - opt_label(ui, tl!("Smoothing")); - smoothing_field(ui, b, if t.pro { 58.0 } else { 66.0 }); - widgets::vline(ui, 22.0); - widgets::checkbox(ui, &mut app.ui.tool_options.pencil_auto_erase, tl!("Auto Erase")); - } - Tool::Brush | Tool::Eraser => { - brush_preset_chip(ui, b, &mut app.ui); - crate::brush_picker::settings_toggle(app, ui); - widgets::vline(ui, 22.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..=photocraft_engine::paint::MAX_BRUSH_SIZE, "px", 76.0); - }); - widgets::vline(ui, 22.0); - 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 held = app.held_erase; - paint_mode_dropdown(ui, "brush-mode", b, &mut app.ui.tool_options.brush_clear, held); - } - // 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); - widgets::toggle(ui, &mut b.pressure_size, tl!("Pressure for Size")); - widgets::toggle(ui, &mut b.pressure_opacity, tl!("Pressure for Opacity")); - } - Tool::MixerBrush => { - brush_preset_chip(ui, b, &mut app.ui); - crate::brush_picker::settings_toggle(app, ui); - widgets::vline(ui, 22.0); - mixer_load_swatch(app, ui); - let m = &mut b.mixer; - for (icon, on, tip) in [ - ("brush", &mut m.load_after_stroke, tl!("Load the brush after each stroke")), - ("brush-cleaning", &mut m.clean_after_stroke, tl!("Clean the brush after each stroke")), - ] { - if icons::button(ui, icon, 24.0, *on, tip).clicked() { - *on = !*on; - } - } - widgets::vline(ui, 22.0); - for (label, value) in [ - (tl!("Wet"), &mut b.mixer.wet), - (tl!("Load"), &mut b.mixer.load), - (tl!("Mix"), &mut b.mixer.mix), - (tl!("Flow"), &mut b.mixer.flow), - ] { - percent_field(ui, label, value, 0.0..=100.0, 62.0); - } - widgets::vline(ui, 22.0); - widgets::checkbox(ui, &mut b.mixer.sample_all_layers, tl!("Sample All Layers")); - } - Tool::RectMarquee | Tool::EllipseMarquee | Tool::SingleRowMarquee | Tool::SingleColumnMarquee => { - ui.spacing_mut().item_spacing.x = 2.0; - for (i, (icon, tip)) in [ - ("square", tl!("New selection").to_string()), - ("plus", crate::i18n::fmt(tl!("Add to selection ({key})"), &[("key", &crate::shortcuts::pretty("Shift"))])), - ("minus", crate::i18n::fmt(tl!("Subtract from selection ({key})"), &[("key", &crate::shortcuts::pretty("Alt"))])), - ( - "squares-subtract", - crate::i18n::fmt(tl!("Intersect with selection ({key})"), &[("key", &crate::shortcuts::pretty("Shift+Alt"))]), - ), - ] - .iter() - .enumerate() - { - if icons::button(ui, icon, 24.0, app.ui.selection_mode == i as u8, tip).clicked() { - app.ui.selection_mode = i as u8; - } - } - ui.spacing_mut().item_spacing.x = 8.0; - widgets::vline(ui, 22.0); - let (units, size) = fixed_size_units(app); - let o = &mut app.ui.tool_options; - opt_label(ui, tl!("Feather")); - widgets::value_field(ui, &mut o.feather, 0.0..=1000.0, "px", 62.0); - // Photoshop greys Anti-alias for the Rectangular Marquee (its edges are always hard). - ui.add_enabled_ui(app.ui.tool == Tool::EllipseMarquee, |ui| widgets::checkbox(ui, &mut o.anti_alias, tl!("Anti-alias"))); - widgets::vline(ui, 22.0); - // A single row or column has no style or size: Photoshop greys them. - let sized = matches!(app.ui.tool, Tool::RectMarquee | Tool::EllipseMarquee); - ui.add_enabled_ui(sized, |ui| opt_label(ui, tl!("Style"))); - let styles = [ - ("normal".to_string(), tl!("Normal")), - ("fixedRatio".to_string(), tl!("Fixed Ratio")), - ("fixedSize".to_string(), tl!("Fixed Size")), - ]; - if ui - .add_enabled_ui(sized, |ui| widgets::dropdown(ui, "marquee-style", tl!("Style"), &mut o.marquee_style, &styles, 96.0)) - .inner - { - (o.marquee_width, o.marquee_height) = if o.marquee_style == "fixedSize" { (64.0, 64.0) } else { (1.0, 1.0) }; - } - let fixed = sized && o.marquee_style != "normal"; - let fixed_size = o.marquee_style == "fixedSize"; - // Fixed Size shows its pixels in the unit picked by right-clicking Width or Height (#7910). - let units = widgets::FieldUnits { unit: photocraft_engine::prefs::Unit::parse(&o.marquee_unit).unwrap_or_default(), ..units }; - ui.add_enabled_ui(fixed, |ui| { - let mut picked = None; - opt_label(ui, tl!("Width")); - if fixed_size { - picked = fixed_size_field(ui, &mut o.marquee_width, units, size[0]); - } else { - widgets::value_field(ui, &mut o.marquee_width, crate::tool_memory::style_range(&o.marquee_style), "", 62.0); - } - if icons::button(ui, "arrow-left-right", 22.0, false, tl!("Swaps height and width")).clicked() { - std::mem::swap(&mut o.marquee_width, &mut o.marquee_height); - } - opt_label(ui, tl!("Height")); - if fixed_size { - picked = fixed_size_field(ui, &mut o.marquee_height, units, size[1]).or(picked); - } else { - widgets::value_field(ui, &mut o.marquee_height, crate::tool_memory::style_range(&o.marquee_style), "", 62.0); - } - if let Some(name) = picked { - o.marquee_unit = name.into(); - } - }); - widgets::vline(ui, 22.0); - select_and_mask_button(app, ui); - } - Tool::Lasso | Tool::PolygonLasso | Tool::MagneticLasso => { - selection_mode_buttons(app, ui); - widgets::vline(ui, 22.0); - opt_label(ui, tl!("Feather")); - widgets::value_field(ui, &mut app.ui.tool_options.feather, 0.0..=1000.0, "px", 62.0); - widgets::checkbox(ui, &mut app.ui.tool_options.anti_alias, tl!("Anti-alias")); - widgets::vline(ui, 22.0); - if app.ui.tool == Tool::MagneticLasso { - let o = &mut app.ui.tool_options; - opt_label(ui, tl!("Width")); - widgets::value_field(ui, &mut o.magnetic_width, 1.0..=256.0, "px", 58.0) - .on_hover_text(tl!("Follows only edges this close to the pointer ([ and ] change it)")); - opt_label(ui, tl!("Contrast")); - widgets::value_field(ui, &mut o.magnetic_contrast, 1.0..=100.0, "%", 58.0) - .on_hover_text(tl!("Higher values follow only edges that contrast sharply with their surroundings")); - opt_label(ui, tl!("Frequency")); - widgets::value_field(ui, &mut o.magnetic_frequency, 0.0..=100.0, "", 50.0) - .on_hover_text(tl!("How often fastening points are placed by themselves")); - if icons::button(ui, "circle-dot", 24.0, o.magnetic_pressure, tl!("Use tablet pressure to change pen width")).clicked() { - o.magnetic_pressure = !o.magnetic_pressure; - } - widgets::vline(ui, 22.0); - } - select_and_mask_button(app, ui); - if crate::lasso_ui::active(app) || (app.ui.tool == Tool::PolygonLasso && !app.ui.polygon.is_empty()) { - hint( - ui, - &crate::i18n::fmt( - tl!("Click the first point or press {key} to close · Esc cancels"), - &[("key", &crate::shortcuts::pretty("Enter"))], - ), - ); - } else if app.ui.tool == Tool::Lasso { - hint(ui, tl!("Hold Alt while drawing for straight segments")); - } - if app.ui.tool == Tool::MagneticLasso && app.ui.magnetic.active() { - hint( - ui, - &crate::i18n::fmt( - tl!("Click the first point or press {key} to close · {del} removes a point · Esc cancels"), - &[("key", &crate::shortcuts::pretty("Enter")), ("del", &crate::shortcuts::pretty("Backspace"))], - ), - ); - } - } - Tool::MagicWand => { - selection_mode_buttons(app, ui); - widgets::vline(ui, 22.0); - opt_label(ui, tl!("Tolerance")); - widgets::value_field(ui, &mut app.ui.tool_options.tolerance, 0.0..=255.0, "", 58.0); - widgets::checkbox(ui, &mut app.ui.tool_options.anti_alias, tl!("Anti-alias")); - widgets::checkbox(ui, &mut app.ui.tool_options.contiguous, tl!("Contiguous")); - widgets::checkbox(ui, &mut app.ui.tool_options.sample_all.magic_wand, tl!("Sample All Layers")); - widgets::vline(ui, 22.0); - if widgets::secondary_button(ui, tl!("Select Subject"), 0.0).clicked() { - let r = app.run("select.subject", json!({})); - crate::retouch_ui::report_smart_result(app, r, tl!("No subject found — try Object Selection or the Lasso")); - } - select_and_mask_button(app, ui); - } - Tool::PaintBucket => { - opt_label(ui, tl!("Fill")); - let mut src = u8::from(app.ui.tool_options.bucket_fill_pattern); - if widgets::dropdown(ui, "bucket-src", tl!("Source"), &mut src, &[(0u8, tl!("Foreground")), (1, tl!("Pattern"))], 100.0) { - app.ui.tool_options.bucket_fill_pattern = src == 1; - } - opt_label(ui, tl!("Mode")); - if let Some(modes) = crate::blend_keys::tool_modes(tool) { - let o = &mut app.ui.tool_options; - let current = if o.bucket_clear { None } else { Some(o.bucket_blend_mode) }; - if let Some(m) = tool_mode_dropdown(ui, "bucket-mode", &modes, current) { - o.bucket_clear = m.is_none(); - if let Some(m) = m { - o.bucket_blend_mode = m; - } - } - } - opt_label(ui, tl!("Opacity")); - widgets::value_field(ui, &mut app.ui.tool_options.fill_opacity, 1.0..=100.0, "%", 62.0); - opt_label(ui, tl!("Tolerance")); - widgets::value_field(ui, &mut app.ui.tool_options.tolerance, 0.0..=255.0, "", 58.0); - widgets::checkbox(ui, &mut app.ui.tool_options.anti_alias, tl!("Anti-alias")); - widgets::checkbox(ui, &mut app.ui.tool_options.contiguous, tl!("Contiguous")); - widgets::checkbox(ui, &mut app.ui.tool_options.sample_all.paint_bucket, tl!("All Layers")); - } - Tool::Gradient => { - // Live "Gradient" (a Gradient Fill layer) or "Classic gradient" (pixels). - let mut classic = app.ui.tool_options.gradient_classic; - if widgets::dropdown(ui, "gradient-mode", tl!("Mode"), &mut classic, &[(false, "Gradient"), (true, "Classic gradient")], 118.0) - { - app.ui.tool_options.gradient_classic = classic; - } - // Live "Gradient" (a Gradient Fill layer) or "Classic gradient" (pixels): - // both paint with the same engine-owned preset (#1651), and either swatch - // click opens the Gradient Editor window, as in Photoshop. - if crate::gradient_ui::preset_swatch(app, ui) { - app.ui.panels.gradient_editor = true; - } - widgets::vline(ui, 22.0); - ui.spacing_mut().item_spacing.x = 2.0; - let before = app.ui.tool_options.clone(); - for (style, icon, tip) in [ - ("linear", "gradient", tl!("Linear Gradient")), - ("radial", "circle", tl!("Radial Gradient")), - ("angle", "rotate-cw", tl!("Angle Gradient")), - ("reflected", "arrow-left-right", tl!("Reflected Gradient")), - ("diamond", "diamond", tl!("Diamond Gradient")), - ] { - if icons::button(ui, icon, 24.0, app.ui.tool_options.gradient_style == style, tip).clicked() { - app.ui.tool_options.gradient_style = style.into(); - } - } - ui.spacing_mut().item_spacing.x = 8.0; - widgets::vline(ui, 22.0); - opt_label(ui, tl!("Mode")); - let opts: Vec<(BlendMode, &str)> = BlendMode::LAYER_MODES.iter().map(|m| (*m, m.label())).collect(); - // The wheel over it steps the mode, as over the Layers panel's (#2061). - widgets::dropdown_wheel_hovered( - ui, - "gradient-blend-mode", - tl!("Blend Mode"), - &mut app.ui.tool_options.gradient_blend_mode, - &opts, - 96.0, - ); - opt_label(ui, tl!("Opacity")); - let r = widgets::value_field(ui, &mut app.ui.tool_options.fill_opacity, 1.0..=100.0, "%", 62.0); - // Live while scrubbed, one undo step per scrub (#5012). - let drag_key = r.id.with("gradient-opacity-drag"); - if r.drag_started() { - let n = ui.ctx().cumulative_pass_nr(); - ui.data_mut(|d| d.insert_temp(drag_key, n)); - } - if r.changed() { - let drag = if r.dragged() { ui.data(|d| d.get_temp::(drag_key)) } else { None }; - crate::gradient_ui::opacity_changed(app, drag); - } - widgets::checkbox(ui, &mut app.ui.tool_options.gradient_reverse, tl!("Reverse")); - widgets::checkbox(ui, &mut app.ui.tool_options.gradient_dither, tl!("Dither")); - // Live mode: the options also change a selected gradient fill layer. - crate::gradient_ui::options_changed(app, &before); - } - Tool::PerspectiveCrop => crate::perspective_crop_ui::options_bar(app, ui), - Tool::Crop => { - let before_ratio = crate::crop_ui::preset_ratio(app); - let doc_size = app.session.active().map_or((0.0, 0.0), |s| (f64::from(s.doc.size.width), f64::from(s.doc.size.height))); - // Ratios, sizes, saved presets, New / Delete Crop Preset… (#2443, #1919). - crate::crop_presets::dropdown(app, ui); - let o = &mut app.ui.tool_options; - let mut ratio_base = None; - if o.crop_ratio == crate::crop_size::WHR { - crate::crop_size::fields(o, ui); - } else { - // Keep partial edits in ToolOptions so the first side survives a frame; - // Original Ratio shows the document's numbers, as Photoshop does. - let (mut rw, mut rh) = crate::crop_size::custom_ratio_fields(o, doc_size); - let decimals = crate::crop_size::RATIO_DECIMALS; - let fw = widgets::value_field_prec(ui, &mut rw, 0.0..=99_999.0, "", 54.0, decimals); - let swap = icons::button(ui, "arrow-left-right", 22.0, false, tl!("Swaps height and width")).clicked(); - let fh = widgets::value_field_prec(ui, &mut rh, 0.0..=99_999.0, "", 54.0, decimals); - let (cw, ch) = (fw.changed(), fh.changed()); - if swap { - std::mem::swap(&mut rw, &mut rh); - } - if cw || ch || swap { - crate::crop_size::set_custom_ratio_fields(o, rw, rh); - } - // Every ratio typed or scrubbed in one edit fits from the frame the edit - // started with: 1:3 on the way to 16:3 mustn't shrink it first (#7752). - let base_id = egui::Id::unique("crop-ratio-edit-base"); - if cw || ch { - ratio_base = ui.data(|d| d.get_temp::<[f64; 4]>(base_id)).or(app.ui.crop_rect); - } - if ![&fw, &fh].iter().any(|f| f.has_focus() || f.dragged()) { - ui.data_mut(|d| d.remove::<[f64; 4]>(base_id)); - } else if let Some(base) = ratio_base { - ui.data_mut(|d| d.insert_temp(base_id, base)); - } - } - widgets::vline(ui, 22.0); - if widgets::secondary_button(ui, tl!("Clear"), 0.0).clicked() { - crate::crop_size::clear_ratio(o); - } - crate::crop_straighten::options_button(&mut app.crop.straighten, ui); - crate::crop_overlay::options_button(o, ui); - let pick_shield_color = crate::crop_shield::options_button(&mut o.crop_shield, ui); - widgets::checkbox(ui, &mut o.crop_delete, tl!("Delete Cropped Pixels")); - // Fill: what a turned or extending crop puts where the image doesn't reach - // (#3823). Generative Expand is not offered. - ui.label(tl!("Fill:")); - widgets::dropdown( - ui, - "crop-fill", - tl!("Fill:"), - &mut o.crop_content_aware, - &[(false, tl!("Background (Default)")), (true, tl!("Content-Aware Fill"))], - 150.0, - ); - if crate::crop_ui::preset_ratio(app) != before_ratio { - match ratio_base { - Some(base) => crate::crop_ui::apply_ratio_from(app, base), - None => crate::crop_ui::apply_ratio(app), - } - } - if pick_shield_color { - crate::crop_shield::pick_custom_color(app); - } - ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - if icons::button( - ui, - "check", - 26.0, - false, - &crate::i18n::fmt(tl!("Commit current crop operation ({key})"), &[("key", &crate::shortcuts::pretty("Enter"))]), - ) - .clicked() - { - crate::canvas::commit_crop(app); - } - if icons::button(ui, "ban", 26.0, false, tl!("Cancel current crop operation (Esc)")).clicked() { - crate::crop_ui::cancel(app); - } - }); - } - // Every theme gets the font, style and size controls (#1387), as with Auto-Select (#1275). - Tool::Type | Tool::VerticalType | Tool::HorizontalTypeMask | Tool::VerticalTypeMask => crate::type_tool::options_bar(app, ui), - Tool::Move => { - let o = &mut app.ui.tool_options; - widgets::checkbox(ui, &mut o.move_auto_select, tl!("Auto-Select:")); - widgets::dropdown( - ui, - "move-target", - tl!("Auto-Select:"), - &mut o.move_target, - &[("layer".to_string(), tl!("Layer")), ("group".to_string(), tl!("Group"))], - 76.0, - ); - widgets::vline(ui, 22.0); - widgets::checkbox(ui, &mut o.move_show_transform, tl!("Show Transform Controls")); - widgets::vline(ui, 22.0); - crate::align_bar::options(app, ui); - } - Tool::Eyedropper => crate::eyedropper_ui::options(app, ui), - Tool::Zoom => { - // Resize Windows to Fit is Preferences › Zoom Resizes Windows itself, as in - // Photoshop: one setting, shown in both places (zoom_window_fit.rs). - let mut fit = app.session.prefs().general.zoom_resizes_windows; - if widgets::checkbox(ui, &mut fit, tl!("Resize Windows to Fit")).changed() { - app.session.prefs.edit(|p| p.general.zoom_resizes_windows = fit); - } - widgets::checkbox(ui, &mut app.ui.tool_options.zoom_scrubby, tl!("Scrubby Zoom")); - hint( - ui, - &crate::i18n::fmt( - tl!("Click to zoom in · {key}-click to zoom out · drag right/left to zoom in/out"), - &[("key", &crate::shortcuts::pretty("Alt"))], - ), - ); - if widgets::secondary_button(ui, tl!("Fit Screen"), 0.0).clicked() - && let Some(i) = app.session.active_index() - { - app.ui.views[i].fit_pending = true; - app.ui.views[i].request_zoom_animation(app.session.prefs().general.animated_zoom); - app.ui.views[i].zoom_anchor = None; - } - if widgets::secondary_button(ui, "100%", 0.0).clicked() - && let Some(i) = app.session.active_index() - { - app.ui.views[i].zoom = 1.0; - app.ui.views[i].request_zoom_animation(app.session.prefs().general.animated_zoom); - app.ui.views[i].zoom_anchor = None; - app.ui.views[i].fit_pending = false; - app.ui.views[i].fill_pending = false; - } - } - Tool::RotateView => { - hint(ui, tl!("Drag around the centre to rotate the view · Shift constrains to 15°")); - if let Some(i) = app.session.active_index() { - ui.label(tl!("Angle")); - let mut angle = app.ui.views.get(i).map(|v| v.rotation).unwrap_or(0.0); - if widgets::value_field(ui, &mut angle, -180.0..=180.0, "°", 56.0).changed() - && let Some(v) = app.ui.views.get_mut(i) - { - v.rotation = crate::rotate_view::wrap_deg(angle); - } - if widgets::secondary_button(ui, tl!("Reset View"), 0.0).clicked() - && let Some(v) = app.ui.views.get_mut(i) - { - v.rotation = 0.0; - } - } - } - Tool::Hand => { - hint(ui, tl!("Drag to pan · hold Space with any tool")); - if widgets::secondary_button(ui, "100%", 0.0).clicked() - && let Some(i) = app.session.active_index() - { - app.ui.views[i].zoom = 1.0; - app.ui.views[i].request_zoom_animation(app.session.prefs().general.animated_zoom); - app.ui.views[i].zoom_anchor = None; - app.ui.views[i].fit_pending = false; - app.ui.views[i].fill_pending = false; - } - if widgets::secondary_button(ui, tl!("Fit Screen"), 0.0).clicked() - && let Some(i) = app.session.active_index() - { - app.ui.views[i].fit_pending = true; - app.ui.views[i].request_zoom_animation(app.session.prefs().general.animated_zoom); - app.ui.views[i].zoom_anchor = None; - app.ui.views[i].fill_pending = false; - } - if widgets::secondary_button(ui, tl!("Fill Screen"), 0.0).clicked() - && let Some(i) = app.session.active_index() - { - app.ui.views[i].fill_pending = true; - app.ui.views[i].request_zoom_animation(app.session.prefs().general.animated_zoom); - app.ui.views[i].zoom_anchor = None; - app.ui.views[i].fit_pending = false; - } - } - // Retouching and smart-selection tools draw their bar in `retouch_ui::options_bar`. - _ => {} - } + tool_specific_options(app, ui, t, tool, b); // 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) { @@ -648,6 +145,488 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) { }); } +/// The per-tool options of the bar: the brush, mixer, marquee, pencil and view controls. +fn tool_specific_options(app: &mut PhotocraftApp, ui: &mut egui::Ui, t: Tokens, tool: Tool, b: &mut BrushSettings) { + match app.ui.tool { + Tool::Brush | Tool::Eraser if t.pro => { + // 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); + // 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 held = app.held_erase; + paint_mode_dropdown(ui, "brush-mode", b, &mut app.ui.tool_options.brush_clear, held); + } + 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, "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); + widgets::vline(ui, 22.0); + if icons::button(ui, "circle-dot", 24.0, b.pressure_size, tl!("Always use pressure for size")).clicked() { + b.pressure_size = !b.pressure_size; + } + } + // Pencil: Photoshop's options (no hardness or flow: the pencil is always hard). + Tool::Pencil => { + brush_preset_chip(ui, b, &mut app.ui); + crate::brush_picker::settings_toggle(app, ui); + widgets::vline(ui, 22.0); + if !t.pro { + opt_label(ui, tl!("Size")); + widgets::value_field(ui, &mut b.size, 1.0..=photocraft_engine::paint::MAX_BRUSH_SIZE, "px", 76.0); + widgets::vline(ui, 22.0); + } + opt_label(ui, tl!("Mode")); + let held = app.held_erase; + paint_mode_dropdown(ui, "pencil-mode", b, &mut app.ui.tool_options.pencil_clear, held); + percent_field(ui, tl!("Opacity"), &mut b.opacity, 0.0..=100.0, if t.pro { 62.0 } else { 66.0 }); + opt_label(ui, tl!("Smoothing")); + smoothing_field(ui, b, if t.pro { 58.0 } else { 66.0 }); + widgets::vline(ui, 22.0); + widgets::checkbox(ui, &mut app.ui.tool_options.pencil_auto_erase, tl!("Auto Erase")); + } + Tool::Brush | Tool::Eraser => { + brush_preset_chip(ui, b, &mut app.ui); + crate::brush_picker::settings_toggle(app, ui); + widgets::vline(ui, 22.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..=photocraft_engine::paint::MAX_BRUSH_SIZE, "px", 76.0); + }); + widgets::vline(ui, 22.0); + 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 held = app.held_erase; + paint_mode_dropdown(ui, "brush-mode", b, &mut app.ui.tool_options.brush_clear, held); + } + // 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); + widgets::toggle(ui, &mut b.pressure_size, tl!("Pressure for Size")); + widgets::toggle(ui, &mut b.pressure_opacity, tl!("Pressure for Opacity")); + } + Tool::MixerBrush => { + brush_preset_chip(ui, b, &mut app.ui); + crate::brush_picker::settings_toggle(app, ui); + widgets::vline(ui, 22.0); + mixer_load_swatch(app, ui); + let m = &mut b.mixer; + for (icon, on, tip) in [ + ("brush", &mut m.load_after_stroke, tl!("Load the brush after each stroke")), + ("brush-cleaning", &mut m.clean_after_stroke, tl!("Clean the brush after each stroke")), + ] { + if icons::button(ui, icon, 24.0, *on, tip).clicked() { + *on = !*on; + } + } + widgets::vline(ui, 22.0); + for (label, value) in + [(tl!("Wet"), &mut b.mixer.wet), (tl!("Load"), &mut b.mixer.load), (tl!("Mix"), &mut b.mixer.mix), (tl!("Flow"), &mut b.mixer.flow)] + { + percent_field(ui, label, value, 0.0..=100.0, 62.0); + } + widgets::vline(ui, 22.0); + widgets::checkbox(ui, &mut b.mixer.sample_all_layers, tl!("Sample All Layers")); + } + Tool::RectMarquee | Tool::EllipseMarquee | Tool::SingleRowMarquee | Tool::SingleColumnMarquee => { + ui.spacing_mut().item_spacing.x = 2.0; + for (i, (icon, tip)) in [ + ("square", tl!("New selection").to_string()), + ("plus", crate::i18n::fmt(tl!("Add to selection ({key})"), &[("key", &crate::shortcuts::pretty("Shift"))])), + ("minus", crate::i18n::fmt(tl!("Subtract from selection ({key})"), &[("key", &crate::shortcuts::pretty("Alt"))])), + ("squares-subtract", crate::i18n::fmt(tl!("Intersect with selection ({key})"), &[("key", &crate::shortcuts::pretty("Shift+Alt"))])), + ] + .iter() + .enumerate() + { + if icons::button(ui, icon, 24.0, app.ui.selection_mode == i as u8, tip).clicked() { + app.ui.selection_mode = i as u8; + } + } + ui.spacing_mut().item_spacing.x = 8.0; + widgets::vline(ui, 22.0); + let (units, size) = fixed_size_units(app); + let o = &mut app.ui.tool_options; + opt_label(ui, tl!("Feather")); + widgets::value_field(ui, &mut o.feather, 0.0..=1000.0, "px", 62.0); + // Photoshop greys Anti-alias for the Rectangular Marquee (its edges are always hard). + ui.add_enabled_ui(app.ui.tool == Tool::EllipseMarquee, |ui| widgets::checkbox(ui, &mut o.anti_alias, tl!("Anti-alias"))); + widgets::vline(ui, 22.0); + // A single row or column has no style or size: Photoshop greys them. + let sized = matches!(app.ui.tool, Tool::RectMarquee | Tool::EllipseMarquee); + ui.add_enabled_ui(sized, |ui| opt_label(ui, tl!("Style"))); + let styles = [("normal".to_string(), tl!("Normal")), ("fixedRatio".to_string(), tl!("Fixed Ratio")), ("fixedSize".to_string(), tl!("Fixed Size"))]; + if ui.add_enabled_ui(sized, |ui| widgets::dropdown(ui, "marquee-style", tl!("Style"), &mut o.marquee_style, &styles, 96.0)).inner { + (o.marquee_width, o.marquee_height) = if o.marquee_style == "fixedSize" { (64.0, 64.0) } else { (1.0, 1.0) }; + } + let fixed = sized && o.marquee_style != "normal"; + let fixed_size = o.marquee_style == "fixedSize"; + // Fixed Size shows its pixels in the unit picked by right-clicking Width or Height (#7910). + let units = widgets::FieldUnits { unit: photocraft_engine::prefs::Unit::parse(&o.marquee_unit).unwrap_or_default(), ..units }; + ui.add_enabled_ui(fixed, |ui| { + let mut picked = None; + opt_label(ui, tl!("Width")); + if fixed_size { + picked = fixed_size_field(ui, &mut o.marquee_width, units, size[0]); + } else { + widgets::value_field(ui, &mut o.marquee_width, crate::tool_memory::style_range(&o.marquee_style), "", 62.0); + } + if icons::button(ui, "arrow-left-right", 22.0, false, tl!("Swaps height and width")).clicked() { + std::mem::swap(&mut o.marquee_width, &mut o.marquee_height); + } + opt_label(ui, tl!("Height")); + if fixed_size { + picked = fixed_size_field(ui, &mut o.marquee_height, units, size[1]).or(picked); + } else { + widgets::value_field(ui, &mut o.marquee_height, crate::tool_memory::style_range(&o.marquee_style), "", 62.0); + } + if let Some(name) = picked { + o.marquee_unit = name.into(); + } + }); + widgets::vline(ui, 22.0); + select_and_mask_button(app, ui); + } + Tool::Lasso | Tool::PolygonLasso | Tool::MagneticLasso => { + selection_mode_buttons(app, ui); + widgets::vline(ui, 22.0); + opt_label(ui, tl!("Feather")); + widgets::value_field(ui, &mut app.ui.tool_options.feather, 0.0..=1000.0, "px", 62.0); + widgets::checkbox(ui, &mut app.ui.tool_options.anti_alias, tl!("Anti-alias")); + widgets::vline(ui, 22.0); + if app.ui.tool == Tool::MagneticLasso { + let o = &mut app.ui.tool_options; + opt_label(ui, tl!("Width")); + widgets::value_field(ui, &mut o.magnetic_width, 1.0..=256.0, "px", 58.0) + .on_hover_text(tl!("Follows only edges this close to the pointer ([ and ] change it)")); + opt_label(ui, tl!("Contrast")); + widgets::value_field(ui, &mut o.magnetic_contrast, 1.0..=100.0, "%", 58.0) + .on_hover_text(tl!("Higher values follow only edges that contrast sharply with their surroundings")); + opt_label(ui, tl!("Frequency")); + widgets::value_field(ui, &mut o.magnetic_frequency, 0.0..=100.0, "", 50.0) + .on_hover_text(tl!("How often fastening points are placed by themselves")); + if icons::button(ui, "circle-dot", 24.0, o.magnetic_pressure, tl!("Use tablet pressure to change pen width")).clicked() { + o.magnetic_pressure = !o.magnetic_pressure; + } + widgets::vline(ui, 22.0); + } + select_and_mask_button(app, ui); + if crate::lasso_ui::active(app) || (app.ui.tool == Tool::PolygonLasso && !app.ui.polygon.is_empty()) { + hint(ui, &crate::i18n::fmt(tl!("Click the first point or press {key} to close · Esc cancels"), &[("key", &crate::shortcuts::pretty("Enter"))])); + } else if app.ui.tool == Tool::Lasso { + hint(ui, tl!("Hold Alt while drawing for straight segments")); + } + if app.ui.tool == Tool::MagneticLasso && app.ui.magnetic.active() { + hint( + ui, + &crate::i18n::fmt( + tl!("Click the first point or press {key} to close · {del} removes a point · Esc cancels"), + &[("key", &crate::shortcuts::pretty("Enter")), ("del", &crate::shortcuts::pretty("Backspace"))], + ), + ); + } + } + Tool::MagicWand => { + selection_mode_buttons(app, ui); + widgets::vline(ui, 22.0); + opt_label(ui, tl!("Tolerance")); + widgets::value_field(ui, &mut app.ui.tool_options.tolerance, 0.0..=255.0, "", 58.0); + widgets::checkbox(ui, &mut app.ui.tool_options.anti_alias, tl!("Anti-alias")); + widgets::checkbox(ui, &mut app.ui.tool_options.contiguous, tl!("Contiguous")); + widgets::checkbox(ui, &mut app.ui.tool_options.sample_all.magic_wand, tl!("Sample All Layers")); + widgets::vline(ui, 22.0); + if widgets::secondary_button(ui, tl!("Select Subject"), 0.0).clicked() { + let r = app.run("select.subject", json!({})); + crate::retouch_ui::report_smart_result(app, r, tl!("No subject found — try Object Selection or the Lasso")); + } + select_and_mask_button(app, ui); + } + Tool::PaintBucket => { + opt_label(ui, tl!("Fill")); + let mut src = u8::from(app.ui.tool_options.bucket_fill_pattern); + if widgets::dropdown(ui, "bucket-src", tl!("Source"), &mut src, &[(0u8, tl!("Foreground")), (1, tl!("Pattern"))], 100.0) { + app.ui.tool_options.bucket_fill_pattern = src == 1; + } + opt_label(ui, tl!("Mode")); + if let Some(modes) = crate::blend_keys::tool_modes(tool) { + let o = &mut app.ui.tool_options; + let current = if o.bucket_clear { None } else { Some(o.bucket_blend_mode) }; + if let Some(m) = tool_mode_dropdown(ui, "bucket-mode", &modes, current) { + o.bucket_clear = m.is_none(); + if let Some(m) = m { + o.bucket_blend_mode = m; + } + } + } + opt_label(ui, tl!("Opacity")); + widgets::value_field(ui, &mut app.ui.tool_options.fill_opacity, 1.0..=100.0, "%", 62.0); + opt_label(ui, tl!("Tolerance")); + widgets::value_field(ui, &mut app.ui.tool_options.tolerance, 0.0..=255.0, "", 58.0); + widgets::checkbox(ui, &mut app.ui.tool_options.anti_alias, tl!("Anti-alias")); + widgets::checkbox(ui, &mut app.ui.tool_options.contiguous, tl!("Contiguous")); + widgets::checkbox(ui, &mut app.ui.tool_options.sample_all.paint_bucket, tl!("All Layers")); + } + Tool::Gradient => { + // Live "Gradient" (a Gradient Fill layer) or "Classic gradient" (pixels). + let mut classic = app.ui.tool_options.gradient_classic; + if widgets::dropdown(ui, "gradient-mode", tl!("Mode"), &mut classic, &[(false, "Gradient"), (true, "Classic gradient")], 118.0) { + app.ui.tool_options.gradient_classic = classic; + } + // Live "Gradient" (a Gradient Fill layer) or "Classic gradient" (pixels): + // both paint with the same engine-owned preset (#1651), and either swatch + // click opens the Gradient Editor window, as in Photoshop. + if crate::gradient_ui::preset_swatch(app, ui) { + app.ui.panels.gradient_editor = true; + } + widgets::vline(ui, 22.0); + ui.spacing_mut().item_spacing.x = 2.0; + let before = app.ui.tool_options.clone(); + for (style, icon, tip) in [ + ("linear", "gradient", tl!("Linear Gradient")), + ("radial", "circle", tl!("Radial Gradient")), + ("angle", "rotate-cw", tl!("Angle Gradient")), + ("reflected", "arrow-left-right", tl!("Reflected Gradient")), + ("diamond", "diamond", tl!("Diamond Gradient")), + ] { + if icons::button(ui, icon, 24.0, app.ui.tool_options.gradient_style == style, tip).clicked() { + app.ui.tool_options.gradient_style = style.into(); + } + } + ui.spacing_mut().item_spacing.x = 8.0; + widgets::vline(ui, 22.0); + opt_label(ui, tl!("Mode")); + let opts: Vec<(BlendMode, &str)> = BlendMode::LAYER_MODES.iter().map(|m| (*m, m.label())).collect(); + // The wheel over it steps the mode, as over the Layers panel's (#2061). + widgets::dropdown_wheel_hovered(ui, "gradient-blend-mode", tl!("Blend Mode"), &mut app.ui.tool_options.gradient_blend_mode, &opts, 96.0); + opt_label(ui, tl!("Opacity")); + let r = widgets::value_field(ui, &mut app.ui.tool_options.fill_opacity, 1.0..=100.0, "%", 62.0); + // Live while scrubbed, one undo step per scrub (#5012). + let drag_key = r.id.with("gradient-opacity-drag"); + if r.drag_started() { + let n = ui.ctx().cumulative_pass_nr(); + ui.data_mut(|d| d.insert_temp(drag_key, n)); + } + if r.changed() { + let drag = if r.dragged() { ui.data(|d| d.get_temp::(drag_key)) } else { None }; + crate::gradient_ui::opacity_changed(app, drag); + } + widgets::checkbox(ui, &mut app.ui.tool_options.gradient_reverse, tl!("Reverse")); + widgets::checkbox(ui, &mut app.ui.tool_options.gradient_dither, tl!("Dither")); + // Live mode: the options also change a selected gradient fill layer. + crate::gradient_ui::options_changed(app, &before); + } + Tool::PerspectiveCrop => crate::perspective_crop_ui::options_bar(app, ui), + Tool::Crop => { + let before_ratio = crate::crop_ui::preset_ratio(app); + let doc_size = app.session.active().map_or((0.0, 0.0), |s| (f64::from(s.doc.size.width), f64::from(s.doc.size.height))); + // Ratios, sizes, saved presets, New / Delete Crop Preset… (#2443, #1919). + crate::crop_presets::dropdown(app, ui); + let o = &mut app.ui.tool_options; + let mut ratio_base = None; + if o.crop_ratio == crate::crop_size::WHR { + crate::crop_size::fields(o, ui); + } else { + // Keep partial edits in ToolOptions so the first side survives a frame; + // Original Ratio shows the document's numbers, as Photoshop does. + let (mut rw, mut rh) = crate::crop_size::custom_ratio_fields(o, doc_size); + let decimals = crate::crop_size::RATIO_DECIMALS; + let fw = widgets::value_field_prec(ui, &mut rw, 0.0..=99_999.0, "", 54.0, decimals); + let swap = icons::button(ui, "arrow-left-right", 22.0, false, tl!("Swaps height and width")).clicked(); + let fh = widgets::value_field_prec(ui, &mut rh, 0.0..=99_999.0, "", 54.0, decimals); + let (cw, ch) = (fw.changed(), fh.changed()); + if swap { + std::mem::swap(&mut rw, &mut rh); + } + if cw || ch || swap { + crate::crop_size::set_custom_ratio_fields(o, rw, rh); + } + // Every ratio typed or scrubbed in one edit fits from the frame the edit + // started with: 1:3 on the way to 16:3 mustn't shrink it first (#7752). + let base_id = egui::Id::unique("crop-ratio-edit-base"); + if cw || ch { + ratio_base = ui.data(|d| d.get_temp::<[f64; 4]>(base_id)).or(app.ui.crop_rect); + } + if ![&fw, &fh].iter().any(|f| f.has_focus() || f.dragged()) { + ui.data_mut(|d| d.remove::<[f64; 4]>(base_id)); + } else if let Some(base) = ratio_base { + ui.data_mut(|d| d.insert_temp(base_id, base)); + } + } + widgets::vline(ui, 22.0); + if widgets::secondary_button(ui, tl!("Clear"), 0.0).clicked() { + crate::crop_size::clear_ratio(o); + } + crate::crop_straighten::options_button(&mut app.crop.straighten, ui); + crate::crop_overlay::options_button(o, ui); + let pick_shield_color = crate::crop_shield::options_button(&mut o.crop_shield, ui); + widgets::checkbox(ui, &mut o.crop_delete, tl!("Delete Cropped Pixels")); + // Fill: what a turned or extending crop puts where the image doesn't reach + // (#3823). Generative Expand is not offered. + ui.label(tl!("Fill:")); + widgets::dropdown( + ui, + "crop-fill", + tl!("Fill:"), + &mut o.crop_content_aware, + &[(false, tl!("Background (Default)")), (true, tl!("Content-Aware Fill"))], + 150.0, + ); + if crate::crop_ui::preset_ratio(app) != before_ratio { + match ratio_base { + Some(base) => crate::crop_ui::apply_ratio_from(app, base), + None => crate::crop_ui::apply_ratio(app), + } + } + if pick_shield_color { + crate::crop_shield::pick_custom_color(app); + } + ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { + if icons::button( + ui, + "check", + 26.0, + false, + &crate::i18n::fmt(tl!("Commit current crop operation ({key})"), &[("key", &crate::shortcuts::pretty("Enter"))]), + ) + .clicked() + { + crate::canvas::commit_crop(app); + } + if icons::button(ui, "ban", 26.0, false, tl!("Cancel current crop operation (Esc)")).clicked() { + crate::crop_ui::cancel(app); + } + }); + } + // Every theme gets the font, style and size controls (#1387), as with Auto-Select (#1275). + Tool::Type | Tool::VerticalType | Tool::HorizontalTypeMask | Tool::VerticalTypeMask => crate::type_tool::options_bar(app, ui), + Tool::Move => { + let o = &mut app.ui.tool_options; + widgets::checkbox(ui, &mut o.move_auto_select, tl!("Auto-Select:")); + widgets::dropdown( + ui, + "move-target", + tl!("Auto-Select:"), + &mut o.move_target, + &[("layer".to_string(), tl!("Layer")), ("group".to_string(), tl!("Group"))], + 76.0, + ); + widgets::vline(ui, 22.0); + widgets::checkbox(ui, &mut o.move_show_transform, tl!("Show Transform Controls")); + widgets::vline(ui, 22.0); + crate::align_bar::options(app, ui); + } + Tool::Eyedropper => crate::eyedropper_ui::options(app, ui), + Tool::Zoom => { + // Resize Windows to Fit is Preferences › Zoom Resizes Windows itself, as in + // Photoshop: one setting, shown in both places (zoom_window_fit.rs). + let mut fit = app.session.prefs().general.zoom_resizes_windows; + if widgets::checkbox(ui, &mut fit, tl!("Resize Windows to Fit")).changed() { + app.session.prefs.edit(|p| p.general.zoom_resizes_windows = fit); + } + widgets::checkbox(ui, &mut app.ui.tool_options.zoom_scrubby, tl!("Scrubby Zoom")); + hint( + ui, + &crate::i18n::fmt( + tl!("Click to zoom in · {key}-click to zoom out · drag right/left to zoom in/out"), + &[("key", &crate::shortcuts::pretty("Alt"))], + ), + ); + if widgets::secondary_button(ui, tl!("Fit Screen"), 0.0).clicked() + && let Some(i) = app.session.active_index() + { + app.ui.views[i].fit_pending = true; + app.ui.views[i].request_zoom_animation(app.session.prefs().general.animated_zoom); + app.ui.views[i].zoom_anchor = None; + } + if widgets::secondary_button(ui, "100%", 0.0).clicked() + && let Some(i) = app.session.active_index() + { + app.ui.views[i].zoom = 1.0; + app.ui.views[i].request_zoom_animation(app.session.prefs().general.animated_zoom); + app.ui.views[i].zoom_anchor = None; + app.ui.views[i].fit_pending = false; + app.ui.views[i].fill_pending = false; + } + } + Tool::RotateView => { + hint(ui, tl!("Drag around the centre to rotate the view · Shift constrains to 15°")); + if let Some(i) = app.session.active_index() { + ui.label(tl!("Angle")); + let mut angle = app.ui.views.get(i).map(|v| v.rotation).unwrap_or(0.0); + if widgets::value_field(ui, &mut angle, -180.0..=180.0, "°", 56.0).changed() + && let Some(v) = app.ui.views.get_mut(i) + { + v.rotation = crate::rotate_view::wrap_deg(angle); + } + if widgets::secondary_button(ui, tl!("Reset View"), 0.0).clicked() + && let Some(v) = app.ui.views.get_mut(i) + { + v.rotation = 0.0; + } + } + } + Tool::Hand => { + hint(ui, tl!("Drag to pan · hold Space with any tool")); + if widgets::secondary_button(ui, "100%", 0.0).clicked() + && let Some(i) = app.session.active_index() + { + app.ui.views[i].zoom = 1.0; + app.ui.views[i].request_zoom_animation(app.session.prefs().general.animated_zoom); + app.ui.views[i].zoom_anchor = None; + app.ui.views[i].fit_pending = false; + app.ui.views[i].fill_pending = false; + } + if widgets::secondary_button(ui, tl!("Fit Screen"), 0.0).clicked() + && let Some(i) = app.session.active_index() + { + app.ui.views[i].fit_pending = true; + app.ui.views[i].request_zoom_animation(app.session.prefs().general.animated_zoom); + app.ui.views[i].zoom_anchor = None; + app.ui.views[i].fill_pending = false; + } + if widgets::secondary_button(ui, tl!("Fill Screen"), 0.0).clicked() + && let Some(i) = app.session.active_index() + { + app.ui.views[i].fill_pending = true; + app.ui.views[i].request_zoom_animation(app.session.prefs().general.animated_zoom); + app.ui.views[i].zoom_anchor = None; + app.ui.views[i].fit_pending = false; + } + } + // Retouching and smart-selection tools draw their bar in `retouch_ui::options_bar`. + _ => {} + } +} + /// Width of the Layers panel's Opacity and Fill fields, with room for their pop-up slider's ▾. pub(super) const LAYER_PCT_W: f32 = 66.0 + widgets::POPUP_ARROW_W; diff --git a/crates/ui-egui/src/panels/preset_panels.rs b/crates/ui-egui/src/panels/preset_panels.rs index b06e3145f7..fcd33e89cb 100644 --- a/crates/ui-egui/src/panels/preset_panels.rs +++ b/crates/ui-egui/src/panels/preset_panels.rs @@ -369,6 +369,49 @@ pub(crate) struct Place<'a> { const GRID_GAP: f32 = 4.0; const GRID_INSET: f32 = 8.0; +struct GroupHeaderContext<'a> { + panel: &'a str, + open: bool, + state: &'a mut PresetUi, + tokens: &'a Tokens, + events: &'a mut Vec, +} + +fn draw_group_header(ui: &mut egui::Ui, group: &GroupView, context: GroupHeaderContext<'_>) -> (Rect, Option, Option) { + let GroupHeaderContext { panel, open, state, tokens, events } = context; + let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), 22.0), Sense::click_and_drag()); + if response.hovered() || response.dragged() { + ui.painter().rect_filled(rect, 2.0, tokens.hover.gamma_multiply(0.5)); + } + let triangle = Rect::from_center_size(pos2(rect.left() + 9.0, rect.center().y), vec2(12.0, 12.0)); + crate::icons::paint(ui, triangle, if open { "chevron-down" } else { "chevron-right" }, 10.0, tokens.text_dim); + let folder = Rect::from_center_size(pos2(rect.left() + 25.0, rect.center().y), vec2(14.0, 14.0)); + crate::icons::paint(ui, folder, if open { "folder-open" } else { "folder" }, 12.0, tokens.icon); + ui.painter().text(pos2(rect.left() + 37.0, rect.center().y), Align2::LEFT_CENTER, &group.name, FontId::proportional(11.5), tokens.text); + if response.clicked() { + let key = format!("{panel}/{}", group.name); + if !state.toggled.remove(&key) { + state.toggled.insert(key); + } + } + response.context_menu(|ui| { + if ui.button(tl!("Rename Group…")).clicked() { + state.renaming = Some((panel.to_string(), format!("group:{}", group.name), group.name.clone())); + ui.close(); + } + if ui.button(tl!("Delete Group")).clicked() { + events.push(Ev::DeleteGroup(group.name.clone())); + ui.close(); + } + }); + let drag = if response.dragged() { ui.ctx().pointer_interact_pos() } else { None }; + if drag.is_some() { + ui.ctx().set_cursor_icon(egui::CursorIcon::Grabbing); + } + let released = if response.drag_stopped() { ui.ctx().pointer_interact_pos() } else { None }; + (rect, drag, released) +} + pub(crate) fn browser( ui: &mut egui::Ui, st: &mut PresetUi, @@ -427,41 +470,12 @@ pub(crate) fn browser( for &gi in &display { let Some(g) = groups.get(gi) else { continue }; let open = group_open(st, panel, gi, &g.name); - let (hr, hresp) = ui.allocate_exact_size(vec2(ui.available_width(), 22.0), Sense::click_and_drag()); - if hresp.hovered() || hresp.dragged() { - ui.painter().rect_filled(hr, 2.0, t.hover.gamma_multiply(0.5)); + let (hr, header_drag, header_release) = draw_group_header(ui, g, GroupHeaderContext { panel, open, state: st, tokens: &t, events: &mut ev }); + if let Some(position) = header_drag { + drag = Some((gi, position)); } - let tri = Rect::from_center_size(pos2(hr.left() + 9.0, hr.center().y), vec2(12.0, 12.0)); - crate::icons::paint(ui, tri, if open { "chevron-down" } else { "chevron-right" }, 10.0, t.text_dim); - let fold = Rect::from_center_size(pos2(hr.left() + 25.0, hr.center().y), vec2(14.0, 14.0)); - crate::icons::paint(ui, fold, if open { "folder-open" } else { "folder" }, 12.0, t.icon); - ui.painter().text(pos2(hr.left() + 37.0, hr.center().y), Align2::LEFT_CENTER, &g.name, FontId::proportional(11.5), t.text); - if hresp.clicked() { - let k = format!("{panel}/{}", g.name); - if !st.toggled.remove(&k) { - st.toggled.insert(k); - } - } - hresp.context_menu(|ui| { - if ui.button(tl!("Rename Group…")).clicked() { - st.renaming = Some((panel.to_string(), format!("group:{}", g.name), g.name.clone())); - ui.close(); - } - if ui.button(tl!("Delete Group")).clicked() { - ev.push(Ev::DeleteGroup(g.name.clone())); - ui.close(); - } - }); - if hresp.dragged() - && let Some(p) = ui.ctx().pointer_interact_pos() - { - drag = Some((gi, p)); - ui.ctx().set_cursor_icon(egui::CursorIcon::Grabbing); - } - if hresp.drag_stopped() - && let Some(p) = ui.ctx().pointer_interact_pos() - { - released = Some((gi, p)); + if let Some(position) = header_release { + released = Some((gi, position)); } headers.push((gi, hr, g.name.clone())); if !open { diff --git a/crates/ui-egui/src/panels/preset_panels/panels.rs b/crates/ui-egui/src/panels/preset_panels/panels.rs index 27a441fa5f..7aa89c5ccc 100644 --- a/crates/ui-egui/src/panels/preset_panels/panels.rs +++ b/crates/ui-egui/src/panels/preset_panels/panels.rs @@ -1,4 +1,7 @@ -use super::*; +use super::{ + Align2, Color32, CornerRadius, Ev, FontId, GroupView, ItemView, PhotocraftApp, Place, Pos2, Rect, Sense, Stroke, TextureHandle, Tokens, Tool, Value, + browser, canvas_drop_rect, empty, generic, json, paint_gradient, pattern_texture, pos2, run, shape_texture, style_texture, vec2, +}; // ------------------------------------------------------------------ Gradients diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rs index 43400674bc..0607c5ca30 100644 --- a/crates/ui-egui/src/panels/properties.rs +++ b/crates/ui-egui/src/panels/properties.rs @@ -1,4 +1,4 @@ -use super::*; +use super::{CornerRadius, Layer, LayerContent, LayerId, PhotocraftApp, Rect, RichText, Sense, Stroke, Tokens, empty, icons, json, pos2, theme, vec2, widgets}; // ----------------------------------------------------------------------------- properties diff --git a/crates/ui-egui/src/panels/smart_ui.rs b/crates/ui-egui/src/panels/smart_ui.rs index 0f0c87ad58..8e531b47b6 100644 --- a/crates/ui-egui/src/panels/smart_ui.rs +++ b/crates/ui-egui/src/panels/smart_ui.rs @@ -130,16 +130,9 @@ pub fn filter_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, doc: &Document, l if t.pro { ui.painter().line_segment([pos2(rect.left() + 30.0, rect.top()), pos2(rect.left() + 30.0, rect.bottom())], Stroke::new(1.0, t.separator)); } - let (name, on) = match index { - None => (tl!("Smart Filters").to_string(), sm.filters_enabled), - Some(i) => (filter_label(&sm.smart_filters[i]), sm.smart_filters[i].visible && sm.filters_enabled), - }; + let (name, on, shown) = filter_row_label(sm, index); let eye = Rect::from_center_size(pos2(rect.left() + indent + if index.is_none() { 9.0 } else { 41.0 }, rect.center().y), vec2(18.0, 18.0)); let eye_resp = ui.interact(eye, ui.scope_id().with(("sf-eye", l.id.0, index)), Sense::click()); - let shown = match index { - None => sm.filters_enabled, - Some(i) => sm.smart_filters[i].visible, - }; if shown { icons::paint(ui, eye, "eye", 12.0, if on { t.icon } else { t.text_faint }); } @@ -153,11 +146,7 @@ pub fn filter_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, doc: &Document, l // The shared mask scales with the thumbnail setting (hidden at None); the header name // follows it, while filter names stay aligned past their eyes. let mask_left = rect.left() + indent + 28.0; - let x = match index { - None if mask_size > 0.0 => mask_left + mask_size + 8.0, - None => mask_left, - Some(_) => rect.left() + indent + 60.0, - }; + let x = filter_label_x(rect.left(), indent, mask_size, index); if index.is_none() && mask_size > 0.0 { let sw = Rect::from_min_size(pos2(mask_left, rect.center().y - mask_size / 2.0), vec2(mask_size, mask_size)); if let Some(mask) = &sm.filter_mask { @@ -237,6 +226,24 @@ pub fn filter_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, doc: &Document, l } } +fn filter_row_label(sm: &SmartObject, index: Option) -> (String, bool, bool) { + match index { + None => (tl!("Smart Filters").to_string(), sm.filters_enabled, sm.filters_enabled), + Some(i) => { + let filter = &sm.smart_filters[i]; + (filter_label(filter), filter.visible && sm.filters_enabled, filter.visible) + } + } +} + +fn filter_label_x(left: f32, indent: f32, mask_size: f32, index: Option) -> f32 { + match index { + None if mask_size > 0.0 => left + indent + 28.0 + mask_size + 8.0, + None => left + indent + 28.0, + Some(_) => left + indent + 60.0, + } +} + /// What a click on the filter mask thumbnail does: target it for painting (selecting the smart /// object), ⌥ view it alone (⇧⌥ as an overlay), ⇧ disable or enable it. fn filter_mask_click(l: &Layer, sm: &SmartObject, m: egui::Modifiers) -> Vec<(String, Value)> { diff --git a/crates/ui-egui/src/panels/status_bar.rs b/crates/ui-egui/src/panels/status_bar.rs index 007a5805a3..843b85d6dc 100644 --- a/crates/ui-egui/src/panels/status_bar.rs +++ b/crates/ui-egui/src/panels/status_bar.rs @@ -1,4 +1,4 @@ -use super::*; +use super::{PhotocraftApp, RichText, Tokens, label, vec2, widgets}; // ----------------------------------------------------------------------------- status bar diff --git a/crates/ui-egui/src/panels/title_bar.rs b/crates/ui-egui/src/panels/title_bar.rs index 10c797eb20..d93315af10 100644 --- a/crates/ui-egui/src/panels/title_bar.rs +++ b/crates/ui-egui/src/panels/title_bar.rs @@ -1,4 +1,4 @@ -use super::*; +use super::{PhotocraftApp, Sense, Tokens, icons, theme, vec2, widgets}; // ----------------------------------------------------------------------------- title bar diff --git a/crates/ui-egui/src/panels/toolbar.rs b/crates/ui-egui/src/panels/toolbar.rs index 6fb61129b9..c6c7a3567d 100644 --- a/crates/ui-egui/src/panels/toolbar.rs +++ b/crates/ui-egui/src/panels/toolbar.rs @@ -1,5 +1,5 @@ use super::options_bar::reveal_focused_control; -use super::*; +use super::{Align2, Color32, PhotocraftApp, Pos2, Rect, Sense, Stroke, StrokeKind, Tokens, Tool, c32, icons, json, pos2, vec2}; // ----------------------------------------------------------------------------- toolbar