mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge #17882 into the merge queue batch
Window menu: Gradients and the other preset panels are enabled and checked (#17721)
This commit is contained in:
commit
f42e0c1fb2
2 files changed
+77
-1
No files matched your search
@@ -8,7 +8,7 @@ use super::screen_mode_names;
|
||||
use super::{LANGUAGE, PIXEL_ASPECTS, PhotocraftApp, SCREEN_MODES, Show, SnapTo, Value, json};
|
||||
|
||||
/// The ids `panel_docking::command` runs for Window › panels and the Type menu's Character and Paragraph.
|
||||
const PANEL_IDS: [&str; 17] = [
|
||||
const PANEL_IDS: [&str; 27] = [
|
||||
"window.panel.layerComps",
|
||||
"window.panel.layers",
|
||||
"window.panel.history",
|
||||
@@ -24,6 +24,16 @@ const PANEL_IDS: [&str; 17] = [
|
||||
"window.panel.histogram",
|
||||
"window.panel.swatches",
|
||||
"window.panel.adjustments",
|
||||
"window.panel.gradients",
|
||||
"window.panel.patterns",
|
||||
"window.panel.styles",
|
||||
"window.panel.shapes",
|
||||
"window.panel.toolPresets",
|
||||
"window.panel.cloneSource",
|
||||
"window.panel.glyphs",
|
||||
"window.panel.characterStyles",
|
||||
"window.panel.paragraphStyles",
|
||||
"window.panel.timeline",
|
||||
"type.panels.character",
|
||||
"type.panels.paragraph",
|
||||
];
|
||||
@@ -433,3 +443,7 @@ fn apply_params(current: f32, p: &Value) -> Result<f32, String> {
|
||||
}
|
||||
Ok(wrap_deg(r))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../window_menu_preset_panels_tests.rs"]
|
||||
mod window_menu_preset_panels_tests;
|
||||
@@ -0,0 +1,62 @@
|
||||
//! Window › Gradients and the other registered panels' items that were greyed are enabled, and checked while their
|
||||
//! panel shows (#17721).
|
||||
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::control::{ControlRequest, Reply};
|
||||
|
||||
/// The issue's six, then the other registered panels that were greyed for the same reason.
|
||||
const PANELS: [&str; 10] =
|
||||
["gradients", "patterns", "styles", "shapes", "toolPresets", "cloneSource", "glyphs", "characterStyles", "paragraphStyles", "timeline"];
|
||||
|
||||
fn app(doc: bool) -> Box<PhotocraftApp> {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
if doc {
|
||||
app.run("file.new", json!({"width": 64, "height": 48})).unwrap();
|
||||
app.sync_views();
|
||||
}
|
||||
app
|
||||
}
|
||||
|
||||
/// The Window menu's items as `ui.menu.list` reports them.
|
||||
fn window_items(app: &mut PhotocraftApp) -> Vec<Value> {
|
||||
let ctx = app.ctx().clone();
|
||||
let (req, _rx) = ControlRequest::new("ui.menu.list", json!({}));
|
||||
let Reply::Done(listed) = crate::control::handle(app, &ctx, &req) else { panic!("ui.menu.list: expected an immediate reply") };
|
||||
listed["result"].as_array().unwrap().iter().filter(|it| it["path"] == json!(["Window"])).cloned().collect()
|
||||
}
|
||||
|
||||
fn item(app: &mut PhotocraftApp, panel: &str) -> Value {
|
||||
let id = format!("window.panel.{panel}");
|
||||
window_items(app).into_iter().find(|it| it["id"] == id.as_str()).unwrap_or_else(|| panic!("{id} is in the Window menu"))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn panel_items_are_enabled_and_checked_while_their_panel_shows() {
|
||||
for doc in [false, true] {
|
||||
let mut a = app(doc);
|
||||
for panel in PANELS {
|
||||
let it = item(&mut a, panel);
|
||||
assert_eq!(it["enabled"], true, "{panel}, document {doc}: {it}");
|
||||
assert_eq!(it["checked"], crate::panel_docking::is_checked(&a, panel), "{panel}, document {doc}: {it}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn choosing_a_panel_item_shows_it_when_hidden_and_hides_it_when_shown() {
|
||||
let mut a = app(true);
|
||||
for panel in PANELS {
|
||||
let id = format!("window.panel.{panel}");
|
||||
crate::panel_docking::show_panel(&mut a, panel, Some(false)).unwrap();
|
||||
assert_eq!(item(&mut a, panel)["checked"], false, "{panel} starts hidden");
|
||||
let ctx = a.ctx().clone();
|
||||
crate::menus::invoke(&mut a, &ctx, &id, json!({})).unwrap();
|
||||
assert!(crate::panel_docking::is_front(&a, panel), "{panel} shows");
|
||||
assert_eq!(item(&mut a, panel)["checked"], true, "{panel}: checked while it shows");
|
||||
crate::menus::invoke(&mut a, &ctx, &id, json!({})).unwrap();
|
||||
assert!(!crate::panel_docking::is_shown(&a, panel), "{panel} hides");
|
||||
assert_eq!(item(&mut a, panel)["checked"], false, "{panel}: unchecked once hidden");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user