PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Merge PR #4221: Options bar: the same tool options in every theme (#4178)
David Mann08f951b90987
diff --cc crates/ui-egui/src/panels.rsindex 8276dd756,92953ac0f..9b4a263dd--- a/crates/ui-egui/src/panels.rs+++ b/crates/ui-egui/src/panels.rs@@@ -975,631 -983,587 +975,572 @@@ pub fn options_bar(app: &mut Photocraft.show(ui, |ui| {ui.style_mut().spacing.scroll = egui::style::ScrollStyle { bar_width: 4.0, ..egui::style::ScrollStyle::floating() };egui::ScrollArea::horizontal().id_salt("tool-options").auto_shrink([false, false]).show(ui, |ui| {- // Font ink can extend beyond its advance width at fractional positions.- // Include its gutter in the container layout, including right-aligned actions.- egui::Frame::NONE.inner_margin(egui::Margin { right: 2, ..Default::default() }).show(ui, |ui| {- crate::direction::horizontal_centered(ui, |ui| {- if t.pro {- crate::chrome_ui::home_button(app, ui);- widgets::vline(ui, 22.0);- }- let tool_icon = icons::button(ui, icons::tool_icon(app.ui.tool), if t.pro { 26.0 } else { 28.0 }, !t.pro, tl!(app.ui.tool.label()));- // Photoshop: right-click the tool icon for Reset Tool / Reset All Tools (#2825).- let mut reset = None;- tool_icon.context_menu(|ui| {- if ui.button(tl!("Reset Tool")).clicked() {- reset = Some("tool.reset");- ui.close();- }- if ui.button(tl!("Reset All Tools")).clicked() {- reset = Some("tool.resetAll");- ui.close();- }- });- if let Some(id) = reset- && let Err(e) = crate::menus::invoke(app, ui.ctx(), id, json!({}))- {- app.ui.status = e;- }- if t.pro {- let (r, _) = ui.allocate_exact_size(vec2(10.0, 20.0), Sense::hover());- icons::paint(ui, r, "chevron-down", 10.0, t.text_faint);- }- widgets::vline(ui, 22.0);- if app.ui.transform.is_some() {- crate::transform_tool::options_bar(app, ui);- return;- }- if crate::symmetry_ui::options_bar(app, ui) || crate::distort_ui::options_bar(app, ui) {- return;- }- let tool = app.ui.tool;- // The options bar shows the active tool's brush: switch it in before drawing the- // chip, so a tool change swaps the brush with it (Photoshop keeps one per tool).- crate::paint_mouse::sync_tool_brush(app);- // Brush edits here go through `tools.setBrush`, one journal entry per gesture (Rule 1).- if (tool.is_brushlike() && !matches!(tool, Tool::Brush | Tool::Pencil | Tool::MixerBrush | Tool::Eraser)) || tool == Tool::QuickSelection {- brush_preset_chip(ui, &app.session.tools.brush, &mut app.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)- || crate::analysis_ui::options_bar(app, ui, tool)- || crate::slice_ui::options_bar(app, ui, tool)- || crate::frame_tool::options_bar(app, ui, tool)- || crate::artboard_tool::options_bar(app, ui, tool)- {- return;- }- 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);+ // Font ink can extend beyond its advance width at fractional positions.+ // Include its gutter in the container layout, including right-aligned actions.+ egui::Frame::NONE.inner_margin(egui::Margin { right: 2, ..Default::default() }).show(ui, |ui| {+ crate::direction::horizontal_centered(ui, |ui| {+ if t.pro {+ crate::chrome_ui::home_button(app, ui);+ widgets::vline(ui, 22.0);}- 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;+ let tool_icon = icons::button(ui, icons::tool_icon(app.ui.tool), if t.pro { 26.0 } else { 28.0 }, !t.pro, tl!(app.ui.tool.label()));+ // Photoshop: right-click the tool icon for Reset Tool / Reset All Tools (#2825).+ let mut reset = None;+ tool_icon.context_menu(|ui| {+ if ui.button(tl!("Reset Tool")).clicked() {+ reset = Some("tool.reset");+ ui.close();}- });- // 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;+ if ui.button(tl!("Reset All Tools")).clicked() {+ reset = Some("tool.resetAll");+ ui.close();}});- 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;+ if let Some(id) = reset+ && let Err(e) = crate::menus::invoke(app, ui.ctx(), id, json!({}))+ {+ app.ui.status = e;}- }- // 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);+ if t.pro {+ let (r, _) = ui.allocate_exact_size(vec2(10.0, 20.0), Sense::hover());+ icons::paint(ui, r, "chevron-down", 10.0, t.text_faint);}- 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);+ if app.ui.transform.is_some() {+ crate::transform_tool::options_bar(app, ui);+ return;}- // 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;- }+ if crate::symmetry_ui::options_bar(app, ui) || crate::distort_ui::options_bar(app, ui) {+ return;}- 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 if t.pro => {- 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()+ let tool = app.ui.tool;+ // The options bar shows the active tool's brush: switch it in before drawing the+ // chip, so a tool change swaps the brush with it (Photoshop keeps one per tool).+ crate::paint_mouse::sync_tool_brush(app);+ // Brush edits here go through `tools.setBrush`, one journal entry per gesture (Rule 1).+ if (tool.is_brushlike() && !matches!(tool, Tool::Brush | Tool::Pencil | Tool::MixerBrush | Tool::Eraser))+ || tool == Tool::QuickSelection{- if icons::button(ui, icon, 24.0, app.ui.selection_mode == i as u8, tip).clicked() {- app.ui.selection_mode = i as u8;- }+ brush_preset_chip(ui, &app.session.tools.brush, &mut app.ui);+ crate::brush_picker::settings_toggle(app, ui);+ widgets::vline(ui, 22.0);}- 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", &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) };+ 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);}- 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, 0.001..=999.0, "", 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, 0.001..=999.0, "", 62.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)+ || crate::analysis_ui::options_bar(app, ui, tool)+ || crate::slice_ui::options_bar(app, ui, tool)+ || crate::frame_tool::options_bar(app, ui, tool)+ || crate::artboard_tool::options_bar(app, ui, tool)+ {+ return;+ }+ 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;+ }}- if let Some(name) = picked {- o.marquee_unit = name.into();+ // 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"));}- });- widgets::vline(ui, 22.0);- select_and_mask_button(app, ui);- }- Tool::Lasso | Tool::PolygonLasso | Tool::MagneticLasso if t.pro => {- 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;+ 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"));}- 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 if t.pro => {- opt_label(ui, tl!("Fill"));- let mut src = u8::from(app.ui.tool_options.bucket_fill_pattern);- if widgets::dropdown(ui, "bucket-src", &mut src, &[(0u8, tl!("Foreground")), (1, tl!("Pattern"))], 100.0) {- app.ui.tool_options.bucket_fill_pattern = src == 1;- }- 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", &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();+ 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"));}- }- 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", &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::<u64>(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 if t.pro => crate::perspective_crop_ui::options_bar(app, ui),- Tool::Crop if t.pro => {- 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);+ 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", &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, 0.001..=999.0, "", 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, 0.001..=999.0, "", 62.0);+ }+ if let Some(name) = picked {+ o.marquee_unit = name.into();+ }+ });+ widgets::vline(ui, 22.0);- if widgets::secondary_button(ui, tl!("Select and Mask…"), 0.0).clicked() {- let _ = crate::menus::invoke(app, ui.ctx(), "select.selectAndMask", json!({}));- }++ select_and_mask_button(app, ui);}- if cw || ch || swap {- crate::crop_size::set_custom_ratio_fields(o, rw, rh);+ 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);+ }- if widgets::secondary_button(ui, tl!("Select and Mask…"), 0.0).clicked() {- let _ = crate::menus::invoke(app, ui.ctx(), "select.selectAndMask", json!({}));- }++ 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"))],+ ),+ );+ }}- // 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::new("crop-ratio-edit-base");- if cw || ch {- ratio_base = ui.data(|d| d.get_temp::<[f64; 4]>(base_id)).or(app.ui.crop_rect);+ 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"));+ }- if widgets::secondary_button(ui, tl!("Select and Mask…"), 0.0).clicked() {- let _ = crate::menus::invoke(app, ui.ctx(), "select.selectAndMask", json!({}));- }++ select_and_mask_button(app, ui);}- 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));+ 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", &mut src, &[(0u8, tl!("Foreground")), (1, tl!("Pattern"))], 100.0) {+ app.ui.tool_options.bucket_fill_pattern = src == 1;+ }+ 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"));}- }- widgets::vline(ui, 22.0);- if widgets::secondary_button(ui, tl!("Clear"), 0.0).clicked() {- if o.crop_ratio == crate::crop_size::WHR {- crate::crop_size::clear(o);- } else {- o.crop_ratio.clear();+ 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", &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", &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::<u64>(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);}- }- 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",- &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),+ 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::new("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() {+ 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);+ 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",+ &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);+ }+ });}- }- 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);+ // 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",+ &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);- ui.spacing_mut().item_spacing.x = 0.0;- for (icon, tip, cmd) in [- ("panels-top-left", tl!("Align left edges"), "layer.align.leftEdges"),- ("app-window", tl!("Align horizontal centers"), "layer.align.horizontalCenters"),- ("panel-right", tl!("Align right edges"), "layer.align.rightEdges"),- ] {- let on = app.session.is_enabled(cmd);- if ui.add_enabled_ui(on, |ui| icons::button(ui, icon, 24.0, false, tip)).inner.clicked() {- let _ = app.run(cmd, json!({}));- }- }- ui.add_space(6.0);- let more = icons::button(ui, "ellipsis", 24.0, false, tl!("Align and distribute"));- egui::Popup::menu(&more).show(|ui| {- ui.set_min_width(200.0);- let mut section = |ui: &mut egui::Ui, title: &str, prefix: &str| {- ui.label(egui::RichText::new(tl!(&title)).small().color(t.text_dim));- for c in photocraft_engine::command_specs().iter().filter(|c| c.id.starts_with(prefix)) {- if ui.add_enabled(app.session.is_enabled(c.id), egui::Button::new(tl!(c.label))).clicked() {- let _ = app.run(c.id, json!({}));- ui.close();- }- }- };- section(ui, tl!("Align"), "layer.align.");- ui.separator();- section(ui, tl!("Distribute"), "layer.distribute.");- });++ crate::align_bar::options(app, ui);}- if icons::button(ui, "ban", 26.0, false, tl!("Cancel current crop operation (Esc)")).clicked() {- crate::crop_ui::cancel(app);+ 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;+ }}- });- }- // 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 if t.pro => {- let o = &mut app.ui.tool_options;- widgets::checkbox(ui, &mut o.move_auto_select, tl!("Auto-Select:"));- widgets::dropdown(- ui,- "move-target",- &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::RectMarquee | Tool::EllipseMarquee => hint(- ui,- &format!(- "Drag to select · {} add · {} subtract · {} intersect · click to deselect",- crate::shortcuts::pretty("Shift"),- crate::shortcuts::pretty("Alt"),- crate::shortcuts::pretty("Shift+Alt")- ),- ),- Tool::SingleRowMarquee | Tool::SingleColumnMarquee => hint(- ui,- &format!(- "Click to select a one-pixel line · {} add · {} subtract · {} intersect",- crate::shortcuts::pretty("Shift"),- crate::shortcuts::pretty("Alt"),- crate::shortcuts::pretty("Shift+Alt")- ),- ),- Tool::Move => {- // The Studio themes keep Photoshop's Auto-Select toggle too (#1275).- widgets::checkbox(ui, &mut app.ui.tool_options.move_auto_select, tl!("Auto-Select:"));- // And Show Transform Controls (#5740): without it the box could not be- // turned on outside the Pro themes.- widgets::checkbox(ui, &mut app.ui.tool_options.move_show_transform, tl!("Show Transform Controls"));- hint(ui, tl!("Drag to move the active layer"));- 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);+ 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;+ }+ }}- 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::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;+ // 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);}- 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;- }- }- Tool::Lasso | Tool::PolygonLasso => hint(- ui,- &crate::i18n::fmt(- tl!("Drag or click polygon points · hold Alt during lasso for straight segments · {add} add · {sub} before drawing subtracts"),- &[("add", &crate::shortcuts::pretty("Shift")), ("sub", &crate::shortcuts::pretty("Alt"))],- ),- ),- Tool::MagneticLasso => hint(- ui,- &crate::i18n::fmt(- tl!("Click, then move along an edge · click to fasten a point · {alt}-click for a straight segment · double-click to close"),- &[("alt", &crate::shortcuts::pretty("Alt"))],- ),- ),- Tool::Crop => hint(- ui,- &crate::i18n::fmt(- tl!("Drag a crop box · drag inside to move · edges resize ({ratio} ratio, {centre} centre) · Space moves while drawing · arrows nudge · X swaps orientation · {commit} commits · Esc cancels"),- &[- ("ratio", &crate::shortcuts::pretty("Shift")),- ("centre", &crate::shortcuts::pretty("Alt")),- ("commit", &crate::shortcuts::pretty("Enter")),- ],- ),- ),- Tool::PerspectiveCrop => hint(- ui,- &crate::i18n::fmt(- tl!("Drag a box or click four corners · drag the corners onto the edges of a skewed shape · {commit} commits · Esc cancels"),- &[("commit", &crate::shortcuts::pretty("Enter"))],- ),- ),- Tool::PaintBucket => hint(ui, tl!("Click to fill similar colours")),- // 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);- });- reveal_focused_control(ui);- });+ crate::brush_panel::commit_gesture(app, ui.ctx(), &brush_before, &brush);+ });+ reveal_focused_control(ui);+ });});});}