Merge branch 'red/t8d' into fw/mac1

This commit is contained in:
aiongg
2026-11-17 00:21:02 +00:00
11 changed files with 60 additions and 22 deletions
+1 -1
View File
@@ -916,7 +916,7 @@ impl FullWindowWorkspace for ContentAwareFillWorkspace {
/// The settings, and the bar's `tool`, `brushSize`, `brushMode` (`"add"`, `"subtract"`), `lassoMode` (`"new"`,
/// `"add"`, `"subtract"`, `"intersect"`) and `expandBy`.
fn json_fields(&self) -> Option<serde_json::Value> {
fn json_fields(&self, _source: &Self::Source) -> Option<serde_json::Value> {
let mut fields = serde_fields(&self.settings)?;
let bar = fields.as_object_mut()?;
let brush_mode = if self.options.brush_add { "add" } else { "subtract" };
+1 -1
View File
@@ -436,7 +436,7 @@ impl FullWindowWorkspace for FilterGalleryWorkspace {
WorkspacePass::new(dialog.output.response, events).result(result)
}
fn json_fields(&self) -> Option<Value> {
fn json_fields(&self, _source: &Self::Source) -> Option<Value> {
let zoom = if self.view.is_fit() { json!("fit") } else { json!(self.view.device_zoom()) };
let effects = serde_json::to_value(&self.session.effects).unwrap_or_default();
Some(json!({ "effects": effects, "select": self.clamped_selection(), "zoom": zoom }))
+1 -1
View File
@@ -737,7 +737,7 @@ impl FullWindowWorkspace for LiquifyWorkspace {
}
/// The settings (the brush keys at the top level) and `preview`.
fn json_fields(&self) -> Option<serde_json::Value> {
fn json_fields(&self, _source: &Self::Source) -> Option<serde_json::Value> {
let mut fields = serde_fields(&self.edit.settings)?;
fields.as_object_mut()?.insert("preview".to_owned(), serde_json::Value::Bool(self.preview));
Some(fields)
+17 -8
View File
@@ -519,7 +519,7 @@ impl FullWindowWorkspace for RawDevelopWorkspace {
const KEY: &'static str = "filter.cameraRaw";
fn show(&mut self, ui: &mut Ui, cx: WorkspaceCx<'_, Self::Source>) -> WorkspacePass<Self::Event, Self::Result> {
let WorkspaceCx { source, revision, open, .. } = cx;
let WorkspaceCx { source, revision, open, hold_ok, ok_waits, .. } = cx;
let env = Env::of(ui);
let words = env.words::<RawDevelopWords>();
let common = env.words::<CommonWords>();
@@ -529,9 +529,11 @@ impl FullWindowWorkspace for RawDevelopWorkspace {
let name = if self.target == RawTarget::OpenRaw { words.name.clone() } else { words.name_filter.clone() };
let title: Label = FullWindowTitle::new(name).subject(self.subject.clone()).zoom(self.view.zoom_percent()).label(&env);
let mut plan = vec![(Footer::Finish(self.target.accept()), FooterButton::new(self.target_label(&words, &common), DialogRole::Accept))];
// A held OK files its answer for the app and keeps the workspace open until the app answers; the buttons that finish wait meanwhile.
let finishing = |button: FooterButton| button.stays_open(hold_ok).enabled(!ok_waits);
let mut plan = vec![(Footer::Finish(self.target.accept()), finishing(FooterButton::new(self.target_label(&words, &common), DialogRole::Accept)))];
if self.target == RawTarget::OpenRaw {
plan.push((Footer::Finish(RawFinish::Done), FooterButton::new(words.done.clone(), DialogRole::Other)));
plan.push((Footer::Finish(RawFinish::Done), finishing(FooterButton::new(words.done.clone(), DialogRole::Other))));
}
plan.push((Footer::Save, FooterButton::new(words.save_settings.clone(), DialogRole::Other).stays_open(true)));
plan.push((Footer::Load, FooterButton::new(words.load_settings.clone(), DialogRole::Other).stays_open(true)));
@@ -804,14 +806,17 @@ impl FullWindowWorkspace for RawDevelopWorkspace {
Some(Footer::Finish(finish)) => finish,
_ => self.target.accept(),
};
let result = match self.requested.take() {
Some(finish) => Some(DialogResult::Ok(self.result(finish))),
None => output.result(|| self.result(finish)),
let (result, held) = match (self.requested.take(), hold_ok) {
(Some(finish), true) => (None, Some(self.result(finish))),
(Some(finish), false) => (Some(DialogResult::Ok(self.result(finish))), None),
// Esc and Cancel close the workspace either way.
(None, true) => (output.closed.map(|_| DialogResult::Cancel), matches!(footer, Some(Footer::Finish(_))).then(|| self.result(finish))),
(None, false) => (output.result(|| self.result(finish)), None),
};
WorkspacePass::new(output.response, events).result(result)
WorkspacePass::new(output.response, events).held(held).result(result)
}
fn json_fields(&self) -> Option<serde_json::Value> {
fn json_fields(&self, source: &Self::Source) -> Option<serde_json::Value> {
let mut fields = serde_fields(&self.settings)?;
if let serde_json::Value::Object(map) = &mut fields {
map.insert("before".to_owned(), serde_json::Value::Bool(self.before));
@@ -819,7 +824,11 @@ impl FullWindowWorkspace for RawDevelopWorkspace {
let view = if self.view.is_fit() { serde_json::Value::from("fit") } else { serde_json::Value::from(self.view.zoom_percent()) };
map.insert("view".to_owned(), view);
let scope = self.scope.as_ref().map(|state| state.settings.clone()).unwrap_or_default();
let lab = scope.lab_readouts;
map.insert("scope".to_owned(), serde_json::to_value(scope).unwrap_or(serde_json::Value::Null));
let read = |at: [f64; 2]| preview::readout_json(source, at, self.before, lab);
map.insert("pointerReadout".to_owned(), self.hover.map_or(serde_json::Value::Null, read));
map.insert("samplerReadouts".to_owned(), self.samplers.points().iter().copied().map(read).collect());
}
Some(fields)
}
+14 -3
View File
@@ -12,8 +12,8 @@ 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,
/// The readouts of `samplers` over the picture `before` or after, from `cache` while `revision`, the picture shown 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,
@@ -27,7 +27,7 @@ pub(super) fn sampler_readouts(
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);
let readouts = SamplerReadouts::new(samplers, read).revision(revision).document(before).get(cache);
if !lab {
return readouts;
}
@@ -44,6 +44,17 @@ pub(super) fn sampler_readouts(
Arc::new(with_lab)
}
/// The readout under `at` as the automation surface lists it: its `position`, `space` (`rgb` in 0..=255, or `lab`
/// when `lab` asks for the Lab value) and `values`; `null` where the source reads no pixel.
pub(super) fn readout_json(source: &dyn RawDevelopSource, at: [f64; 2], before: bool, lab: bool) -> serde_json::Value {
let (space, values) = match source.sample(at, before, lab) {
Some(ScopeReadout::Rgb(rgb)) => ("rgb", rgb.map(|v| v * 255.0)),
Some(ScopeReadout::Lab(lab)) => ("lab", lab),
_ => return serde_json::Value::Null,
};
serde_json::json!({ "position": at, "space": space, "values": values })
}
/// 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() }
+1 -1
View File
@@ -915,7 +915,7 @@ impl FullWindowWorkspace for SelectMaskWorkspace {
/// The settings, and the bar's `tool`, `mode` (`"add"`, `"subtract"`), `size` (of the current tool), `hardness`,
/// `sampleAllLayers`, and `hideView`.
fn json_fields(&self) -> Option<serde_json::Value> {
fn json_fields(&self, _source: &Self::Source) -> Option<serde_json::Value> {
let mut fields = serde_fields(&self.settings)?;
let bar = fields.as_object_mut()?;
let mode = if self.options.add { "add" } else { "subtract" };
+1 -1
View File
@@ -514,7 +514,7 @@ impl FullWindowWorkspace for VanishingPointWorkspace {
WorkspacePass::new(shown.output.response.clone(), events).result(result)
}
fn json_fields(&self) -> Option<Value> {
fn json_fields(&self, _source: &Self::Source) -> Option<Value> {
let mut fields = serde_fields(&self.settings)?;
let map = fields.as_object_mut()?;
let selected = self.editor.selected().map_or(Value::Null, Value::from);
+1 -1
View File
@@ -507,7 +507,7 @@ impl FullWindowWorkspace for WideAngleWorkspace {
WorkspacePass::new(shown.output.response.clone(), events).result(result)
}
fn json_fields(&self) -> Option<Value> {
fn json_fields(&self, _source: &Self::Source) -> Option<Value> {
let mut fields = serde_fields(&self.session)?;
fields.as_object_mut()?.insert("preview".to_owned(), Value::Bool(self.preview_on));
Some(fields)
+17 -1
View File
@@ -218,6 +218,22 @@ fn raw_develop_switches_raws_and_finishes_with_each_footer_button() {
assert_eq!(finish(&host), Some(RawFinish::Ok));
}
#[trial]
fn a_held_ok_files_its_answer_and_keeps_the_workspace_open_until_the_app_answers() {
let host = Rc::new(RefCell::new(DialogHost::new()));
let mut fixture = fixture(&host, &Rc::new(Cell::new(false)));
host.borrow_mut().open(HostedWorkspace::new(RawDevelopWorkspace::new(open(RawTarget::OpenRaw)), Source::new()).held_ok());
fixture.idle(10);
let done = fixture.by_label("Done").expect("Done");
fixture.click(&done).idle(4);
let held = host.borrow_mut().get_mut::<Hosted>().expect("Done keeps the workspace open").take_ok();
assert_eq!(held.map(|result| result.finish), Some(RawFinish::Done), "Done files its answer for the app");
host.borrow_mut().get_mut::<Hosted>().expect("open").answer_ok(Ok(()));
fixture.idle(4);
assert_eq!(finish(&host), Some(RawFinish::Done), "the app's answer closes the workspace with the filed result");
}
/// The key `key` going down or up, as a keyboard reports it.
fn key_event(key: Key, pressed: bool) -> Event {
Event::Key { key, physical_key: Some(key), pressed, repeat: false, modifiers: Modifiers::NONE }
@@ -284,7 +300,7 @@ fn readout_shown(fixture: &Fixture) -> bool {
}
fn scope_json(host: &Rc<RefCell<DialogHost>>) -> serde_json::Value {
let fields = host.borrow_mut().get_mut::<Hosted>().and_then(|hosted| hosted.workspace().json_fields());
let fields = host.borrow_mut().get_mut::<Hosted>().and_then(|hosted| hosted.workspace().json_fields(&**hosted.source()));
fields.and_then(|fields| fields.get("scope").cloned()).unwrap_or_default()
}
@@ -39,8 +39,10 @@ pub trait FullWindowWorkspace: Send + 'static {
/// it binds to `open` ([`opened`](crate::dialog::FullWindowDialog::opened)).
fn show(&mut self, ui: &mut Ui, cx: WorkspaceCx<'_, Self::Source>) -> WorkspacePass<Self::Event, Self::Result>;
/// The workspace's fields as JSON for the automation surface; `None` when it has none.
fn json_fields(&self) -> Option<serde_json::Value> {
/// The workspace's fields as JSON for the automation surface; `None` when it has none. `source` is what the app
/// shows the workspace, for the fields that read it (the readout under the pointer).
fn json_fields(&self, source: &Self::Source) -> Option<serde_json::Value> {
let _ = source;
None
}
@@ -321,7 +323,7 @@ impl<W: FullWindowWorkspace> StackDialog for HostedWorkspace<W> {
}
fn json_fields(&self) -> Option<serde_json::Value> {
self.workspace.json_fields()
self.workspace.json_fields(&*self.source)
}
fn set_json_field(&mut self, ctx: &Context, field: &str, value: serde_json::Value) -> Result<(), String> {
@@ -153,7 +153,7 @@ impl FullWindowWorkspace for BrushWorkspace {
WorkspacePass::new(shown.output.response, events).result(result).held(held)
}
fn json_fields(&self) -> Option<serde_json::Value> {
fn json_fields(&self, _source: &Self::Source) -> Option<serde_json::Value> {
Some(serde_json::json!({ "brush": self.brush }))
}