A full-window workspace reports the canvas it shows its image on (WorkspacePass::canvas); the dialog host names the canvas of the latest open dialog that has one (StackDialog::canvas, DialogHost::canvas), where an app's tool input in document points goes

This commit is contained in:
aiongg
2026-11-17 07:19:41 +00:00
parent fe8fdf6eea
commit b0810ed1f4
9 changed files with 54 additions and 11 deletions
+1 -1
View File
@@ -432,7 +432,7 @@ impl ContentAwareFillWorkspace {
(shown.output.result(|| work.command()), None)
};
let events = std::mem::take(&mut work.events);
WorkspacePass::new(shown.output.response, events).held(held).result(result)
WorkspacePass::new(shown.output.response, events).held(held).result(result).canvas(work.canvas_id)
}
/// The app's colour picker answered a [`FillEvent::PickColor`] request. A key this workspace
+6 -4
View File
@@ -412,11 +412,13 @@ impl FullWindowWorkspace for FilterGalleryWorkspace {
if let Some(checker) = checkerboard {
canvas = canvas.checkerboard(checker);
}
canvas.show(ui);
(view, status)
let canvas = canvas.show(ui).response.id;
(view, status, canvas)
});
// Once per pass, after the real run: the view it settled and the render status are stored.
dialog.settle(|_, (view, status)| {
let mut canvas = None;
dialog.settle(|_, (view, status, shown_canvas)| {
canvas = Some(*shown_canvas);
let view = std::mem::take(view);
let mut workspace = shared.borrow_mut();
workspace.status = status.clone();
@@ -433,7 +435,7 @@ impl FullWindowWorkspace for FilterGalleryWorkspace {
events.push(FilterGalleryEvent::Select(workspace.selected));
}
let result = dialog.output.result(|| workspace.session.clone());
WorkspacePass::new(dialog.output.response, events).result(result)
WorkspacePass::new(dialog.output.response, events).result(result).canvas(canvas)
}
fn json_fields(&self, _source: &Self::Source) -> Option<Value> {
+1 -1
View File
@@ -604,7 +604,7 @@ impl LiquifyWorkspace {
}
let result = shown.output.result(|| this.done());
let events = std::mem::take(&mut this.edit.events);
WorkspacePass::new(shown.output.response, events).result(result)
WorkspacePass::new(shown.output.response, events).result(result).canvas(this.view.canvas_id)
}
/// What OK applies.
+1 -1
View File
@@ -814,7 +814,7 @@ impl FullWindowWorkspace for RawDevelopWorkspace {
(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).held(held).result(result)
WorkspacePass::new(output.response, events).held(held).result(result).canvas(self.canvas)
}
fn json_fields(&self, source: &Self::Source) -> Option<serde_json::Value> {
+1 -1
View File
@@ -660,7 +660,7 @@ impl SelectMaskWorkspace {
this.done(&ctx)
});
let events = std::mem::take(&mut this.events);
WorkspacePass::new(shown.output.response, events).result(result)
WorkspacePass::new(shown.output.response, events).result(result).canvas(this.canvas_id)
}
/// The start of a pass: the first pass reads the stored settings, a change the app made to the settings since the
+3 -1
View File
@@ -371,6 +371,7 @@ impl FullWindowWorkspace for VanishingPointWorkspace {
let slots = slots();
let status: RefCell<Option<Pending<PreviewDone, String>>> = RefCell::new(None);
let events = RefCell::new(Vec::<VanishingPointEvent>::new());
let shown_canvas = std::cell::Cell::new(None);
let this = RefCell::new(&mut *self);
let shown = FullWindowDialog::new(title)
@@ -495,6 +496,7 @@ impl FullWindowWorkspace for VanishingPointWorkspace {
}
}
state.canvas = shown.as_ref().map(|canvas| canvas.response.id);
shown_canvas.set(state.canvas);
work.zoom_percent = state.view.zoom_percent();
out.extend(work.editor.take_events());
events.borrow_mut().extend(out);
@@ -511,7 +513,7 @@ impl FullWindowWorkspace for VanishingPointWorkspace {
}
events.extend(this.editor.take_status().map(VanishingPointEvent::Refused));
let result = shown.output.result(|| this.command(source.paste().is_some()));
WorkspacePass::new(shown.output.response.clone(), events).result(result)
WorkspacePass::new(shown.output.response.clone(), events).result(result).canvas(shown_canvas.get())
}
fn json_fields(&self, _source: &Self::Source) -> Option<Value> {
+3 -1
View File
@@ -309,6 +309,7 @@ impl FullWindowWorkspace for WideAngleWorkspace {
let preview_on = Cell::new(self.preview_on);
let actions = RefCell::new(Vec::<Action>::new());
let zoom_percent = Cell::new(self.zoom_percent);
let shown_canvas = Cell::new(None);
let add = Cell::new(self.add_requested);
let common = env.words::<CommonWords>();
let ctx = ui.ctx().clone();
@@ -406,6 +407,7 @@ impl FullWindowWorkspace for WideAngleWorkspace {
let out = canvas.show(ui);
zoom_percent.set(view.zoom_percent());
body.canvas = Some(out.response.id);
shown_canvas.set(body.canvas);
let mut queued = actions.borrow_mut();
queued.extend(body.constraint.take_edits().into_iter().map(Action::Constraint));
@@ -504,7 +506,7 @@ impl FullWindowWorkspace for WideAngleWorkspace {
}
}
let result = shown.output.result(|| self.session.clone());
WorkspacePass::new(shown.output.response.clone(), events).result(result)
WorkspacePass::new(shown.output.response.clone(), events).result(result).canvas(shown_canvas.get())
}
fn json_fields(&self, _source: &Self::Source) -> Option<Value> {
@@ -109,12 +109,15 @@ pub struct WorkspacePass<E, R> {
/// The result OK would give, reported in the pass the Accept button is picked under `cx.hold_ok`; `result`
/// stays `None` then.
pub held: Option<R>,
/// The canvas the workspace showed its image on this pass (the id of its `FullWindowCanvas`'s response, which
/// keys the canvas's tool host): where the app's tool input in document points goes while the workspace is open.
pub canvas: Option<egui::Id>,
}
impl<E, R> WorkspacePass<E, R> {
/// A pass with `events` that leaves the workspace open.
pub fn new(response: Response, events: Vec<E>) -> Self {
WorkspacePass { response, events, result: None, held: None }
WorkspacePass { response, events, result: None, held: None, canvas: None }
}
/// The result a held OK gives this pass.
@@ -130,6 +133,13 @@ impl<E, R> WorkspacePass<E, R> {
self.result = result;
self
}
/// The canvas the workspace showed its image on this pass; `None` for a pass that showed none (a measuring run).
#[must_use]
pub fn canvas(mut self, canvas: Option<egui::Id>) -> Self {
self.canvas = canvas;
self
}
}
/// A [`FullWindowWorkspace`] the [`DialogHost`](crate::dialog::DialogHost) owns, with the app's source. It keeps the
@@ -172,6 +182,8 @@ pub struct HostedWorkspace<W: FullWindowWorkspace> {
/// The held OK's answer until the app answers it (the workspace disables its OK meanwhile), and why the app
/// refused the last one, until OK files again.
held: HeldAnswer<W::Result>,
/// The canvas the workspace shows its image on, as its latest pass that showed one reported it.
canvas: Option<egui::Id>,
#[cfg(feature = "testing")]
facts: crate::testing::StoryOutput,
}
@@ -188,6 +200,7 @@ impl<W: FullWindowWorkspace> HostedWorkspace<W> {
revision: 0,
hold_ok: false,
held: HeldAnswer::new(),
canvas: None,
#[cfg(feature = "testing")]
facts: crate::testing::StoryOutput::default(),
}
@@ -273,6 +286,9 @@ impl<W: FullWindowWorkspace> StackDialog for HostedWorkspace<W> {
ok_waits: self.held.is_waiting(),
};
let pass = self.workspace.show(ui, cx);
if pass.canvas.is_some() {
self.canvas = pass.canvas;
}
#[cfg(feature = "testing")]
{
self.facts = crate::contract::Outcome::story_facts(&pass.response);
@@ -293,6 +309,10 @@ impl<W: FullWindowWorkspace> StackDialog for HostedWorkspace<W> {
Some(W::KEY)
}
fn canvas(&self) -> Option<egui::Id> {
self.canvas
}
/// OK as the Accept button: a held workspace files the result and answers none, and answers the held result once
/// the app accepted it.
fn confirm(&mut self, ctx: &Context) -> Option<W::Result> {
+17
View File
@@ -82,6 +82,12 @@ pub trait StackDialog: Any + Send {
None
}
/// The canvas the dialog shows the document on, which takes the app's tool input in document points while the
/// dialog is open: a full-window workspace's. `None` (the default) for a dialog without one.
fn canvas(&self) -> Option<egui::Id> {
None
}
/// The dialog's values as a JSON object, keyed as [`set_json_field`](StackDialog::set_json_field) takes them:
/// what automation lists for the open dialog (`ui.inspect`). `None` (the default) for a dialog without values.
fn json_fields(&self) -> Option<Value> {
@@ -183,6 +189,7 @@ trait AnyStackDialog: Send {
fn instance(&self) -> Option<DialogId>;
fn confirm_erased(&mut self, ctx: &Context) -> Option<Box<dyn Any + Send>>;
fn held_state(&self) -> Option<HeldOk>;
fn canvas(&self) -> Option<egui::Id>;
fn json_fields(&self) -> Option<Value>;
fn set_json_field(&mut self, ctx: &Context, field: &str, value: Value) -> Result<(), String>;
fn show_erased(&mut self, ui: &mut Ui, stack: &DialogStack) -> Option<Box<dyn Any + Send>>;
@@ -220,6 +227,10 @@ impl<D: StackDialog> AnyStackDialog for D {
StackDialog::held_state(self)
}
fn canvas(&self) -> Option<egui::Id> {
StackDialog::canvas(self)
}
fn json_fields(&self) -> Option<Value> {
StackDialog::json_fields(self)
}
@@ -471,6 +482,12 @@ impl DialogHost {
self.open.iter().find(|dialog| dialog.id() == id)?.held_state()
}
/// The canvas of the most recently opened dialog that shows the document on one ([`StackDialog::canvas`]): where
/// the app's tool input in document points goes while it is open. `None` when no open dialog has one.
pub fn canvas(&self) -> Option<egui::Id> {
self.open.iter().rev().find_map(|dialog| dialog.canvas())
}
/// [`confirm`](DialogHost::confirm) for the open dialog `id` names, whatever its type.
pub fn confirm_by_id(&mut self, ctx: &Context, id: DialogId) -> bool {
match self.position_by_id(id) {