Full-window workspaces take Undo, Redo and the mask view keys themselves

Commands::take_step declares Undo and Redo on the instance around a body and takes the next one fired at it. Liquify, Filter Gallery, Select and Mask, Content-Aware Fill, Vanishing Point and Adaptive Wide Angle step their history from it in their own pass, cancelling an open stroke first; their public step methods go, and so does the shortcuts dialog's hand-written copy. Select and Mask runs MaskViewKeys in its body, and mask_view goes.
This commit is contained in:
aiongg
2026-11-12 14:32:40 +00:00
parent c32baa96ba
commit 446fcf0aa4
12 changed files with 149 additions and 207 deletions
+8 -31
View File
@@ -216,7 +216,7 @@ type Ants = (SamplingPlane, Arc<Vec<(Point, Point)>>);
///
/// Keys ([`FillCommands`], on the body's scope, none while a text field edits): B, L, H, Z pick the tools; `[` and
/// `]` the brush size ([`FillToolOptions::step_size`]); ⌘H hides or shows the tint. The zoom chords are the
/// dialog's view commands. The app routes ⌘Z and ⇧⌘Z (`EditCommands::Undo`, `Redo`) to [`step`](Self::step); Enter
/// dialog's view commands. ⌘Z and ⇧⌘Z step the history (a field being edited steps its own text first); Enter
/// is OK and Esc Cancel (Esc during a stroke or lasso cancels that only). A tool switch or an undo during a stroke
/// cancels it first (`CancelReason::Removed`, `CancelReason::UndoDuringGesture`).
#[derive(Pattern)]
@@ -257,10 +257,6 @@ pub struct ContentAwareFillWorkspace {
color_owed: bool,
/// The outline of the fill area's covered cells, kept for as long as the plane is the same.
ants: Option<Ants>,
/// Steps the app asked for while a stroke was open; the next `show` cancels the stroke, then steps.
requested: Vec<Step>,
/// A stroke, a lasso or a resize was open at the end of the last pass.
busy: bool,
/// This pass's events and colour request.
events: Vec<FillEvent>,
pick_color: Option<ColorRequest>,
@@ -306,8 +302,6 @@ impl ContentAwareFillWorkspace {
settings_gesture: false,
color_owed: false,
ants: None,
requested: Vec::new(),
busy: false,
events: Vec::new(),
pick_color: None,
}
@@ -354,7 +348,6 @@ impl ContentAwareFillWorkspace {
let title =
FullWindowTitle::new(env.words::<FillWords>().name.clone()).subject(self.subject.clone()).zoom(self.view.zoom_percent()).label(&env);
let settings_before = self.settings.clone();
let asked_steps = std::mem::take(&mut self.requested);
self.pick_color = None;
let slots = FillTool::slots();
let mut open = self.open;
@@ -379,7 +372,7 @@ impl ContentAwareFillWorkspace {
})
.show(ui, |ui, cx| {
let mut guard = this.borrow_mut();
guard.show_body(ui, cx, &env, &slots, source, &asked_steps);
guard.show_body(ui, cx, &env, &slots, source);
});
let work = this.into_inner();
@@ -467,20 +460,6 @@ impl ContentAwareFillWorkspace {
self.synced();
self.error = Some(FillIssue::Message(message));
}
/// Undo or redo from the app's Edit menu; returns whether it stepped, or with a stroke open whether it will:
/// the next [`show`](Self::show) cancels the stroke (`UndoDuringGesture`) first, then steps.
pub fn step(&mut self, step: Step) -> bool {
// pc: crates/ui-egui/src/dialogs/caf_ui/controls.rs:151-159 (⌘Z, ⇧⌘Z).
if self.busy {
self.requested.push(step);
return match step {
Step::Undo => self.history.can_undo(),
_ => self.history.can_redo(),
};
}
self.step_now(step)
}
}
impl ContentAwareFillWorkspace {
@@ -535,16 +514,17 @@ impl ContentAwareFillWorkspace {
}
/// The body: the steps and keys, the options bar, the tool strip and the canvas; then the preview job.
fn show_body(&mut self, ui: &mut Ui, cx: &mut BodyCx<'_>, env: &Env, slots: &[ToolSlot<FillTool>], source: &dyn FillSource, asked: &[Step]) {
fn show_body(&mut self, ui: &mut Ui, cx: &mut BodyCx<'_>, env: &Env, slots: &[ToolSlot<FillTool>], source: &dyn FillSource) {
let ctx = ui.ctx().clone();
let words = env.words::<FillWords>();
while let Some((command, _)) = cx.take_command::<ViewCommands>() {
self.view.apply(command);
}
// An open stroke is cancelled first; the step follows.
for step in asked {
while let Some(step) = cx.take_step(self.history.can_undo(), self.history.can_redo()) {
// pc: crates/ui-egui/src/dialogs/caf_ui/controls.rs:151-159 (⌘Z, ⇧⌘Z).
self.cancel_gesture(&ctx, CancelReason::UndoDuringGesture);
self.step_now(*step);
self.step_now(step);
}
{
while let Some((command, fired)) = cx.take_command::<FillCommands>() {
@@ -593,7 +573,6 @@ impl ContentAwareFillWorkspace {
});
}
self.absorb_canvas_events();
self.busy = self.canvas.busy();
self.ask_for_preview(cx, source);
}
@@ -732,12 +711,10 @@ impl ContentAwareFillWorkspace {
self.error = None;
}
fn step_now(&mut self, step: Step) -> bool {
let stepped = self.history.step(&mut self.session, step);
if stepped {
fn step_now(&mut self, step: Step) {
if self.history.step(&mut self.session, step) {
self.synced();
}
stepped
}
/// Switches to `tool`, cancelling the old tool's gesture first.
+11 -10
View File
@@ -139,8 +139,8 @@ struct Pass<'w> {
/// The Filter Gallery workspace.
///
/// Keys: the zoom commands zoom the preview, never the canvas behind; Undo and Redo reach the stack's history
/// through [`step`](Self::step); Enter OK, Esc Cancel.
/// Keys: the zoom commands zoom the preview, never the canvas behind; ⌘Z and ⇧⌘Z step the stack's history (a field
/// being edited steps its own text first); Enter OK, Esc Cancel.
#[derive(Pattern)]
pub struct FilterGalleryWorkspace {
session: FilterGallerySession,
@@ -264,6 +264,9 @@ impl FilterGalleryWorkspace {
.show(ui, |ui, cx| {
let mut pass = pass.borrow_mut();
let workspace = &mut *pass.workspace;
while let Some(step) = cx.take_step(workspace.history.can_undo(), workspace.history.can_redo()) {
workspace.step(step);
}
let mut view = workspace.view;
while let Some((command, _)) = cx.take_command::<ViewCommands>() {
view.apply(command);
@@ -339,15 +342,13 @@ impl FilterGalleryWorkspace {
self.queued.push(FilterGalleryEvent::Stack(EffectChange::with_fields(index, fields)));
}
/// Undo or redo from the app's Edit menu; returns whether it stepped. The next pass clamps the
/// selection and reports it as a `Select` event when it moved.
pub fn step(&mut self, step: Step) -> bool {
if !self.history.step(&mut self.session, step) {
return false;
/// Undoes or redoes, keeping the selection on a layer that remains. The pass reports the selection as a `Select`
/// event when it moved.
fn step(&mut self, step: Step) {
if self.history.step(&mut self.session, step) {
self.selected = self.selected.min(self.session.effects.len().saturating_sub(1));
self.revision += 1;
}
self.selected = self.selected.min(self.session.effects.len().saturating_sub(1));
self.revision += 1;
true
}
/// Records the session as one undo step named `name`, after `before`.
+21 -46
View File
@@ -240,8 +240,8 @@ struct LiquifyView {
///
/// Keys ([`LiquifyCommands`], on the scope of the dialog's body): W R E C S B O F D L pick the Liquify tools and H, Z the Hand
/// and Zoom tools; `[` and `]` scale the brush, ⌘H shows or hides the mask, ⌘I inverts the mask, ⌘D clears it. The
/// dialog applies the zoom commands to its view. The app forwards ⌘Z and ⇧⌘Z (`EditCommands::Undo`, `Redo`) to
/// [`step`](Self::step); Enter is OK and Esc Cancel (Esc during a stroke cancels the stroke only). A tool switch or
/// dialog applies the zoom commands to its view. ⌘Z and ⇧⌘Z step the workspace's history (a field being edited
/// steps its own text first); Enter is OK and Esc Cancel (Esc during a stroke cancels the stroke only). A tool switch or
/// an undo during a stroke cancels it first (`CancelReason::Removed`, `CancelReason::UndoDuringGesture`); the app's
/// field is rebuilt by the [`LiquifyEvent::Replay`] that follows.
///
@@ -257,12 +257,6 @@ pub struct LiquifyWorkspace {
checkerboard: Checker,
/// The backdrop the app was last asked for, while Show Backdrop is on.
asked: Option<Option<u64>>,
/// Events that happened between passes ([`step`](Self::step)), reported by the next `show`.
queued: Vec<LiquifyEvent>,
/// A step the app asked for while a stroke was open; the next `show` cancels the stroke, then steps.
requested: Vec<Step>,
/// A stroke, a lasso or a resize was open at the end of the last pass.
busy: bool,
/// The zoom on screen at the end of the last pass, for the title.
zoom_percent: f64,
/// The timing of the latest stroke, as of the last pass.
@@ -300,9 +294,6 @@ impl LiquifyWorkspace {
navigation: open.navigation,
checkerboard: open.checkerboard,
asked: None,
queued: Vec::new(),
requested: Vec::new(),
busy: false,
zoom_percent: 100.0,
timing: None,
cursor: None,
@@ -327,7 +318,7 @@ impl LiquifyWorkspace {
/// Shows the workspace for this pass.
///
/// A [`FullWindowDialog`] titled by [`FullWindowTitle`] (the subject and the zoom), with the Properties column ([`LiquifyPanel`], OK and Cancel at its bottom) in the dialog's
/// side region. The body, in order: the events [`step`](Self::step) queued; the commands, in the scope of
/// side region. The body, in order: Undo and Redo; the commands, in the scope of
/// [`LiquifyCommands`]; the tool strip (a `ToolRail` over [`LiquifyTool::slots`]; a pick
/// cancels the old tool's gesture with `Removed`); the canvas ([`FullWindowCanvas`]) with the source's image under
/// [`BackdropLayering`], the freeze mask as a `RasterOverlay` tinted red while Show Mask is on, the mesh while
@@ -342,8 +333,7 @@ impl LiquifyWorkspace {
let layers = source.layers();
let title = FullWindowTitle::new(words.name.clone()).subject(self.subject.clone()).zoom(self.zoom_percent).label(&env);
let settings_before = self.edit.settings.clone();
let mut asked_steps = std::mem::take(&mut self.requested);
self.edit.events = std::mem::take(&mut self.queued);
self.edit.events.clear();
if !self.edit.settings.show_backdrop {
self.asked = None;
} else if self.asked.is_none() {
@@ -352,17 +342,6 @@ impl LiquifyWorkspace {
self.edit.events.push(LiquifyEvent::BackdropWanted(of));
self.asked = Some(of);
}
// An open stroke is cancelled first; the replay of the step supersedes the one the cancel reports. This runs before
// the container, so an undo during a releasing stroke cancels it instead of undoing.
for step in asked_steps.drain(..) {
self.edit.cancel_gesture(&ui.ctx().clone(), &mut self.view, CancelReason::UndoDuringGesture);
if self.edit.history.step(&mut self.edit.session, step) {
if matches!(self.edit.events.last(), Some(LiquifyEvent::Replay(_))) {
self.edit.events.pop();
}
self.edit.events.push(LiquifyEvent::Replay(self.edit.session.steps().to_vec()));
}
}
let slots = LiquifyTool::slots();
let this = RefCell::new(&mut *self);
@@ -396,6 +375,10 @@ impl LiquifyWorkspace {
let ctx = ui.ctx().clone();
let mut guard = this.borrow_mut();
let work: &mut LiquifyWorkspace = &mut guard;
// Before the canvas runs, so an undo during a releasing stroke cancels it instead of undoing.
while let Some(step) = cx.take_step(work.edit.history.can_undo(), work.edit.history.can_redo()) {
work.edit.step(&ctx, &mut work.view, step);
}
let state = &mut work.view;
state.canvas.navigate(work.navigation);
while let Some((command, _)) = cx.take_command::<ViewCommands>() {
@@ -496,7 +479,6 @@ impl LiquifyWorkspace {
}
work.zoom_percent = work.view.view.zoom_percent();
work.edit.absorb_canvas_events(&mut work.view);
work.busy = work.view.canvas.busy();
work.timing = work.view.canvas.timing();
});
let this = this.into_inner();
@@ -522,26 +504,6 @@ impl LiquifyWorkspace {
pub fn settings(&self) -> &LiquifySettings {
&self.edit.settings
}
/// Undo or redo from the app's Edit menu. Returns whether a step will happen; its
/// [`LiquifyEvent::Replay`] comes with the next [`show`](Self::show)'s events. With a stroke
/// open the step waits for that pass, which cancels the stroke (`UndoDuringGesture`) first.
pub fn step(&mut self, step: Step) -> bool {
// pc: crates/ui-egui/src/dialogs/liquify_ui.rs:340 `undo`, :351 `redo`.
if self.busy {
self.requested.push(step);
return match step {
Step::Undo => self.edit.history.can_undo(),
Step::Redo => self.edit.history.can_redo(),
_ => false,
};
}
let stepped = self.edit.history.step(&mut self.edit.session, step);
if stepped {
self.queued.push(LiquifyEvent::Replay(self.edit.session.steps().to_vec()));
}
stepped
}
}
impl Edit {
@@ -614,6 +576,19 @@ impl Edit {
self.absorb_canvas_events(state);
}
/// Undoes or redoes, cancelling an open stroke first (`UndoDuringGesture`); the replay of the step supersedes the
/// one the cancel reports.
fn step(&mut self, ctx: &egui::Context, state: &mut LiquifyView, step: Step) {
// pc: crates/ui-egui/src/dialogs/liquify_ui.rs:340 `undo`, :351 `redo`.
self.cancel_gesture(ctx, state, CancelReason::UndoDuringGesture);
if self.history.step(&mut self.session, step) {
if matches!(self.events.last(), Some(LiquifyEvent::Replay(_))) {
self.events.pop();
}
self.events.push(LiquifyEvent::Replay(self.session.steps().to_vec()));
}
}
/// Switches to `tool`, cancelling the old tool's gesture first.
fn pick(&mut self, ctx: &egui::Context, state: &mut LiquifyView, tool: LiquifyTool) {
if tool != self.settings.tool {
+11 -11
View File
@@ -17,36 +17,36 @@ use craft_ui::contract::CommandSet;
#[non_exhaustive]
pub enum MaskViewKeys {
/// Onion Skin.
#[command(label = "Onion Skin", default = "O")]
#[command(modal = "in_dialogs", label = "Onion Skin", default = "O")]
OnionSkin,
/// Marching Ants.
#[command(label = "Marching Ants", default = "M")]
#[command(modal = "in_dialogs", label = "Marching Ants", default = "M")]
MarchingAnts,
/// Overlay.
#[command(label = "Overlay", default = "V")]
#[command(modal = "in_dialogs", label = "Overlay", default = "V")]
Overlay,
/// On Black.
#[command(label = "On Black", default = "A")]
#[command(modal = "in_dialogs", label = "On Black", default = "A")]
OnBlack,
/// On White.
#[command(label = "On White", default = "T")]
#[command(modal = "in_dialogs", label = "On White", default = "T")]
OnWhite,
/// Black & White.
#[command(label = "Black & White", default = "K")]
#[command(modal = "in_dialogs", label = "Black & White", default = "K")]
BlackAndWhite,
/// On Layers.
#[command(label = "On Layers", default = "Y")]
#[command(modal = "in_dialogs", label = "On Layers", default = "Y")]
OnLayers,
/// The next view in menu order.
#[command(label = "Next View", default = "F")]
#[command(modal = "in_dialogs", label = "Next View", default = "F")]
NextView,
/// Show Edge.
#[command(label = "Show Edge", default = "J")]
#[command(modal = "in_dialogs", label = "Show Edge", default = "J")]
ShowEdge,
/// Show Original.
#[command(label = "Show Original", default = "P")]
#[command(modal = "in_dialogs", label = "Show Original", default = "P")]
ShowOriginal,
/// The image without the view, while the key is held.
#[command(label = "Hide View (Hold)", kind = "momentary", default = "X")]
#[command(modal = "in_dialogs", label = "Hide View (Hold)", kind = "momentary", default = "X")]
HideView,
}
+19 -42
View File
@@ -64,7 +64,7 @@ use craft_ui::dialog::{FullWindowCanvas, FullWindowDialog, FullWindowSide, FullW
use craft_ui::layout_components::{Row, Stack};
use craft_ui::primitives::Checker;
use craft_ui::rails::{LastUsed, ToolRail};
use craft_ui::runtime::commands::{CommandSet as _, Commands as _, FirePhase};
use craft_ui::runtime::commands::{CommandSet as _, Commands as _};
use craft_ui::runtime::edit::next_gesture_id;
use craft_ui::runtime::env::Env;
use craft_ui::runtime::pending::{Job, Pending};
@@ -228,9 +228,8 @@ impl Outcome for SelectMaskOutput {
///
/// Keys ([`SelectMaskCommands`], on the dialog's scope; none while a text field edits): W, R, B, L, H, Z pick the
/// tools, a pressed-again W or L (or Shift+W, Shift+L) cycles its group; `[` and `]` the brush size
/// ([`BrushSizes::step`]); the app forwards the fired `MaskViewKeys` (O M V A T K Y, F, J, P and X held) to
/// [`mask_view`](Self::mask_view) and ⌘Z, ⇧⌘Z to
/// [`step`](Self::step). Backspace and Delete remove the polygon's last vertex; Enter closes an open polygon first,
/// ([`BrushSizes::step`]); `MaskViewKeys` pick the view (O M V A T K Y, F, J, P, and X held hides it); ⌘Z and ⇧⌘Z
/// step the history (a field being edited steps its own text first; an open stroke is cancelled first). Backspace and Delete remove the polygon's last vertex; Enter closes an open polygon first,
/// else is OK; Esc drops it first, else is Cancel.
#[derive(Clone, Pattern)]
pub struct SelectMaskWorkspace {
@@ -262,8 +261,6 @@ pub struct SelectMaskWorkspace {
/// The key of the request a released brush stroke was made under: the stroke stays drawn until another key's
/// preview is ready.
trail_since: Option<String>,
/// Steps the app asked for while a stroke was open; the next `show` cancels the stroke, then steps.
requested: Vec<Step>,
/// The zoom on screen at the end of the last pass, for the title.
zoom_percent: f64,
/// This pass's events.
@@ -301,7 +298,6 @@ impl SelectMaskWorkspace {
panel_open: false,
request: None,
trail_since: None,
requested: Vec::new(),
zoom_percent: 100.0,
events: Vec::new(),
pick_color: None,
@@ -336,8 +332,8 @@ impl SelectMaskWorkspace {
///
/// A [`FullWindowDialog`] titled by [`FullWindowTitle`] (the document and the zoom), in the scope of
/// [`SelectMaskCommands`], with the Properties column ([`SelectMaskPanel`], the preview's status, Reset at the
/// footer's leading end, OK and Cancel) in the dialog's side region. The body, in order: the steps
/// [`step`](Self::step) held back, the commands, [`SelectMaskBar`], the tool strip (a pick cancels the old
/// footer's leading end, OK and Cancel) in the dialog's side region. The body, in order: Undo and
/// Redo, the commands, [`SelectMaskBar`], the tool strip (a pick cancels the old
/// tool's gesture with `Removed`), the canvas ([`FullWindowCanvas`]) with the source's view (the image while X
/// is held), the ants as a `SelectionOverlay` control while the recipe has them, the brush resize preview, and
/// [`SelectMaskCanvasTool`], the Zoom tool or the canvas's Hand as its tool. Commits from the canvas go through
@@ -351,13 +347,6 @@ impl SelectMaskWorkspace {
let common = env.words::<CommonWords>();
let title = FullWindowTitle::new(words.name.clone()).subject(self.subject.clone()).zoom(self.zoom_percent).label(&env);
let settings_before = self.settings.clone();
// Steps asked while a stroke was open run before the canvas: an open stroke is cancelled first, so its
// Commit never lands on the restored session.
for step in std::mem::take(&mut self.requested) {
self.cancel_gesture(ui.ctx(), CancelReason::UndoDuringGesture);
self.canvas.drop_polygon();
self.step_now(step);
}
let slots = SelectMaskTool::slots();
let request = self.request_now();
let key = format!("{request:?}");
@@ -404,9 +393,17 @@ impl SelectMaskWorkspace {
let work: &mut SelectMaskWorkspace = &mut guard;
work.zoom_tool.options = work.navigation;
// Before the canvas runs: an open stroke is cancelled first, so its Commit never lands on the restored
// session.
while let Some(step) = cx.take_step(work.history.can_undo(), work.history.can_redo()) {
work.step(&ctx, step);
}
while let Some((command, _)) = cx.take_command::<ViewCommands>() {
work.view.apply(command);
}
while let Some((command, fired)) = cx.take_command::<MaskViewKeys>() {
work.mask_view.run(command, fired.phase);
}
while let Some((command, fired)) = cx.take_command::<SelectMaskCommands>() {
if let Some(tool) = command.tool() {
@@ -541,27 +538,6 @@ impl SelectMaskWorkspace {
pub fn recipe(&self) -> MaskViewRecipe {
self.mask_view.recipe()
}
/// Undo or redo from the app's Edit menu (`EditCommands::Undo`, `Redo`). Returns whether it stepped. With a stroke
/// open the step waits for the next pass, which cancels the stroke (`UndoDuringGesture`) first.
pub fn step(&mut self, step: Step) -> bool {
// pc: crates/ui-egui/src/dialogs/select_mask_ui.rs:644 `undo`, :672 `redo`.
if self.canvas.busy() {
self.requested.push(step);
return match step {
Step::Undo => self.history.can_undo(),
_ => self.history.can_redo(),
};
}
self.canvas.drop_polygon();
self.step_now(step)
}
/// Runs a fired view command (`MaskViewKeys`: the views O M V A T K Y, F, J, P, and X held) on the view state.
/// Returns whether it changed the view. The app calls it with each fired command and its phase.
pub fn mask_view(&mut self, command: MaskViewKeys, phase: FirePhase) -> bool {
self.mask_view.run(command, phase).is_some()
}
}
impl SelectMaskWorkspace {
@@ -591,15 +567,16 @@ impl SelectMaskWorkspace {
self.history.record(&EditEvent::set(Mixed::Same(before), self.session.clone(), name, None));
}
/// Steps the history now.
fn step_now(&mut self, step: Step) -> bool {
let moved = self.history.step(&mut self.session, step);
if moved {
/// Undoes or redoes, cancelling an open stroke (`UndoDuringGesture`) and dropping an open polygon first.
fn step(&mut self, ctx: &egui::Context, step: Step) {
// pc: crates/ui-egui/src/dialogs/select_mask_ui.rs:644 `undo`, :672 `redo`.
self.cancel_gesture(ctx, CancelReason::UndoDuringGesture);
self.canvas.drop_polygon();
if self.history.step(&mut self.session, step) {
self.error = None;
self.settings.refine = self.session.refine.clone();
self.settled = self.session.clone();
}
moved
}
/// Records a button's edit (Select Subject, Clear Selection, Invert) as a `Set`.
+6 -25
View File
@@ -213,8 +213,8 @@ struct NewPlaneState {
/// while Vanishing Point is open. The view and the strip's memory live in the dialog's body.
///
/// Keys ([`VanishingPointCommands`], on the dialog's scope): V, C, S, H, Z pick the tools; Delete and Backspace remove
/// the selected plane while the canvas has the keyboard. The app forwards ⌘Z and ⇧⌘Z (`EditCommands::Undo`, `Redo`) to
/// [`step`](Self::step); Enter is OK and
/// the selected plane while the canvas has the keyboard. ⌘Z and ⇧⌘Z step the history (a field being edited steps its own
/// text first); Enter is OK and
/// Esc Cancel (with the canvas focused, Esc drops pending corners first, and during a drag cancels the drag only). A
/// tool switch cancels the old tool's gesture (`CancelReason::Removed`), and so does an undo
/// (`CancelReason::UndoDuringGesture`).
@@ -236,8 +236,6 @@ pub struct VanishingPointWorkspace {
hand: HandTool,
zoom: ZoomTool,
new_plane: NewPlaneState,
/// Steps the app asked for while a drag was open: the next `show` cancels the drag, then steps.
requested: Vec<Step>,
/// The zoom on screen at the end of the last pass, for the title.
zoom_percent: f64,
}
@@ -260,7 +258,6 @@ impl VanishingPointWorkspace {
hand: HandTool::new(open.navigation),
zoom: ZoomTool::new(open.navigation),
new_plane: NewPlaneState::default(),
requested: Vec::new(),
zoom_percent: 100.0,
}
}
@@ -295,7 +292,6 @@ impl VanishingPointWorkspace {
let common = env.words::<CommonWords>();
let title = FullWindowTitle::new(words.name.clone()).subject(self.subject.clone()).zoom(self.zoom_percent).label(&env);
let settings_before = self.settings;
let mut asked = std::mem::take(&mut self.requested);
let slots = slots();
let status: RefCell<Option<Pending<PreviewDone, String>>> = RefCell::new(None);
let events = RefCell::new(Vec::<VanishingPointEvent>::new());
@@ -319,7 +315,8 @@ impl VanishingPointWorkspace {
let mut out = Vec::new();
// An open drag is cancelled first, so the step finds the session as the history has it.
for step in asked.drain(..) {
while let Some(step) = cx.take_step(work.history.can_undo(), work.history.can_redo()) {
// pc: crates/ui-egui/src/dialogs/vp_ui.rs:383 `step`.
work.cancel_gesture(&ctx, &state, CancelReason::UndoDuringGesture, &mut out);
work.step_now(step);
}
@@ -445,20 +442,6 @@ impl VanishingPointWorkspace {
pub fn settings(&self) -> &VanishingPointSettings {
&self.settings
}
/// Undo or redo from the app's Edit menu; returns whether a step will happen. With a drag open the step waits for
/// the next [`show`](Self::show), which cancels the drag (`UndoDuringGesture`) first.
pub fn step(&mut self, step: Step) -> bool {
// pc: crates/ui-egui/src/dialogs/vp_ui.rs:383 `step`.
if self.editor.busy() {
self.requested.push(step);
return match step {
Step::Undo => self.history.can_undo(),
_ => self.history.can_redo(),
};
}
self.step_now(step)
}
}
/// The strip: Edit Plane (V), Create Plane (C), Stamp (S), a gap, Hand (H) and Zoom (Z); each slot runs the tool's
@@ -476,14 +459,12 @@ fn slots() -> Vec<ToolSlot<Pick>> {
impl VanishingPointWorkspace {
/// Steps the history now; the editor drops what the old session left (pending corners, a stale selection).
fn step_now(&mut self, step: Step) -> bool {
let stepped = self.history.step(&mut self.session, step);
if stepped {
fn step_now(&mut self, step: Step) {
if self.history.step(&mut self.session, step) {
self.editor.after_step(&self.session);
self.recorded = self.session.clone();
self.revision += 1;
}
stepped
}
/// Cancels the gesture the strip's tool holds with `reason`: the editor puts back what the press found (the
+12 -21
View File
@@ -186,8 +186,8 @@ const TOOL_SLOT: [(WideAngleTool, WideAngleCommands); 3] = [
/// The Adaptive Wide Angle workspace.
///
/// Keys: A, H, Z (the tool commands); Delete and Backspace the focused constraint; the zoom commands the view; Enter
/// OK; Esc Cancel (a drag in progress first). Undo and redo are the app's Edit commands, forwarded to
/// [`step`](Self::step).
/// OK; Esc Cancel (a drag in progress first). ⌘Z and ⇧⌘Z step the history, ending a drag in progress first (a field
/// being edited steps its own text first).
#[derive(Pattern)]
pub struct WideAngleWorkspace {
session: WideAngleSession,
@@ -204,7 +204,6 @@ pub struct WideAngleWorkspace {
navigation: NavigationOptions,
/// The panel's Add button was pressed and the form is not open yet.
add_requested: bool,
steps: Vec<Step>,
}
impl WideAngleWorkspace {
@@ -220,7 +219,6 @@ impl WideAngleWorkspace {
zoom_percent: 100.0,
navigation: NavigationOptions::default(),
add_requested: false,
steps: Vec::new(),
}
}
@@ -244,19 +242,6 @@ impl WideAngleWorkspace {
&self.session
}
/// Undo or redo from the app's Edit menu; returns whether it will step. The next [`show`](Self::show) ends a drag
/// in progress first, then steps.
pub fn step(&mut self, step: Step) -> bool {
let can = match step {
Step::Undo => self.history.can_undo(),
Step::Redo => self.history.can_redo(),
_ => false,
};
// The body ends a drag in its own pass, so a step is queued even when there is nothing to undo.
self.steps.push(step);
can
}
/// Shows the workspace for this pass: the title, the strip, the side column ([`WideAnglePanel`], OK and Cancel),
/// the canvas (the corrected preview while Preview is on and no drag runs, else the source) with the Constraint
/// tool (or Hand, Zoom) and the [`ConstraintLines`], and the constraint menu while a constraint asked for it.
@@ -272,8 +257,8 @@ impl WideAngleWorkspace {
let snapshot = self.session.clone();
let size = self.size;
let navigation = self.navigation;
let steps = std::mem::take(&mut self.steps);
let ending = !steps.is_empty();
let can_step = (self.history.can_undo(), self.history.can_redo());
let steps = RefCell::new(Vec::<Step>::new());
let preview_on = Cell::new(self.preview_on);
let actions = RefCell::new(Vec::<Action>::new());
let timing = Cell::new(self.timing);
@@ -308,7 +293,13 @@ impl WideAngleWorkspace {
if add.replace(false) {
body.adding = true;
}
if ending {
// A drag in progress ends first; the steps run after the dialog, before this pass's edits.
let mut stepping = false;
while let Some(step) = cx.take_step(can_step.0, can_step.1) {
steps.borrow_mut().push(step);
stepping = true;
}
if stepping {
end_gesture(&ctx, &mut body, CancelReason::UndoDuringGesture);
}
@@ -441,7 +432,7 @@ impl WideAngleWorkspace {
self.add_requested = add.get();
self.timing = timing.get();
self.zoom_percent = zoom_percent.get();
for step in steps {
for step in steps.into_inner() {
self.history.step(&mut self.session, step);
}
let mut events = Vec::new();
+8 -9
View File
@@ -7,7 +7,6 @@ use std::sync::Arc;
use std::time::Duration;
use craft_behavior::PixelSize;
use craft_behavior::edit_history::Step;
use craft_host::{AppInfo, Host};
use craft_imaging::ui::filter_gallery::{
EffectChange, EffectLayer, FilterCatalog, FilterCategory, FilterGalleryEvent, FilterGalleryOpen, FilterGalleryOutput, FilterGallerySession,
@@ -21,7 +20,7 @@ use craft_ui::primitives::Revision;
use craft_ui::primitives::textures::{FakeThumbSource, ThumbnailOptions, Thumbnails};
use craft_ui::testing::{Fixture, trial};
use craft_ui::value_drag::SliderScale;
use egui::{Color32, ColorImage, Vec2};
use egui::{Color32, ColorImage, Key, Modifiers, Vec2};
const WINDOW: Vec2 = Vec2::new(1100.0, 640.0);
const LAYER: PixelSize = PixelSize::new(400, 300);
@@ -162,10 +161,10 @@ impl Rig {
}
}
// The workspace's `step` clamps the selection to the layers that remain and leaves the `Select` event to the
// pass's comparison with the selection the app knows: it is reported once.
// ⌘Z steps the stack's history: the selection moves onto the layers that remain, and the `Select` event comes from
// the pass's comparison with the selection the app knows, once.
#[trial]
fn gallery_workspace_step_clamps_the_selection_without_queuing_select() {
fn gallery_undo_by_key_clamps_the_selection_and_reports_select_once() {
let mut rig = rig(FilterGallerySession::new("cutout", &Catalog), true);
let add = rig.fixture.by_label("New effect layer").expect("the stack offers New");
rig.fixture.click(&add).settle();
@@ -174,12 +173,12 @@ fn gallery_workspace_step_clamps_the_selection_without_queuing_select() {
let selects = |rig: &Rig| rig.events().iter().filter(|event| matches!(event, FilterGalleryEvent::Select(0))).count();
assert_eq!(selects(&rig), 0);
assert!(rig.workspace.borrow_mut().step(Step::Undo));
rig.fixture.key(Key::Z, Modifiers::COMMAND).settle();
assert_eq!(rig.workspace.borrow().session().effects.len(), 1);
assert_eq!(rig.workspace.borrow().selected(), 0, "the selection moves onto the layer that remains");
rig.fixture.settle();
assert_eq!(selects(&rig), 1, "the next pass reports `Select` from its comparison, once");
assert!(!rig.workspace.borrow_mut().step(Step::Undo), "nothing left to undo");
assert_eq!(selects(&rig), 1, "the pass reports `Select` from its comparison, once");
rig.fixture.key(Key::Z, Modifiers::COMMAND).settle();
assert_eq!(rig.workspace.borrow().session().effects.len(), 1, "nothing left to undo");
}
// The app answers a color request by key and `Srgba`: the selected effect's field takes it as one undo step.
+3 -4
View File
@@ -3,7 +3,6 @@
use std::cell::RefCell;
use std::rc::Rc;
use craft_behavior::edit_history::Step;
use craft_behavior::{CancelReason, PixelSize};
use craft_imaging::ui::liquify::{
LiquifyBrush, LiquifyEvent, LiquifyMesh, LiquifyOpen, LiquifySource, LiquifyTool, LiquifyWorkspace, MeshSize, StrokeEvent, StrokeRecorder,
@@ -11,8 +10,9 @@ use craft_imaging::ui::liquify::{
use craft_ui::canvas::{PixelRect, RasterSource};
use craft_ui::primitives::Revision;
use craft_ui::runtime::access::Role;
use craft_ui::testing::input::key_press;
use craft_ui::testing::{Fixture, pointer, trial};
use egui::{Color32, ColorImage, Event, Pos2, Vec2};
use egui::{Color32, ColorImage, Event, Key, Modifiers, Pos2, Vec2};
/// The document's size in pixels.
const DOCUMENT: [u32; 2] = [800, 600];
@@ -137,8 +137,7 @@ fn liquify_undo_mid_stroke_cancels_the_stroke_then_steps() {
open_stroke(&mut fixture, below);
app.borrow_mut().events.clear();
assert!(app.borrow_mut().workspace.step(Step::Undo), "the step waits for the next pass");
fixture.frame(Vec::new());
fixture.frame(vec![key_press(Key::Z, Modifiers::COMMAND)]);
let events = app.borrow().events.clone();
assert!(
matches!(
+21 -1
View File
@@ -9,6 +9,7 @@ use std::time::Duration;
use craft_behavior::PixelSize;
use craft_host::{AppInfo, Host, InlineJobs};
use craft_imaging::trace::MaskSource;
use craft_imaging::ui::mask_view::MaskViewMode;
use craft_imaging::ui::select_mask::{
SelectMaskEvent, SelectMaskLimits, SelectMaskOpen, SelectMaskPreviewRequest, SelectMaskSource, SelectMaskWorkspace,
};
@@ -17,8 +18,10 @@ use craft_ui::canvas::{PixelRect, RasterSource};
use craft_ui::primitives::Revision;
use craft_ui::runtime::access::Role;
use craft_ui::runtime::pending::Job;
use craft_ui::testing::focus::key_release;
use craft_ui::testing::input::key_press;
use craft_ui::testing::{Fixture, pointer, trial};
use egui::{Color32, ColorImage, Pos2, Vec2};
use egui::{Color32, ColorImage, Key, Modifiers, Pos2, Vec2};
/// The document's size in pixels.
const DOCUMENT: [u32; 2] = [800, 600];
@@ -127,3 +130,20 @@ fn select_mask_preview_is_asked_for_only_when_it_changes() {
press_label(&mut fixture, "Invert");
assert_eq!(jobs.load(Ordering::SeqCst), first + 1, "an edit asks for a new preview");
}
// The view keys work from inside the workspace with no help from the app: K picks Black & White, X held hides the
// view until it is released.
#[trial]
fn select_mask_view_keys_pick_the_view_and_x_held_hides_it() {
let (mut fixture, app, _) = open();
fixture.key(Key::Tab, Modifiers::NONE).settle();
fixture.key(Key::K, Modifiers::NONE).settle();
assert_eq!(app.borrow().workspace.recipe().mode, MaskViewMode::BlackAndWhite);
fixture.frame(vec![key_press(Key::X, Modifiers::NONE)]);
fixture.settle();
assert!(app.borrow().workspace.recipe().hidden, "X held hides the view");
fixture.frame(vec![key_release(Key::X, Modifiers::NONE)]);
fixture.settle();
assert!(!app.borrow().workspace.recipe().hidden, "the release shows it again");
}
+6 -7
View File
@@ -78,10 +78,11 @@
use std::cell::RefCell;
use std::collections::BTreeMap;
use craft_behavior::edit_history::Step;
use craft_keymap::{Binding, Builtins, CommandDef, CommandRef, ForeignSet, ImportOptions, Keymap, ProfileError, Profiles, Trigger};
use craft_ui::contract::{Animate as _, Bind, NoValue, Pattern, SaveKey, ShowContainer as _};
use craft_ui::dialog::{Dialog, DialogOutput};
use craft_ui::runtime::commands::{CommandState, Commands as _, EditCommands};
use craft_ui::runtime::commands::Commands as _;
use craft_ui::runtime::overlay::CloseReason;
use craft_ui::sections::{DialogRole, FooterButton};
use egui::{Response, Ui};
@@ -529,12 +530,10 @@ fn frame(ui: &mut Ui, env: &mut Env<'_>, state: &mut DialogState) -> ShortcutsOu
.show(ui, |ui, cx| {
let mut guard = session.borrow_mut();
let Session { env, state } = &mut *guard;
cx.publish(EditCommands::Undo, CommandState::new().enabled(!state.modal() && state.can_undo()));
cx.publish(EditCommands::Redo, CommandState::new().enabled(!state.modal() && state.can_redo()));
while let Some((command, _)) = cx.take_command::<EditCommands>() {
match command {
EditCommands::Undo if !state.modal() => state.undo(env),
EditCommands::Redo if !state.modal() => state.redo(env),
while let Some(step) = cx.take_step(!state.modal() && state.can_undo(), !state.modal() && state.can_redo()) {
match step {
Step::Undo => state.undo(env),
Step::Redo => state.redo(env),
_ => {}
}
}
@@ -26,6 +26,7 @@ pub(crate) use board::{begin, binds_scoped, edit_chords, end, install, note_focu
pub(crate) use board::{fire_bound, fire_resolved, resolve_bound, resolve_scoped};
use craft_behavior::CommandFlags;
use craft_behavior::edit_history::Step;
use craft_keymap::{Chord, Overrides};
use egui::{Context, Id, ViewportId};
use std::borrow::Cow;
@@ -327,6 +328,28 @@ pub trait Commands: CommandAccess {
.or_else(|| board::take(ctx, board::innermost(ctx, chain, S::SCOPE.name()), true, S::from_ref))
}
/// Declares Undo and Redo on the innermost instance around this context, enabled as `can_undo` and `can_redo`
/// say, and takes the next of them fired at it this pass. A body with its own history calls it in a `while let`
/// loop and steps that history: inside a modal layer Undo and Redo reach the instance that declares them, after a
/// focused text field that has a step of its own to take (11.3).
fn take_step(&mut self, can_undo: bool, can_redo: bool) -> Option<Step> {
fn step(command: &CommandRef) -> Option<Step> {
match EditCommands::from_ref(command)? {
EditCommands::Undo => Some(Step::Undo),
EditCommands::Redo => Some(Step::Redo),
_ => None,
}
}
self.publish(EditCommands::Undo, CommandState::new().enabled(can_undo));
self.publish(EditCommands::Redo, CommandState::new().enabled(can_redo));
let (ctx, chain) = (self.command_ctx(), self.command_chain());
chain
.innermost_any()
.and_then(|declaring| board::take(ctx, Some(declaring), false, step))
.or_else(|| board::take(ctx, board::innermost(ctx, chain, CommandScope::APP.name()), true, step))
.map(|(step, _)| step)
}
/// `command` as this context shows it: the label, icon and chord with the scoped bindings of the scopes above
/// the context, and the enabled state of its instance. `None` when the command is scoped and no instance of its
/// scope is above the context.