Options-bar and tool writes bump the tool options' revision only when they change a value (FW-365 F6b)

This commit is contained in:
aiongg committed 2026-11-27 01:21:44 +00:00
1 parent 02c84a6f94
commit 56bf471c4a
23 files changed
+274 -236

No files matched your search

-4
View File
@@ -162,11 +162,7 @@ impl PhotocraftApp {
// A software adapter or CPU mode chosen at startup is every document's reason.
crate::render_path::frame(self);
// Every frame that started its stage record closes it, whichever way `ui_body` returns.
// Controls and panels write their values back on every pass; only the writes that change an option move its
// revision, which the options bar's version holds, so a pass that changed nothing leaves the bar settled.
let options = self.ui.tool_options.checkpoint();
self.ui_body(ui);
self.ui.tool_options.settle(options);
// What an injected step changed is the target of the rest of its request: only a change
// between passes withdraws queued input (`withdraw_stale_input`).
#[cfg(not(target_arch = "wasm32"))]
+13 -5
View File
@@ -254,16 +254,24 @@ fn a_tool_option_runs_the_options_bar_once() {
}
/// A bar that runs and writes every control's value back leaves the tool options' revision alone, so idle frames never
/// move what the bar's version holds.
/// move what the bar's version holds, whichever tool's bar is showing.
#[test]
fn an_idle_options_bar_leaves_the_tool_options_revision() {
let mut h = harness();
let mut moved = Vec::new();
for tool in crate::state::Tool::ALL {
h.state_mut().ui.tool = tool;
h.run_steps(4);
let settled = h.state().ui.tool_options.revision();
h.run_steps(6);
if h.state().ui.tool_options.revision() != settled {
moved.push(tool);
}
}
assert!(moved.is_empty(), "idle frames moved the tool options under {moved:?}");
// A changed option runs the bar, whose own writes then change nothing more.
h.state_mut().ui.tool = crate::state::Tool::Move;
h.run_steps(4);
let settled = h.state().ui.tool_options.revision();
h.run_steps(10);
assert_eq!(h.state().ui.tool_options.revision(), settled, "ten idle frames");
// A changed option runs the bar, whose own writes then change nothing more.
let on = h.state().ui.tool_options.move_auto_select;
h.state_mut().ui.tool_options.move_auto_select = !on;
let changed = h.state().ui.tool_options.revision();
+2 -2
View File
@@ -345,8 +345,8 @@ pub(super) fn labelled<R>(ui: &mut egui::Ui, label: &str, mut add: impl FnMut(&m
}
/// A check box named `label` over `value`.
pub(super) fn check(ui: &mut egui::Ui, label: &str, value: &mut bool) {
Checkbox::new(Bind::bound(value)).label(label.to_owned()).show(ui);
pub(super) fn check(ui: &mut egui::Ui, label: &str, value: Bind<'_, bool>) {
Checkbox::new(value).label(label.to_owned()).show(ui);
}
/// A number field named `label` over `value` (in `unit` when it is not empty), limited to `range`. The events of this
+26 -17
View File
@@ -1,6 +1,6 @@
//! The Paint Bucket's members of the options bar, and the Mode list of the Paint Bucket and the stamp tools.
use craft::ui::contract::{Bind, Entry, Show as _};
use craft::ui::contract::{Bind, Entry, Show as _, bind_tracked};
use craft::ui::patterns::blend_keys::{BlendKeyEntry, blend_entries};
use craft::ui::pickers::Select;
use photocraft_doc::BlendMode;
@@ -67,25 +67,34 @@ pub(super) fn members(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
}
let entries = mode_entries(Tool::PaintBucket, true, false);
let sources = [Entry::new(false, tl!("Foreground").to_owned()), Entry::new(true, tl!("Pattern").to_owned())];
let o = &mut app.ui.tool_options;
labelled(ui, tl!("Fill"), |ui| Select::new(tl!("Source").to_owned(), Bind::bound(&mut o.bucket_fill_pattern), &sources).show(ui));
let mut mode = if o.bucket_clear { PaintMode::Clear } else { PaintMode::Blend(o.bucket_blend_mode) };
{
let mut pattern = Some(bind_tracked!(app.ui.tool_options => bucket_fill_pattern));
labelled(ui, tl!("Fill"), |ui| pattern.take().map(|pattern| Select::new(tl!("Source").to_owned(), pattern, &sources).show(ui)));
}
let o = &app.ui.tool_options;
let shown = if o.bucket_clear { PaintMode::Clear } else { PaintMode::Blend(o.bucket_blend_mode) };
let mut mode = shown;
labelled(ui, tl!("Mode"), |ui| mode_select(Bind::bound(&mut mode), &entries).show(ui));
match mode {
PaintMode::Clear => o.bucket_clear = true,
PaintMode::Blend(blend) => {
o.bucket_clear = false;
o.bucket_blend_mode = blend;
let (opacity, tolerance) = (o.fill_opacity, o.tolerance);
if mode != shown {
let o = &mut app.ui.tool_options;
match mode {
PaintMode::Clear => o.bucket_clear = true,
PaintMode::Blend(blend) => {
o.bucket_clear = false;
o.bucket_blend_mode = blend;
}
PaintMode::Behind => {}
}
PaintMode::Behind => {}
}
if let Some(opacity) = number_field(ui, tl!("Opacity"), o.fill_opacity, 1.0..=100.0, "%").landed() {
o.fill_opacity = *opacity;
if let Some(opacity) = number_field(ui, tl!("Opacity"), opacity, 1.0..=100.0, "%").landed() {
app.ui.tool_options.fill_opacity = *opacity;
}
if let Some(tolerance) = number_field(ui, tl!("Tolerance"), o.tolerance, 0.0..=255.0, "").landed() {
o.tolerance = *tolerance;
if let Some(tolerance) = number_field(ui, tl!("Tolerance"), tolerance, 0.0..=255.0, "").landed() {
app.ui.tool_options.tolerance = *tolerance;
}
check(ui, tl!("Anti-alias"), &mut o.anti_alias);
check(ui, tl!("Contiguous"), &mut o.contiguous);
check(ui, tl!("All Layers"), &mut o.sample_all.paint_bucket);
let (anti_alias, contiguous, all_layers) = bind_tracked!(app.ui.tool_options => anti_alias, contiguous, sample_all.paint_bucket);
check(ui, tl!("Anti-alias"), anti_alias);
check(ui, tl!("Contiguous"), contiguous);
check(ui, tl!("All Layers"), all_layers);
}
@@ -1,7 +1,7 @@
//! The options bar's members of the Move, Eyedropper, Zoom, Rotate View and Hand tools.
use craft::ui::canvas::{NavigateBar, NavigationOptions};
use craft::ui::contract::{Bind, Entry, Show as _};
use craft::ui::contract::{Bind, Entry, Show as _, bind_tracked};
use craft::ui::display::Divider;
use craft::ui::pickers::Select;
@@ -21,12 +21,12 @@ pub(super) fn members(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
/// Auto-Select, its target, Show Transform Controls, then the align strip.
fn move_members(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
let o = &mut app.ui.tool_options;
check(ui, tl!("Auto-Select:"), &mut o.move_auto_select);
let (auto_select, target, transform) = bind_tracked!(app.ui.tool_options => move_auto_select, move_target, move_show_transform);
check(ui, tl!("Auto-Select:"), auto_select);
let targets = [Entry::new("group".to_owned(), tl!("Group").to_owned()), Entry::new("layer".to_owned(), tl!("Layer").to_owned())];
Select::new(tl!("Auto-Select:").to_owned(), Bind::bound(&mut o.move_target), &targets).show(ui);
Select::new(tl!("Auto-Select:").to_owned(), target, &targets).show(ui);
Divider::vertical().show(ui);
check(ui, tl!("Show Transform Controls"), &mut o.move_show_transform);
check(ui, tl!("Show Transform Controls"), transform);
Divider::vertical().show(ui);
crate::align_bar::show(app, ui);
}
@@ -60,7 +60,9 @@ fn view_members(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
// Zoom Out is the bar's `out`; the tool keeps the direction as `zoom_in`.
let mut out = !app.ui.tool_options.zoom_in;
let shown = NavigateBar::zoom(Bind::bound(&mut view), target, &mut options, Bind::bound(&mut out)).show(ui);
app.ui.tool_options.zoom_in = !out;
if app.ui.tool_options.zoom_in == out {
app.ui.tool_options.zoom_in = !out;
}
crate::chrome_ui::zoom_alert(app, shown.invalid_zoom);
write_view(app, index, &view, !shown.view.is_empty());
} else {
+1 -1
View File
@@ -599,7 +599,7 @@ mod tests {
let mut s = SampleAllLayers::default();
assert!(s.slot(Tool::Brush).is_none());
for t in [Tool::MagicWand, Tool::PaintBucket, Tool::Blur, Tool::Sharpen, Tool::Smudge, Tool::Remove] {
*s.slot(t).unwrap() = true;
*s.slot_mut(t).unwrap() = true;
assert!(s.get(t), "{t:?}");
}
assert!(!s.get(Tool::QuickSelection));
+29 -17
View File
@@ -416,29 +416,41 @@ impl Default for SampleAllLayers {
}
}
/// The field of `SampleAllLayers` that `$tool` keeps, borrowed as `$borrow`.
macro_rules! sample_all_slot {
($this:ident, $tool:ident, $($borrow:tt)+) => {
Some(match $tool {
Tool::MagicWand => $($borrow)+ $this.magic_wand,
Tool::QuickSelection => $($borrow)+ $this.quick_selection,
Tool::ObjectSelection => $($borrow)+ $this.object_selection,
Tool::PaintBucket => $($borrow)+ $this.paint_bucket,
Tool::MagicEraser => $($borrow)+ $this.magic_eraser,
Tool::SpotHealing => $($borrow)+ $this.spot_healing,
Tool::Patch => $($borrow)+ $this.patch,
Tool::ContentAwareMove => $($borrow)+ $this.content_aware_move,
Tool::Remove => $($borrow)+ $this.remove,
Tool::Blur => $($borrow)+ $this.blur,
Tool::Sharpen => $($borrow)+ $this.sharpen,
Tool::Smudge => $($borrow)+ $this.smudge,
_ => return None,
})
};
}
impl SampleAllLayers {
/// `tool`'s setting; false for a tool without the option.
pub fn get(mut self, tool: Tool) -> bool {
self.slot(tool).is_some_and(|v| *v)
self.slot(tool).unwrap_or(false)
}
/// `tool`'s setting, or `None` for a tool without the option.
pub fn slot(&mut self, tool: Tool) -> Option<&mut bool> {
Some(match tool {
Tool::MagicWand => &mut self.magic_wand,
Tool::QuickSelection => &mut self.quick_selection,
Tool::ObjectSelection => &mut self.object_selection,
Tool::PaintBucket => &mut self.paint_bucket,
Tool::MagicEraser => &mut self.magic_eraser,
Tool::SpotHealing => &mut self.spot_healing,
Tool::Patch => &mut self.patch,
Tool::ContentAwareMove => &mut self.content_aware_move,
Tool::Remove => &mut self.remove,
Tool::Blur => &mut self.blur,
Tool::Sharpen => &mut self.sharpen,
Tool::Smudge => &mut self.smudge,
_ => return None,
})
pub fn slot(&self, tool: Tool) -> Option<bool> {
sample_all_slot!(self, tool, &).copied()
}
/// `tool`'s setting to write, or `None` for a tool without the option.
pub fn slot_mut(&mut self, tool: Tool) -> Option<&mut bool> {
sample_all_slot!(self, tool, &mut)
}
}
+4 -4
View File
@@ -6,7 +6,7 @@
use craft::behavior::IconId;
use craft::ui::buttons::{IconButton, ToggleButton};
use craft::ui::choice::{Checkbox, Segmented};
use craft::ui::contract::{Bind, Entry, Props as _, Show as _};
use craft::ui::contract::{Bind, Entry, Props as _, Show as _, bind_tracked};
use craft::ui::display::Divider;
use craft::ui::pickers::Select;
use photocraft_engine::adjustment_brush_cmds::{self as ab, ENTRIES, INDEXED_ALERT};
@@ -152,7 +152,7 @@ pub fn options_bar(ui: &mut egui::Ui, app: &mut PhotocraftApp, tool: Tool) -> bo
let choose = tl!("Choose an object and have the adjustment applied to it");
IconButton::new(IconId::new("square-dashed-mouse-pointer")).label(choose).tooltip(choose).enabled(false).show(ui);
// On, the canvas tints what the active adjustment layer's mask reveals (`raster_source::MaskTint`, #12520).
Checkbox::new(Bind::bound(&mut app.ui.tool_options.adjustment_brush_overlay))
Checkbox::new(bind_tracked!(app.ui.tool_options => adjustment_brush_overlay))
.label(tl!("Overlay").to_owned())
.tooltip(tl!("Show or hide the painted mask areas").to_owned())
.show(ui);
@@ -160,7 +160,7 @@ pub fn options_bar(ui: &mut egui::Ui, app: &mut PhotocraftApp, tool: Tool) -> bo
let mut alerts = Vec::new();
let mut opacity = (brush.opacity * 100.0).round();
let out = option_cells::number(tl!("Opacity:"), &mut opacity, 1.0..=100.0).whole().unit("%").show(ui);
let out = option_cells::number(tl!("Opacity:"), Bind::bound(&mut opacity), 1.0..=100.0).whole().unit("%").show(ui);
key = out.events.iter().find_map(|e| crate::history_keys::coalesce("brush", e)).or(key);
brush.opacity = opacity / 100.0;
alerts.extend(out.out_of_range);
@@ -173,7 +173,7 @@ pub fn options_bar(ui: &mut egui::Ui, app: &mut PhotocraftApp, tool: Tool) -> bo
key = pressure.events.iter().find_map(|e| crate::history_keys::coalesce("brush", e)).or(key);
}
let mut flow = brush.flow * 100.0;
let out = option_cells::number(tl!("Flow:"), &mut flow, 1.0..=100.0).unit("%").show(ui);
let out = option_cells::number(tl!("Flow:"), Bind::bound(&mut flow), 1.0..=100.0).unit("%").show(ui);
key = out.events.iter().find_map(|e| crate::history_keys::coalesce("brush", e)).or(key);
brush.flow = flow / 100.0;
alerts.extend(out.out_of_range);
+4 -4
View File
@@ -7,7 +7,7 @@ use craft::draw::ui::measure::{RulerBar, RulerLine};
use craft::theme::Srgba;
use craft::ui::buttons::{Button, IconButton, ToggleButton};
use craft::ui::choice::Swatch;
use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _};
use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _, bind_tracked};
use craft::ui::display::{Divider, Text};
use craft::ui::form::Field;
use craft::ui::pickers::Select;
@@ -161,8 +161,8 @@ fn count(app: &mut PhotocraftApp, ui: &mut egui::Ui, doc: &photocraft_doc::Docum
Divider::vertical().show(ui);
let (marker, label) = (g.marker_size as f32, g.label_size as f32);
let (mut new_marker, mut new_label) = (marker, label);
let marker_out = option_cells::number(tl!("Marker Size"), &mut new_marker, MARKER_SIZE).whole().show(ui);
let label_out = option_cells::number(tl!("Label Size"), &mut new_label, LABEL_SIZE).whole().show(ui);
let marker_out = option_cells::number(tl!("Marker Size"), Bind::bound(&mut new_marker), MARKER_SIZE).whole().show(ui);
let label_out = option_cells::number(tl!("Label Size"), Bind::bound(&mut new_label), LABEL_SIZE).whole().show(ui);
// A typed size out of range takes the closest value and says so once (#13530).
for alert in [&marker_out.out_of_range, &label_out.out_of_range].into_iter().flatten() {
option_cells::range_alert(app, ui, alert);
@@ -207,7 +207,7 @@ fn sampler(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
let n = app.session.active().map_or(0, |d| d.color_samplers.len());
// One Sample Size setting, shared with the Eyedropper (#11732).
// PLAN: assumed `SamplerOptions::show(ui)` returns an output with `clear_all: bool`.
let out = SamplerOptions::new(n, Bind::bound(&mut app.ui.tool_options.eyedropper.size)).show(ui);
let out = SamplerOptions::new(n, bind_tracked!(app.ui.tool_options => eyedropper.size)).show(ui);
if out.clear_all {
run(app, "view.colorSamplers.clear", json!({}));
}
+18 -19
View File
@@ -7,7 +7,7 @@
use craft::behavior::IconId;
use craft::ui::buttons::ToggleButton;
use craft::ui::choice::{Checkbox, Segmented};
use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _};
use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _, bind_tracked};
use craft::ui::display::Divider;
use craft::ui::form::Field;
use craft::ui::pickers::Select;
@@ -148,8 +148,8 @@ pub(crate) fn stored_tolerance(v: f32) -> f32 {
}
/// A check box named `label` over `value`.
fn check(ui: &mut egui::Ui, label: &str, value: &mut bool, tip: Option<&str>) {
let mut checkbox = Checkbox::new(Bind::bound(value)).label(label.to_owned());
fn check(ui: &mut egui::Ui, label: &str, value: Bind<'_, bool>, tip: Option<&str>) {
let mut checkbox = Checkbox::new(value).label(label.to_owned());
if let Some(tip) = tip {
checkbox = checkbox.tooltip(tip.to_owned());
}
@@ -168,28 +168,27 @@ pub fn options_bar(ui: &mut egui::Ui, app: &mut PhotocraftApp, tool: Tool) -> bo
}
fn magic_eraser_members(ui: &mut egui::Ui, app: &mut PhotocraftApp) {
let o = &mut app.ui.tool_options;
// The field clamps without an alert, as the reference's Magic Eraser Tolerance does.
let _ = option_cells::number(tl!("Tolerance:"), &mut o.tolerance, 0.0..=255.0).show(ui);
check(ui, tl!("Anti-alias"), &mut o.anti_alias, None);
check(ui, tl!("Contiguous"), &mut o.contiguous, None);
check(ui, tl!("Sample All Layers"), &mut o.sample_all.magic_eraser, None);
let _ = option_cells::number(tl!("Tolerance:"), bind_tracked!(app.ui.tool_options => tolerance), 0.0..=255.0).show(ui);
let (anti_alias, contiguous, sample_all) = bind_tracked!(app.ui.tool_options => anti_alias, contiguous, sample_all.magic_eraser);
check(ui, tl!("Anti-alias"), anti_alias, None);
check(ui, tl!("Contiguous"), contiguous, None);
check(ui, tl!("Sample All Layers"), sample_all, None);
Divider::vertical().show(ui);
let _ = option_cells::number(tl!("Opacity:"), &mut o.magic_eraser_opacity, 1.0..=100.0).unit("%").show(ui);
let _ = option_cells::number(tl!("Opacity:"), bind_tracked!(app.ui.tool_options => magic_eraser_opacity), 1.0..=100.0).unit("%").show(ui);
}
fn background_eraser_members(ui: &mut egui::Ui, app: &mut PhotocraftApp) {
let mut alerts = Vec::new();
{
let o = &mut app.ui.tool_options;
let sampling = [
Entry::new("continuous".to_string(), tl!("Sampling: Continuous")).icon(IconId::new("eyedropper")),
Entry::new("once".to_string(), tl!("Sampling: Once")).icon(IconId::new("target")),
Entry::new("backgroundSwatch".to_string(), tl!("Sampling: Background Swatch")).icon(IconId::new("square")),
];
let picked = Segmented::new(tl!("Sampling"), Bind::given(o.bg_sampling.clone()), &sampling).show(ui).value().cloned();
let picked = Segmented::new(tl!("Sampling"), Bind::given(app.ui.tool_options.bg_sampling.clone()), &sampling).show(ui).value().cloned();
if let Some(sampling) = picked {
o.bg_sampling = sampling;
app.ui.tool_options.bg_sampling = sampling;
}
Divider::vertical().show(ui);
@@ -201,7 +200,7 @@ fn background_eraser_members(ui: &mut egui::Ui, app: &mut PhotocraftApp) {
// In a `Field`, as Color Replacement's Limits: a bare control's label only names it (#16338).
let picked = Field::new(tl!("Limits:"))
.show(ui, |ui, _| {
Select::new(tl!("Limits:"), Bind::given(o.bg_limits.clone()), &limits)
Select::new(tl!("Limits:"), Bind::given(app.ui.tool_options.bg_limits.clone()), &limits)
.tooltip(tl!("How far to let the erasing spread").to_owned())
.show(ui)
.events
@@ -211,20 +210,20 @@ fn background_eraser_members(ui: &mut egui::Ui, app: &mut PhotocraftApp) {
.inner
.flatten();
if let Some(limits) = picked {
o.bg_limits = limits;
app.ui.tool_options.bg_limits = limits;
}
// Shown as the stroke reads it; written back only when the user edits it.
let shown = stored_tolerance(o.bg_tolerance);
let shown = stored_tolerance(app.ui.tool_options.bg_tolerance);
let mut tolerance = shown;
let alert = option_cells::number(tl!("Tolerance:"), &mut tolerance, 1.0..=100.0)
let alert = option_cells::number(tl!("Tolerance:"), Bind::bound(&mut tolerance), 1.0..=100.0)
.whole()
.unit("%")
.tooltip(tl!("Erase range of similar colors"))
.show(ui)
.out_of_range;
if tolerance != shown {
o.bg_tolerance = tolerance;
app.ui.tool_options.bg_tolerance = tolerance;
}
alerts.extend(alert);
}
@@ -233,7 +232,7 @@ fn background_eraser_members(ui: &mut egui::Ui, app: &mut PhotocraftApp) {
let before = (*app.session.tools.brush).clone();
let mut brush = before.clone();
let mut angle = brush.angle;
let angle_out = option_cells::number(tl!("Angle"), &mut angle, -180.0..=180.0)
let angle_out = option_cells::number(tl!("Angle"), Bind::bound(&mut angle), -180.0..=180.0)
.whole()
.unit("°")
.icon(IconSpec::svg(IconId::new("rotate_cw")))
@@ -244,7 +243,7 @@ fn background_eraser_members(ui: &mut egui::Ui, app: &mut PhotocraftApp) {
brush.angle = angle;
alerts.extend(angle_out.out_of_range);
check(ui, tl!("Protect Foreground Color"), &mut app.ui.tool_options.bg_protect_fg, Some(tl!("Do not erase the foreground swatch color")));
check(ui, tl!("Protect Foreground Color"), bind_tracked!(app.ui.tool_options => bg_protect_fg), Some(tl!("Do not erase the foreground swatch color")));
let pressure = ToggleButton::new(tl!("Always use pressure for size"), Bind::given(brush.pressure_size))
.icon(IconId::new("target"))
+5 -1
View File
@@ -10,7 +10,11 @@ use crate::PhotocraftApp;
/// The options bar for the Eyedropper tool.
pub fn options(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
EyedropperBar::new(&mut app.ui.tool_options.eyedropper).show(ui);
let mut options = app.ui.tool_options.eyedropper;
EyedropperBar::new(&mut options).show(ui);
if options != app.ui.tool_options.eyedropper {
app.ui.tool_options.eyedropper = options;
}
}
#[cfg(test)]
+19 -16
View File
@@ -3,7 +3,7 @@
use craft::draw::ui::gradient::{GradientFillWords, GradientStyle, GradientSwatch};
use craft::ui::choice::{Checkbox, Segmented};
use craft::ui::contract::{Bind, Entry, LabelKind, Props as _, Show as _, ShowContainer as _, SideLabel};
use craft::ui::contract::{Bind, Entry, LabelKind, Props as _, Show as _, ShowContainer as _, SideLabel, bind_tracked};
use craft::ui::display::Divider;
use craft::ui::form::Field;
use craft::ui::patterns::blend_keys::{BlendKeyEntry, blend_entries};
@@ -51,37 +51,40 @@ pub(crate) fn bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
let blends = blend_modes();
let open_editor;
{
let o = &mut app.ui.tool_options;
let mut classic = o.gradient_classic && !locked_live;
let mut classic = app.ui.tool_options.gradient_classic && !locked_live;
Field::new(tl!("Gradient mode").to_owned()).side(SideLabel::new().kind(LabelKind::Hidden)).show(ui, |ui, _| {
Select::new(tl!("Gradient mode").to_owned(), Bind::bound(&mut classic), &modes).enabled(!locked_live).show(ui);
});
if !locked_live {
o.gradient_classic = classic;
if !locked_live && classic != app.ui.tool_options.gradient_classic {
app.ui.tool_options.gradient_classic = classic;
}
open_editor = GradientSwatch::new(tl!("Gradient picker").to_string(), &tool_stops).sampler(&sampler).show(ui).clicked;
Divider::vertical().show(ui);
let style = stops::style_named(&o.gradient_style);
let style = stops::style_named(&app.ui.tool_options.gradient_style);
if let Some(next) = Segmented::new(Label::from(tl!("Gradient style").to_string()), Bind::given(style), &styles).show(ui).value().copied() {
o.gradient_style = stops::style_name(next).to_owned();
app.ui.tool_options.gradient_style = stops::style_name(next).to_owned();
}
if classic {
labelled(ui, tl!("Mode"), |ui| {
Select::new(tl!("Blend Mode").to_owned(), Bind::bound(&mut o.gradient_blend_mode), &blends).show(ui);
});
let fill_opacity = app.ui.tool_options.fill_opacity;
{
let mut blend = bind_tracked!(app.ui.tool_options => gradient_blend_mode);
labelled(ui, tl!("Mode"), |ui| {
Select::new(tl!("Blend Mode").to_owned(), blend.reborrowed(), &blends).show(ui);
});
}
labelled(ui, tl!("Opacity"), |ui| {
let field =
NumberField::new(tl!("Opacity").to_owned(), Bind::given(Some(f64::from(o.fill_opacity)))).range(1.0..=100.0).unit("%").scrub_by_label();
NumberField::new(tl!("Opacity").to_owned(), Bind::given(Some(f64::from(fill_opacity)))).range(1.0..=100.0).unit("%").scrub_by_label();
if let Some(next) = field.show(ui).value().copied().flatten() {
o.fill_opacity = next as f32;
app.ui.tool_options.fill_opacity = next as f32;
}
});
}
if let Some(on) = Checkbox::new(Bind::given(o.gradient_reverse)).label(tl!("Reverse").to_owned()).show(ui).value().copied() {
o.gradient_reverse = on;
if let Some(on) = Checkbox::new(Bind::given(app.ui.tool_options.gradient_reverse)).label(tl!("Reverse").to_owned()).show(ui).value().copied() {
app.ui.tool_options.gradient_reverse = on;
}
if let Some(on) = Checkbox::new(Bind::given(o.gradient_dither)).label(tl!("Dither").to_owned()).show(ui).value().copied() {
o.gradient_dither = on;
if let Some(on) = Checkbox::new(Bind::given(app.ui.tool_options.gradient_dither)).label(tl!("Dither").to_owned()).show(ui).value().copied() {
app.ui.tool_options.gradient_dither = on;
}
}
if open_editor {
@@ -68,7 +68,9 @@ pub(crate) fn prepare(app: &PhotocraftApp, tool: &mut MagneticLassoTool<PcEdges>
/// Writes the tool's settings back after the run, so `[` and `]` reach the options store.
pub(crate) fn store(app: &mut PhotocraftApp, tool: &MagneticLassoTool<PcEdges>) {
app.ui.tool_options.magnetic = *tool.settings();
if app.ui.tool_options.magnetic != *tool.settings() {
app.ui.tool_options.magnetic = *tool.settings();
}
}
/// Selects the closed border as drawn, in `mode` (the family's operation-to-mode name). Fewer than
+4 -4
View File
@@ -18,7 +18,7 @@ use crate::PhotocraftApp;
/// commits, so showing a bar never rounds a fraction another tool shares.
pub(crate) struct NumberCell<'a> {
caption: Label,
value: &'a mut f32,
value: Bind<'a, f32>,
range: RangeInclusive<f64>,
unit: Option<Label>,
whole: bool,
@@ -29,7 +29,7 @@ pub(crate) struct NumberCell<'a> {
}
/// A number cell named `caption` over `value`, held to `range`.
pub(crate) fn number<'a>(caption: impl Into<Label>, value: &'a mut f32, range: RangeInclusive<f64>) -> NumberCell<'a> {
pub(crate) fn number<'a>(caption: impl Into<Label>, value: Bind<'a, f32>, range: RangeInclusive<f64>) -> NumberCell<'a> {
NumberCell { caption: caption.into(), value, range, unit: None, whole: false, popup_slider: false, tooltip: None, enabled: true, icon: None }
}
@@ -79,14 +79,14 @@ impl<'a> NumberCell<'a> {
/// Shows the cell. Returns the pass's edit events, which a caller keys its history step by
/// (`history_keys::coalesce`), and the alert of a typed value that was clamped to the range.
pub(crate) fn show(self, ui: &mut egui::Ui) -> NumberCellOutput {
let Self { caption, value, range, unit, whole, popup_slider, tooltip, enabled, icon } = self;
let Self { caption, mut value, range, unit, whole, popup_slider, tooltip, enabled, icon } = self;
let mut side = SideLabel::new().scrub(true);
if let Some(icon) = icon {
side = side.icon(icon).layout(FieldLayout::Inside);
}
let mut out = NumberCellOutput { events: EditEvents::default(), out_of_range: None };
Field::new(caption.clone()).enabled(enabled).side(side).sizing(Sizing::Content).show(ui, |ui, _| {
let mut field = NumberField::named(caption.clone(), Bind::bound(&mut *value)).range(range.clone()).scrub_by_label();
let mut field = NumberField::named(caption.clone(), value.reborrowed()).range(range.clone()).scrub_by_label();
if whole {
let codec = NumberCodec::new(Env::of(ui).units().reader(None), 0);
field = field.step(1.0).commit_decimals(0).codec(codec);
@@ -20,7 +20,7 @@ use craft::behavior::kurbo::Size;
use craft::draw::ui::crop::{CropDocKey, CropDocument, PerspectiveCropBar, PerspectiveCropEvent, PerspectiveCropTool, PerspectiveInput};
use craft::ui::bars::BarOutput;
use craft::ui::canvas::{CropShield, ToolHostResponse};
use craft::ui::contract::Bind;
use craft::ui::contract::bind_tracked;
use craft::ui::runtime::edit::cancel_all;
use photocraft_engine::perspective_crop_cmds::{BITMAP_MODE_ERROR, UNSUPPORTED_LAYERS_ERROR};
use serde_json::json;
@@ -204,8 +204,11 @@ pub fn committed(app: &mut PhotocraftApp, out: &BarOutput) {
/// range alert once.
pub fn options(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
let document = document(app).unwrap_or_else(|| CropDocument::new(CropDocKey::new(0), Size::ZERO, 72.0));
let options = &mut *app.ui.tool_options;
let shown = PerspectiveCropBar::new(&mut options.perspective_crop, &document, Bind::bound(&mut options.perspective_crop_grid)).show(ui);
let mut size = app.ui.tool_options.perspective_crop.clone();
let shown = PerspectiveCropBar::new(&mut size, &document, bind_tracked!(app.ui.tool_options => perspective_crop_grid)).show(ui);
if size != app.ui.tool_options.perspective_crop {
app.ui.tool_options.perspective_crop = size;
}
if let Some(alert) = shown.out_of_range {
crate::option_cells::range_alert(app, ui, &alert);
}
+49 -57
View File
@@ -3,7 +3,7 @@
use craft::behavior::Value;
use craft::ui::choice::{Checkbox, Radio, RadioGroup};
use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _};
use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _, bind_tracked};
use craft::ui::display::Divider;
use craft::ui::form::Field;
use craft::ui::pickers::Select;
@@ -21,31 +21,30 @@ const STRUCTURE_TIP: &str = "Adjust how strictly the source structure is preserv
const COLOR_TIP: &str = "Adjust how much the source color can be modified";
/// A check box over `value`, with an optional tooltip.
pub(super) fn check(ui: &mut egui::Ui, label: &str, value: &mut bool, enabled: bool, tip: Option<&str>) {
let mut cell = Checkbox::new(Bind::given(*value)).label(label.to_owned()).enabled(enabled);
pub(super) fn check(ui: &mut egui::Ui, label: &str, value: Bind<'_, bool>, enabled: bool, tip: Option<&str>) {
let mut cell = Checkbox::new(value).label(label.to_owned()).enabled(enabled);
if let Some(tip) = tip {
cell = cell.tooltip(tip.to_owned());
}
if let Some(on) = cell.show(ui).value().copied() {
*value = on;
}
cell.show(ui);
}
/// A select over `entries` captioned by a field label, with an optional tooltip.
pub(super) fn choose<T: Value + Clone + 'static>(ui: &mut egui::Ui, caption: &str, value: &mut T, entries: &[Entry<T>], enabled: bool, tip: Option<&str>) {
let picked = Field::new(caption.to_owned())
.show(ui, |ui, _| {
let mut cell = Select::new(caption.to_owned(), Bind::given(value.clone()), entries).enabled(enabled);
if let Some(tip) = tip {
cell = cell.tooltip(tip.to_owned());
}
cell.show(ui).value().cloned()
})
.inner
.flatten();
if let Some(picked) = picked {
*value = picked;
}
pub(super) fn choose<T: Value + Clone + 'static>(
ui: &mut egui::Ui,
caption: &str,
mut value: Bind<'_, T>,
entries: &[Entry<T>],
enabled: bool,
tip: Option<&str>,
) {
Field::new(caption.to_owned()).show(ui, |ui, _| {
let mut cell = Select::new(caption.to_owned(), value.reborrowed(), entries).enabled(enabled);
if let Some(tip) = tip {
cell = cell.tooltip(tip.to_owned());
}
cell.show(ui);
});
}
/// The entries of a string option from `(engine value, label)` pairs.
@@ -54,19 +53,12 @@ pub(super) fn string_entries(items: &[(&str, &str)]) -> Vec<Entry<String>> {
}
/// A radio group over a string option.
fn radios(ui: &mut egui::Ui, label: &str, value: &mut String, items: &[(&str, &str)]) {
let picked = RadioGroup::new(label.to_owned(), Bind::given(value.clone()))
.show(ui, |ui, _| {
for (v, l) in items {
Radio::new((*v).to_owned()).label((*l).to_owned()).show(ui);
}
})
.output
.value()
.cloned();
if let Some(picked) = picked {
*value = picked;
}
fn radios(ui: &mut egui::Ui, label: &str, value: Bind<'_, String>, items: &[(&str, &str)]) {
RadioGroup::new(label.to_owned(), value).show(ui, |ui, _| {
for (v, l) in items {
Radio::new((*v).to_owned()).label((*l).to_owned()).show(ui);
}
});
}
/// The first alert of two cells, both of which have been shown.
@@ -77,11 +69,11 @@ fn first(a: Option<RangeAlert>, b: Option<RangeAlert>) -> Option<RangeAlert> {
/// Remove's options. The apply and cancel pair belongs to the bar's pending strip.
pub(super) fn remove(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Option<RangeAlert> {
let composite = crate::canvas::paint_target(app).as_str() == Some("pixels");
let o = &mut app.ui.tool_options;
let (sample_all, after_each, new_layer) = bind_tracked!(app.ui.tool_options => sample_all.remove, remove_after_each_stroke, remove_new_layer);
// The reference's options bar, in its order and words (#12546).
check(ui, tl!("Sample all layers"), &mut o.sample_all.remove, true, Some(tl!("Sample content from all visible layers")));
check(ui, tl!("Remove after each stroke"), &mut o.remove_after_each_stroke, true, Some(tl!("Remove area after a single stroke")));
check(ui, tl!("Create new layer"), &mut o.remove_new_layer, composite, Some(tl!("Create new layer with results")));
check(ui, tl!("Sample all layers"), sample_all, true, Some(tl!("Sample content from all visible layers")));
check(ui, tl!("Remove after each stroke"), after_each, true, Some(tl!("Remove area after a single stroke")));
check(ui, tl!("Create new layer"), new_layer, composite, Some(tl!("Create new layer with results")));
None
}
@@ -89,17 +81,17 @@ pub(super) fn remove(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Option<Range
pub(super) fn patch(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Option<RangeAlert> {
crate::panels::options_bar::selection::operation_segments(app, ui, true);
Divider::vertical().show(ui);
let o = &mut app.ui.tool_options;
let kinds = [Entry::new(false, tl!("Normal")), Entry::new(true, tl!("Content-Aware"))];
choose(ui, tl!("Patch"), &mut o.patch_content_aware, &kinds, true, None);
choose(ui, tl!("Patch"), bind_tracked!(app.ui.tool_options => patch_content_aware), &kinds, true, None);
let mut alert = None;
if o.patch_content_aware {
let structure = number(tl!("Structure"), &mut o.patch_structure, 1.0..=7.0).whole().show(ui).out_of_range;
let color = number(tl!("Color"), &mut o.patch_color, 0.0..=10.0).whole().show(ui).out_of_range;
check(ui, tl!("Sample All Layers"), &mut o.sample_all.patch, true, None);
if app.ui.tool_options.patch_content_aware {
let (structure, color, sample_all) = bind_tracked!(app.ui.tool_options => patch_structure, patch_color, sample_all.patch);
let structure = number(tl!("Structure"), structure, 1.0..=7.0).whole().show(ui).out_of_range;
let color = number(tl!("Color"), color, 0.0..=10.0).whole().show(ui).out_of_range;
check(ui, tl!("Sample All Layers"), sample_all, true, None);
alert = first(structure, color);
} else {
radios(ui, tl!("Patch"), &mut o.patch_mode, &[("source", tl!("Source")), ("destination", tl!("Destination"))]);
radios(ui, tl!("Patch"), bind_tracked!(app.ui.tool_options => patch_mode), &[("source", tl!("Source")), ("destination", tl!("Destination"))]);
}
Divider::vertical().show(ui);
hint(ui, tl!("Lasso around an area, then drag the selection"));
@@ -111,14 +103,14 @@ pub(super) fn content_aware_move(ui: &mut egui::Ui, app: &mut PhotocraftApp) ->
let live = crate::cam_transform::active(app);
crate::panels::options_bar::selection::operation_segments(app, ui, !live);
Divider::vertical().show(ui);
let o = &mut app.ui.tool_options;
let (mode, cam_structure, cam_color, sample_all, on_drop) =
bind_tracked!(app.ui.tool_options => cam_mode, cam_structure, cam_color, sample_all.content_aware_move, cam_transform_on_drop);
let modes = string_entries(&[("move", tl!("Move")), ("extend", tl!("Extend"))]);
choose(ui, tl!("Mode"), &mut o.cam_mode, &modes, !live, Some(tl!("Choose a remix mode")));
let structure =
number(tl!("Structure"), &mut o.cam_structure, 1.0..=7.0).whole().popup_slider().tooltip(tl!(STRUCTURE_TIP)).enabled(!live).show(ui).out_of_range;
let color = number(tl!("Color"), &mut o.cam_color, 0.0..=10.0).whole().popup_slider().tooltip(tl!(COLOR_TIP)).enabled(!live).show(ui).out_of_range;
check(ui, tl!("Sample All Layers"), &mut o.sample_all.content_aware_move, !live, Some(tl!("Enable to remix all layers")));
check(ui, tl!("Transform On Drop"), &mut o.cam_transform_on_drop, !live, Some(tl!("Allows rotation and scaling of selection")));
choose(ui, tl!("Mode"), mode, &modes, !live, Some(tl!("Choose a remix mode")));
let structure = number(tl!("Structure"), cam_structure, 1.0..=7.0).whole().popup_slider().tooltip(tl!(STRUCTURE_TIP)).enabled(!live).show(ui).out_of_range;
let color = number(tl!("Color"), cam_color, 0.0..=10.0).whole().popup_slider().tooltip(tl!(COLOR_TIP)).enabled(!live).show(ui).out_of_range;
check(ui, tl!("Sample All Layers"), sample_all, !live, Some(tl!("Enable to remix all layers")));
check(ui, tl!("Transform On Drop"), on_drop, !live, Some(tl!("Allows rotation and scaling of selection")));
if !live {
Divider::vertical().show(ui);
hint(ui, tl!("Lasso around an area, then drag the selection"));
@@ -128,15 +120,15 @@ pub(super) fn content_aware_move(ui: &mut egui::Ui, app: &mut PhotocraftApp) ->
/// Spot Healing's options.
pub(super) fn spot_healing(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Option<RangeAlert> {
let o = &mut app.ui.tool_options;
let (spot_type, sample_all) = bind_tracked!(app.ui.tool_options => spot_type, sample_all.spot_healing);
radios(
ui,
tl!("Type"),
&mut o.spot_type,
spot_type,
&[("contentAware", tl!("Content-Aware")), ("createTexture", tl!("Create Texture")), ("proximityMatch", tl!("Proximity Match"))],
);
Divider::vertical().show(ui);
check(ui, tl!("Sample All Layers"), &mut o.sample_all.spot_healing, true, None);
check(ui, tl!("Sample All Layers"), sample_all, true, None);
None
}
@@ -146,11 +138,11 @@ pub(super) fn clone(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Option<RangeA
let source_unset = app.session.presets().clone.active().source.is_none();
let clone_stamp = app.ui.tool == Tool::CloneStamp;
let indexed = crate::retouch_ui::clone_stamp_indexed(app);
let o = &mut app.ui.tool_options;
check(ui, tl!("Aligned"), &mut o.clone_aligned, true, clone_stamp.then(|| tl!("Keep the same source offset between strokes")));
let (aligned, clone_sample) = bind_tracked!(app.ui.tool_options => clone_aligned, clone_sample);
check(ui, tl!("Aligned"), aligned, true, clone_stamp.then(|| tl!("Keep the same source offset between strokes")));
let samples = string_entries(&[("current", tl!("Current Layer")), ("currentAndBelow", tl!("Current & Below")), ("all", tl!("All Layers"))]);
let mut greyed = "current".to_owned();
let sample = if indexed { &mut greyed } else { &mut o.clone_sample };
let sample = if indexed { Bind::bound(&mut greyed) } else { clone_sample };
choose(ui, tl!("Sample"), sample, &samples, !indexed, clone_stamp.then(|| tl!("Choose which layers to sample")));
if source_unset {
Divider::vertical().show(ui);
@@ -4,7 +4,7 @@
use craft::behavior::IconId;
use craft::ui::buttons::ToggleButton;
use craft::ui::choice::Checkbox;
use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing};
use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing, bind_tracked};
use craft::ui::display::{Divider, Shade, Text};
use craft::ui::form::Field;
use craft::ui::pickers::Select;
@@ -68,14 +68,21 @@ pub(super) fn art_history(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Option<
.into_iter()
.map(|(k, l)| Entry::new(k.to_string(), l.to_string()))
.collect();
let o = &mut app.ui.tool_options;
Field::new(tl!("Style")).side(SideLabel::new().scrub(true)).sizing(Sizing::Content).show(ui, |ui, _| {
Select::new(tl!("Style"), Bind::bound(&mut o.art_history_style), &styles).show(ui);
});
{
let mut style = bind_tracked!(app.ui.tool_options => art_history_style);
Field::new(tl!("Style")).side(SideLabel::new().scrub(true)).sizing(Sizing::Content).show(ui, |ui, _| {
Select::new(tl!("Style"), style.reborrowed(), &styles).show(ui);
});
}
// Area: whole pixels 0..500, no slider; Tolerance: whole percents 0..100 with a slider. A value
// typed past either range becomes the closest one with the reference's own alert (#12630).
let area = number(tl!("Area"), &mut o.art_history_area, 0.0..=500.0).whole().unit("px").tooltip(tl!("Painting area diameter")).show(ui).out_of_range;
let tolerance = number(tl!("Tolerance"), &mut o.art_history_tolerance, 0.0..=100.0)
let area = number(tl!("Area"), bind_tracked!(app.ui.tool_options => art_history_area), 0.0..=500.0)
.whole()
.unit("px")
.tooltip(tl!("Painting area diameter"))
.show(ui)
.out_of_range;
let tolerance = number(tl!("Tolerance"), bind_tracked!(app.ui.tool_options => art_history_tolerance), 0.0..=100.0)
.whole()
.unit("%")
.popup_slider()
@@ -99,7 +106,7 @@ fn art_history_angle_pressure(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Opt
let before = (*app.session.tools.brush).clone();
let mut brush = before.clone();
let mut angle = brush.angle;
let angle_out = number(tl!("Angle"), &mut angle, -180.0..=180.0)
let angle_out = number(tl!("Angle"), Bind::bound(&mut angle), -180.0..=180.0)
.whole()
.unit("°")
.icon(IconSpec::svg(IconId::new("rotate_cw")))
@@ -132,9 +139,9 @@ pub(super) fn pattern_stamp(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Optio
let patterns: Vec<Entry<String>> = app.session.patterns.items.iter().map(|p| Entry::new(p.id.clone(), p.display_name().to_string())).collect();
let held = photocraft_engine::presets::patterns::current(&app.session).or(app.session.patterns.items.first()).map(|p| p.id.clone());
let mut picked = held.clone().unwrap_or_default();
let o = &mut app.ui.tool_options;
Checkbox::new(Bind::bound(&mut o.pattern_stamp_aligned)).label(tl!("Aligned")).show(ui);
Checkbox::new(Bind::bound(&mut o.pattern_stamp_impressionist)).label(tl!("Impressionist")).show(ui);
let (aligned, impressionist) = bind_tracked!(app.ui.tool_options => pattern_stamp_aligned, pattern_stamp_impressionist);
Checkbox::new(aligned).label(tl!("Aligned")).show(ui);
Checkbox::new(impressionist).label(tl!("Impressionist")).show(ui);
Divider::vertical().show(ui);
if patterns.is_empty() {
Text::new(tl!("No patterns")).shade(Shade::Faint).show(ui);
@@ -143,8 +150,8 @@ pub(super) fn pattern_stamp(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Optio
Select::new(tl!("Pattern"), Bind::bound(&mut picked), &patterns).show(ui);
});
}
let scale = number(tl!("Scale"), &mut o.pattern_stamp_scale, 1.0..=1000.0).unit("%").show(ui).out_of_range;
let angle = number(tl!("Angle"), &mut o.pattern_stamp_angle, -180.0..=180.0).unit("°").show(ui).out_of_range;
let scale = number(tl!("Scale"), bind_tracked!(app.ui.tool_options => pattern_stamp_scale), 1.0..=1000.0).unit("%").show(ui).out_of_range;
let angle = number(tl!("Angle"), bind_tracked!(app.ui.tool_options => pattern_stamp_angle), -180.0..=180.0).unit("°").show(ui).out_of_range;
if !patterns.is_empty() && held.as_deref() != Some(picked.as_str()) {
let _ = app.run("pattern.presets.select", json!({"pattern": picked}));
}
@@ -153,9 +160,9 @@ pub(super) fn pattern_stamp(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Optio
/// Red Eye: Pupil Size and Darken Amount.
pub(super) fn red_eye(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Option<RangeAlert> {
let o = &mut app.ui.tool_options;
let pupil = number(tl!("Pupil Size"), &mut o.red_eye_pupil_size, 1.0..=100.0).show(ui).out_of_range;
let darken = number(tl!("Darken Amount"), &mut o.red_eye_darken, 0.0..=100.0).show(ui).out_of_range;
let (pupil_size, darken_amount) = bind_tracked!(app.ui.tool_options => red_eye_pupil_size, red_eye_darken);
let pupil = number(tl!("Pupil Size"), pupil_size, 1.0..=100.0).show(ui).out_of_range;
let darken = number(tl!("Darken Amount"), darken_amount, 0.0..=100.0).show(ui).out_of_range;
Divider::vertical().show(ui);
hint(ui, tl!("Click a red pupil to neutralize it"));
pupil.or(darken)
@@ -2,7 +2,7 @@
use craft::behavior::IconId;
use craft::ui::buttons::{Button, IconButton};
use craft::ui::contract::{Entry, Props as _, Show as _, Trigger, clicked};
use craft::ui::contract::{Entry, Props as _, Show as _, Trigger, bind_tracked, clicked};
use craft::ui::display::Divider;
use craft::ui::menu::Menu;
use craft::ui::runtime::access::PopupKind;
@@ -24,9 +24,9 @@ fn select_subject(ui: &mut egui::Ui, app: &mut PhotocraftApp, empty: &str) {
/// Quick Selection's options.
pub(super) fn quick_selection(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Option<RangeAlert> {
let o = &mut app.ui.tool_options;
check(ui, tl!("Sample All Layers"), &mut o.sample_all.quick_selection, true, None);
check(ui, tl!("Enhance Edge"), &mut o.enhance_edge, true, None);
let (sample_all, enhance_edge) = bind_tracked!(app.ui.tool_options => sample_all.quick_selection, enhance_edge);
check(ui, tl!("Sample All Layers"), sample_all, true, None);
check(ui, tl!("Enhance Edge"), enhance_edge, true, None);
hint(ui, crate::i18n::fmt(tl!("{key} to subtract"), &[("key", &crate::shortcuts::pretty("Alt"))]));
Divider::vertical().show(ui);
select_subject(ui, app, tl!("No subject found — try Object Selection or the Lasso"));
@@ -57,13 +57,14 @@ fn finder_buttons(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
Entry::new(GearOption::Manual, tl!("Manual Refresh").to_string()).checked(!auto),
];
let picked = Menu::new(label).opened_by(&button, Trigger::Press).pick(ui, &entries).picked;
let o = &mut app.ui.tool_options;
match picked {
Some(GearOption::Finder) => o.object_finder = !o.object_finder,
Some(GearOption::Subtract) => o.object_subtract = !o.object_subtract,
Some(GearOption::Auto) => o.object_finder_mode = ObjectFinderMode::Auto,
Some(GearOption::Manual) => o.object_finder_mode = ObjectFinderMode::Manual,
None => {}
if let Some(picked) = picked {
let o = &mut app.ui.tool_options;
match picked {
GearOption::Finder => o.object_finder = !o.object_finder,
GearOption::Subtract => o.object_subtract = !o.object_subtract,
GearOption::Auto => o.object_finder_mode = ObjectFinderMode::Auto,
GearOption::Manual => o.object_finder_mode = ObjectFinderMode::Manual,
}
}
if clicked(&refresh) {
crate::object_finder::refresh(app);
@@ -76,9 +77,9 @@ pub(super) fn object_selection(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Op
crate::panels::options_bar::selection::operation_segments(app, ui, true);
Divider::vertical().show(ui);
finder_buttons(app, ui);
let o = &mut app.ui.tool_options;
check(ui, tl!("Sample All Layers"), &mut o.sample_all.object_selection, true, None);
check(ui, tl!("Hard Edge"), &mut o.object_hard_edge, true, None);
let (sample_all, hard_edge) = bind_tracked!(app.ui.tool_options => sample_all.object_selection, object_hard_edge);
check(ui, tl!("Sample All Layers"), sample_all, true, None);
check(ui, tl!("Hard Edge"), hard_edge, true, None);
Divider::vertical().show(ui);
select_subject(ui, app, tl!("No subject found — try a rectangle around the object"));
None
+27 -27
View File
@@ -2,8 +2,8 @@
use craft::behavior::{IconId, NumberCodec};
use craft::ui::buttons::ToggleButton;
use craft::ui::choice::Segmented;
use craft::ui::contract::{Bind, Entry, FieldLayout, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing};
use craft::ui::choice::{Checkbox, Segmented};
use craft::ui::contract::{Bind, Entry, FieldLayout, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing, bind_tracked};
use craft::ui::display::Divider;
use craft::ui::form::Field;
use craft::ui::primitives::IconSpec;
@@ -34,15 +34,15 @@ fn smudge_modes() -> Vec<Entry<BlendMode>> {
/// The options of Dodge and Burn.
pub(super) fn dodge_burn(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Option<RangeAlert> {
let o = &mut app.ui.tool_options;
let (tone_range, exposure, protect) = bind_tracked!(app.ui.tool_options => tone_range, exposure, protect_tones);
let ranges = string_entries(&[("shadows", tl!("Shadows")), ("midtones", tl!("Midtones")), ("highlights", tl!("Highlights"))]);
choose(ui, tl!("Range"), &mut o.tone_range, &ranges, true, Some(tl!("Painting Mode")));
choose(ui, tl!("Range"), tone_range, &ranges, true, Some(tl!("Painting Mode")));
// Whole numbers 1..100 with the range alert and a slider arrow; Dodge shares the field (#12669).
let exposure =
number(tl!("Exposure"), &mut o.exposure, 1.0..=100.0).whole().unit("%").popup_slider().tooltip(tl!("Set exposure for stroke")).show(ui).out_of_range;
number(tl!("Exposure"), exposure, 1.0..=100.0).whole().unit("%").popup_slider().tooltip(tl!("Set exposure for stroke")).show(ui).out_of_range;
let before = (*app.session.tools.brush).clone();
let mut brush = before.clone();
let angle = number(tl!("Angle"), &mut brush.angle, -180.0..=180.0)
let angle = number(tl!("Angle"), Bind::bound(&mut brush.angle), -180.0..=180.0)
.whole()
.unit("°")
.icon(IconSpec::svg(IconId::new("rotate_cw")))
@@ -50,7 +50,7 @@ pub(super) fn dodge_burn(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Option<R
.show(ui);
let mut key = angle.events.iter().find_map(|event| crate::history_keys::coalesce("brush", event));
check(ui, tl!("Protect Tones"), &mut o.protect_tones, true, Some(tl!("Minimizes clipping in shadows and highlights, and keeps colors from shifting hue")));
check(ui, tl!("Protect Tones"), protect, true, Some(tl!("Minimizes clipping in shadows and highlights, and keeps colors from shifting hue")));
let pressure = ToggleButton::new(tl!("Always use pressure for size"), Bind::given(brush.pressure_size))
.icon(IconId::new("target"))
@@ -67,11 +67,11 @@ pub(super) fn dodge_burn(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Option<R
/// The options of Sponge.
pub(super) fn sponge(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Option<RangeAlert> {
let o = &mut app.ui.tool_options;
let (sponge_mode, sponge_flow, vibrance) = bind_tracked!(app.ui.tool_options => sponge_mode, sponge_flow, vibrance);
let modes = string_entries(&[("desaturate", tl!("Desaturate")), ("saturate", tl!("Saturate"))]);
choose(ui, tl!("Mode"), &mut o.sponge_mode, &modes, true, None);
let flow = number(tl!("Flow"), &mut o.sponge_flow, 1.0..=100.0).whole().unit("%").popup_slider().show(ui).out_of_range;
check(ui, tl!("Vibrance"), &mut o.vibrance, true, None);
choose(ui, tl!("Mode"), sponge_mode, &modes, true, None);
let flow = number(tl!("Flow"), sponge_flow, 1.0..=100.0).whole().unit("%").popup_slider().show(ui).out_of_range;
check(ui, tl!("Vibrance"), vibrance, true, None);
flow
}
@@ -129,26 +129,27 @@ fn smudge_angle(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Option<RangeAlert
/// The options of Blur, Sharpen and Smudge.
pub(super) fn blur_sharpen_smudge(ui: &mut egui::Ui, app: &mut PhotocraftApp, tool: Tool) -> Option<RangeAlert> {
let o = &mut app.ui.tool_options;
if tool == Tool::Smudge {
choose(ui, tl!("Mode"), &mut o.smudge_mode, &smudge_modes(), true, Some(tl!("Painting Mode")));
choose(ui, tl!("Mode"), bind_tracked!(app.ui.tool_options => smudge_mode), &smudge_modes(), true, Some(tl!("Painting Mode")));
}
// The cell writes only on a commit, so a shared fraction is not rounded (#12650).
let strength = number(tl!("Strength"), &mut o.strength, 1.0..=100.0).whole().unit("%").show(ui).out_of_range;
let strength = number(tl!("Strength"), bind_tracked!(app.ui.tool_options => strength), 1.0..=100.0).whole().unit("%").show(ui).out_of_range;
let angle = match tool {
Tool::Smudge => smudge_angle(ui, app),
Tool::Sharpen => brush_angle(ui, app),
_ => None,
};
let o = &mut app.ui.tool_options;
if let Some(all) = o.sample_all.slot(tool) {
check(ui, tl!("Sample All Layers"), all, true, None);
if let Some(all) = app.ui.tool_options.sample_all.slot(tool)
&& let Some(next) = Checkbox::new(Bind::given(all)).label(tl!("Sample All Layers").to_owned()).show(ui).value().copied()
&& let Some(slot) = app.ui.tool_options.sample_all.slot_mut(tool)
{
*slot = next;
}
if tool == Tool::Sharpen {
check(ui, tl!("Protect Detail"), &mut o.protect_detail, true, None);
check(ui, tl!("Protect Detail"), bind_tracked!(app.ui.tool_options => protect_detail), true, None);
}
if tool == Tool::Smudge {
check(ui, tl!("Finger Painting"), &mut o.finger_painting, true, None);
check(ui, tl!("Finger Painting"), bind_tracked!(app.ui.tool_options => finger_painting), true, None);
}
strength.or(angle)
}
@@ -158,7 +159,7 @@ pub(super) fn blur_sharpen_smudge(ui: &mut egui::Ui, app: &mut PhotocraftApp, to
fn brush_angle(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Option<RangeAlert> {
let before = (*app.session.tools.brush).clone();
let mut brush = before.clone();
let out = number(tl!("Angle"), &mut brush.angle, -180.0..=180.0)
let out = number(tl!("Angle"), Bind::bound(&mut brush.angle), -180.0..=180.0)
.whole()
.unit("°")
.icon(IconSpec::svg(IconId::new("rotate_cw")))
@@ -172,28 +173,27 @@ fn brush_angle(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Option<RangeAlert>
/// The options of Color Replacement.
pub(super) fn color_replacement(ui: &mut egui::Ui, app: &mut PhotocraftApp) -> Option<RangeAlert> {
let o = &mut app.ui.tool_options;
let modes = string_entries(&[("hue", tl!("Hue")), ("saturation", tl!("Saturation")), ("color", tl!("Color")), ("luminosity", tl!("Luminosity"))]);
choose(ui, tl!("Mode"), &mut o.cr_mode, &modes, true, Some(tl!("Painting Mode")));
choose(ui, tl!("Mode"), bind_tracked!(app.ui.tool_options => cr_mode), &modes, true, Some(tl!("Painting Mode")));
Divider::vertical().show(ui);
let sampling = [
Entry::new("continuous".to_owned(), tl!("Sampling: Continuous")).icon(IconSpec::svg(IconId::new("eyedropper"))),
Entry::new("once".to_owned(), tl!("Sampling: Once")).icon(IconSpec::svg(IconId::new("target"))),
Entry::new("backgroundSwatch".to_owned(), tl!("Sampling: Background Swatch")).icon(IconSpec::svg(IconId::new("square"))),
];
if let Some(picked) = Segmented::new(tl!("Sampling"), Bind::given(o.cr_sampling.clone()), &sampling).show(ui).value().cloned() {
o.cr_sampling = picked;
if let Some(picked) = Segmented::new(tl!("Sampling"), Bind::given(app.ui.tool_options.cr_sampling.clone()), &sampling).show(ui).value().cloned() {
app.ui.tool_options.cr_sampling = picked;
}
Divider::vertical().show(ui);
let limits = string_entries(&[("discontiguous", tl!("Discontiguous")), ("contiguous", tl!("Contiguous")), ("findEdges", tl!("Find Edges"))]);
choose(ui, tl!("Limits"), &mut o.cr_limits, &limits, true, Some(tl!("Determines the spread of replaced color")));
let tolerance = number(tl!("Tolerance"), &mut o.cr_tolerance, 1.0..=100.0)
choose(ui, tl!("Limits"), bind_tracked!(app.ui.tool_options => cr_limits), &limits, true, Some(tl!("Determines the spread of replaced color")));
let tolerance = number(tl!("Tolerance"), bind_tracked!(app.ui.tool_options => cr_tolerance), 1.0..=100.0)
.whole()
.unit("%")
.tooltip(tl!("Tolerance for choosing related colors"))
.show(ui)
.out_of_range;
check(ui, tl!("Anti-alias"), &mut o.cr_anti_alias, true, Some(tl!("Anti-alias brush application")));
check(ui, tl!("Anti-alias"), bind_tracked!(app.ui.tool_options => cr_anti_alias), true, Some(tl!("Anti-alias brush application")));
tolerance
}
+2 -2
View File
@@ -287,7 +287,7 @@ fn dab_tools_send_their_bar_values() {
let mut app = app();
stripes(&mut app, 4, "pixels");
app.run("layer.new.layer", json!({})).unwrap();
*app.ui.tool_options.sample_all.slot(tool).unwrap() = all;
*app.ui.tool_options.sample_all.slot_mut(tool).unwrap() = all;
drag(&mut app, tool);
let a = active(&app).surface().unwrap().rgba(30, 30)[3];
assert_eq!(a > 0.0, all, "{tool:?} sampleAllLayers={all}: alpha {a}");
@@ -301,7 +301,7 @@ fn dab_tools_send_their_bar_values() {
for t in
[Tool::MagicWand, Tool::QuickSelection, Tool::ObjectSelection, Tool::PaintBucket, Tool::MagicEraser, Tool::SpotHealing, Tool::Patch, Tool::Remove]
{
*others.slot(t).unwrap() = true;
*others.slot_mut(t).unwrap() = true;
}
app.ui.tool_options.sample_all = others;
assert!(!app.ui.tool_options.sample_all.get(tool));
+2 -2
View File
@@ -6,7 +6,7 @@ use craft::draw::stroke::StrokeStyle;
use craft::draw::ui::RADIUS_RANGE;
use craft::draw::ui::shape::{ShapeAppearance, ShapeBar, ShapeChange, ShapePaint, ShapeToolSettings, ShapeWords};
use craft::draw::ui::shape_drag::ShapeKind;
use craft::ui::contract::{Bind, Props as _, Show as _, ShowContainer as _};
use craft::ui::contract::{Bind, Props as _, Show as _, ShowContainer as _, bind_tracked};
use craft::ui::dialog::{Alert, HostedAlert};
use craft::ui::display::Divider;
use craft::ui::form::Field;
@@ -167,7 +167,7 @@ fn tool_extras(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) {
// The tool's own corner radius for the next polygon, after Sides (#13302); the active shape is not touched.
// A value typed past the Rectangle Radius's range takes the closest one and says so.
Divider::vertical().show(ui);
let out = crate::option_cells::number(tl!("Radius"), &mut app.ui.tool_options.polygon_corner_radius, RADIUS_RANGE).unit("px").show(ui);
let out = crate::option_cells::number(tl!("Radius"), bind_tracked!(app.ui.tool_options => polygon_corner_radius), RADIUS_RANGE).unit("px").show(ui);
if let Some(alert) = out.out_of_range {
crate::option_cells::range_alert(app, ui, &alert);
}
+2 -2
View File
@@ -162,7 +162,7 @@ pub fn reset_options(o: &mut ToolOptions, tool: Tool) {
}
// Sample All Layers is each tool's own (#5524): only `tool`'s goes back.
let d = ToolOptions::default();
if let Some(all) = o.sample_all.slot(tool) {
if let Some(all) = o.sample_all.slot_mut(tool) {
*all = d.sample_all.get(tool);
}
}
@@ -172,7 +172,7 @@ pub fn reset_options(o: &mut ToolOptions, tool: Tool) {
pub fn sample_all_key(tool: Tool) -> Option<String> {
let base = crate::state::SampleAllLayers::default();
let mut probe = base;
let slot = probe.slot(tool)?;
let slot = probe.slot_mut(tool)?;
*slot = !*slot;
let (Ok(Value::Object(b)), Ok(Value::Object(m))) = (serde_json::to_value(base), serde_json::to_value(probe)) else { return None };
m.into_iter().find(|(k, v)| b.get(k) != Some(v)).map(|(k, _)| k)
+12 -12
View File
@@ -7,7 +7,7 @@ use craft::draw::ui::shape::{self as fw, Arrowheads, ArrowheadsPopover, ShapePan
use craft::theme::Srgba;
use craft::ui::buttons::Button;
use craft::ui::choice::Checkbox;
use craft::ui::contract::{Bind, Props as _, Show as _, ShowContainer as _, SideLabel, clicked};
use craft::ui::contract::{Bind, Props as _, Show as _, ShowContainer as _, SideLabel, bind_tracked, clicked};
use craft::ui::display::{Divider, Text};
use craft::ui::form::Field;
use craft::ui::layout_components::Row;
@@ -98,7 +98,7 @@ fn bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool, open: &mut BarOpe
}
if is_shape_tool(tool) {
// Shape draws a shape layer, Path adds the outline to the work path (#9453).
VectorModeSelect::new(Bind::bound(&mut app.ui.tool_options.shape_mode), &SHAPE_TOOL_MODES).show(ui);
VectorModeSelect::new(bind_tracked!(app.ui.tool_options => shape_mode), &SHAPE_TOOL_MODES).show(ui);
if draws_path(&app.ui.tool_options) {
Divider::vertical().show(ui);
make_buttons(app, ui);
@@ -172,7 +172,7 @@ fn pen_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool, open: &mut Ba
// Photoshop's Pen lists Shape, Path and a greyed Pixels; the other pens keep theirs.
let offered: &[(VectorMode, bool)] = if tool == Tool::Pen { &PEN_MODES } else { &OTHER_PEN_MODES };
let mode_before = app.ui.tool_options.vector_mode;
VectorModeSelect::new(Bind::bound(&mut app.ui.tool_options.vector_mode), offered).show(ui);
VectorModeSelect::new(bind_tracked!(app.ui.tool_options => vector_mode), offered).show(ui);
// #12910 measured: in an Indexed Color document the Pen lists Shape and keeps the entry enabled,
// but picking it leaves the tool in Path mode. Only a pick through this dropdown counts: a Shape
// mode that arrived another way (a tool preset, `penMode`) is not measured and keeps today's
@@ -186,16 +186,16 @@ fn pen_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool, open: &mut Ba
// their popups; a pick sets the tool defaults the next Pen shape is painted with.
crate::shape_options::pen_paint_swatches(app, ui);
let ppi = document_ppi(app);
let o = &mut app.ui.tool_options;
let o = &app.ui.tool_options;
let look = fw::ShapeAppearance::new(Paint::None, Paint::None, f64::from(o.stroke_width)).stroke_style((&o.shape_stroke).into());
let out = StrokeCells::new(&look, ppi).corners(true).stroke_open(Bind::bound(&mut app.ui.shape_stroke_open)).show(ui);
for event in &out.events {
match event.value() {
Some(fw::ShapeChange::StrokeWidth(w)) => o.stroke_width = *w as f32,
Some(fw::ShapeChange::StrokeWidth(w)) => app.ui.tool_options.stroke_width = *w as f32,
Some(fw::ShapeChange::StrokeStyle { style, width, .. }) => {
o.shape_stroke = crate::shape_stroke_ui::StrokeOptions::from_style(style);
app.ui.tool_options.shape_stroke = crate::shape_stroke_ui::StrokeOptions::from_style(style);
if let Some(w) = width {
o.stroke_width = *w as f32;
app.ui.tool_options.stroke_width = *w as f32;
}
}
_ => {}
@@ -225,13 +225,13 @@ fn pen_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool, open: &mut Ba
super::alignment::pen_option(app, ui);
Divider::vertical().show(ui);
path_operations_menu(app, ui);
let o = &mut app.ui.tool_options;
if tool == Tool::Pen {
Divider::vertical().show(ui);
// The gear's popover replaces the Rubber Band item (tools-03 D3).
// PLAN: `PathOptionsOutput::pick_color` (key PATH_OPTIONS_COLOR_KEY) is answered by the owner of the colour picker dialog.
let _ = PathOptionsPopover::new(label(tl!("Set additional pen and path options")), Bind::bound(&mut o.path_options)).show(ui, &mut open.path_options);
Checkbox::new(Bind::bound(&mut o.pen_auto_add_delete)).label(label(tl!("Auto Add/Delete"))).show(ui);
let _ = PathOptionsPopover::new(label(tl!("Set additional pen and path options")), bind_tracked!(app.ui.tool_options => path_options))
.show(ui, &mut open.path_options);
Checkbox::new(bind_tracked!(app.ui.tool_options => pen_auto_add_delete)).label(label(tl!("Auto Add/Delete"))).show(ui);
}
let enter = crate::shortcuts::pretty("Enter");
match tool {
@@ -240,13 +240,13 @@ fn pen_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool, open: &mut Ba
// In a `Field`: a bare control's label only names it, it is not drawn (#16338).
let picked = Field::new(label(tl!("Curve Fit:")))
.show(ui, |ui, _| {
let field = NumberField::new(label(tl!("Curve Fit:")), Bind::given(Some(f64::from(o.curve_fit))));
let field = NumberField::new(label(tl!("Curve Fit:")), Bind::given(Some(f64::from(app.ui.tool_options.curve_fit))));
field.range(0.5..=10.0).unit_kind(UnitKind::Pixels).show(ui).value().copied()
})
.inner
.flatten();
if let Some(Some(v)) = picked {
o.curve_fit = v as f32;
app.ui.tool_options.curve_fit = v as f32;
}
let alt = crate::shortcuts::pretty("Alt");
hint(ui, &crate::i18n::fmt(tl!("Drag: draw freehand · {alt}-click: straight segment · Release on the start point: close"), &[("alt", &alt)]));