mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-28 00:59:29 +01:00
Fix filter picker visibility and swap error context
This commit is contained in:
1 parent
8cdd5dc296
commit
b966d13da2
5 files changed
+100
-3
No files matched your search
@@ -511,16 +511,19 @@ fn swapped_filter(s: &Session, effect: LayerId, id: &str, p: &Value) -> Result<(
|
||||
}
|
||||
|
||||
let def = crate::filter_lib::find(id).ok_or_else(|| bad(CMD, format!("unknown filter `{id}` (see filter.list)")))?;
|
||||
if !def.is_filter_effect() {
|
||||
let mut kind = crate::filter_lib::build(def.id, &Value::Null)?;
|
||||
let EffectKind::Filter(filter) = &mut kind else {
|
||||
return Err(bad(CMD, format!("{} is its own effect type: add it with effect.add.filter", def.label)));
|
||||
}
|
||||
};
|
||||
|
||||
let mask = s.doc.project.layer(owner)?.mask.as_ref();
|
||||
let on_mask = mask.is_some_and(|mask| mask.effects.iter().any(|masked| masked.id == effect));
|
||||
if on_mask && !def.mask {
|
||||
return Err(bad(CMD, format!("{} goes on layer content, not on masks", def.label)));
|
||||
}
|
||||
Ok((crate::filter_lib::build(def.id, p)?, def.label))
|
||||
|
||||
crate::filter_lib::apply(p, filter, CMD)?;
|
||||
Ok((kind, def.label))
|
||||
}
|
||||
|
||||
/// The stack (a mask's or a layer's content effects) holding effect `eid`, and its position there.
|
||||
|
||||
@@ -156,3 +156,17 @@ fn only_filter_effects_swap_and_only_to_filters() {
|
||||
assert!(execute(&mut s, "effect.set", &json!({"effect": filter.0, "filter": "nope"})).is_err());
|
||||
assert!(matches!(effect(&s, filter).kind, EffectKind::Filter(Filter::Invert)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_swap_parameters_report_effect_set_and_preserve_history() {
|
||||
let mut s = session();
|
||||
let id = add(&mut s, "effect.add.filter", json!({"filter": "invert", "target": "content"}));
|
||||
let before = effect(&s, id);
|
||||
let history = s.history_labels();
|
||||
|
||||
let error = execute(&mut s, "effect.set", &json!({"effect": id.0, "filter": "colorBalance", "shadows": "invalid", "name": "Changed"})).unwrap_err();
|
||||
|
||||
assert!(matches!(error, texturecraft_engine::EngineError::BadParams { ref cmd, .. } if cmd == "effect.set"), "{error}");
|
||||
assert_eq!(effect(&s, id), before);
|
||||
assert_eq!(s.history_labels(), history);
|
||||
}
|
||||
@@ -246,6 +246,7 @@ fn effect_menu(app: &mut TextureCraftApp, ui: &mut Ui, layer: &Layer) {
|
||||
if command == "effect.add.filter"
|
||||
&& let Some(effect) = added.as_ref().and_then(|result| result["effect"].as_u64())
|
||||
{
|
||||
app.ui.dock.focus(crate::docking::Panel::Properties);
|
||||
crate::filter_slot::open_picker_when_shown(ui.ctx(), effect);
|
||||
}
|
||||
|
||||
|
||||
@@ -127,3 +127,73 @@ fn add_filter_on_a_mask_adds_it_to_the_mask() {
|
||||
assert!(harness.query_by_label("Sharpen").is_some(), "the mask filter's picker is open");
|
||||
assert!(harness.query_by_label("Grayscale").is_none(), "the picker leaves out content-only filters");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_filter_reopens_closed_properties_to_show_its_picker() {
|
||||
let (mut harness, _) = app_with_invert();
|
||||
harness.state_mut().ui.dock.close(texturecraft_ui_egui::docking::Panel::Properties);
|
||||
harness.run_steps(3);
|
||||
assert!(harness.query_by_role_and_label(Role::ComboBox, "Invert").is_none());
|
||||
|
||||
add_filter_from_the_wand(&mut harness);
|
||||
|
||||
assert!(harness.query_by_role_and_label(Role::ComboBox, "HSL Perceptive").is_some(), "Add filter reveals Properties");
|
||||
assert!(harness.query_by_label("Sharpen").is_some(), "the picker opens immediately");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keyboard_opens_the_slot_and_outside_click_closes_it() {
|
||||
let (mut harness, effect) = app_with_invert();
|
||||
for key in [egui::Key::Enter, egui::Key::Space] {
|
||||
harness.get_by_role_and_label(Role::ComboBox, "Invert").focus();
|
||||
harness.key_press(key);
|
||||
harness.run_steps(3);
|
||||
assert!(egui::Popup::is_any_open(&harness.ctx));
|
||||
|
||||
let position = harness.state().viewport_rect.center();
|
||||
harness.hover_at(position);
|
||||
for pressed in [true, false] {
|
||||
harness.event(egui::Event::PointerButton { pos: position, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE });
|
||||
harness.run_steps(1);
|
||||
}
|
||||
harness.run_steps(3);
|
||||
assert!(!egui::Popup::is_any_open(&harness.ctx));
|
||||
assert!(matches!(kind(&harness, effect), EffectKind::Filter(Filter::Invert)));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "requires an offscreen GPU adapter and TC_UI_SNAPSHOTS"]
|
||||
fn filter_picker_snapshots_and_frame_timings() {
|
||||
let output = std::path::PathBuf::from(std::env::var_os("TC_UI_SNAPSHOTS").expect("set TC_UI_SNAPSHOTS"));
|
||||
std::fs::create_dir_all(&output).unwrap();
|
||||
let mut session = texturecraft_engine::sample_session(256, 64).unwrap();
|
||||
execute(&mut session, "layer.add.fill", &Value::Null).unwrap();
|
||||
execute(&mut session, "effect.add.filter", &json!({"target": "content", "filter": "invert"})).unwrap();
|
||||
let mut harness = Harness::builder().with_size(egui::vec2(1600.0, 960.0)).wgpu().build_eframe(|cc| {
|
||||
eprintln!("selected graphics adapter: {:?}", cc.wgpu_render_state.as_ref().unwrap().adapter.get_info());
|
||||
TextureCraftApp::new(cc, session)
|
||||
});
|
||||
harness.run_steps(20);
|
||||
let start = std::time::Instant::now();
|
||||
open_picker(&mut harness);
|
||||
eprintln!("picker open and first 3 UI frames: {:.3} ms", start.elapsed().as_secs_f64() * 1000.0);
|
||||
harness.run_steps(20);
|
||||
for (brightness, name) in
|
||||
[(texturecraft_ui_egui::theme::Brightness::MediumDark, "filter-picker"), (texturecraft_ui_egui::theme::Brightness::Light, "filter-picker-light")]
|
||||
{
|
||||
harness.state_mut().ui.prefs.brightness = brightness;
|
||||
harness.run_steps(3);
|
||||
harness.render().unwrap().save(output.join(format!("{name}.png"))).unwrap();
|
||||
}
|
||||
let start = std::time::Instant::now();
|
||||
harness.run_steps(120);
|
||||
eprintln!("warm open picker: {:.3} ms/UI frame (120 frames, excluding GPU readback)", start.elapsed().as_secs_f64() * 1000.0 / 120.0);
|
||||
|
||||
harness.event(egui::Event::Text("sharp".into()));
|
||||
harness.run_steps(3);
|
||||
harness.render().unwrap().save(output.join("filter-picker-search.png")).unwrap();
|
||||
harness.get_by_label("Sharpen").click();
|
||||
harness.run_steps(3);
|
||||
harness.render().unwrap().save(output.join("filter-picker-selected.png")).unwrap();
|
||||
}
|
||||
@@ -19,6 +19,15 @@ index}` reorders an effect within its stack (0 = bottom) and `effect.duplicate {
|
||||
one just above itself. `effect.copy {effect?}` and `effect.cut {effect?}` put an effect on the
|
||||
layer clipboard, and `effect.paste {layer?, target?}` adds it to another layer's content or mask.
|
||||
|
||||
`effect.set {effect, filter: "blur", radius: 5}` replaces a filter in place, preserving its
|
||||
stack position, blend, opacity and visibility. Replacement filters start from defaults plus
|
||||
the supplied parameters; naming the current filter instead edits it without resetting omitted
|
||||
parameters. Default effect names follow the new filter, custom names remain, and an explicit
|
||||
`name` overrides either. Only filter effects can be replaced this way, and masks reject
|
||||
content-only filters. `filter.list` lists the available IDs; levels and material finishes
|
||||
must be added separately with `effect.add.filter`. A successful replacement is one undo step;
|
||||
a rejected replacement changes nothing.
|
||||
|
||||
`edit.undo {steps?}` and `edit.redo {steps?}` go back or forward several steps at once (as far
|
||||
as the history reaches); `edit.history` lists the steps done and the undone ones, next first.
|
||||
Any command takes `merge: true` to fold its edit into the previous undo step when that step has
|
||||
|
||||
Reference in new issue
Block a user