mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Reveal layers selected through automation
This commit is contained in:
1 parent
1553cd3c9e
commit
3979c0cc32
3 files changed
+64
No files matched your search
@@ -171,9 +171,11 @@ fn execute_command(app: &mut PhotocraftApp, ctx: &egui::Context, req: &ControlRe
|
||||
return run_waiting(app, wait, |app| {
|
||||
// These bypass `menus::invoke`: a Type box drag in progress applies its box first.
|
||||
crate::type_box_preview::end_drag(app);
|
||||
let revealed = crate::layer_reveal::mark(app);
|
||||
let previous = std::mem::replace(&mut app.programmatic_playback, true);
|
||||
let result = app.run(id, params);
|
||||
app.programmatic_playback = previous;
|
||||
crate::layer_reveal::file(app, revealed);
|
||||
result
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
use egui_kittest::Harness;
|
||||
use photocraft_doc::LayerContent;
|
||||
use photocraft_engine::Session;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::control::{ControlRequest, Reply};
|
||||
use crate::layers_panel_nodes::{layer_id, row_drawn};
|
||||
use crate::{PhotocraftApp, state::Tool};
|
||||
|
||||
#[test]
|
||||
fn automation_reveals_the_new_active_layer_in_a_closed_group() {
|
||||
let mut session = Session::new();
|
||||
session.execute("file.new", json!({"width": 64, "height": 48})).unwrap();
|
||||
session.execute("layer.new.layer", json!({"name": "Child"})).unwrap();
|
||||
session.execute("layer.groupLayers", json!({})).unwrap();
|
||||
let group = session.active().unwrap().active_layer.unwrap();
|
||||
session.execute("layer.setExpanded", json!({"layer": group.0, "expanded": false})).unwrap();
|
||||
// Put the group below the visible rows, so revealing it must also scroll the panel.
|
||||
for index in 0..40 {
|
||||
session.execute("layer.new.layer", json!({"name": format!("Top {index}")})).unwrap();
|
||||
}
|
||||
|
||||
let mut harness = Harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0).with_max_steps(64).build_eframe(|cc| {
|
||||
PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());
|
||||
let mut app = PhotocraftApp::with_context(cc.egui_ctx.clone(), session, crate::Services::default());
|
||||
app.ui.tool = Tool::Move;
|
||||
app.ui.tool_options.move_expand_group_on_click = false;
|
||||
app
|
||||
});
|
||||
let ctx = harness.ctx.clone();
|
||||
let (req, _rx) = ControlRequest::new("ui.set", json!({"dock": {"collapsed": ["color", "properties", "history", "navigator"]}}));
|
||||
crate::control::handle(harness.state_mut(), &ctx, &req);
|
||||
harness.run_steps(8);
|
||||
|
||||
let group_open = |app: &PhotocraftApp| {
|
||||
let doc = &app.session.active().unwrap().doc;
|
||||
matches!(&doc.layer(group).unwrap().content, LayerContent::Group(group) if group.expanded)
|
||||
};
|
||||
let select = |app: &mut PhotocraftApp, name: &str| {
|
||||
let (req, _rx) = ControlRequest::new("engine.execute", json!({"command": "layer.select", "params": {"name": name}}));
|
||||
assert!(matches!(crate::control::handle(app, &ctx, &req), Reply::Done(reply) if reply["ok"] == true));
|
||||
};
|
||||
|
||||
assert!(!group_open(harness.state()));
|
||||
assert!(!row_drawn(&harness, "Child"));
|
||||
let child = layer_id(harness.state(), "Child");
|
||||
select(harness.state_mut(), "Child");
|
||||
assert_eq!(harness.state().session.active().unwrap().active_layer, Some(child));
|
||||
harness.run_steps(8);
|
||||
assert!(group_open(harness.state()), "automation opens the group even when canvas picks keep it closed");
|
||||
assert!(row_drawn(&harness, "Child"), "the selected row is scrolled into view");
|
||||
|
||||
harness.state_mut().session.execute("layer.setExpanded", json!({"layer": group.0, "expanded": false})).unwrap();
|
||||
harness.run_steps(3);
|
||||
assert!(!row_drawn(&harness, "Child"));
|
||||
select(harness.state_mut(), "Child");
|
||||
harness.run_steps(8);
|
||||
assert!(!group_open(harness.state()), "selecting the already-active layer leaves its closed group alone");
|
||||
assert!(!row_drawn(&harness, "Child"));
|
||||
}
|
||||
@@ -969,6 +969,8 @@ mod move_history_names_tests;
|
||||
#[cfg(test)]
|
||||
mod move_shift_diagonal_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod layer_reveal_automation_tests;
|
||||
#[cfg(test)]
|
||||
mod layers_footer_tests;
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in new issue
Block a user