mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-26 17:30:45 +01:00
Generators panel: Restore defaults keeps the Resolution band, the input card offers anchors below the owner, a swapped kind drops its point pick, size columns step with the arrow keys
- Restore defaults resets the Parameters only, as its band says (it was disabled when only the resolution differed, yet reset it otherwise) - an inherited generator's slots list the anchors below both the owner and the instance, as the Properties picker does (others were refused) - a pick armed on a generator swapped to a kind without that point is dropped - a focused size column takes the arrow keys, each press one step - the picker snapshot hovers the tile by its ListBoxOption role
This commit is contained in:
1 parent
30dcceb3ef
commit
ff298779c2
6 files changed
+114
-17
No files matched your search
@@ -5,7 +5,7 @@ use serde_json::json;
|
||||
use texturecraft_engine::core::{LayerId, Source};
|
||||
|
||||
use crate::TextureCraftApp;
|
||||
use crate::dock::{anchor_label, anchors_below, image_drop, mesh_map_color};
|
||||
use crate::dock::{anchor_label, image_drop, mesh_map_color, project_effect_anchors_below};
|
||||
use crate::fill_material_panel::{source_choice, source_tabs};
|
||||
use crate::generator_input_slot::GeneratorInputSlot;
|
||||
use crate::i18n::{baked_map_label, tr, trf};
|
||||
@@ -93,7 +93,7 @@ pub(crate) fn input_card(
|
||||
}
|
||||
let current = source.map(|source| source_choice(&app.session, source));
|
||||
let tabs = || {
|
||||
let anchors = if slot.takes_anchor() { anchors_below(&app.session.doc.project, layer) } else { Vec::new() };
|
||||
let anchors = if slot.takes_anchor() { project_effect_anchors_below(&app.session.doc.project, layer, LayerId(id)) } else { Vec::new() };
|
||||
let mut tabs = source_tabs(&app.session, &anchors, tokens.button, false);
|
||||
|
||||
// A generator's inputs read images, values and anchor points, never a procedural
|
||||
|
||||
@@ -169,18 +169,11 @@ pub(crate) fn micro_params(kind: GeneratorKind, micro: &MicroDetails) -> Value {
|
||||
params
|
||||
}
|
||||
|
||||
/// The `effect.set` params that put generator effect `id` back to the defaults of its kind; its images stay in their slots
|
||||
/// The `effect.set` params that put generator effect `id`'s parameters back to the defaults of its kind; its images stay in their slots and its resolution, in a band of its own, stays as set
|
||||
pub(crate) fn defaults_of(id: u64, generator: &Generator) -> Value {
|
||||
let kind = generator.kind;
|
||||
let defaults = Generator::new(kind);
|
||||
let params = json!({
|
||||
"effect": id,
|
||||
"seed": defaults.seed,
|
||||
"invert": defaults.invert,
|
||||
"resolution": format!("{:?}", defaults.resolution.mode),
|
||||
"customResolution": defaults.resolution.custom,
|
||||
"resolutionFactor": defaults.resolution.factor,
|
||||
});
|
||||
let params = json!({"effect": id, "seed": defaults.seed, "invert": defaults.invert});
|
||||
if let Some(controls) = &defaults.controls {
|
||||
return merged(params, kind_params(controls));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Picking a 3D generator's point on the mesh: its crosshair button arms it, the next click in the 3D view sets the point, Esc or the button again cancels
|
||||
|
||||
use texturecraft_engine::core::LayerId;
|
||||
use texturecraft_engine::core::{EffectKind, GeneratorKind, LayerId};
|
||||
use texturecraft_engine::{Session, StackTarget};
|
||||
|
||||
/// Which point of which generator effect the next click in the 3D view sets
|
||||
@@ -12,6 +12,13 @@ pub(crate) struct PointPick {
|
||||
pub(crate) point: &'static str,
|
||||
}
|
||||
|
||||
impl PointPick {
|
||||
/// Whether a `kind` generator has the point this pick sets
|
||||
fn belongs_to(&self, kind: GeneratorKind) -> bool {
|
||||
matches!((kind, self.point), (GeneratorKind::ThreeDDistance, "distance") | (GeneratorKind::ThreeDLinearGradient, "start" | "end"))
|
||||
}
|
||||
}
|
||||
|
||||
/// Where the armed pick is kept: a transient UI mode, like the depth of field's focus pick
|
||||
fn pick_id() -> egui::Id {
|
||||
egui::Id::unique("tc_generator_point_pick")
|
||||
@@ -28,10 +35,14 @@ pub(crate) fn toggle(ctx: &egui::Context, pick: PointPick) {
|
||||
set(ctx, next);
|
||||
}
|
||||
|
||||
/// The armed pick while its effect is still the selected one; a pick whose effect was deselected or deleted is dropped
|
||||
/// The armed pick while its effect is still the selected one and still has its point; a pick whose effect was deselected, deleted or swapped to a kind without that point is dropped
|
||||
pub(crate) fn armed_on(ctx: &egui::Context, session: &Session) -> Option<PointPick> {
|
||||
let pick = armed(ctx)?;
|
||||
if session.target == StackTarget::Effect(LayerId(pick.effect)) {
|
||||
let has_point = match session.doc.project.effect(LayerId(pick.effect)).map(|(_, effect)| &effect.kind) {
|
||||
Some(EffectKind::Generator(generator)) => pick.belongs_to(generator.kind),
|
||||
_ => false,
|
||||
};
|
||||
if has_point && session.target == StackTarget::Effect(LayerId(pick.effect)) {
|
||||
return Some(pick);
|
||||
}
|
||||
set(ctx, None);
|
||||
|
||||
@@ -18,6 +18,9 @@ const FACE_AIR: f32 = 2.0;
|
||||
/// Width of a column's track and fill
|
||||
const COLUMN_TRACK_WIDTH: f32 = 2.0;
|
||||
|
||||
/// How far one arrow key press moves a focused column: a twentieth of its track
|
||||
const KEY_STEP: f32 = 0.05;
|
||||
|
||||
impl PropertySheet<'_> {
|
||||
/// One 0..1 vertical slider per name in `values`, side by side across the panel
|
||||
pub(crate) fn size_columns(&mut self, names: &[&str], values: &mut [f32]) -> SizeColumnsResponse {
|
||||
@@ -43,6 +46,23 @@ impl PropertySheet<'_> {
|
||||
moved = true;
|
||||
}
|
||||
}
|
||||
|
||||
// A focused column keeps the arrow keys: up and right raise it, down and left lower it, each press its own step
|
||||
if hit.has_focus() {
|
||||
self.ui.memory_mut(|memory| {
|
||||
memory.set_focus_lock_filter(id, egui::EventFilter { horizontal_arrows: true, vertical_arrows: true, ..Default::default() })
|
||||
});
|
||||
let presses = self.ui.input(|input| {
|
||||
let raised = input.num_presses(egui::Key::ArrowUp) + input.num_presses(egui::Key::ArrowRight);
|
||||
let lowered = input.num_presses(egui::Key::ArrowDown) + input.num_presses(egui::Key::ArrowLeft);
|
||||
raised as f32 - lowered as f32
|
||||
});
|
||||
let stepped = (*value + presses * KEY_STEP).clamp(0.0, 1.0);
|
||||
if stepped != *value {
|
||||
*value = stepped;
|
||||
moved = true;
|
||||
}
|
||||
}
|
||||
if let Some(merge) = crate::widgets::press_edit(self.ui, id, moved) {
|
||||
response.edit = Some((index, merge));
|
||||
}
|
||||
|
||||
@@ -102,7 +102,10 @@ fn restore_defaults_puts_the_generator_back_to_its_kind_defaults() {
|
||||
|
||||
click_live(&mut harness, Role::Button, "Restore defaults");
|
||||
|
||||
assert_eq!(generator(&harness, effect), Generator::new(GeneratorKind::Curvature));
|
||||
// Resolution has its own band: restoring the parameters leaves it as set
|
||||
let restored = generator(&harness, effect);
|
||||
assert_eq!(restored.resolution.factor, -2);
|
||||
assert_eq!(Generator { resolution: Generator::new(GeneratorKind::Curvature).resolution, ..restored }, Generator::new(GeneratorKind::Curvature));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -250,6 +253,29 @@ fn a_curvature_size_column_sets_its_size_alone_in_one_step() {
|
||||
assert_eq!(harness.state().session.history_labels().len(), history + 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_focused_curvature_size_column_steps_with_the_arrow_keys() {
|
||||
let (mut harness, effect) = harness(false);
|
||||
let last = generator(&harness, effect).detail.unwrap().weights.len() - 1;
|
||||
harness.get_by_role_and_label(Role::Slider, "Huge").scroll_to_me();
|
||||
harness.run_steps(3);
|
||||
harness.get_by_role_and_label(Role::Slider, "Huge").focus();
|
||||
harness.run_steps(2);
|
||||
let before = generator(&harness, effect).detail.unwrap().weights;
|
||||
let history = harness.state().session.history_labels().len();
|
||||
|
||||
harness.key_press(egui::Key::ArrowDown);
|
||||
harness.run_steps(3);
|
||||
let lowered = generator(&harness, effect).detail.unwrap().weights;
|
||||
harness.key_press(egui::Key::ArrowUp);
|
||||
harness.run_steps(3);
|
||||
|
||||
assert!(lowered[last] < before[last], "down lowered Huge: {} -> {}", before[last], lowered[last]);
|
||||
assert_eq!(lowered[..last], before[..last], "the other sizes kept theirs");
|
||||
assert!((generator(&harness, effect).detail.unwrap().weights[last] - before[last]).abs() < 1e-6, "up raised it back");
|
||||
assert_eq!(harness.state().session.history_labels().len(), history + 2, "each press is a step");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restore_defaults_puts_a_light_back_on_its_defaults() {
|
||||
let (mut harness, effect) = harness_with(false, json!({"generator": "direction", "lightHorizontal": 10.0, "highlightLevel": 0.7, "invert": true}));
|
||||
@@ -279,6 +305,45 @@ fn micro_details_show_their_settings_once_switched_on() {
|
||||
assert!(slot_reading(&harness, "Empty").rect().is_positive(), "Micro Height on: its slot, empty");
|
||||
}
|
||||
|
||||
/// An instance showing its source's generator offers its Micro Height only the anchor points below both: one between the source and the instance is refused by the source's mask
|
||||
#[test]
|
||||
fn an_inherited_generators_micro_height_lists_only_anchors_below_its_owner() {
|
||||
const BELOW: &str = "Height below";
|
||||
const BETWEEN: &str = "Height between";
|
||||
let mut session = texturecraft_engine::sample_session(512, 256).unwrap();
|
||||
session.active_set = 1;
|
||||
let low = execute(&mut session, "layer.add.fill", &json!({})).unwrap()["layer"].clone();
|
||||
execute(&mut session, "effect.add.anchor", &json!({"layer": low, "target": "content", "name": BELOW})).unwrap();
|
||||
let source = execute(&mut session, "layer.add.fill", &json!({"color": [0.8, 0.3, 0.1]})).unwrap()["layer"].clone();
|
||||
execute(&mut session, "mask.add.black", &json!({"layer": source})).unwrap();
|
||||
let added = execute(&mut session, "effect.add.generator", &json!({"layer": source, "generator": "dirt", "microHeight": true})).unwrap();
|
||||
let effect = LayerId(added["effect"].as_u64().unwrap());
|
||||
let between = execute(&mut session, "layer.add.fill", &json!({})).unwrap()["layer"].clone();
|
||||
execute(&mut session, "effect.add.anchor", &json!({"layer": between, "target": "content", "name": BETWEEN})).unwrap();
|
||||
let instance = execute(&mut session, "layer.instance", &json!({"layer": source})).unwrap()["layer"].clone();
|
||||
execute(&mut session, "layer.select", &json!({"layer": instance})).unwrap();
|
||||
session.target = texturecraft_engine::StackTarget::Effect(effect);
|
||||
let mut harness = Harness::builder().with_size(egui::vec2(1600.0, 2400.0)).build_eframe(|context| TextureCraftApp::new(context, session));
|
||||
harness.state_mut().ui.dock.close(Panel::Layers);
|
||||
harness.state_mut().ui.dock.focus(Panel::Properties);
|
||||
harness.run_steps(6);
|
||||
|
||||
harness.get_by_role_and_label(Role::Button, "Micro Details").scroll_to_me();
|
||||
harness.run_steps(3);
|
||||
harness.get_by_role_and_label(Role::Button, "Micro Details").click();
|
||||
harness.run_steps(3);
|
||||
slot_reading(&harness, "Empty").scroll_to_me();
|
||||
harness.run_steps(3);
|
||||
slot_reading(&harness, "Empty").click();
|
||||
harness.run_steps(3);
|
||||
harness.get_by_role_and_label(Role::Tab, "Anchor points").click();
|
||||
harness.run_steps(3);
|
||||
|
||||
let offered: Vec<_> = harness.get_all_by_role(Role::ListBoxOption).filter_map(|row| row.accesskit_node().label()).collect();
|
||||
assert!(offered.iter().any(|label| label.contains(BELOW)), "the anchor below the source is offered: {offered:?}");
|
||||
assert!(!offered.iter().any(|label| label.contains(BETWEEN)), "the anchor above the source is excluded: {offered:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "requires a GPU adapter and TC_UI_SNAPSHOTS"]
|
||||
fn generator_panel_snapshots() {
|
||||
@@ -438,6 +503,14 @@ fn a_point_pick_waits_for_the_view_until_escape() {
|
||||
harness.run_steps(3);
|
||||
|
||||
assert!(!is_on(&harness, Role::Button, end), "a pick left behind is dropped");
|
||||
|
||||
// A kind without the point drops it too: swapped back, it waits no more
|
||||
click_live(&mut harness, Role::Button, end);
|
||||
for kind in ["position", "3dLinearGradient"] {
|
||||
execute(&mut harness.state_mut().session, "effect.set", &json!({"effect": effect.0, "generator": kind})).unwrap();
|
||||
harness.run_steps(3);
|
||||
}
|
||||
assert!(!is_on(&harness, Role::Button, end), "a pick on a swapped kind is dropped");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -95,8 +95,8 @@ fn generator_picker_snapshots() {
|
||||
harness.render().unwrap().save(output.join(format!("{name}.png"))).unwrap();
|
||||
}
|
||||
|
||||
// The picker's tile is the button named Dirt
|
||||
harness.get_by_role_and_label(Role::Button, "Dirt").hover();
|
||||
// The picker's tile is the list option named Dirt
|
||||
harness.get_by_role_and_label(Role::ListBoxOption, "Dirt").hover();
|
||||
for _ in 0..10 {
|
||||
harness.run_steps(5);
|
||||
std::thread::sleep(std::time::Duration::from_millis(300));
|
||||
|
||||
Reference in new issue
Block a user