mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 01:18:43 +00:00
Merge commit 'b7ccf085c7' into ci-fixes
This commit is contained in:
commit
a45db9ee62
4 files changed
+44
-25
No files matched your search
@@ -123,7 +123,8 @@ impl Session {
|
||||
/// [`Self::is_enabled`] for a call with `params`: their `"target"` can enable a command, as a
|
||||
/// targeted layer mask enables Image › Adjustments › Invert on an adjustment layer (#780).
|
||||
pub fn is_enabled_with(&self, id: &str, params: &Value) -> bool {
|
||||
self.disabled_reason_with(id, params).is_none()
|
||||
// An unknown id is disabled; its reason would rank every command id for "did you mean".
|
||||
commands::find(id).is_some_and(|spec| self.spec_disabled_reason(spec, id, params).is_none())
|
||||
}
|
||||
|
||||
/// Why the command can't run now (None = it can): its own precondition, or a background job
|
||||
@@ -134,8 +135,13 @@ impl Session {
|
||||
|
||||
/// [`Self::disabled_reason`] for a call with `params`.
|
||||
pub fn disabled_reason_with(&self, id: &str, params: &Value) -> Option<String> {
|
||||
let Some(s) = commands::find(id) else { return Some(EngineError::UnknownCommand(id.into()).to_string()) };
|
||||
self.precondition(s, &channel_cmds::inject_target(self, id, params.clone())).err().or_else(|| self.job_conflict(id, s.journal))
|
||||
let Some(spec) = commands::find(id) else { return Some(EngineError::UnknownCommand(id.into()).to_string()) };
|
||||
self.spec_disabled_reason(spec, id, params)
|
||||
}
|
||||
|
||||
/// [`Self::disabled_reason_with`] for the catalogue entry `spec` of `id`.
|
||||
fn spec_disabled_reason(&self, spec: &commands::CommandSpec, id: &str, params: &Value) -> Option<String> {
|
||||
self.precondition(spec, &channel_cmds::inject_target(self, id, params.clone())).err().or_else(|| self.job_conflict(id, spec.journal))
|
||||
}
|
||||
|
||||
/// The command's own precondition for a call with `params` (their target filled in).
|
||||
|
||||
@@ -177,7 +177,8 @@ pub(crate) fn is_screen_mode(id: &str) -> bool {
|
||||
/// The PhotoCraft row of a screen-mode command of the shell: the command gate judges the framework command as the
|
||||
/// menus judge that row.
|
||||
pub(crate) fn screen_mode_row(command: &CommandRef) -> Option<&'static str> {
|
||||
bridge_of(command).filter(|(_, bridged)| matches!(bridged, Bridged::ScreenMode(_))).map(|(id, _)| id)
|
||||
// The command gate asks this for every command a pass resolves: only the screen-mode rows build their command.
|
||||
RUNTIME_COMMANDS.iter().find(|(_, bridged)| matches!(bridged, Bridged::ScreenMode(_)) && bridged.command() == *command).map(|(id, _)| *id)
|
||||
}
|
||||
|
||||
/// The id of the command that steps a tool group to its next tool: the group is named by its key.
|
||||
|
||||
@@ -317,11 +317,21 @@ impl Tool {
|
||||
_ => "•",
|
||||
}
|
||||
}
|
||||
/// The tool `s` names: its variant name, that name without "marquee", or its label, in any case and with spaces,
|
||||
/// `_` and `-` ignored. The first tool of [`Tool::ALL`] a spelling names wins.
|
||||
pub fn from_name(s: &str) -> Option<Tool> {
|
||||
let n = s.to_ascii_lowercase().replace([' ', '_', '-'], "");
|
||||
Tool::ALL.into_iter().find(|t| {
|
||||
let a = format!("{t:?}").to_ascii_lowercase();
|
||||
n == a || n == a.replace("marquee", "") || n == t.label().to_ascii_lowercase().replace(' ', "")
|
||||
})
|
||||
// The toolbar resolves its whole layout through here every frame: one table instead of formatting every tool's names per lookup.
|
||||
static NAMES: std::sync::OnceLock<std::collections::HashMap<String, Tool>> = std::sync::OnceLock::new();
|
||||
let names = NAMES.get_or_init(|| {
|
||||
let mut names = std::collections::HashMap::new();
|
||||
for t in Tool::ALL {
|
||||
let a = format!("{t:?}").to_ascii_lowercase();
|
||||
for spelling in [a.replace("marquee", ""), t.label().to_ascii_lowercase().replace(' ', ""), a] {
|
||||
names.entry(spelling).or_insert(t);
|
||||
}
|
||||
}
|
||||
names
|
||||
});
|
||||
names.get(&s.to_ascii_lowercase().replace([' ', '_', '-'], "")).copied()
|
||||
}
|
||||
}
|
||||
@@ -68,26 +68,28 @@ fn value(app: &PhotocraftApp, target: ChannelTarget) -> f32 {
|
||||
}
|
||||
|
||||
/// Render real modal controls with accessibility enabled for input-driven assertions.
|
||||
/// The app's context is set up already ([`PhotocraftApp::new`]).
|
||||
fn harness(app: Box<PhotocraftApp>) -> Harness<'static, Box<PhotocraftApp>> {
|
||||
let h = Harness::builder().with_context(app.ctx().clone()).with_size(egui::vec2(1200.0, 900.0)).build_ui_state(|ui, app| dialogs::run(app, ui), app);
|
||||
PhotocraftApp::setup_context(&h.ctx, Default::default());
|
||||
h
|
||||
Harness::builder().with_context(app.ctx().clone()).with_size(egui::vec2(1200.0, 900.0)).build_ui_state(|ui, app| dialogs::run(app, ui), app)
|
||||
}
|
||||
|
||||
/// The whole app, canvas included: the pointer requests of a picker's samples reach the canvas pass only here.
|
||||
fn canvas_harness(app: Box<PhotocraftApp>) -> Harness<'static, Box<PhotocraftApp>> {
|
||||
// The app keeps the context it was made on: the harness runs the frames on it, so the canvas the app reads is the one drawn.
|
||||
let mut h = Harness::builder().with_context(app.ctx().clone()).with_size(egui::vec2(1200.0, 900.0)).with_max_steps(64).build_eframe(move |cc| {
|
||||
PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());
|
||||
app
|
||||
});
|
||||
/// The document canvas and the dialogs over it: a picker's samples are pointer requests the canvas pass takes, as in
|
||||
/// the app. The rest of the window (panels, menus, bars) plays no part in sampling, so it is left out.
|
||||
fn canvas_harness(mut app: Box<PhotocraftApp>) -> Harness<'static, Box<PhotocraftApp>> {
|
||||
// The window's frame keeps a view per document; the canvas alone draws the views it is given.
|
||||
app.sync_views();
|
||||
let mut h = Harness::builder().with_context(app.ctx().clone()).with_size(egui::vec2(1200.0, 900.0)).with_max_steps(64).build_ui_state(
|
||||
|ui, app| {
|
||||
egui::CentralPanel::default().show(ui, |ui| photocraft_ui_egui::canvas::document_area(app, ui));
|
||||
dialogs::run(app, ui);
|
||||
},
|
||||
app,
|
||||
);
|
||||
h.run_steps(3);
|
||||
// A 32 px document at 100 % sits under the dialog's centred window, which stops the picker's press: zoom to 12x so the left part of the image lies clear of the dialog (no animation, so the view is final at once).
|
||||
h.state_mut().run("prefs.set", json!({"values": {"general.animatedZoom": false}})).unwrap();
|
||||
for _ in 0..8 {
|
||||
h.state_mut().run("view.zoomIn", json!({})).unwrap();
|
||||
h.run_steps(2);
|
||||
}
|
||||
// The dialog's window is centred and stops a press under it: at 12x with the view centred right of the 32 px image,
|
||||
// the image's top-left part lies clear of the dialog, at the canvas's left.
|
||||
let reply = control(&mut h, "ui.set", json!({"zoom": 12, "center": [38, 16]}));
|
||||
assert_eq!(reply["ok"], true, "the view zooms: {reply}");
|
||||
h
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user