dialogs-w18: net change of 9 commits

- dialogs-w18: written from its sheet
- dialogs-w18: repair 1
- dialogs-w18: the grading tail reads dialogs-w17's blending and balance words; zone memory arms are statements (combine)
- dialogs-w18: review fixes (review-1)
- Integration: a kept binding with nothing stored reads its reset value
- dialogs-w18: review fixes (review-1): the mixer tab is a kept binding
- Integration: a component reads its running gesture's start value
- dialogs-w18: tone-zone drag reports absolute values (item 2)
- dialogs-w18: a mixed tone-zone value steps and drags from the zones' reset values (dialogs run round)
This commit is contained in:
aiongg
2026-11-15 04:46:07 +00:00
parent 6487acdbf4
commit 5a6839a3b3
16 changed files with 978 additions and 137 deletions
+1 -1
View File
@@ -90,7 +90,7 @@ pub use mask_view::{MaskViewControls, MaskViewControlsOutput, MaskViewKeys, Mask
pub use scopes::{
COLORS_CHANNEL, ChannelOverlay, ClipWarning, ClippingDiagnostic, ClippingFrame, ClippingMode, ClippingOverlay, ClippingWarnings, HistogramSet,
ScopeChannel, ScopeCommand, ScopeFrame, ScopeMenuAction, ScopePanel, ScopePanelOutput, ScopePanelState, ScopeReadout, ScopeSettings, ScopeSource,
ScopeView, ScopeWords, ScopeZoneEdit, ToneZone, ToneZones, VectorscopeFrame, VectorscopePlot, ZoneChange, scope_point,
ScopeView, ScopeWords, ToneZone, ToneZones, VectorscopeFrame, VectorscopePlot, ZoneScale, ZoneValues, scope_point,
};
pub use select::{
LassoTool, MagneticLassoTool, MagneticSettings, MarqueeKind, MarqueeTool, PolygonLassoTool, SelectEvent, SelectWords, SelectionShape,
+336 -9
View File
@@ -1,10 +1,24 @@
//! The control column: sections of sliders over the settings.
use craft_ui::contract::{Bind, EditResponse, NoValue, Outcome, Pattern, Props};
use egui::{Response, Ui};
use std::ops::RangeInclusive;
use craft_behavior::EditEvents;
use craft_ui::buttons::Button;
use craft_ui::contract::{Bind, EditResponse, Entry, NoValue, Outcome, Pattern, Props, SaveKey, Show as _, ShowContainer as _, clicked};
use craft_ui::form::SliderField;
use craft_ui::layout_components::Stack;
use craft_ui::pickers::Select;
use craft_ui::runtime::env::{Env, Label};
use craft_ui::sections::Section;
use craft_ui::style::DataColor;
use craft_ui::value_drag::TrackFace;
use egui::{Color32, Response, Ui};
use super::mixer;
use super::words::RawDevelopWords;
use super::Demosaic;
use crate::raw::RawDevelopSettings;
use crate::raw::{RawDevelopSettings, VignetteStyle};
use crate::ui::curve::{Curve, CurveEditor, ToneRamp};
/// What the control column reports.
#[derive(Debug)]
@@ -16,6 +30,8 @@ pub struct RawDevelopPanelOutput {
pub edit: EditResponse<RawDevelopSettings>,
/// The Auto button was pressed.
pub auto: bool,
/// The demosaic the user picked this pass, while a raw is being opened.
pub demosaic: Option<Demosaic>,
}
impl Outcome for RawDevelopPanelOutput {
@@ -26,11 +42,275 @@ impl Outcome for RawDevelopPanelOutput {
}
}
/// One plain slider row: its label word, the settings field it edits, its range, step and optional track colours.
/// One table of these drives every plain row of the column, and the scope's tone zones find their field here by key.
#[derive(Clone, Copy)]
pub(super) struct Slider {
/// The settings field's name, the key of a tone zone.
pub(super) key: &'static str,
word: fn(&RawDevelopWords) -> &Label,
pub(super) get: fn(&RawDevelopSettings) -> f32,
pub(super) set: fn(&mut RawDevelopSettings, f32),
pub(super) min: f64,
pub(super) max: f64,
pub(super) step: f64,
stops: Option<fn() -> Vec<DataColor>>,
}
/// A slider row over the settings field `$field`; its label is the word of the same name, or `$word` when given
/// (`field: word`).
macro_rules! slider {
($field:ident, $min:expr, $max:expr) => {
slider!($field, $min, $max, 1.0, None)
};
($field:ident, $min:expr, $max:expr, $step:expr) => {
slider!($field, $min, $max, $step, None)
};
($field:ident, $min:expr, $max:expr, $step:expr, $stops:expr) => {
slider!($field: $field, $min, $max, $step, $stops)
};
($field:ident: $word:ident, $min:expr, $max:expr) => {
slider!($field: $word, $min, $max, 1.0, None)
};
($field:ident: $word:ident, $min:expr, $max:expr, $step:expr, $stops:expr) => {
Slider {
key: stringify!($field),
word: |w| &w.$word,
get: |s| s.$field,
set: |s, v| s.$field = v,
min: $min,
max: $max,
step: $step,
stops: $stops,
}
};
}
/// The Light section's rows below Auto.
pub(super) const LIGHT: &[Slider] = &[
slider!(exposure, -5.0, 5.0, 0.05),
slider!(contrast, -100.0, 100.0),
slider!(highlights, -100.0, 100.0),
slider!(shadows, -100.0, 100.0),
slider!(whites, -100.0, 100.0),
slider!(blacks, -100.0, 100.0),
];
const COLOR: &[Slider] = &[
slider!(temperature, -100.0, 100.0, 1.0, Some(temperature_stops)),
slider!(tint, -100.0, 100.0, 1.0, Some(tint_stops)),
slider!(vibrance, -100.0, 100.0),
slider!(saturation, -100.0, 100.0),
];
const EFFECTS: &[Slider] = &[slider!(texture, -100.0, 100.0), slider!(clarity, -100.0, 100.0), slider!(dehaze, -100.0, 100.0)];
const VIGNETTE: &[Slider] = &[
slider!(vignette_amount, -100.0, 100.0),
slider!(vignette_midpoint, 0.0, 100.0),
slider!(vignette_roundness, -100.0, 100.0),
slider!(vignette_feather, 0.0, 100.0),
slider!(vignette_highlights, 0.0, 100.0),
];
const GRAIN: &[Slider] = &[slider!(grain_amount, 0.0, 100.0), slider!(grain_size, 0.0, 100.0), slider!(grain_roughness, 0.0, 100.0)];
const CURVE_REGIONS: &[Slider] = &[
slider!(curve_highlights, -100.0, 100.0),
slider!(curve_lights, -100.0, 100.0),
slider!(curve_darks, -100.0, 100.0),
slider!(curve_shadows, -100.0, 100.0),
];
const DETAIL: &[Slider] = &[
slider!(sharpen_amount, 0.0, 150.0),
slider!(sharpen_radius, 0.5, 3.0, 0.1),
slider!(sharpen_detail, 0.0, 100.0),
slider!(sharpen_masking, 0.0, 100.0),
slider!(noise_luminance, 0.0, 100.0),
slider!(noise_luminance_detail, 0.0, 100.0),
slider!(noise_color, 0.0, 100.0),
slider!(noise_color_detail, 0.0, 100.0),
];
/// The Color Grading section's rows below the four wheels.
pub(super) const GRADING_TAIL: &[Slider] = &[slider!(grade_blending: blending, 0.0, 100.0), slider!(grade_balance: balance, -100.0, 100.0)];
/// The Calibration section's first row.
const CALIBRATION: &[Slider] = &[slider!(shadow_tint, -100.0, 100.0)];
/// Every table of plain rows.
const TABLES: [&[Slider]; 9] = [LIGHT, COLOR, EFFECTS, VIGNETTE, GRAIN, CURVE_REGIONS, DETAIL, GRADING_TAIL, CALIBRATION];
/// The label word of the one row that edits the settings field `field` (its serde name, as the automation surface
/// writes it); `None` for a field no one row edits.
pub(super) fn field_word<'w>(words: &'w RawDevelopWords, field: &str) -> Option<&'w Label> {
let row = TABLES.iter().flat_map(|table| table.iter()).find(|row| row.key.replace('_', "").eq_ignore_ascii_case(field))?;
Some((row.word)(words))
}
/// The track of Temperature: cool to warm.
fn temperature_stops() -> Vec<DataColor> {
vec![
DataColor::new(Color32::from_rgb(0x46, 0x82, 0xff)),
DataColor::new(Color32::from_rgb(0xe8, 0xe8, 0xe8)),
DataColor::new(Color32::from_rgb(0xf5, 0xc2, 0x30)),
]
}
/// The track of Tint: green to magenta.
fn tint_stops() -> Vec<DataColor> {
vec![
DataColor::new(Color32::from_rgb(0x4c, 0xaf, 0x50)),
DataColor::new(Color32::from_rgb(0xe8, 0xe8, 0xe8)),
DataColor::new(Color32::from_rgb(0xd0, 0x40, 0xb0)),
]
}
/// The curve's levels: the settings hold point curves in 0..=255.
const LEVELS: f32 = 255.0;
/// The curve editor's value for the settings' points; an empty list is the linear curve.
fn curve_of(points: &[[f32; 2]]) -> Curve {
if points.is_empty() { Curve::identity(LEVELS) } else { Curve::smooth(points.to_vec()) }
}
/// The settings' points for the editor's curve: the unchanged curve is the empty list. A drawn curve has no points and
/// reads as linear; the column offers no pencil.
fn points_of(curve: &Curve) -> Vec<[f32; 2]> {
const IDENTITY: [[f32; 2]; 2] = [[0.0, 0.0], [LEVELS, LEVELS]];
match curve.points() {
Some(points) if points != &IDENTITY[..] => points.to_vec(),
_ => Vec::new(),
}
}
/// A control's edit of one field as an edit of the settings: the settings at the start of the pass with that field
/// replaced.
pub(super) fn lift<T>(events: EditEvents<T>, base: &RawDevelopSettings, set: &impl Fn(&mut RawDevelopSettings, T)) -> EditEvents<RawDevelopSettings> {
events.map(|value| {
let mut settings = base.clone();
set(&mut settings, value);
settings
})
}
/// What the rows of one pass add up to.
#[derive(Default)]
struct Pass {
edit: EditEvents<RawDevelopSettings>,
auto: bool,
demosaic: Option<Demosaic>,
}
/// The rows of one pass: the settings they started from, those Reset restores, and what they add up to.
pub(super) struct Rows<'p> {
pub(super) base: &'p RawDevelopSettings,
pub(super) defaults: &'p RawDevelopSettings,
pass: Pass,
}
impl<'p> Rows<'p> {
fn new(base: &'p RawDevelopSettings, defaults: &'p RawDevelopSettings) -> Self {
Rows { base, defaults, pass: Pass::default() }
}
/// A slider with a number field over `value`; `set` writes an edit into the settings, and the edit is the pass's.
#[allow(clippy::too_many_arguments)]
pub(super) fn slider(
&mut self,
ui: &mut Ui,
label: &Label,
value: f32,
default: f32,
range: RangeInclusive<f64>,
step: f64,
stops: Option<Vec<DataColor>>,
set: impl Fn(&mut RawDevelopSettings, f32),
) {
let mut field = SliderField::new(label.clone(), Bind::given(f64::from(value)).reset(f64::from(default)), range).step(step);
if let Some(stops) = &stops {
field = field.track_face(TrackFace::new(ToneRamp::new(stops)));
}
let events = field.show(ui).events;
self.pass.edit.extend(lift(events, self.base, &|settings: &mut RawDevelopSettings, v: f64| set(settings, v as f32)));
}
/// One slider row for each entry of `table`.
pub(super) fn table(&mut self, ui: &mut Ui, words: &RawDevelopWords, table: &[Slider]) {
for row in table {
let stops = row.stops.map(|stops| stops());
self.slider(ui, (row.word)(words), (row.get)(self.base), (row.get)(self.defaults), row.min..=row.max, row.step, stops, row.set);
}
}
/// The Curve section's editor over the point curve.
fn curve(&mut self, ui: &mut Ui, label: &Label) {
let curve = curve_of(&self.base.point_curve);
let shown = CurveEditor::new(label.clone(), Bind::given(curve)).levels(LEVELS as u32).show(ui);
self.pass.edit.extend(lift(shown.edit.events, self.base, &|settings: &mut RawDevelopSettings, curve: Curve| {
settings.point_curve = points_of(&curve);
}));
}
/// The three region splits under the editor: between shadows and darks, darks and lights, lights and highlights.
fn splits(&mut self, ui: &mut Ui, words: &RawDevelopWords) {
let labels = [&words.curve_shadow_split, &words.curve_midtone_split, &words.curve_highlight_split];
for (i, label) in labels.into_iter().enumerate() {
let (value, default) = (self.base.curve_splits[i], self.defaults.curve_splits[i]);
self.slider(ui, label, value, default, 0.0..=100.0, 1.0, None, move |settings, v| settings.curve_splits[i] = v);
}
}
/// The Calibration section's rows: Shadows Tint, then each primary's Hue and Saturation.
fn calibration(&mut self, ui: &mut Ui, words: &RawDevelopWords) {
self.table(ui, words, CALIBRATION);
let primaries = [&words.primary_red, &words.primary_green, &words.primary_blue];
for (i, primary) in primaries.into_iter().enumerate() {
let fill = [("primary", primary.as_str())];
let hue = Label::from(words.calibration_hue.fill(&fill));
let (value, default) = (self.base.calibration_hue[i], self.defaults.calibration_hue[i]);
self.slider(ui, &hue, value, default, -100.0..=100.0, 1.0, None, move |settings, v| settings.calibration_hue[i] = v);
let sat = Label::from(words.calibration_sat.fill(&fill));
let (value, default) = (self.base.calibration_sat[i], self.defaults.calibration_sat[i]);
self.slider(ui, &sat, value, default, -100.0..=100.0, 1.0, None, move |settings, v| settings.calibration_sat[i] = v);
}
}
/// The Vignetting style select.
fn vignette_style(&mut self, ui: &mut Ui, words: &RawDevelopWords) {
let entries = [
Entry::new(VignetteStyle::HighlightPriority, words.highlight_priority.clone()),
Entry::new(VignetteStyle::ColorPriority, words.color_priority.clone()),
Entry::new(VignetteStyle::PaintOverlay, words.paint_overlay.clone()),
];
let events = Select::new(words.vignette_style.clone(), Bind::given(self.base.vignette_style), &entries).show(ui).events;
self.pass.edit.extend(lift(events, self.base, &|settings: &mut RawDevelopSettings, style: VignetteStyle| settings.vignette_style = style));
}
/// The Demosaic select of the Detail section.
fn demosaic(&mut self, ui: &mut Ui, words: &RawDevelopWords, current: Demosaic) {
let entries = [
Entry::new(Demosaic::Ahd, words.demosaic_ahd.clone()),
Entry::new(Demosaic::Mhc, words.demosaic_mhc.clone()),
Entry::new(Demosaic::Bilinear, words.demosaic_bilinear.clone()),
];
let events = Select::new(words.demosaic.clone(), Bind::given(current), &entries).show(ui).events;
if let Some(picked) = events.value().copied() {
self.pass.demosaic = Some(picked);
}
}
}
/// A collapsible section whose open state is remembered under `craft_imaging.raw_develop.section.<name>`.
pub(super) fn section(label: &Label, name: &str, open: bool) -> Section<'static> {
Section::new(label.clone()).remember(SaveKey::named(format!("craft_imaging.raw_develop.section.{name}"))).initially_open(open)
}
/// The control column: Light, Color, Effects, Curve, Color Mixer, Color Grading, Detail and Calibration sections. Each
/// row shows `Bind::given(f64::from(value))` and writes its edit back as `f32`.
#[must_use = "show the panel with `show`"]
#[derive(Pattern, Props)]
#[allow(dead_code)] // P3(dialogs-w18): dl.K67
pub struct RawDevelopPanel<'a> {
settings: Bind<'a, RawDevelopSettings>,
/// The demosaic select shows while a raw is being opened.
@@ -41,13 +321,60 @@ pub struct RawDevelopPanel<'a> {
impl<'a> RawDevelopPanel<'a> {
/// The panel over `settings`.
pub fn new(settings: Bind<'a, RawDevelopSettings>) -> Self {
let _ = settings;
todo!("dl.K67")
RawDevelopPanel { settings, demosaic: None }
}
/// Draws the sections.
/// Draws the sections. A body that runs twice in one pass (the measuring run, then the real one) builds its rows
/// afresh each run; only the real run sees input, so the edit is the real run's.
pub fn show(self, ui: &mut Ui) -> RawDevelopPanelOutput {
let _ = (self, ui);
todo!("dl.K67")
let Self { mut settings, demosaic } = self;
let words = Env::of(ui).words::<RawDevelopWords>();
let defaults = RawDevelopSettings::default();
let shown = Stack::new().show(ui, |ui, root| {
let Some(base) = settings.reborrow().read(root).and_then(|held| held.same().cloned()) else { return Pass::default() };
let mut rows = Rows::new(&base, &defaults);
section(&words.section_light, "light", true).show(ui, |ui, _| {
if clicked(&Button::new(words.auto.clone()).id_salt("auto").show(ui)) {
rows.pass.auto = true;
}
rows.table(ui, &words, LIGHT);
});
section(&words.section_color, "color", false).show(ui, |ui, _| {
rows.table(ui, &words, COLOR);
});
section(&words.section_effects, "effects", false).show(ui, |ui, _| {
rows.table(ui, &words, EFFECTS);
rows.vignette_style(ui, &words);
rows.table(ui, &words, VIGNETTE);
rows.table(ui, &words, GRAIN);
});
section(&words.section_curve, "curve", false).show(ui, |ui, _| {
rows.curve(ui, &words.section_curve);
rows.table(ui, &words, CURVE_REGIONS);
rows.splits(ui, &words);
});
mixer::color_mixer(ui, &mut rows, &words);
mixer::color_grading(ui, &mut rows, &words);
section(&words.section_detail, "detail", false).show(ui, |ui, _| {
if let Some(current) = demosaic {
rows.demosaic(ui, &words, current);
}
rows.table(ui, &words, DETAIL);
});
section(&words.section_calibration, "calibration", false).show(ui, |ui, _| {
rows.calibration(ui, &words);
});
for event in &rows.pass.edit {
settings.reborrow().write(root, event);
}
rows.pass
});
let pass = shown.inner.unwrap_or_default();
RawDevelopPanelOutput {
edit: EditResponse::lifted(shown.output.clone(), pass.edit, None),
response: shown.output,
auto: pass.auto,
demosaic: pass.demosaic,
}
}
}
+108
View File
@@ -0,0 +1,108 @@
//! The Color Mixer and Color Grading sections of the control column.
use craft_ui::contract::{Bind, Entry, Show as _, ShowContainer as _};
use craft_ui::choice::Segmented;
use craft_ui::runtime::env::Label;
use craft_ui::sections::{HeaderStrength, Section};
use craft_ui::style::DataColor;
use egui::{Color32, Ui};
use super::controls::{GRADING_TAIL, Rows, section};
use super::words::RawDevelopWords;
use crate::raw::{GradeWheel, RawDevelopSettings};
/// The Color Mixer's tabs: the band property a row edits.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
enum MixerTab {
Hue,
Saturation,
Luminance,
}
impl MixerTab {
/// Reads and writes the tab's value of band `k`.
fn accessors(self) -> (fn(&RawDevelopSettings, usize) -> f32, fn(&mut RawDevelopSettings, usize, f32)) {
match self {
MixerTab::Hue => (|s, k| s.hsl_hue[k], |s, k, v| s.hsl_hue[k] = v),
MixerTab::Saturation => (|s, k| s.hsl_sat[k], |s, k, v| s.hsl_sat[k] = v),
MixerTab::Luminance => (|s, k| s.hsl_lum[k], |s, k, v| s.hsl_lum[k] = v),
}
}
}
/// The eight bands: their word and the hue (degrees) their track is drawn around.
const BANDS: [(fn(&RawDevelopWords) -> &Label, f32); 8] = [
(|w| &w.band_reds, 0.0),
(|w| &w.band_oranges, 30.0),
(|w| &w.band_yellows, 60.0),
(|w| &w.band_greens, 120.0),
(|w| &w.band_aquas, 180.0),
(|w| &w.band_blues, 240.0),
(|w| &w.band_purples, 270.0),
(|w| &w.band_magentas, 300.0),
];
/// The track of a band's row on `tab`: the hue shifting around the band, the saturation rising, the luminance rising.
fn band_stops(tab: MixerTab, hue: f32) -> Vec<DataColor> {
let color = |h: f32, s: f32, v: f32| {
let unit = (h / 360.0).rem_euclid(1.0);
DataColor::new(Color32::from(egui::ecolor::Hsva::new(unit, s, v, 1.0)))
};
match tab {
MixerTab::Hue => vec![color(hue - 30.0, 0.9, 1.0), color(hue, 0.9, 1.0), color(hue + 30.0, 0.9, 1.0)],
MixerTab::Saturation => vec![color(hue, 0.15, 0.9), color(hue, 1.0, 1.0)],
MixerTab::Luminance => vec![color(hue, 0.9, 0.25), color(hue, 0.9, 0.7), color(hue, 0.3, 1.0)],
}
}
/// One grading wheel: its word and its settings field.
#[derive(Clone, Copy)]
struct Wheel {
word: fn(&RawDevelopWords) -> &Label,
get: fn(&RawDevelopSettings) -> &GradeWheel,
get_mut: fn(&mut RawDevelopSettings) -> &mut GradeWheel,
}
const WHEELS: [Wheel; 4] = [
Wheel { word: |w| &w.wheel_shadows, get: |s| &s.grade_shadows, get_mut: |s| &mut s.grade_shadows },
Wheel { word: |w| &w.wheel_midtones, get: |s| &s.grade_midtones, get_mut: |s| &mut s.grade_midtones },
Wheel { word: |w| &w.wheel_highlights, get: |s| &s.grade_highlights, get_mut: |s| &mut s.grade_highlights },
Wheel { word: |w| &w.wheel_global, get: |s| &s.grade_global, get_mut: |s| &mut s.grade_global },
];
/// The Color Mixer section: the Hue, Saturation and Luminance tabs over the eight bands. The tabs keep the chosen tab,
/// Hue until one is picked.
pub(super) fn color_mixer(ui: &mut Ui, rows: &mut Rows<'_>, words: &RawDevelopWords) {
section(&words.section_color_mixer, "color_mixer", false).show(ui, |ui, _| {
let tabs = [
Entry::new(MixerTab::Hue, words.mixer_hue.clone()),
Entry::new(MixerTab::Saturation, words.mixer_saturation.clone()),
Entry::new(MixerTab::Luminance, words.mixer_luminance.clone()),
];
let shown = Segmented::new(words.section_color_mixer.clone(), Bind::kept().reset(MixerTab::Hue), &tabs).show(ui);
let kept = shown.shown.as_ref().and_then(|held| held.same()).map(|tab| **tab);
let tab = shown.value().copied().or(kept).unwrap_or(MixerTab::Hue);
let (get, set) = tab.accessors();
let (base, defaults) = (rows.base, rows.defaults);
for (k, (word, hue)) in BANDS.iter().enumerate() {
let stops = Some(band_stops(tab, *hue));
rows.slider(ui, word(words), get(base, k), get(defaults, k), -100.0..=100.0, 1.0, stops, move |settings, v| set(settings, k, v));
}
});
}
/// The Color Grading section: Hue, Saturation and Luminance rows for each wheel, then Blending and Balance.
pub(super) fn color_grading(ui: &mut Ui, rows: &mut Rows<'_>, words: &RawDevelopWords) {
section(&words.section_color_grading, "color_grading", false).show(ui, |ui, _| {
for wheel in WHEELS {
Section::fixed((wheel.word)(words).clone()).strength(HeaderStrength::Caption).show(ui, |ui, _| {
let (now, was) = ((wheel.get)(rows.base), (wheel.get)(rows.defaults));
let (now, was) = (*now, *was);
rows.slider(ui, &words.mixer_hue, now.hue, was.hue, 0.0..=360.0, 1.0, None, move |s, v| (wheel.get_mut)(s).hue = v);
rows.slider(ui, &words.mixer_saturation, now.sat, was.sat, 0.0..=100.0, 1.0, None, move |s, v| (wheel.get_mut)(s).sat = v);
rows.slider(ui, &words.mixer_luminance, now.lum, was.lum, -100.0..=100.0, 1.0, None, move |s, v| (wheel.get_mut)(s).lum = v);
});
}
rows.table(ui, words, GRADING_TAIL);
});
}
@@ -0,0 +1,54 @@
//! The preview's controls on the workspace canvas: the colour samplers' readouts and the clipping overlay. The
//! workspace owns the sampler tool, the points and the cache; these functions read the source for them.
use std::sync::Arc;
use craft_color::ui::{ColorSamplers, SamplerCache, SamplerReadout, SamplerReadouts};
use craft_theme::Srgba;
use craft_ui::primitives::Revision;
use craft_ui::runtime::env::Label;
use super::source::RawDevelopSource;
use crate::scopes::ClippingMask;
use crate::ui::scopes::{ClippingMode, ClippingOverlay, ScopeReadout};
/// The readouts of `samplers` over the picture `before` or after, from `cache` while `revision` and the points are
/// unchanged. The samplers ask in RGB; with `lab` (Show Lab Color Readouts) each readout also carries its Lab value,
/// asked of the source again for the few points.
pub(super) fn sampler_readouts(
samplers: &ColorSamplers,
source: &dyn RawDevelopSource,
before: bool,
revision: u64,
lab: bool,
cache: &mut SamplerCache,
) -> Arc<Vec<SamplerReadout>> {
let read = |at: [f64; 2]| match source.sample(at, before, false) {
Some(ScopeReadout::Rgb([r, g, b])) => Srgba { r, g, b, a: 1.0 },
_ => Srgba { r: 0.0, g: 0.0, b: 0.0, a: 0.0 },
};
let readouts = SamplerReadouts::new(samplers, read).revision(revision).get(cache);
if !lab {
return readouts;
}
let mut with_lab = (*readouts).clone();
for readout in &mut with_lab {
let at = readout.position.map(|v| v as f64);
readout.lab = match source.sample(at, before, true) {
Some(ScopeReadout::Lab([l, a, b])) => Some([l.round().clamp(0.0, 100.0) as i16, a.round().clamp(-128.0, 127.0) as i16, b.round().clamp(-128.0, 127.0) as i16]),
_ => None,
};
}
Arc::new(with_lab)
}
/// The source's clipping mask and its revision while a warning is on; nothing when `mode` shows none.
pub(super) fn clipping_state(source: &dyn RawDevelopSource, mode: ClippingMode) -> Option<(Arc<ClippingMask>, Revision)> {
if matches!(mode, ClippingMode::None) { None } else { source.clipping() }
}
/// The overlay of `held` (from [`clipping_state`]) in `mode`. The overlay rebuilds its texture only when the revision,
/// the mode or the theme's inks change.
pub(super) fn clipping_overlay<'a>(label: impl Into<Label>, held: &'a (Arc<ClippingMask>, Revision), mode: ClippingMode) -> ClippingOverlay<'a> {
ClippingOverlay::new(label, &held.0, held.1, mode)
}
+143 -23
View File
@@ -1,82 +1,202 @@
//! The docked and floating scope of the workspace.
use craft_ui::contract::{Bind, Pattern, Props};
use std::sync::Arc;
use craft_behavior::{EditEvent, EditEvents, Mixed};
use craft_ui::buttons::Button;
use craft_ui::contract::{BodyCx, Bind, EditResponse, Pattern, Props, SaveKey, Show as _, ShowContainer as _, clicked};
use craft_ui::layout_components::Stack;
use craft_ui::runtime::env::{Env, Label};
use craft_ui::sections::HeaderAction;
use craft_ui::dialog::Dialog;
use egui::Ui;
use craft_ui::contract::EditResponse;
use super::controls::{LIGHT, Slider, section};
use super::words::RawDevelopWords;
use crate::raw::RawDevelopSettings;
use crate::ui::scopes::{ScopeFrame, ScopePanelOutput, ScopePanelState};
use crate::ui::scopes::{ScopeFrame, ScopePanel, ScopePanelOutput, ScopePanelState, ScopeWords, ToneZone, ZoneScale, ZoneValues};
/// What the docked and the floating scope report: the scope panel's events and the tone-zone edits of the bound
/// settings.
// P3(dialogs-w18): dl.K67 `RawScopeStripOutput`
#[derive(Debug)]
#[non_exhaustive]
pub struct RawScopeStripOutput {
/// The scope panel's events.
pub panel: ScopePanelOutput,
/// The scope panel's events; `None` while the panel is not shown (a collapsed strip, a closed window).
pub panel: Option<ScopePanelOutput>,
/// The edits of the settings' tone zones.
pub edit: EditResponse<RawDevelopSettings>,
}
/// The slider row a tone zone edits: the zone's key is the settings field's name.
fn zone_slider(key: &str) -> Option<&'static Slider> {
LIGHT.iter().find(|row| row.key == key)
}
/// The zone's value as the tooltip and the screen reader word it.
fn zone_text(row: &Slider, settings: &RawDevelopSettings) -> String {
let value = (row.get)(settings);
if row.step < 1.0 { format!("{value:.2}") } else { format!("{value:.0}") }
}
/// How a zone's slider row moves: its range and step, its default as the reset, and a drag across the plot's width
/// that spans twice the range's end (PhotoCraft's tone-zone drag).
fn zone_scale(row: &Slider) -> ZoneScale {
let limit = row.max as f32;
ZoneScale::new(row.min as f32..=limit, limit * 2.0, row.step as f32, (row.get)(&RawDevelopSettings::default()))
}
/// The values of the zones' fields in `settings`, in the zones' order.
fn zone_values(settings: &RawDevelopSettings) -> ZoneValues {
ZoneValues(ToneZone::CAMERA_RAW.iter().map(|zone| zone_slider(zone.key).map_or(0.0, |row| (row.get)(settings))).collect())
}
/// `base` with each zone's field set to its value in `values`.
fn with_zones(base: &RawDevelopSettings, values: &ZoneValues) -> RawDevelopSettings {
let mut settings = base.clone();
for (zone, value) in ToneZone::CAMERA_RAW.iter().zip(&values.0) {
if let Some(row) = zone_slider(zone.key) {
(row.set)(&mut settings, *value);
}
}
settings
}
/// The scope panel with Camera Raw's tone zones over the bound settings, and the zone edits written back to them.
fn zone_panel(
ui: &mut Ui,
cx: &mut BodyCx<'_>,
state: &mut ScopePanelState,
frame: Option<&ScopeFrame<'_>>,
settings: &mut Bind<'_, RawDevelopSettings>,
has_selection: bool,
) -> RawScopeStripOutput {
let base = settings.reborrow().read(cx).and_then(|held| held.same().cloned());
let rows: Vec<Option<&Slider>> = ToneZone::CAMERA_RAW.iter().map(|zone| zone_slider(zone.key)).collect();
// A zone without a row keeps a range of one value, so it never moves.
let scales: Vec<ZoneScale> = rows.iter().map(|row| row.map_or(ZoneScale::new(0.0..=0.0, 0.0, 0.0, 0.0), zone_scale)).collect();
let texts: Vec<Label> = rows
.iter()
.map(|row| {
let text = base.as_ref().zip(*row).map(|(settings, row)| zone_text(row, settings));
Label::from(text.unwrap_or_default())
})
.collect();
let values = base.as_ref().map_or(Mixed::Mixed, |base| Mixed::Same(zone_values(base)));
let panel = ScopePanel::new(state);
// Without a frame the panel draws nothing: the host shows its own "Calculating..." line.
let panel = match frame {
Some(frame) => panel.frame(frame),
None => panel,
};
let panel = panel.zones(&ToneZone::CAMERA_RAW, &scales, &texts, Bind::given(values)).has_selection(has_selection).show(ui);
// The zones' values in the settings around them; nothing edits a mixed value.
let events = base.as_ref().map(|base| panel.zone.clone().map(|values| with_zones(base, &values))).unwrap_or_default();
for event in &events {
settings.reborrow().write(cx, event);
}
let edit = EditResponse::lifted(panel.response.clone(), events, None);
RawScopeStripOutput { panel: Some(panel), edit }
}
/// The output of a scope whose panel is not shown: no panel and no edit, on the response of what holds it.
fn unshown(response: &egui::Response) -> RawScopeStripOutput {
RawScopeStripOutput { panel: None, edit: EditResponse::lifted(response.clone(), EditEvents::new(), None) }
}
/// The docked scope above the controls: a `ScopePanel` with Camera Raw's tone zones and typical histogram scale, its
/// context menu and a Float action in the section header.
#[must_use = "show the strip with `show`"]
#[derive(Pattern, Props)]
#[allow(dead_code)] // P3(dialogs-w18): dl.K67
pub struct RawScopeStrip<'a> {
state: &'a mut ScopePanelState,
frame: Option<&'a ScopeFrame<'a>>,
settings: Bind<'a, RawDevelopSettings>,
/// Whether the scope floats; its Float action sets it.
#[prop]
floating: Option<Bind<'a, bool>>,
/// The picture has a selection: the scope menu offers Show Selected Region.
#[prop]
has_selection: bool,
}
impl<'a> RawScopeStrip<'a> {
/// The strip over `state` and the host's `frame`, showing the zone values of `settings`.
// P3(dialogs-w18): dl.K67 `settings`
pub fn new(state: &'a mut ScopePanelState, frame: Option<&'a ScopeFrame<'a>>, settings: Bind<'a, RawDevelopSettings>) -> Self {
let _ = (state, frame, settings);
todo!("dl.K67")
RawScopeStrip { state, frame, settings, floating: None, has_selection: false }
}
/// Draws the scope.
// P3(dialogs-w18): dl.K67 `RawScopeStripOutput`
pub fn show(self, ui: &mut Ui) -> RawScopeStripOutput {
let _ = (self, ui);
todo!("dl.K67")
let Self { state, frame, mut settings, mut floating, has_selection } = self;
let env = Env::of(ui);
let words = env.words::<RawDevelopWords>();
let title = env.words::<ScopeWords>().histogram.clone();
let shown = Stack::new().show(ui, |ui, root| {
let section = section(&title, "scope", true)
.actions(floating.is_some().then_some(HeaderAction::Float))
.show(ui, |ui, cx| zone_panel(ui, cx, &mut *state, frame, &mut settings, has_selection));
if section.output.action == Some(HeaderAction::Float)
&& let Some(floating) = floating.as_mut()
{
let event = EditEvent::set(Mixed::Same(false), true, Arc::from(words.float.as_str()), None);
floating.reborrow().write(root, &event);
}
section.inner
});
match shown.inner.flatten() {
Some(out) => out,
None => unshown(&shown.output),
}
}
}
/// The floating scope: a modeless child dialog of the workspace, resizable and remembered; its Dock action clears
/// `floating`.
#[must_use = "show the scope with `show`"]
#[derive(Pattern)]
#[allow(dead_code)] // P3(dialogs-w18): dl.K67
#[derive(Pattern, Props)]
pub struct RawFloatingScope<'a> {
state: &'a mut ScopePanelState,
frame: Option<&'a ScopeFrame<'a>>,
floating: Bind<'a, bool>,
settings: Bind<'a, RawDevelopSettings>,
/// The picture has a selection: the scope menu offers Show Selected Region.
#[prop]
has_selection: bool,
}
impl<'a> RawFloatingScope<'a> {
/// The floating scope over `state` and the host's `frame`, showing the zone values of `settings`.
// P3(dialogs-w18): dl.K67 `settings`
pub fn new(
state: &'a mut ScopePanelState,
frame: Option<&'a ScopeFrame<'a>>,
floating: Bind<'a, bool>,
settings: Bind<'a, RawDevelopSettings>,
) -> Self {
let _ = (state, frame, floating, settings);
todo!("dl.K67")
RawFloatingScope { state, frame, floating, settings, has_selection: false }
}
/// Draws the scope.
// P3(dialogs-w18): dl.K67 `RawScopeStripOutput`
/// Draws the scope. The window's close action and Dock both write `false` to `floating` (the dialog's open state is
/// the binding).
pub fn show(self, ui: &mut Ui) -> RawScopeStripOutput {
let _ = (self, ui);
todo!("dl.K67")
let Self { state, frame, floating, mut settings, has_selection } = self;
let env = Env::of(ui);
let words = env.words::<RawDevelopWords>();
let title = env.words::<ScopeWords>().histogram.clone();
let shown = Dialog::new(title)
.modeless()
.resizable(true)
.remember(SaveKey::new("craft_imaging.raw_develop.scope_window"))
.opened(floating)
.show(ui, |ui, cx| {
let out = zone_panel(ui, cx, &mut *state, frame, &mut settings, has_selection);
if clicked(&Button::new(words.dock.clone()).id_salt("dock").show(ui)) {
cx.request_close();
}
out
});
match shown.inner {
Some(out) => out,
None => unshown(&shown.output.response),
}
}
}
+2 -2
View File
@@ -19,7 +19,7 @@
//! |---|---|
//! | The panel | [`ScopePanel`], [`ScopePanelOutput`], [`ScopePanelState`], [`ScopeSettings`], [`ScopeView`], [`ScopeWords`] |
//! | The data | [`ScopeFrame`], [`HistogramSet`], [`ScopeChannel`], [`ChannelOverlay`], [`ScopeSource`], [`ScopeReadout`], [`VectorscopeFrame`], [`ClippingFrame`] |
//! | Tone zones | [`ToneZones`], [`ToneZone`], [`ScopeZoneEdit`], [`ZoneChange`] |
//! | Tone zones | [`ToneZones`], [`ToneZone`], [`ZoneScale`], [`ZoneValues`] |
//! | Commands | [`ScopeCommand`], [`ScopePanel::panel_rows`], [`ScopePanel::run_command`], [`ScopeMenuAction`] |
//! | Clipping | [`ClipWarning`], [`ClippingOverlay`], [`ClippingMode`], [`ClippingWarnings`], [`ClippingDiagnostic`] |
//! | Vectorscope alone | [`VectorscopePlot`], [`scope_point`] |
@@ -42,4 +42,4 @@ pub use panel::{
};
pub use vectorscope::{VectorscopeFrame, VectorscopePlot, scope_point};
pub use words::ScopeWords;
pub use zones::{ScopeZoneEdit, ToneZone, ToneZones, ZoneChange};
pub use zones::{ToneZone, ToneZones, ZoneScale, ZoneValues};
+25 -10
View File
@@ -12,7 +12,7 @@ use super::menu::{ScopeCommand, ScopeMenuAction};
use super::plot::{Shown, plot_data, resolve_channel};
use super::vectorscope::VectorscopePlot;
use super::words::ScopeWords;
use super::zones::{ScopeZoneEdit, ToneZone, ToneZones};
use super::zones::{ToneZone, ToneZones, ZoneScale, ZoneValues};
use crate::scopes::{HistogramStatistics, histogram_statistics};
use crate::ui::histogram::{ChannelColor, Histogram, HistogramData, LevelRange, PlotHeight, StaleMark};
use craft_behavior::{ColumnWidth, EditEvents, IconId, Proposal};
@@ -87,7 +87,9 @@ pub struct ScopePanel<'a> {
#[prop]
markers: &'a [(f32, Label)],
zones: &'a [ToneZone],
zone_values: &'a [Label],
zone_scales: &'a [ZoneScale],
zone_texts: &'a [Label],
zone_values: Bind<'a, ZoneValues>,
/// The document has a selection: the scope menu offers Show Selected Region.
#[prop]
has_selection: bool,
@@ -96,13 +98,25 @@ pub struct ScopePanel<'a> {
impl<'a> ScopePanel<'a> {
/// A scope panel over `state`.
pub fn new(state: &'a mut ScopePanelState) -> Self {
ScopePanel { state, frame: None, sources: &[], markers: &[], zones: &[], zone_values: &[], has_selection: false }
ScopePanel {
state,
frame: None,
sources: &[],
markers: &[],
zones: &[],
zone_scales: &[],
zone_texts: &[],
zone_values: Bind::kept(),
has_selection: false,
}
}
/// The tone zones over the plot ([`ToneZone::CAMERA_RAW`] or [`ToneZone::LIGHTROOM`]) and each zone's value text,
/// in the same order (the tooltip and the slider's value).
pub fn zones(mut self, zones: &'a [ToneZone], values: &'a [Label]) -> Self {
/// The tone zones over the plot ([`ToneZone::CAMERA_RAW`] or [`ToneZone::LIGHTROOM`]) and, in the same order, each
/// zone's scale and value text (the tooltip and the slider's value), over the values of the controls they edit.
pub fn zones(mut self, zones: &'a [ToneZone], scales: &'a [ZoneScale], texts: &'a [Label], values: Bind<'a, ZoneValues>) -> Self {
self.zones = zones;
self.zone_scales = scales;
self.zone_texts = texts;
self.zone_values = values;
self
}
@@ -138,7 +152,7 @@ struct Report {
refresh: bool,
source_changed: bool,
channel_changed: bool,
zone: EditEvents<ScopeZoneEdit>,
zone: EditEvents<ZoneValues>,
hovered_level: Option<f32>,
clipping_toggled: bool,
}
@@ -221,7 +235,8 @@ impl Pass<'_> {
self.report.refresh |= histogram.refresh || (!zoned && histogram.double_click);
let mut openers = vec![histogram.response.clone()];
if zoned {
let edit = ToneZones::new(words.tone_zones.clone(), self.panel.zones, self.panel.zone_values).show_at(ui, rect);
let (zones, scales, texts) = (self.panel.zones, self.panel.zone_scales, self.panel.zone_texts);
let edit = ToneZones::new(words.tone_zones.clone(), zones, scales, texts).value(self.panel.zone_values.reborrowed()).show_at(ui, rect);
self.report.zone = edit.events;
}
if let Some(clipping) = frame.clipping {
@@ -418,8 +433,8 @@ pub struct ScopePanelOutput {
pub source_changed: bool,
/// The Channel changed.
pub channel_changed: bool,
/// The tone-zone edits, in order, with their gesture; the host maps them to its control.
pub zone: EditEvents<ScopeZoneEdit>,
/// The tone-zone edits of the zones' values, in order, with their gesture; the host maps them to its controls.
pub zone: EditEvents<ZoneValues>,
/// The whole level under the pointer on the main plot.
pub hovered_level: Option<f32>,
/// The selected level range after this pass (also in [`ScopePanelState::range`]).
+39 -24
View File
@@ -7,8 +7,8 @@
use super::zones::ZONE;
use super::{
COLORS_CHANNEL, ChannelOverlay, ClipWarning, ClippingFrame, ClippingMode, ClippingOverlay, ClippingWarnings, HistogramSet, ScopeChannel,
ScopeFrame, ScopePanel, ScopePanelState, ScopeSettings, ScopeSource, ScopeView, ScopeZoneEdit, ToneZone, ToneZones, VectorscopeFrame,
VectorscopePlot, ZoneChange,
ScopeFrame, ScopePanel, ScopePanelState, ScopeSettings, ScopeSource, ScopeView, ToneZone, ToneZones, VectorscopeFrame, VectorscopePlot,
ZoneScale, ZoneValues,
};
use crate::scopes::{ChannelMask, ClippingMask, HUES, SATURATIONS, Vectorscope, hue_saturation};
use crate::ui::histogram::ChannelColor;
@@ -185,16 +185,35 @@ fn zone_text(key: &str, value: f32) -> String {
if key == "exposure" { format!("{value:+.2}") } else { format!("{value:+.0}") }
}
/// Each Camera Raw zone's value text, empty while the values are mixed.
fn zone_texts(values: Option<&ZoneValues>) -> Vec<Label> {
let text = |at: usize, zone: &ToneZone| values.and_then(|values| values.0.get(at)).map(|value| zone_text(zone.key, *value));
ToneZone::CAMERA_RAW.iter().enumerate().map(|(at, zone)| Label::from(text(at, zone).unwrap_or_default())).collect()
}
/// Each Camera Raw zone's scale: Exposure in stops, -5 to 5, the others -100 to 100; a drag across the plot spans twice
/// the range's end.
fn zone_scales() -> [ZoneScale; 5] {
ToneZone::CAMERA_RAW.map(|zone| match zone.key {
"exposure" => ZoneScale::new(-5.0..=5.0, 10.0, 0.05, 0.0),
_ => ZoneScale::new(-100.0..=100.0, 200.0, 1.0, 0.0),
})
}
/// The zone values the zone stories start from.
fn first_values() -> ZoneValues {
ZoneValues(vec![0.0; ToneZone::CAMERA_RAW.len()])
}
#[story(ScopePanel<'static>, covers = [Default], drive = Drive::Never)]
fn tone_zones(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let values = *data.value("zone-values", [0.0f32; 5]);
let state = data.value("zones", ScopePanelState { settings: view(ScopeView::Expanded), ..ScopePanelState::default() });
let start = (ScopePanelState { settings: view(ScopeView::Expanded), ..ScopePanelState::default() }, first_values());
let (state, values) = data.value("zones", start);
let curves = curves(Mode::Rgb, 0.0);
let channels = scope_channels(&curves);
let frame = ScopeFrame::histogram(HistogramSet::new(&channels));
let zones = ToneZone::CAMERA_RAW;
let texts: Vec<Label> = zones.iter().zip(values).map(|(zone, value)| Label::from(zone_text(zone.key, value))).collect();
ScopePanel::new(state).frame(&frame).zones(&zones, &texts).show(ui).into()
let (zones, scales, texts) = (ToneZone::CAMERA_RAW, zone_scales(), zone_texts(Some(&*values)));
ScopePanel::new(state).frame(&frame).zones(&zones, &scales, &texts, Bind::bound(values)).show(ui).into()
}
/// Generated pixels in a skin cluster, a sky and some foliage, with a few saturated ones.
@@ -313,38 +332,34 @@ fn clip_warning_that_is_refused(ui: &mut Ui, data: &mut StoryData) -> StoryOutpu
ClipWarning::new("Highlight Clipping Warning (O)", Bind::bound(on).check(refuse), ChannelMask::R).show(ui).into()
}
/// The edit the zone stories start from.
fn first_edit() -> ScopeZoneEdit {
ScopeZoneEdit { zone: 0, key: ToneZone::CAMERA_RAW[0].key, change: ZoneChange::Step(0) }
}
/// The zones of a story over a picture, the value text of each, and the story's canvas.
fn zones_story(ui: &mut Ui, mut value: Bind<'_, ScopeZoneEdit>) -> StoryOutput {
let zones = ToneZone::CAMERA_RAW;
let texts: Vec<Label> = zones.iter().map(|zone| Label::from(zone_text(zone.key, 0.0))).collect();
/// The zones of a story over a picture, with each zone's scale and value text, and the story's canvas.
fn zones_story(ui: &mut Ui, mut value: Bind<'_, ZoneValues>, texts: &[Label]) -> StoryOutput {
let (zones, scales) = (ToneZone::CAMERA_RAW, zone_scales());
let image = MockImage::default();
story_canvas(ui, Some(&image), StoryView::Fit, |ui, rect| {
ToneZones::new("Tone zones", &zones, &texts).value(value.reborrowed()).show_at(ui, rect).into()
ToneZones::new("Tone zones", &zones, &scales, texts).value(value.reborrowed()).show_at(ui, rect).into()
})
}
#[story(ToneZones<'static>, covers = [Default], drive = Drive::Drag(Grip::part(ZONE.at(1)).toward(vec2(1.0, 0.0))))]
fn zones_over_a_plot(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let edit = data.value("edit", first_edit());
zones_story(ui, Bind::bound(edit))
let values = data.value("values", first_values());
let texts = zone_texts(Some(&*values));
zones_story(ui, Bind::bound(values), &texts)
}
#[story(ToneZones<'static>, covers = [Mixed], drive = Drive::Never)]
fn zones_that_differ(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let edit = data.value("mixed", Mixed::<ScopeZoneEdit>::Mixed);
zones_story(ui, Bind::bound_mixed(edit))
let values = data.value("mixed", Mixed::<ZoneValues>::Mixed);
zones_story(ui, Bind::bound_mixed(values), &zone_texts(None))
}
#[story(ToneZones<'static>, covers = [Invalid], drive = Drive::Never)]
fn zones_that_are_refused(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let edit = data.value("refused", first_edit());
let refuse = |_: &ScopeZoneEdit| Validity::Refuse(Message::new("Not available"));
zones_story(ui, Bind::bound(edit).check(refuse))
let values = data.value("refused", first_values());
let texts = zone_texts(Some(&*values));
let refuse = |_: &ZoneValues| Validity::Refuse(Message::new("Not available"));
zones_story(ui, Bind::bound(values).check(refuse), &texts)
}
#[story(ClippingOverlay<'static>, covers = [Default], drive = Drive::Never)]
+106 -53
View File
@@ -1,7 +1,8 @@
//! Tone zones ([`ToneZone`], [`ScopeZoneEdit`], [`ToneZones`]): Camera Raw's and Lightroom's draggable ranges over the
//! histogram.
//! Tone zones ([`ToneZone`], [`ZoneScale`], [`ZoneValues`], [`ToneZones`]): Camera Raw's and Lightroom's draggable
//! ranges over the histogram.
use super::words::ScopeWords;
use craft_behavior::Mixed;
use craft_behavior::{AccessAction, CursorIcon, Metrics, NavMove, PartKey, PressPhase, Sense};
use craft_ui::contract::{
Access, Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, Focus as _, Input, Name, Numeric, PartsCx, Pointer as _, Props as _,
@@ -13,6 +14,7 @@ use craft_ui::runtime::env::Label;
use craft_ui::runtime::focus::{ActivateKeys, KeyUse};
use craft_ui::style::{ComponentStyle, FocusLook, StyleColor, StyleCx};
use egui::{CornerRadius, Rect, Vec2};
use std::ops::RangeInclusive;
/// One zone's slider node and part; the index names the zone.
pub(super) const ZONE: PartKey = PartKey::new("zone");
@@ -20,9 +22,6 @@ pub(super) const ZONE: PartKey = PartKey::new("zone");
/// Shift drags a tenth as far (LightCraft's fine factor).
const FINE: f32 = 0.1;
/// The slider nodes accept any value: the zone's range belongs to the host's control.
const UNBOUNDED: f64 = 1.0e9;
/// The steps one arrow press with Shift held takes.
const LARGE_STEP: i32 = 10;
@@ -83,33 +82,50 @@ impl ToneZone {
}
}
/// What the user did to one zone.
/// How the control one zone edits moves, as the host's slider row for it has it.
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub enum ZoneChange {
/// A drag over the plot, one gesture: the signed share of the plot width moved since the press (Shift drags a
/// tenth as far). The host maps the share to its control (PhotoCraft: `share x limit x 2`, limit 5 for Exposure,
/// else 100) and makes one undo step for the drag.
Drag(f32),
/// Arrow keys with the plot focused, or a screen reader's Increment and Decrement: this many of the control's own
/// steps (Right and Up +1, Left and Down -1, Shift x10). One undo step each.
Step(i32),
/// A double click on the zone: the host resets the control to its default. One undo step.
Reset,
/// A screen reader's SetValue, in the control's own units.
SetValue(f64),
pub struct ZoneScale {
/// The lowest value.
pub min: f32,
/// The highest value.
pub max: f32,
/// The change a drag across the plot's full width makes (PhotoCraft: twice the range's end, so 10 stops for
/// Exposure and 200 for the others). Shift drags a tenth as far.
pub drag: f32,
/// The change of one arrow key press or screen reader Increment.
pub step: f32,
/// The value a double click on the zone restores.
pub reset: f32,
}
/// A tone-zone edit.
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub struct ScopeZoneEdit {
/// The zone's index in the slice given to [`ToneZones::new`].
pub zone: usize,
/// The zone's key.
pub key: &'static str,
/// What happened.
pub change: ZoneChange,
impl ZoneScale {
/// A control over `range` that a drag across the plot's width moves by `drag`, an arrow key by `step`, and a
/// double click resets to `reset`.
pub fn new(range: RangeInclusive<f32>, drag: f32, step: f32, reset: f32) -> Self {
ZoneScale { min: *range.start(), max: *range.end(), drag, step, reset }
}
/// `value` held to the range.
fn hold(&self, value: f32) -> f32 {
value.max(self.min).min(self.max)
}
}
/// The values of the controls the tone zones edit, one per zone in the zones' order, each in its control's units.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ZoneValues(pub Vec<f32>);
impl ZoneValues {
/// These values with zone `at` set to what `to` makes of its value and scale, held to the zone's range; `None`
/// when the zone has no value or no scale.
fn with(&self, scales: &[ZoneScale], at: usize, to: impl FnOnce(f32, &ZoneScale) -> f32) -> Option<ZoneValues> {
let scale = scales.get(at)?;
let mut next = self.clone();
let value = next.0.get_mut(at)?;
*value = scale.hold(to(*value, scale));
Some(next)
}
}
/// The style of the tone zones: the hovered zone's band and the strip along the plot's top that belongs to the clipping
@@ -139,27 +155,32 @@ struct Held {
/// press locks the zone under it for the whole drag; the hovered or pressed zone shows its band; Page Up and Page Down
/// move the focused zone, the arrows step it and a double click resets it.
///
/// The value is the last edit; an app reads the edit events and maps them to its controls. AccessKit: a group named
/// [`ScopeWords::tone_zones`] holding one slider per zone, named by its label.
/// The value is the [`ZoneValues`] of the controls the zones edit, each moved as its [`ZoneScale`] says: a drag sets
/// the pressed zone's value to its value at the press plus the travel's share of the plot width times
/// [`ZoneScale::drag`], one gesture; each arrow press, Increment, Decrement, SetValue and double
/// click is a one-shot change. An app maps the values to its controls. AccessKit: a group named
/// [`ScopeWords::tone_zones`] holding one slider per zone, named by its label, with the zone's value and range.
#[derive(craft_ui::contract::Component, craft_ui::contract::Props)]
pub struct ToneZones<'a> {
#[common]
common: Common,
/// The last edit, bound so the host can show it as mixed or refuse it.
/// The values of the controls the zones edit.
#[prop]
value: Bind<'a, ScopeZoneEdit>,
value: Bind<'a, ZoneValues>,
zones: &'a [ToneZone],
values: &'a [Label],
scales: &'a [ZoneScale],
texts: &'a [Label],
}
impl<'a> ToneZones<'a> {
/// The zones over the plot, each zone's value text in the same order (the tooltip and the slider's value).
pub fn new(label: impl Into<Label>, zones: &'a [ToneZone], values: &'a [Label]) -> Self {
ToneZones { common: Common::new(), value: Bind::kept(), zones, values }.label(label).ltr_axis()
/// The zones over the plot, with each zone's scale and value text in the same order (the text is the tooltip's
/// and the slider's value).
pub fn new(label: impl Into<Label>, zones: &'a [ToneZone], scales: &'a [ZoneScale], texts: &'a [Label]) -> Self {
ToneZones { common: Common::new(), value: Bind::kept(), zones, scales, texts }.label(label).ltr_axis()
}
fn value_text(&self, zone: usize) -> &str {
self.values.get(zone).map_or("", Label::as_str)
self.texts.get(zone).map_or("", Label::as_str)
}
/// The rect of a zone below the strip.
@@ -177,7 +198,7 @@ impl Component for ToneZones<'_> {
const OVERLAYS: bool = false;
const KEYS: KeyUse = KeyUse::of(Input::Pointer).with_moves().with_value(true).with_activate(ActivateKeys::Neither);
type Style = ToneZonesStyle;
type Output = EditResponse<ScopeZoneEdit>;
type Output = EditResponse<ZoneValues>;
fn style(cx: &StyleCx<'_>, _: ToneZonesStyleKey) -> ToneZonesStyle {
ToneZonesStyle {
@@ -210,7 +231,7 @@ impl Component for ToneZones<'_> {
}
}
fn bind(&mut self) -> Option<BindMut<'_, ScopeZoneEdit>> {
fn bind(&mut self) -> Option<BindMut<'_, ZoneValues>> {
Some(self.value.reborrow())
}
@@ -219,12 +240,23 @@ impl Component for ToneZones<'_> {
if zones.is_empty() {
return;
}
let scales = self.scales;
let width = cx.rect.width().max(1.0);
let edit = |zone: usize, change: ZoneChange| ScopeZoneEdit { zone, key: zones[zone].key, change };
// A mixed value steps and drags from the zones' reset values, as a slider steps from its middle.
let resets = ZoneValues(scales.iter().map(|scale| scale.reset).collect());
// The value now with zone `at` set by `to`: arrows, Increment, Decrement, SetValue and a reset.
let shown = |cx: &Cx<'_, Self>, at: usize, to: &dyn Fn(f32, &ZoneScale) -> f32| cx.value().unwrap_or(&resets).with(scales, at, to);
for at in 0..zones.len() {
let press = cx.part(ZONE.at(at as u64)).press;
let fine = if press.mods.shift { FINE } else { 1.0 };
let share = |origin: egui::Pos2, pos: egui::Pos2| (pos.x - origin.x) / width * fine;
// The gesture's start with the zone moved by the travel since the press.
let dragged = |cx: &Cx<'_, Self>, origin: egui::Pos2, pos: egui::Pos2| {
let moved = |value: f32, scale: &ZoneScale| value + (pos.x - origin.x) / width * fine * scale.drag;
match cx.gesture_before()? {
Mixed::Same(start) => start.with(scales, at, moved),
Mixed::Mixed => resets.with(scales, at, moved),
}
};
match press.phase {
PressPhase::Down { .. } => {
cx.focus_own();
@@ -236,16 +268,27 @@ impl Component for ToneZones<'_> {
held.focused = Some(at);
held.pressed = Some(at);
cx.begin();
cx.propose(edit(at, ZoneChange::Drag(share(start.origin, pos))));
if let Some(values) = dragged(cx, start.origin, pos) {
cx.propose(values);
}
}
PressPhase::Drag { start, pos, .. } => {
if let Some(values) = dragged(cx, start.origin, pos) {
cx.propose(values);
}
}
PressPhase::Drag { start, pos, .. } => cx.propose(edit(at, ZoneChange::Drag(share(start.origin, pos)))),
PressPhase::Release { start, pos, click, .. } => {
cx.memory::<Held>().pressed = None;
if cx.gesture().is_some() {
cx.propose(edit(at, ZoneChange::Drag(share(start.origin, pos))));
if let Some(values) = dragged(cx, start.origin, pos) {
cx.propose(values);
}
cx.commit();
} else if click && start.clicks >= 2 {
cx.set(edit(at, ZoneChange::Reset));
} else if click
&& start.clicks >= 2
&& let Some(values) = shown(cx, at, &|_: f32, scale: &ZoneScale| scale.reset)
{
cx.set(values);
}
}
_ => {}
@@ -285,12 +328,16 @@ impl Component for ToneZones<'_> {
_ => continue,
};
cx.memory::<Held>().focused = Some(focused);
cx.set(edit(focused, ZoneChange::Step(steps)));
if let Some(values) = shown(cx, focused, &|value: f32, scale: &ZoneScale| value + steps as f32 * scale.step) {
cx.set(values);
}
}
for at in 0..zones.len() {
let key = ZONE.at(at as u64);
if let Some(value) = cx.intents().take_set_value_at(key).filter(|value| value.is_finite() && !running) {
cx.set(edit(at, ZoneChange::SetValue(value)));
if let Some(to) = cx.intents().take_set_value_at(key).filter(|value| value.is_finite() && !running)
&& let Some(values) = shown(cx, at, &|_: f32, _: &ZoneScale| to as f32)
{
cx.set(values);
}
}
while let Some(request) = cx.intents().take_access() {
@@ -300,8 +347,8 @@ impl Component for ToneZones<'_> {
AccessAction::Decrement => -1,
_ => continue,
};
if !running {
cx.set(edit(at, ZoneChange::Step(steps)));
if !running && let Some(values) = shown(cx, at, &|value: f32, scale: &ZoneScale| value + steps as f32 * scale.step) {
cx.set(values);
}
}
}
@@ -311,7 +358,13 @@ impl Component for ToneZones<'_> {
for (at, zone) in self.zones.iter().enumerate() {
let node = access.node(ZONE.at(at as u64), Role::SLIDER);
node.name = Name::Text(zone.label(&words).to_owned());
node.numeric = Some(Numeric::new(0.0, -UNBOUNDED..=UNBOUNDED).step(1.0).text(self.value_text(at).to_owned()));
let Some(scale) = self.scales.get(at) else { continue };
let range = f64::from(scale.min)..=f64::from(scale.max);
let numeric = match cx.value().and_then(|values| values.0.get(at)) {
Some(value) => Numeric::new(f64::from(*value), range),
None => Numeric::empty(range),
};
node.numeric = Some(numeric.step(f64::from(scale.step)).text(self.value_text(at).to_owned()));
}
}
@@ -328,7 +381,7 @@ impl Component for ToneZones<'_> {
ui.draw().fill(&band, cx.style.band);
}
fn finish(self, cx: Cx<'_, Self>) -> EditResponse<ScopeZoneEdit> {
fn finish(self, cx: Cx<'_, Self>) -> EditResponse<ZoneValues> {
cx.edit_response()
}
}
+17 -6
View File
@@ -2,23 +2,30 @@
//! buttons, the tone zones and the commands.
use craft_behavior::EditEvent;
use craft_imaging::ui::{ScopeZoneEdit, ToneZone, ToneZones};
use craft_ui::contract::Show as _;
use craft_imaging::ui::{ToneZone, ToneZones, ZoneScale, ZoneValues};
use craft_ui::contract::{Bind, Show as _};
use craft_ui::runtime::env::Label;
use craft_ui::testing::{Fixture, trial};
use egui::vec2;
use std::cell::RefCell;
use std::rc::Rc;
/// A fixture of the tone zones alone over a 200 by 100 plot at the origin, and the edits they report.
fn zone_rig() -> (Fixture, Rc<RefCell<Vec<EditEvent<ScopeZoneEdit>>>>) {
/// The zone values the rig starts from: each zone at its index, in -100 to 100.
fn start_values() -> ZoneValues {
ZoneValues(vec![0.0, 1.0, 2.0, 3.0, 4.0])
}
/// A fixture of the tone zones alone over a 200 by 100 plot at the origin, over values that start at
/// [`start_values`] and stay there, and the edits they report.
fn zone_rig() -> (Fixture, Rc<RefCell<Vec<EditEvent<ZoneValues>>>>) {
let edits = Rc::new(RefCell::new(Vec::new()));
let seen = Rc::clone(&edits);
let mut fixture = Fixture::new(move |ui| {
let zones = ToneZone::CAMERA_RAW;
let scales = zones.map(|_| ZoneScale::new(-100.0..=100.0, 200.0, 1.0, 0.0));
let texts: Vec<Label> = ["0", "1", "2", "3", "4"].map(Label::from).to_vec();
let rect = ui.max_rect();
let out = ToneZones::new("Tone zones", &zones, &texts).show_at(ui, rect);
let out = ToneZones::new("Tone zones", &zones, &scales, &texts).value(Bind::given(start_values())).show_at(ui, rect);
seen.borrow_mut().extend(out.events);
});
fixture.settle();
@@ -34,5 +41,9 @@ fn tone_zone_drag_is_one_gesture() {
let events = edits.borrow();
let begins = events.iter().filter(|event| matches!(event, EditEvent::Begin { .. } | EditEvent::Set { .. })).count();
assert_eq!(begins, 1, "one gesture per drag: {events:?}");
assert!(events.iter().filter_map(|event| event.value()).all(|edit| edit.key == "shadows"), "the press locks the zone: {events:?}");
let start = start_values();
let only_shadows = |values: &ZoneValues| (0..5).all(|at| at == 1 || values.0[at] == start.0[at]);
assert!(events.iter().filter_map(|event| event.value()).all(only_shadows), "the press locks the zone: {events:?}");
let last = events.iter().rev().find_map(|event| event.value()).expect("the drag reports values");
assert!(last.0[1] > start.0[1], "a drag to the right raises Shadows from its value at the press: {events:?}");
}
+11 -2
View File
@@ -31,8 +31,8 @@ impl CxCore<'_> {
}
}
/// Values and edits (chapter 10). `value`, `validity`, `gesture`, `adopt` and `edit_response` take `&self`, so `paint`
/// can call them.
/// Values and edits (chapter 10). `value`, `validity`, `gesture`, `gesture_before`, `adopt` and `edit_response` take
/// `&self`, so `paint` can call them.
pub trait Edit {
/// The component's value type.
type Value: Value;
@@ -47,6 +47,11 @@ pub trait Edit {
/// Where this pass's gesture stands.
fn gesture(&self) -> Option<GesturePhase>;
/// The value the running gesture began with, as its `Begin` reported it: the same in every pass of the gesture,
/// while [`value`](Self::value) follows each proposal. A control whose proposals count from the press (a drag
/// by its travel) reads its start here. `None` while no gesture runs, the pass that ends one included.
fn gesture_before(&self) -> Option<Mixed<Self::Value>>;
/// Maps each of the child's events onto a clone of this component's shown value and queues the resulting events, in
/// the child's order, for step 15. A composite whose own value is mixed or not yet shown maps the edits onto
/// `start` instead; its events then begin from a mixed value.
@@ -170,6 +175,10 @@ impl<C: Component> Edit for Cx<'_, C> {
Some(if began && !updated { GesturePhase::Begin } else { GesturePhase::Update })
}
fn gesture_before(&self) -> Option<Mixed<ValueOf<C>>> {
self.core.memory.recall::<Gesture<ValueOf<C>>>(gesture_key(self.core.id)).before
}
fn adopt<V: Value>(&self, child: &EditResponse<V>, start: &ValueOf<C>, map: impl Fn(&V, &mut ValueOf<C>)) {
let before = self.before();
for event in &child.events {
+8 -6
View File
@@ -136,7 +136,8 @@ impl<'a, T: Value> Bind<'a, T> {
Self::from_source(Source::MutMixed(v))
}
/// No caller value: the component keeps it in session memory under its id.
/// No caller value: the component keeps it in session memory under its id. Until something is stored, it reads
/// as the [`reset`](Self::reset) value when one is given, else as nothing.
pub fn kept() -> Self {
Self::from_source(Source::Kept)
}
@@ -173,7 +174,7 @@ impl<'a, T: Value> Bind<'a, T> {
self
}
/// The value a reset gesture restores.
/// The value a reset gesture restores, and the value a kept binding reads while nothing is stored.
pub fn reset(mut self, default: T) -> Self {
self.reset = Some(default);
self
@@ -299,13 +300,14 @@ impl<T: Value> BindMut<'_, T> {
self.check.map_or(Validity::Ok, |check| check(value))
}
/// The value of a kept binding: the saved tier when it has a `SaveKey`, else session memory under `id`. `held`
/// is the shown copy, reused when equal.
/// The value of a kept binding: the saved tier when it has a `SaveKey`, else session memory under `id`, else the
/// reset value while nothing is stored. `held` is the shown copy, reused when equal.
pub(crate) fn kept(&self, stage: &mut MemoryStage, id: Id, held: &Held<T>) -> Option<Arc<T>> {
match self.save {
let stored = match self.save {
Some(save) => (save.load)(stage, &save.key, held),
None => stage.session::<Option<T>>(id).as_ref().map(|value| reuse_arc(held, value)),
}
};
stored.or_else(|| self.reset.map(|value| reuse_arc(held, value)))
}
/// Stores the value of a kept binding where `kept` reads it.
@@ -0,0 +1,75 @@
//! The gesture record a component reads: the value its running gesture began with.
use craft_behavior::Mixed;
use craft_ui::contract::{Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, Props as _, Role, Show as _};
use craft_ui::style::StyleCx;
use craft_ui::testing::{Frames, trial};
use craft_ui_test_kit::contract::PlainStyle;
use egui::Vec2;
/// What a [`Dragger`] does in one pass.
#[derive(Clone, Copy)]
enum Step {
Idle,
Propose(u8),
Commit,
}
/// A leaf over a `u8` binding that proposes, commits or does nothing as `step` says, and reports its gesture's start.
#[derive(Component)]
struct Dragger<'a> {
#[common]
common: Common,
value: Bind<'a, u8>,
step: Step,
before: &'a mut Option<Mixed<u8>>,
}
impl Component for Dragger<'_> {
const ROLE: Role = Role::None;
type Style = PlainStyle;
type Output = EditResponse<u8>;
fn style(_: &StyleCx<'_>, _: DraggerStyleKey) -> PlainStyle {
PlainStyle::min(Vec2::splat(10.0))
}
fn bind(&mut self) -> Option<BindMut<'_, u8>> {
Some(self.value.reborrow())
}
fn update(&mut self, cx: &mut Cx<'_, Self>) {
match self.step {
Step::Idle => {}
Step::Propose(to) => cx.propose(to),
Step::Commit => cx.commit(),
}
*self.before = cx.gesture_before();
}
fn finish(self, cx: Cx<'_, Self>) -> EditResponse<u8> {
cx.edit_response()
}
}
/// The start a running gesture reads stays the value at its begin while the bound value follows each proposal, and
/// there is none before or after the gesture.
#[trial]
fn a_gesture_reads_the_value_it_began_with_until_it_ends() {
let mut frames = Frames::new();
let mut value = 4u8;
let mut show = |step: Step, value: &mut u8| {
let mut before = None;
frames.frame(vec![], |ui| {
Dragger { common: Common::new(), value: Bind::bound(&mut *value), step, before: &mut before }.id_salt("dragger").show(ui);
});
before
};
assert_eq!(show(Step::Idle, &mut value), None, "no gesture yet");
assert_eq!(show(Step::Propose(5), &mut value), Some(Mixed::Same(4)), "the begin pass reads the value at the press");
assert_eq!(show(Step::Propose(9), &mut value), Some(Mixed::Same(4)), "an update reads the same start");
assert_eq!(value, 9, "the binding follows the proposals");
assert_eq!(show(Step::Idle, &mut value), Some(Mixed::Same(4)), "a pass with no proposal still reads it");
assert_eq!(show(Step::Commit, &mut value), None, "the pass that commits has none");
assert_eq!(show(Step::Idle, &mut value), None, "none after the gesture");
}
@@ -1,6 +1,7 @@
//! The component contract and the show pipeline: the steps each shape runs, and the rules the steps keep.
mod fixes;
mod gesture;
mod hit_order;
mod pointer;
mod style;
@@ -1,6 +1,7 @@
//! The style step and what the pipeline keeps of a component's inputs: app replacements, style-affecting app
//! values, faces, the shown value and memory eviction.
use craft_behavior::Mixed;
use craft_ui::contract::{Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, Props as _, Remember as _, Role, Show as _};
use craft_ui::style::StyleCx;
use craft_ui::testing::{Frames, trial};
@@ -74,6 +75,55 @@ fn showing_and_measuring_clone_the_bound_value_only_when_it_changed() {
assert_eq!(CLONES.load(Ordering::SeqCst) - before, 2, "a changed value is cloned once");
}
/// A leaf over a `u8` binding that sets `to` in its update when one is given.
#[derive(Component)]
struct Setter<'a> {
#[common]
common: Common,
value: Bind<'a, u8>,
to: Option<u8>,
}
impl Component for Setter<'_> {
const ROLE: Role = Role::None;
type Style = PlainStyle;
type Output = EditResponse<u8>;
fn style(_: &StyleCx<'_>, _: SetterStyleKey) -> PlainStyle {
PlainStyle::min(Vec2::splat(10.0))
}
fn bind(&mut self) -> Option<BindMut<'_, u8>> {
Some(self.value.reborrow())
}
fn update(&mut self, cx: &mut Cx<'_, Self>) {
if let Some(to) = self.to {
cx.set(to);
}
}
fn finish(self, cx: Cx<'_, Self>) -> EditResponse<u8> {
cx.edit_response()
}
}
/// A kept binding with nothing stored shows its reset value; once an edit is stored it shows the edit.
#[trial]
fn a_kept_binding_reads_its_reset_value_until_an_edit_is_stored() {
let mut frames = Frames::new();
let mut show = |to: Option<u8>| {
let mut shown = None;
frames.frame(vec![], |ui| {
shown = Setter { common: Common::new(), value: Bind::kept().reset(3), to }.id_salt("setter").show(ui).shown;
});
shown
};
assert_eq!(show(None), Some(Mixed::Same(Arc::new(3))), "nothing stored: the reset value");
show(Some(7));
assert_eq!(show(None), Some(Mixed::Same(Arc::new(7))), "the stored edit");
}
static DROPPED: AtomicU32 = AtomicU32::new(0);
static CALLED_CONTEXT: AtomicU32 = AtomicU32::new(0);
static CTX: Mutex<Option<Context>> = Mutex::new(None);
+2 -1
View File
@@ -1974,11 +1974,12 @@ The component traits, context types, `PaintUi`, `Looks`, the pipeline and its st
- `craft_ui::contract::EDIT_MENU`: `pub const EDIT_MENU: &str`. The popup name of a text part's edit menu: step 8b registers it for every text part, and the text control opens
- `craft_ui::contract::EdgePress`: `pub struct EdgePress<'a, K>`. The line between two adjacent rows as a target of its own while `mods` are held (Photoshop's Alt-click between two
- `pub fn new(mods: Mods, test: impl Fn(&K, &K) -> Option<Cursor> + 'a) -> Self`. The edge press while exactly `mods` are held, on the lines `test` takes.
- `craft_ui::contract::Edit`: `pub trait Edit`. Values and edits (chapter 10). `value`, `validity`, `gesture`, `adopt` and `edit_response` take `&self`, so `paint`
- `craft_ui::contract::Edit`: `pub trait Edit`. Values and edits (chapter 10). `value`, `validity`, `gesture`, `gesture_before`, `adopt` and `edit_response` take
- `type Value`. The component's value type.
- `fn value(&self) -> Option<&Self::Value>`. The shown value: the running gesture's proposal, else the binding's. `None` for a mixed binding, a kept
- `fn validity(&self) -> Validity<Self::Value>`. What the binding's check says about the shown value.
- `fn gesture(&self) -> Option<GesturePhase>`. Where this pass's gesture stands.
- `fn gesture_before(&self) -> Option<Mixed<Self::Value>>`. The value the running gesture began with, as its `Begin` reported it: the same in every pass of the gesture,
- `fn adopt<V: Value>(&self, child: &EditResponse<V>, start: &Self::Value, map: impl Fn(&V, &mut Self::Value))`. Maps each of the child's events onto a clone of this component's shown value and queues the resulting events, in
- `fn edit_response(&self) -> EditResponse<Self::Value>`. The `EditResponse` a value component returns from `finish`.
- `fn propose(&mut self, v: Self::Value)`. Sets the running gesture's value, beginning a gesture if none runs and the press that carries it has had no