| author | |
| committer | |
| log | ff950de2d8df46a71fe6ad45cbb5b20c133047e2 |
| tree | 2b02741ed3b9b3b1aad9d658e87180d30cafec4c |
| parent | f60d159351e7c773c239e898fbd488906efe1579 |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
Pages, groups and control kinds come from scripts/tool_catalog.json (parsed once
off-thread into a OnceLock). RGBA/range/toggle inputs fuse into one row; rows use
Slider, ScrewControl, RangeSlider, ColorPicker, SegmentedControl and CompactDisclosure.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>11 files changed, 2059 insertions(+), 1625 deletions(-)
crates/app/src/inspector/catalog.rs created+181| ... | ... | @@ -0,0 +1,181 @@ |
| 1 | //! Fusion 21.1 `:GetInputList()` / `:GetAttrs()` catalog (`scripts/tool_catalog.json`), parsed | |
| 2 | //! once into typed [`InputDef`]s and pre-grouped [`ToolLayout`]s. Frames only read the result. | |
| 3 | ||
| 4 | use super::layout::{ToolLayout, build_layout}; | |
| 5 | use draw::trace::Value; | |
| 6 | use std::collections::HashMap; | |
| 7 | use std::sync::OnceLock; | |
| 8 | ||
| 9 | /// The Fusion `INPID_InputControl`s the Inspector can edit. | |
| 10 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] | |
| 11 | pub enum Control { | |
| 12 | Slider, | |
| 13 | Screw, | |
| 14 | Range, | |
| 15 | Color, | |
| 16 | MultiButton, | |
| 17 | Combo, | |
| 18 | Checkbox, | |
| 19 | Offset, | |
| 20 | Text, | |
| 21 | } | |
| 22 | ||
| 23 | /// One input as Fusion registers it, before grouping into rows. | |
| 24 | #[derive(Clone, Debug)] | |
| 25 | pub struct InputDef { | |
| 26 | pub id: String, | |
| 27 | pub name: String, | |
| 28 | pub control: Control, | |
| 29 | /// The value is a `FuID`/text string rather than a number. | |
| 30 | pub fuid: bool, | |
| 31 | /// `Number` default in `[0]`; `Point` default `[x, y]`. | |
| 32 | pub default: [f64; 2], | |
| 33 | pub default_text: String, | |
| 34 | /// `INP_MinScale`/`INP_MaxScale`: the range a slider spans. | |
| 35 | pub scale: [f64; 2], | |
| 36 | /// `INP_MinAllowed`/`INP_MaxAllowed`: the hard clamp for typed values. | |
| 37 | pub allowed: [Option<f64>; 2], | |
| 38 | pub integer: bool, | |
| 39 | pub page: Option<String>, | |
| 40 | pub entries: Vec<String>, | |
| 41 | /// `(IC_ControlGroup, IC_ControlID)` binding sibling inputs into one control. | |
| 42 | pub group: Option<(i64, u32)>, | |
| 43 | } | |
| 44 | ||
| 45 | impl InputDef { | |
| 46 | pub fn new(id: &str, name: &str, control: Control) -> Self { | |
| 47 | Self { | |
| 48 | id: id.to_owned(), | |
| 49 | name: name.to_owned(), | |
| 50 | control, | |
| 51 | fuid: false, | |
| 52 | default: [0.0; 2], | |
| 53 | default_text: String::new(), | |
| 54 | scale: [0.0, 1.0], | |
| 55 | allowed: [None; 2], | |
| 56 | integer: false, | |
| 57 | page: None, | |
| 58 | entries: Vec::new(), | |
| 59 | group: None, | |
| 60 | } | |
| 61 | } | |
| 62 | } | |
| 63 | ||
| 64 | pub struct ToolCatalogEntry { | |
| 65 | pub layout: ToolLayout, | |
| 66 | } | |
| 67 | ||
| 68 | static CATALOG: OnceLock<HashMap<String, ToolCatalogEntry>> = OnceLock::new(); | |
| 69 | ||
| 70 | /// The parsed catalog, once a worker has built it; frames use this so they never parse. | |
| 71 | pub fn ready() -> Option<&'static HashMap<String, ToolCatalogEntry>> { | |
| 72 | CATALOG.get() | |
| 73 | } | |
| 74 | ||
| 75 | /// Builds the catalog on first use. Call from a worker thread, never inside a frame. | |
| 76 | pub fn catalog() -> &'static HashMap<String, ToolCatalogEntry> { | |
| 77 | CATALOG.get_or_init(|| { | |
| 78 | let root: Value = include_str!("../../../../scripts/tool_catalog.json") | |
| 79 | .parse() | |
| 80 | .expect("scripts/tool_catalog.json is valid JSON"); | |
| 81 | let tools = root["tools"].as_object().expect("catalog has a `tools` object"); | |
| 82 | tools | |
| 83 | .iter() | |
| 84 | .map(|(kind, tool)| { | |
| 85 | let raw = tool["inputs"].as_array().map_or(&[][..], Vec::as_slice); | |
| 86 | let all_ids = raw.iter().filter_map(|i| i["id"].as_str()).map(str::to_owned).collect(); | |
| 87 | let inputs = raw.iter().filter_map(parse_input).collect(); | |
| 88 | (kind.clone(), ToolCatalogEntry { layout: build_layout(kind, inputs, all_ids) }) | |
| 89 | }) | |
| 90 | .collect() | |
| 91 | }) | |
| 92 | } | |
| 93 | ||
| 94 | fn parse_input(v: &Value) -> Option<InputDef> { | |
| 95 | let id = v["id"].as_str()?; | |
| 96 | let data_type = v["data_type"].as_str()?; | |
| 97 | let fuid = matches!(data_type, "FuID" | "Text"); | |
| 98 | let entries: Vec<String> = v["combo_entries"] | |
| 99 | .as_array() | |
| 100 | .map(|a| a.iter().filter_map(|e| e.as_str().map(str::to_owned)).collect()) | |
| 101 | .unwrap_or_default(); | |
| 102 | let control = control_for(v["input_control"].as_str()?, data_type, !entries.is_empty())?; | |
| 103 | let num = |key: &str| v[key].as_f64(); | |
| 104 | let mut scale = [num("min_scale").unwrap_or(0.0), num("max_scale").unwrap_or(1.0)]; | |
| 105 | if scale[1] <= scale[0] { | |
| 106 | scale[1] = scale[0] + 1.0; | |
| 107 | } | |
| 108 | let default = match &v["default"] { | |
| 109 | Value::Array(a) => [a.first().and_then(Value::as_f64).unwrap_or(0.5), a.get(1).and_then(Value::as_f64).unwrap_or(0.5)], | |
| 110 | d => [d.as_f64().unwrap_or(0.0), 0.0], | |
| 111 | }; | |
| 112 | let name = v["name"].as_str().map_or_else(|| humanize(id), str::to_owned); | |
| 113 | Some(InputDef { | |
| 114 | fuid, | |
| 115 | default, | |
| 116 | default_text: v["default"].as_str().unwrap_or_default().to_owned(), | |
| 117 | scale, | |
| 118 | allowed: [num("min_allowed"), num("max_allowed")], | |
| 119 | integer: v["integer"].as_bool().unwrap_or(false), | |
| 120 | page: v["page"].as_str().map(str::to_owned), | |
| 121 | entries, | |
| 122 | group: v["control_group"].as_i64().map(|g| (g, v["control_id"].as_u64().unwrap_or(0) as u32)), | |
| 123 | ..InputDef::new(id, &name, control) | |
| 124 | }) | |
| 125 | } | |
| 126 | ||
| 127 | /// Maps a Fusion control to an editable one; `None` hides inputs with no editor (images, masks, curves). | |
| 128 | pub(super) fn control_for(name: &str, data_type: &str, has_entries: bool) -> Option<Control> { | |
| 129 | match (name, data_type) { | |
| 130 | ("OffsetControl", "Point") => Some(Control::Offset), | |
| 131 | ("TextEditControl" | "FileControl" | "FontFileControl", "Text" | "FuID") => Some(Control::Text), | |
| 132 | ("ComboControl" | "ComboIDControl", "Number" | "FuID") if has_entries => Some(Control::Combo), | |
| 133 | ("MultiButtonControl" | "MultiButtonIDControl", "Number" | "FuID") if has_entries => Some(Control::MultiButton), | |
| 134 | ("CheckboxControl", "Number") => Some(Control::Checkbox), | |
| 135 | ("ColorControl", "Number") => Some(Control::Color), | |
| 136 | ("RangeControl", "Number") => Some(Control::Range), | |
| 137 | ("ScrewControl", "Number") => Some(Control::Screw), | |
| 138 | (_, "Number") => Some(Control::Slider), | |
| 139 | _ => None, | |
| 140 | } | |
| 141 | } | |
| 142 | ||
| 143 | /// `ShutterAngle` -> `Shutter Angle`; dotted ids read as their last two segments. | |
| 144 | pub fn humanize(id: &str) -> String { | |
| 145 | let segments: Vec<&str> = id.split('.').collect(); | |
| 146 | let tail = &segments[segments.len().saturating_sub(2)..]; | |
| 147 | let mut out = String::new(); | |
| 148 | for seg in tail { | |
| 149 | let mut prev: Option<char> = None; | |
| 150 | for c in seg.chars() { | |
| 151 | let boundary = prev.is_some_and(|p| { | |
| 152 | (p.is_lowercase() && c.is_uppercase()) || (p.is_alphabetic() && c.is_ascii_digit()) | |
| 153 | }); | |
| 154 | if (boundary || prev.is_none()) && !out.is_empty() { | |
| 155 | out.push(' '); | |
| 156 | } | |
| 157 | out.push(c); | |
| 158 | prev = Some(c); | |
| 159 | } | |
| 160 | } | |
| 161 | out | |
| 162 | } | |
| 163 | ||
| 164 | #[cfg(test)] | |
| 165 | mod tests { | |
| 166 | use super::*; | |
| 167 | ||
| 168 | #[test] | |
| 169 | fn parses_every_tool() { | |
| 170 | let cat = catalog(); | |
| 171 | assert!(cat.len() > 100, "only {} tools", cat.len()); | |
| 172 | assert!(cat.values().any(|t| !t.layout.pages.is_empty())); | |
| 173 | } | |
| 174 | ||
| 175 | #[test] | |
| 176 | fn humanizes_ids() { | |
| 177 | assert_eq!(humanize("ShutterAngle"), "Shutter Angle"); | |
| 178 | assert_eq!(humanize("Red1"), "Red 1"); | |
| 179 | assert_eq!(humanize("Transform3DOp.Translate.X"), "Translate X"); | |
| 180 | } | |
| 181 | } |
crates/app/src/inspector/chrome.rs created+271| ... | ... | @@ -0,0 +1,271 @@ |
| 1 | //! The Inspector's frame: header (bypass, name, reset), page tabs, clip summary, stats footer. | |
| 2 | ||
| 3 | use super::edit::Cx; | |
| 4 | use super::{InspectorAction, InspectorPalette}; | |
| 5 | use engine::EvalStats; | |
| 6 | use model::is_supported_tool; | |
| 7 | use ui::{Spec, Ui, fill, fit, px}; | |
| 8 | use winit::keyboard::{Key, NamedKey}; | |
| 9 | ||
| 10 | /// The node-name edit buffer, synced with the selected node. | |
| 11 | #[derive(Default)] | |
| 12 | pub(super) struct Rename { | |
| 13 | pub node: Option<model::NodeId>, | |
| 14 | pub buf: String, | |
| 15 | } | |
| 16 | ||
| 17 | pub(super) fn empty_state(ui: &mut Ui, p: InspectorPalette) { | |
| 18 | ui.open( | |
| 19 | "insp-empty", | |
| 20 | Spec { size: [fill(), fill()], axis: ui::Axis::Y, pad: [14.0, 18.0], gap: 8.0, ..Spec::default() }, | |
| 21 | ); | |
| 22 | ui.leaf( | |
| 23 | "empty-title", | |
| 24 | Spec { size: [fill(), px(20.0)], text: Some("No Node Selected"), font_size: Some(12.5), medium: true, color: Some(p.text), ..Spec::default() }, | |
| 25 | ); | |
| 26 | ui.leaf( | |
| 27 | "empty-hint", | |
| 28 | Spec { | |
| 29 | size: [fill(), fit()], | |
| 30 | text: Some("Select a node in the Flow graph to inspect and keyframe its parameters, or press Shift+Space to add a tool."), | |
| 31 | font_size: Some(11.0), | |
| 32 | overflow: ui::Overflow::Wrap, | |
| 33 | color: Some(p.text_dim), | |
| 34 | ..Spec::default() | |
| 35 | }, | |
| 36 | ); | |
| 37 | ui.close(); | |
| 38 | } | |
| 39 | ||
| 40 | /// Bypass pill, name field and reset action; below them the tool badge and frame number. | |
| 41 | /// Returns whether reset-to-defaults was clicked. | |
| 42 | pub(super) fn header(ui: &mut Ui, pane_id: ui::Id, rename: &mut Rename, cx: &mut Cx) -> bool { | |
| 43 | let p = cx.p; | |
| 44 | let node_id = cx.node; | |
| 45 | let current_name = cx.comp.node(node_id).name.clone(); | |
| 46 | let name_field = pane_id.child(("node-name", node_id.0)); | |
| 47 | if rename.node != Some(node_id) || (ui.focused() != Some(name_field) && rename.buf != current_name) { | |
| 48 | rename.node = Some(node_id); | |
| 49 | rename.buf = current_name.clone(); | |
| 50 | } | |
| 51 | ||
| 52 | ui.open( | |
| 53 | "insp-header", | |
| 54 | Spec { size: [fill(), ui::children()], axis: ui::Axis::Y, pad: [10.0, 8.0], gap: 6.0, fill: Some(p.panel_bg), border: Some(p.rule), ..Spec::default() }, | |
| 55 | ); | |
| 56 | ui.open("insp-name-row", Spec { size: [fill(), px(26.0)], axis: ui::Axis::X, gap: 6.0, ..Spec::default() }); | |
| 57 | ||
| 58 | let bypassed = cx.comp.node(node_id).bypassed; | |
| 59 | let (fill_c, border_c) = if bypassed { | |
| 60 | ([0.85, 0.28, 0.28, 0.28], [0.92, 0.36, 0.36, 0.75]) | |
| 61 | } else { | |
| 62 | ([0.24, 0.78, 0.48, 0.18], [0.28, 0.82, 0.52, 0.55]) | |
| 63 | }; | |
| 64 | let pill = ui.leaf( | |
| 65 | ("insp-pass", node_id.0), | |
| 66 | Spec { | |
| 67 | cursor: Some(winit::window::CursorIcon::Pointer), | |
| 68 | flags: ui::Flags::CLICKABLE, | |
| 69 | size: [px(64.0), px(24.0)], | |
| 70 | text: Some(if bypassed { "Bypassed" } else { "Active" }), | |
| 71 | font_size: Some(10.5), | |
| 72 | medium: true, | |
| 73 | color: Some(p.text), | |
| 74 | fill: Some(fill_c), | |
| 75 | border: Some(border_c), | |
| 76 | radius: 12.0, | |
| 77 | center: true, | |
| 78 | ..Spec::default() | |
| 79 | }, | |
| 80 | ); | |
| 81 | if pill.clicked { | |
| 82 | cx.history.push_snapshot(cx.comp, "Toggle Passthrough"); | |
| 83 | cx.comp.toggle_passthrough(node_id); | |
| 84 | cx.actions.push(InspectorAction::ParamEdited(node_id)); | |
| 85 | } | |
| 86 | ||
| 87 | let name_sig = ui::text_field( | |
| 88 | ui, | |
| 89 | name_field, | |
| 90 | &mut rename.buf, | |
| 91 | "Node name", | |
| 92 | Spec { | |
| 93 | size: [fill(), px(24.0)], | |
| 94 | font_size: Some(12.0), | |
| 95 | medium: true, | |
| 96 | fill: Some(p.bg), | |
| 97 | border: Some(p.rule), | |
| 98 | hover_border: Some(p.accent), | |
| 99 | radius: 4.0, | |
| 100 | pad: [6.0, 2.0], | |
| 101 | ..Spec::default() | |
| 102 | }, | |
| 103 | ); | |
| 104 | let entered = name_sig | |
| 105 | .events | |
| 106 | .iter() | |
| 107 | .any(|ev| matches!(ev, ui::Event::Key { key: Key::Named(NamedKey::Enter), .. })); | |
| 108 | if entered && rename.buf.trim() != current_name { | |
| 109 | let desired = rename.buf.trim().to_owned(); | |
| 110 | cx.history.begin_group(cx.comp, "Rename Node"); | |
| 111 | match cx.comp.rename_node(node_id, &desired) { | |
| 112 | Ok(applied) => { | |
| 113 | cx.history.commit_group(cx.comp); | |
| 114 | rename.buf = applied; | |
| 115 | cx.actions.push(InspectorAction::NodeRenamed(node_id)); | |
| 116 | } | |
| 117 | Err(e) => { | |
| 118 | cx.history.cancel_group(cx.comp); | |
| 119 | rename.buf = current_name; | |
| 120 | cx.actions.push(InspectorAction::StatusNotice(e)); | |
| 121 | } | |
| 122 | } | |
| 123 | ui.set_focus(None); | |
| 124 | } | |
| 125 | ||
| 126 | let reset = ui | |
| 127 | .leaf( | |
| 128 | ("insp-reset", node_id.0), | |
| 129 | Spec { | |
| 130 | cursor: Some(winit::window::CursorIcon::Pointer), | |
| 131 | flags: ui::Flags::CLICKABLE, | |
| 132 | size: [px(24.0), px(24.0)], | |
| 133 | text: Some("↺"), | |
| 134 | font_size: Some(13.0), | |
| 135 | color: Some(p.text_dim), | |
| 136 | hover_fill: Some(p.bg), | |
| 137 | radius: 4.0, | |
| 138 | center: true, | |
| 139 | ..Spec::default() | |
| 140 | }, | |
| 141 | ) | |
| 142 | .clicked; | |
| 143 | ui.close(); | |
| 144 | ||
| 145 | let kind = cx.comp.node(node_id).kind.as_str(); | |
| 146 | ui.open("insp-meta-row", Spec { size: [fill(), px(18.0)], axis: ui::Axis::X, gap: 6.0, ..Spec::default() }); | |
| 147 | ui.leaf( | |
| 148 | "insp-kind-badge", | |
| 149 | Spec { | |
| 150 | size: [fit(), px(18.0)], | |
| 151 | text: Some(kind), | |
| 152 | font_size: Some(10.0), | |
| 153 | medium: true, | |
| 154 | color: Some(p.accent), | |
| 155 | fill: Some([p.accent[0], p.accent[1], p.accent[2], 0.14]), | |
| 156 | border: Some([p.accent[0], p.accent[1], p.accent[2], 0.40]), | |
| 157 | radius: 3.0, | |
| 158 | pad: [6.0, 0.0], | |
| 159 | center: true, | |
| 160 | ..Spec::default() | |
| 161 | }, | |
| 162 | ); | |
| 163 | if !is_supported_tool(kind) { | |
| 164 | ui.leaf( | |
| 165 | "insp-preserved-badge", | |
| 166 | Spec { | |
| 167 | size: [fit(), px(18.0)], | |
| 168 | text: Some("preserved"), | |
| 169 | font_size: Some(9.5), | |
| 170 | medium: true, | |
| 171 | color: Some([0.98, 0.78, 0.40, 1.0]), | |
| 172 | fill: Some([0.24, 0.16, 0.06, 0.85]), | |
| 173 | border: Some([0.92, 0.64, 0.24, 0.60]), | |
| 174 | radius: 3.0, | |
| 175 | pad: [5.0, 0.0], | |
| 176 | center: true, | |
| 177 | ..Spec::default() | |
| 178 | }, | |
| 179 | ); | |
| 180 | } | |
| 181 | ui.leaf("insp-spacer", Spec { size: [fill(), px(18.0)], ..Spec::default() }); | |
| 182 | ui.leaf( | |
| 183 | "insp-frame", | |
| 184 | Spec { size: [fit(), px(18.0)], text: Some(&format!("f{:.0}", cx.frame)), font_size: Some(10.0), color: Some(p.text_dim), center: true, ..Spec::default() }, | |
| 185 | ); | |
| 186 | ui.close(); | |
| 187 | ui.close(); | |
| 188 | reset | |
| 189 | } | |
| 190 | ||
| 191 | /// Underlined page tabs; returns the tab clicked. | |
| 192 | pub(super) fn tabs(ui: &mut Ui, p: InspectorPalette, names: &[&str], active: usize) -> Option<usize> { | |
| 193 | ui.open( | |
| 194 | "insp-tabs", | |
| 195 | Spec { size: [fill(), px(28.0)], axis: ui::Axis::X, flags: ui::Flags::CLIP, pad: [6.0, 0.0], border: Some(p.rule), ..Spec::default() }, | |
| 196 | ); | |
| 197 | let mut clicked = None; | |
| 198 | for (i, name) in names.iter().enumerate() { | |
| 199 | let on = i == active; | |
| 200 | ui.open(("tab", i), Spec { size: [ui::children(), fill()], axis: ui::Axis::Y, ..Spec::default() }); | |
| 201 | let signal = ui.leaf( | |
| 202 | "label", | |
| 203 | Spec { | |
| 204 | cursor: Some(winit::window::CursorIcon::Pointer), | |
| 205 | flags: ui::Flags::CLICKABLE, | |
| 206 | size: [fit(), fill()], | |
| 207 | text: Some(name), | |
| 208 | font_size: Some(11.0), | |
| 209 | medium: on, | |
| 210 | color: Some(if on { p.text } else { p.text_dim }), | |
| 211 | hover_fill: Some(p.panel_bg), | |
| 212 | pad: [8.0, 0.0], | |
| 213 | center: true, | |
| 214 | ..Spec::default() | |
| 215 | }, | |
| 216 | ); | |
| 217 | ui.leaf("rule", Spec { size: [fill(), px(2.0)], fill: on.then_some(p.accent), ..Spec::default() }); | |
| 218 | ui.close(); | |
| 219 | if signal.clicked { | |
| 220 | clicked = Some(i); | |
| 221 | } | |
| 222 | } | |
| 223 | ui.close(); | |
| 224 | clicked | |
| 225 | } | |
| 226 | ||
| 227 | /// The Loader/Saver's first clip path. | |
| 228 | pub(super) fn clip_summary(ui: &mut Ui, cx: &Cx) { | |
| 229 | let node = cx.comp.node(cx.node); | |
| 230 | let heading = if node.kind == "Saver" { "Output Filename" } else { "Clip Filename" }; | |
| 231 | let path = node | |
| 232 | .clips | |
| 233 | .first() | |
| 234 | .map(|c| c.filename.as_str()) | |
| 235 | .or_else(|| { | |
| 236 | node.raw | |
| 237 | .get_table("Inputs")? | |
| 238 | .get_table("Clip")? | |
| 239 | .get_table("Value")? | |
| 240 | .get_str("Filename") | |
| 241 | }) | |
| 242 | .unwrap_or("(no clip)"); | |
| 243 | let p = cx.p; | |
| 244 | ui.open( | |
| 245 | "insp-loader-clip", | |
| 246 | Spec { size: [fill(), ui::children()], axis: ui::Axis::Y, gap: 3.0, pad: [6.0, 5.0], fill: Some(p.panel_bg), border: Some(p.rule), radius: 4.0, ..Spec::default() }, | |
| 247 | ); | |
| 248 | ui.leaf("clip-lbl", Spec { size: [fill(), px(14.0)], text: Some(heading), font_size: Some(10.0), color: Some(p.text_dim), ..Spec::default() }); | |
| 249 | ui.leaf( | |
| 250 | "clip-path", | |
| 251 | Spec { size: [fill(), fit()], text: Some(path), font_size: Some(10.5), overflow: ui::Overflow::Wrap, color: Some(p.text), ..Spec::default() }, | |
| 252 | ); | |
| 253 | ui.close(); | |
| 254 | } | |
| 255 | ||
| 256 | pub(super) fn footer(ui: &mut Ui, p: InspectorPalette, stats: &EvalStats) { | |
| 257 | let line = format!( | |
| 258 | "Eval {:.1}ms · {} nodes · cache {}/{} · {:.0}MB", | |
| 259 | stats.eval_ms, | |
| 260 | stats.nodes_evaluated, | |
| 261 | stats.cache_hits, | |
| 262 | stats.cache_hits + stats.cache_misses, | |
| 263 | stats.cached_vram_mb, | |
| 264 | ); | |
| 265 | ui.open( | |
| 266 | "insp-footer", | |
| 267 | Spec { size: [fill(), px(24.0)], axis: ui::Axis::X, pad: [10.0, 4.0], fill: Some(p.panel_bg), border: Some(p.rule), ..Spec::default() }, | |
| 268 | ); | |
| 269 | ui.leaf("insp-stats-txt", Spec { size: [fill(), fill()], text: Some(&line), font_size: Some(10.0), color: Some(p.text_dim), ..Spec::default() }); | |
| 270 | ui.close(); | |
| 271 | } |
crates/app/src/inspector/controls.rs created+372| ... | ... | @@ -0,0 +1,372 @@ |
| 1 | //! Fusion's four-column parameter row — right-aligned label, control, value box(es), keyframe | |
| 2 | //! diamond — and one renderer per control kind, built from the Knife `ui` primitives. | |
| 3 | ||
| 4 | use super::edit::{Cx, NumberEdit}; | |
| 5 | use super::layout::{Channel, ControlDef, Kind}; | |
| 6 | use super::widgets::{MARK_W, expression_badge, format_param_number, keyframe_button}; | |
| 7 | use model::ParamValue; | |
| 8 | use ui::{Spec, Ui, fill, fit, px}; | |
| 9 | use winit::keyboard::{Key, NamedKey}; | |
| 10 | ||
| 11 | const LABEL_W: f32 = 115.0; | |
| 12 | const ROW_H: f32 = 24.0; | |
| 13 | const BOX_H: f32 = 20.0; | |
| 14 | ||
| 15 | pub(super) fn render(ui: &mut Ui, cx: &mut Cx, def: &ControlDef) { | |
| 16 | let channels = def.channels.as_slice(); | |
| 17 | let animatable = match def.kind { | |
| 18 | Kind::Slider | Kind::Screw | Kind::Range | Kind::Color | Kind::Checkbox | Kind::Toggles => true, | |
| 19 | Kind::Segmented | Kind::Combo => !def.fuid, | |
| 20 | Kind::Point | Kind::Text => false, | |
| 21 | }; | |
| 22 | let marks = if animatable { channels } else { &[] }; | |
| 23 | match def.kind { | |
| 24 | Kind::Slider => { | |
| 25 | let ch = &channels[0]; | |
| 26 | let sub = sub_labels(&ch.id); | |
| 27 | let height = px(if sub.is_some() { ROW_H + 14.0 } else { ROW_H }); | |
| 28 | row(ui, cx, &def.label, &ch.id, marks, height, |ui, cx| { | |
| 29 | let value = cx.number(ch); | |
| 30 | let mut spec = ui::Slider::new(value as f32, ch.scale[0] as f32, ch.scale[1] as f32, cx.default_of(ch) as f32); | |
| 31 | spec.step = ch.integer.then_some(1.0); | |
| 32 | spec.sub_labels = sub; | |
| 33 | spec.label = &def.label; | |
| 34 | if let Some(next) = ui::slider(ui, ("sld", cx.node.0, ch.id.as_str()), spec) { | |
| 35 | cx.write_numbers(&def.label, &[(ch, f64::from(next))], true); | |
| 36 | } | |
| 37 | number_box(ui, cx, ch, None, value, px(52.0)); | |
| 38 | }); | |
| 39 | } | |
| 40 | Kind::Screw => { | |
| 41 | let ch = &channels[0]; | |
| 42 | row(ui, cx, &def.label, &ch.id, marks, px(ROW_H), |ui, cx| { | |
| 43 | let value = cx.number(ch); | |
| 44 | let mut spec = ui::ScrewControl::new(value as f32, cx.default_of(ch) as f32); | |
| 45 | spec.sensitivity = ((ch.scale[1] - ch.scale[0]) / 360.0).max(0.001) as f32; | |
| 46 | spec.bounds = ch.allowed[0].zip(ch.allowed[1]).map(|(lo, hi)| [lo as f32, hi as f32]); | |
| 47 | spec.width = fill(); | |
| 48 | spec.label = &def.label; | |
| 49 | if let Some(next) = ui::screw_control(ui, ("scw", cx.node.0, ch.id.as_str()), spec) { | |
| 50 | cx.write_numbers(&def.label, &[(ch, f64::from(next))], true); | |
| 51 | } | |
| 52 | number_box(ui, cx, ch, None, value, px(52.0)); | |
| 53 | }); | |
| 54 | } | |
| 55 | Kind::Range => { | |
| 56 | let [start, end] = [&channels[0], &channels[1]]; | |
| 57 | row(ui, cx, &def.label, &start.id, marks, px(ROW_H), |ui, cx| { | |
| 58 | let [s, e] = [cx.number(start), cx.number(end)]; | |
| 59 | let mut spec = ui::RangeSlider::new( | |
| 60 | s as f32, | |
| 61 | e as f32, | |
| 62 | start.scale[0] as f32, | |
| 63 | start.scale[1] as f32, | |
| 64 | [cx.default_of(start) as f32, cx.default_of(end) as f32], | |
| 65 | ); | |
| 66 | spec.step = start.integer.then_some(1.0); | |
| 67 | spec.label = &def.label; | |
| 68 | if let Some([ns, ne]) = ui::range_slider(ui, ("rng", cx.node.0, start.id.as_str()), spec) { | |
| 69 | let moved = |old: f64, new: f32| (f64::from(new) - old).abs() > 1e-6; | |
| 70 | let edits: Vec<_> = [(start, s, ns), (end, e, ne)] | |
| 71 | .into_iter() | |
| 72 | .filter(|&(_, old, new)| moved(old, new)) | |
| 73 | .map(|(ch, _, new)| (ch, f64::from(new))) | |
| 74 | .collect(); | |
| 75 | cx.write_numbers(&def.label, &edits, true); | |
| 76 | } | |
| 77 | number_box(ui, cx, start, None, s, px(44.0)); | |
| 78 | number_box(ui, cx, end, None, e, px(44.0)); | |
| 79 | }); | |
| 80 | } | |
| 81 | Kind::Color => color(ui, cx, def), | |
| 82 | Kind::Checkbox => { | |
| 83 | let ch = &channels[0]; | |
| 84 | row(ui, cx, &def.label, &ch.id, marks, px(ROW_H), |ui, cx| { | |
| 85 | let on = cx.number(ch) >= 0.5; | |
| 86 | if checkbox(ui, ("chk", cx.node.0, ch.id.as_str()), on, &def.label) { | |
| 87 | cx.write_numbers(&def.label, &[(ch, f64::from(u8::from(!on)))], false); | |
| 88 | } | |
| 89 | spacer(ui); | |
| 90 | }); | |
| 91 | } | |
| 92 | Kind::Toggles => row(ui, cx, &def.label, &channels[0].id, marks, px(ROW_H), |ui, cx| { | |
| 93 | for (ch, name) in channels.iter().zip(&def.entries) { | |
| 94 | let on = cx.number(ch) >= 0.5; | |
| 95 | if toggle_button(ui, cx, ("tgl", cx.node.0, ch.id.as_str()), name, on) { | |
| 96 | cx.write_numbers(name, &[(ch, f64::from(u8::from(!on)))], false); | |
| 97 | } | |
| 98 | } | |
| 99 | spacer(ui); | |
| 100 | }), | |
| 101 | Kind::Segmented => { | |
| 102 | let ch = &channels[0]; | |
| 103 | row(ui, cx, &def.label, &ch.id, marks, px(ROW_H + 2.0), |ui, cx| { | |
| 104 | let segments: Vec<_> = def.entries.iter().map(|e| ui::MultiSegment::text(e)).collect(); | |
| 105 | let mut spec = ui::SegmentedControl::new(&segments, choice_index(cx, def)); | |
| 106 | spec.width = fill(); | |
| 107 | spec.label = &def.label; | |
| 108 | if let Some(next) = ui::segmented_control(ui, ("seg", cx.node.0, ch.id.as_str()), spec) { | |
| 109 | write_choice(cx, def, next); | |
| 110 | } | |
| 111 | }); | |
| 112 | } | |
| 113 | Kind::Combo => { | |
| 114 | let ch = &channels[0]; | |
| 115 | row(ui, cx, &def.label, &ch.id, marks, px(ROW_H + 6.0), |ui, cx| { | |
| 116 | let current = choice_index(cx, def); | |
| 117 | let items: Vec<_> = def | |
| 118 | .entries | |
| 119 | .iter() | |
| 120 | .enumerate() | |
| 121 | .map(|(i, e)| ui::popup::Item { text: e, current: i == current, ..Default::default() }) | |
| 122 | .collect(); | |
| 123 | let shown = def.entries.get(current).map_or("", String::as_str); | |
| 124 | let part = ("cmb", cx.node.0, ch.id.as_str()); | |
| 125 | if let Some(next) = ui::form::select(ui, part, &def.label, shown, &items, fill(), true) { | |
| 126 | write_choice(cx, def, next); | |
| 127 | } | |
| 128 | }); | |
| 129 | } | |
| 130 | Kind::Point => { | |
| 131 | let ch = &channels[0]; | |
| 132 | row(ui, cx, &def.label, &ch.id, marks, px(ROW_H), |ui, cx| { | |
| 133 | let point = cx.point(ch); | |
| 134 | for (axis, name) in ["X", "Y"].into_iter().enumerate() { | |
| 135 | ui.leaf(name, Spec { size: [px(10.0), fill()], text: Some(name), font_size: Some(10.0), color: Some(cx.p.text_dim), center: true, ..Spec::default() }); | |
| 136 | number_box(ui, cx, ch, Some(axis), point[axis], fill()); | |
| 137 | } | |
| 138 | spacer(ui); | |
| 139 | }); | |
| 140 | } | |
| 141 | Kind::Text => text(ui, cx, def), | |
| 142 | } | |
| 143 | } | |
| 144 | ||
| 145 | /// `(left, right)` words under a slider's track. | |
| 146 | fn sub_labels(id: &str) -> Option<(&'static str, &'static str)> { | |
| 147 | (id == "SubtractiveAdditive").then_some(("Subtractive", "Additive")) | |
| 148 | } | |
| 149 | ||
| 150 | fn spacer(ui: &mut Ui) { | |
| 151 | ui.leaf("pad", Spec { size: [px(0.0), fill()], ..Spec::default() }); | |
| 152 | } | |
| 153 | ||
| 154 | /// Label column, `body`, then the expression badge and keyframe diamond of `marks`. | |
| 155 | fn row(ui: &mut Ui, cx: &mut Cx, label: &str, key: impl std::hash::Hash, marks: &[Channel], height: ui::Extent, body: impl FnOnce(&mut Ui, &mut Cx)) { | |
| 156 | ui.open( | |
| 157 | ("row", cx.node.0, key), | |
| 158 | Spec { size: [fill(), height], axis: ui::Axis::X, gap: 6.0, pad: [4.0, 1.0], ..Spec::default() }, | |
| 159 | ); | |
| 160 | let label_h = if height == ui::children() { px(ROW_H - 2.0) } else { fill() }; | |
| 161 | ui.open("lbl", Spec { size: [px(LABEL_W), label_h], axis: ui::Axis::X, flags: ui::Flags::CLIP, ..Spec::default() }); | |
| 162 | ui.leaf("fill", Spec { size: [fill(), fill()], ..Spec::default() }); | |
| 163 | ui.leaf( | |
| 164 | "text", | |
| 165 | Spec { size: [fit(), label_h], text: Some(label), font_size: Some(10.5), color: Some(cx.p.text_dim), ..Spec::default() }, | |
| 166 | ); | |
| 167 | ui.close(); | |
| 168 | body(ui, cx); | |
| 169 | if cx.has_expression(marks) { | |
| 170 | expression_badge(ui); | |
| 171 | } | |
| 172 | if marks.is_empty() { | |
| 173 | ui.leaf("mark-gap", Spec { size: [px(MARK_W), fill()], ..Spec::default() }); | |
| 174 | } else { | |
| 175 | let state = cx.key_state(marks); | |
| 176 | if keyframe_button(ui, cx, state) { | |
| 177 | cx.toggle_keyframes(label, marks, state); | |
| 178 | } | |
| 179 | } | |
| 180 | ui.close(); | |
| 181 | } | |
| 182 | ||
| 183 | /// The numeric well beside a control; typing commits when it loses the keys. | |
| 184 | fn number_box(ui: &mut Ui, cx: &mut Cx, ch: &Channel, axis: Option<usize>, value: f64, width: ui::Extent) { | |
| 185 | let id = ui.id(("num", cx.node.0, ch.id.as_str(), axis)); | |
| 186 | let focused = ui.focused() == Some(id); | |
| 187 | if focused && cx.edit.number.as_ref().is_none_or(|e| e.id != id) { | |
| 188 | cx.edit.number = Some(NumberEdit { id, buf: format_value(ch, value), channel: ch.clone(), axis }); | |
| 189 | ui.focus_all(id); | |
| 190 | } | |
| 191 | let mut shown; | |
| 192 | let buf = match cx.edit.number.as_mut() { | |
| 193 | Some(edit) if focused => &mut edit.buf, | |
| 194 | _ => { | |
| 195 | shown = format_value(ch, value); | |
| 196 | &mut shown | |
| 197 | } | |
| 198 | }; | |
| 199 | let signal = ui::text_field( | |
| 200 | ui, | |
| 201 | id, | |
| 202 | buf, | |
| 203 | "", | |
| 204 | Spec { | |
| 205 | size: [width, px(BOX_H)], | |
| 206 | font_size: Some(10.5), | |
| 207 | fill: Some(cx.p.panel_bg), | |
| 208 | border: Some(cx.p.rule), | |
| 209 | hover_border: Some(cx.p.accent), | |
| 210 | radius: 3.0, | |
| 211 | pad: [4.0, 2.0], | |
| 212 | ..Spec::default() | |
| 213 | }, | |
| 214 | ); | |
| 215 | for event in &signal.events { | |
| 216 | match event { | |
| 217 | ui::Event::Key { key: Key::Named(NamedKey::Enter), .. } => ui.set_focus(None), | |
| 218 | ui::Event::Key { key: Key::Named(NamedKey::Escape), .. } => { | |
| 219 | cx.edit.number = None; | |
| 220 | ui.set_focus(None); | |
| 221 | } | |
| 222 | _ => {} | |
| 223 | } | |
| 224 | } | |
| 225 | } | |
| 226 | ||
| 227 | fn format_value(ch: &Channel, value: f64) -> String { | |
| 228 | if ch.integer { format!("{}", value.round()) } else { format_param_number(value) } | |
| 229 | } | |
| 230 | ||
| 231 | fn checkbox(ui: &mut Ui, part: impl std::hash::Hash, on: bool, label: &str) -> bool { | |
| 232 | let id = ui.id(part); | |
| 233 | let signal = ui.signal(id); | |
| 234 | ui.open_as( | |
| 235 | id, | |
| 236 | Spec { | |
| 237 | cursor: Some(winit::window::CursorIcon::Pointer), | |
| 238 | flags: ui::Flags::CLICKABLE | ui::Flags::FOCUSABLE, | |
| 239 | size: [px(BOX_H), px(BOX_H)], | |
| 240 | role: Some(accesskit::Role::CheckBox), | |
| 241 | ..Spec::default() | |
| 242 | }, | |
| 243 | ); | |
| 244 | ui::check(ui, "mark", Some(on), true, signal.hovered, Some(id)); | |
| 245 | ui.close(); | |
| 246 | if let Some(node) = ui.access(id) { | |
| 247 | node.set_label(label); | |
| 248 | } | |
| 249 | let space = signal.events.iter().any(|e| matches!(e, ui::Event::Key { key: Key::Named(NamedKey::Space), .. })); | |
| 250 | signal.clicked || space | |
| 251 | } | |
| 252 | ||
| 253 | fn toggle_button(ui: &mut Ui, cx: &Cx, part: impl std::hash::Hash, label: &str, on: bool) -> bool { | |
| 254 | let p = cx.p; | |
| 255 | ui.leaf( | |
| 256 | part, | |
| 257 | Spec { | |
| 258 | cursor: Some(winit::window::CursorIcon::Pointer), | |
| 259 | flags: ui::Flags::CLICKABLE, | |
| 260 | size: [fit(), px(BOX_H)], | |
| 261 | text: Some(label), | |
| 262 | font_size: Some(10.5), | |
| 263 | medium: on, | |
| 264 | color: Some(if on { p.text } else { p.text_dim }), | |
| 265 | fill: Some(if on { [p.accent[0], p.accent[1], p.accent[2], 0.28] } else { p.panel_bg }), | |
| 266 | border: Some(if on { p.accent } else { p.rule }), | |
| 267 | hover_border: Some(p.accent), | |
| 268 | radius: 3.0, | |
| 269 | pad: [7.0, 0.0], | |
| 270 | center: true, | |
| 271 | ..Spec::default() | |
| 272 | }, | |
| 273 | ) | |
| 274 | .clicked | |
| 275 | } | |
| 276 | ||
| 277 | fn choice_index(cx: &Cx, def: &ControlDef) -> usize { | |
| 278 | let ch = &def.channels[0]; | |
| 279 | if def.fuid { | |
| 280 | let current = cx.comp.node(cx.node).static_str(&ch.id).unwrap_or(&def.default_text); | |
| 281 | def.entries.iter().position(|e| e == current).unwrap_or(def.default_index) | |
| 282 | } else { | |
| 283 | cx.number(ch).round().max(0.0) as usize | |
| 284 | } | |
| 285 | } | |
| 286 | ||
| 287 | fn write_choice(cx: &mut Cx, def: &ControlDef, index: usize) { | |
| 288 | let ch = &def.channels[0]; | |
| 289 | if def.fuid { | |
| 290 | cx.write_value(&def.label, &ch.id, ParamValue::FuId(def.entries[index].clone())); | |
| 291 | } else { | |
| 292 | cx.write_numbers(&def.label, &[(ch, index as f64)], false); | |
| 293 | } | |
| 294 | } | |
| 295 | ||
| 296 | /// Inline picker over the R/G/B(/A) channels, with a slider row per channel under it. | |
| 297 | fn color(ui: &mut Ui, cx: &mut Cx, def: &ControlDef) { | |
| 298 | let channels = def.channels.as_slice(); | |
| 299 | let current: Vec<f64> = channels.iter().map(|ch| cx.number(ch)).collect(); | |
| 300 | row(ui, cx, &def.label, ("group", &channels[0].id), channels, ui::children(), |ui, cx| { | |
| 301 | let rgba = [0, 1, 2, 3].map(|i| current.get(i).map_or(1.0, |v| v.clamp(0.0, 1.0) as f32)); | |
| 302 | let mut spec = ui::ColorPicker::new(rgba); | |
| 303 | spec.width = fill(); | |
| 304 | spec.label = &def.label; | |
| 305 | let response = ui::color_picker(ui, ("clr", cx.node.0, channels[0].id.as_str()), spec); | |
| 306 | if let Some(next) = response.changed { | |
| 307 | let edits: Vec<_> = channels | |
| 308 | .iter() | |
| 309 | .zip(next) | |
| 310 | .zip(rgba) | |
| 311 | .filter(|((_, new), old)| (new - old).abs() > 1e-6) | |
| 312 | .map(|((ch, new), _)| (ch, f64::from(new))) | |
| 313 | .collect(); | |
| 314 | cx.write_numbers(&def.label, &edits, true); | |
| 315 | } | |
| 316 | }); | |
| 317 | for (ch, name) in channels.iter().zip(["Red", "Green", "Blue", "Alpha"]) { | |
| 318 | row(ui, cx, name, &ch.id, &[], px(ROW_H), |ui, cx| { | |
| 319 | let value = cx.number(ch); | |
| 320 | let mut spec = ui::Slider::new(value as f32, 0.0, 1.0, cx.default_of(ch) as f32); | |
| 321 | spec.label = name; | |
| 322 | if let Some(next) = ui::slider(ui, ("clr-sld", cx.node.0, ch.id.as_str()), spec) { | |
| 323 | cx.write_numbers(&def.label, &[(ch, f64::from(next))], true); | |
| 324 | } | |
| 325 | number_box(ui, cx, ch, None, value, px(52.0)); | |
| 326 | }); | |
| 327 | } | |
| 328 | } | |
| 329 | ||
| 330 | /// A text well; edits apply live and fold into one undo step until it loses the keys. | |
| 331 | fn text(ui: &mut Ui, cx: &mut Cx, def: &ControlDef) { | |
| 332 | let ch = &def.channels[0]; | |
| 333 | row(ui, cx, &def.label, &ch.id, &[], px(ROW_H), |ui, cx| { | |
| 334 | let id = ui.id(("txt", cx.node.0, ch.id.as_str())); | |
| 335 | let focused = ui.focused() == Some(id); | |
| 336 | let model = cx.comp.node(cx.node).static_str(&ch.id).unwrap_or(&def.default_text).to_owned(); | |
| 337 | if focused && cx.edit.text.as_ref().is_none_or(|(owner, _)| *owner != id) { | |
| 338 | cx.edit.text = Some((id, model.clone())); | |
| 339 | } | |
| 340 | let mut shown = model; | |
| 341 | let buf = match cx.edit.text.as_mut() { | |
| 342 | Some((_, buf)) if focused => buf, | |
| 343 | _ => &mut shown, | |
| 344 | }; | |
| 345 | let before = buf.clone(); | |
| 346 | let signal = ui::text_field( | |
| 347 | ui, | |
| 348 | id, | |
| 349 | buf, | |
| 350 | &def.label, | |
| 351 | Spec { | |
| 352 | size: [fill(), px(BOX_H)], | |
| 353 | font_size: Some(10.5), | |
| 354 | fill: Some(cx.p.panel_bg), | |
| 355 | border: Some(cx.p.rule), | |
| 356 | hover_border: Some(cx.p.accent), | |
| 357 | radius: 3.0, | |
| 358 | pad: [6.0, 2.0], | |
| 359 | ..Spec::default() | |
| 360 | }, | |
| 361 | ); | |
| 362 | if *buf != before { | |
| 363 | let value = if def.fuid { ParamValue::FuId(buf.clone()) } else { ParamValue::Text(buf.clone()) }; | |
| 364 | cx.history.push_coalesced(cx.comp, format!("Edit {}", def.label), format!("text:{}:{}", cx.node.0, ch.id)); | |
| 365 | cx.comp.set_input_value(cx.node, &ch.id, value); | |
| 366 | cx.actions.push(super::InspectorAction::ParamEdited(cx.node)); | |
| 367 | } | |
| 368 | if signal.events.iter().any(|e| matches!(e, ui::Event::Key { key: Key::Named(NamedKey::Enter), .. })) { | |
| 369 | cx.history.break_coalescing(); | |
| 370 | } | |
| 371 | }); | |
| 372 | } |
crates/app/src/inspector/dynamic.rs created+156| ... | ... | @@ -0,0 +1,156 @@ |
| 1 | //! Inputs the catalog cannot describe: a node's own `UserControls`, tools Fusion's introspection | |
| 2 | //! skipped (curated schemas), and live inputs no row covers. | |
| 3 | ||
| 4 | use super::catalog::{Control, InputDef, control_for, humanize}; | |
| 5 | use super::layout::{ToolLayout, build_layout}; | |
| 6 | use super::schemas::{ParamKind, infer_float_range, schema_for_kind}; | |
| 7 | use model::{Comp, LuaKey, LuaTable, NodeId, ParamValue}; | |
| 8 | use std::collections::HashSet; | |
| 9 | ||
| 10 | /// Rows for each `UserControls` entry of a tool/macro/group table, grouped into pages by | |
| 11 | /// `ICS_ControlPage`. | |
| 12 | pub fn user_defs(raw: &LuaTable) -> Vec<InputDef> { | |
| 13 | let Some(controls) = raw.get_table("UserControls") else { return Vec::new() }; | |
| 14 | controls | |
| 15 | .entries | |
| 16 | .iter() | |
| 17 | .filter_map(|(key, value)| { | |
| 18 | let LuaKey::Str(id) = key else { return None }; | |
| 19 | user_def(id, value.as_table()?) | |
| 20 | }) | |
| 21 | .collect() | |
| 22 | } | |
| 23 | ||
| 24 | fn user_def(id: &str, t: &LuaTable) -> Option<InputDef> { | |
| 25 | let data_type = t.get_str("LINKID_DataType").unwrap_or("Number"); | |
| 26 | let entries: Vec<String> = t | |
| 27 | .positional_values() | |
| 28 | .filter_map(|v| v.as_table()) | |
| 29 | .filter_map(|e| e.get_str("CCS_AddString").or(e.get_str("CCID_AddID")).or(e.get_str("MBTNC_AddButton"))) | |
| 30 | .map(str::to_owned) | |
| 31 | .collect(); | |
| 32 | let control_name = t.get_str("INPID_InputControl").unwrap_or(match data_type { | |
| 33 | "Point" => "OffsetControl", | |
| 34 | "Text" | "FuID" => "TextEditControl", | |
| 35 | _ => "SliderControl", | |
| 36 | }); | |
| 37 | let control = control_for(control_name, data_type, !entries.is_empty())?; | |
| 38 | let mut scale = [t.get_f64("INP_MinScale").unwrap_or(0.0), t.get_f64("INP_MaxScale").unwrap_or(1.0)]; | |
| 39 | if scale[1] <= scale[0] { | |
| 40 | scale[1] = scale[0] + 1.0; | |
| 41 | } | |
| 42 | let name = t.get_str("LINKS_Name").map_or_else(|| humanize(id), str::to_owned); | |
| 43 | Some(InputDef { | |
| 44 | fuid: matches!(data_type, "FuID" | "Text"), | |
| 45 | default: if data_type == "Point" { | |
| 46 | [t.get_f64("INP_DefaultX").unwrap_or(0.5), t.get_f64("INP_DefaultY").unwrap_or(0.5)] | |
| 47 | } else { | |
| 48 | [t.get_f64("INP_Default").unwrap_or(0.0), 0.0] | |
| 49 | }, | |
| 50 | default_text: t.get_str("INP_Default").unwrap_or_default().to_owned(), | |
| 51 | scale, | |
| 52 | allowed: [t.get_f64("INP_MinAllowed"), t.get_f64("INP_MaxAllowed")], | |
| 53 | integer: t.get_bool("INP_Integer").unwrap_or(false), | |
| 54 | page: Some(t.get_str("ICS_ControlPage").unwrap_or("User").to_owned()), | |
| 55 | entries, | |
| 56 | group: t.get_f64("IC_ControlGroup").map(|g| (g as i64, t.get_f64("IC_ControlID").unwrap_or(0.0) as u32)), | |
| 57 | ..InputDef::new(id, &name, control) | |
| 58 | }) | |
| 59 | } | |
| 60 | ||
| 61 | /// Rows for live inputs of `node` that `covered` rejects, typed by their stored value. | |
| 62 | pub fn extra_defs(comp: &Comp, node: NodeId, covered: impl Fn(&str) -> bool) -> Vec<InputDef> { | |
| 63 | let mut keys: Vec<&String> = comp | |
| 64 | .node(node) | |
| 65 | .inputs | |
| 66 | .iter() | |
| 67 | .filter(|(key, b)| { | |
| 68 | let wired = b.source_op.as_deref().is_some_and(|op| comp.node_by_name.contains_key(op)); | |
| 69 | !covered(key) | |
| 70 | && !(wired && b.value.is_none()) | |
| 71 | && (b.value.is_some() || b.expression.is_some() || b.source_op.is_some()) | |
| 72 | }) | |
| 73 | .map(|(key, _)| key) | |
| 74 | .collect(); | |
| 75 | keys.sort(); | |
| 76 | keys.into_iter() | |
| 77 | .map(|key| { | |
| 78 | let value = comp.node(node).inputs[key].value.as_ref(); | |
| 79 | let (control, fuid) = match value { | |
| 80 | Some(ParamValue::Point(_)) => (Control::Offset, false), | |
| 81 | Some(ParamValue::Text(_)) => (Control::Text, false), | |
| 82 | Some(ParamValue::FuId(_)) => (Control::Text, true), | |
| 83 | _ => (Control::Slider, false), | |
| 84 | }; | |
| 85 | let number = value.and_then(ParamValue::as_f64).unwrap_or(0.0); | |
| 86 | InputDef { | |
| 87 | fuid, | |
| 88 | default: value.and_then(ParamValue::as_point).unwrap_or([number, 0.0]), | |
| 89 | default_text: value.and_then(ParamValue::as_str).unwrap_or_default().to_owned(), | |
| 90 | scale: if control == Control::Slider { infer_float_range(key, number).into() } else { [0.0, 1.0] }, | |
| 91 | page: Some("Other".to_owned()), | |
| 92 | ..InputDef::new(key, key, control) | |
| 93 | } | |
| 94 | }) | |
| 95 | .collect() | |
| 96 | } | |
| 97 | ||
| 98 | /// A layout from the curated schema, for tools the Fusion catalog skipped. | |
| 99 | pub fn curated_layout(kind: &str) -> Option<ToolLayout> { | |
| 100 | let schema = schema_for_kind(kind); | |
| 101 | if schema.is_empty() { | |
| 102 | return None; | |
| 103 | } | |
| 104 | let mut defs = Vec::new(); | |
| 105 | let mut covered = HashSet::new(); | |
| 106 | for spec in schema { | |
| 107 | let base = |control| InputDef { page: Some("Controls".to_owned()), ..InputDef::new(spec.name, spec.label, control) }; | |
| 108 | match spec.kind { | |
| 109 | ParamKind::Float { min, max, default, .. } => { | |
| 110 | defs.push(InputDef { default: [default, 0.0], scale: [min, max], ..base(Control::Slider) }); | |
| 111 | } | |
| 112 | ParamKind::Vec2 { default, .. } => defs.push(InputDef { default, ..base(Control::Offset) }), | |
| 113 | ParamKind::Bool { default } => { | |
| 114 | defs.push(InputDef { default: [f64::from(u8::from(default)), 0.0], integer: true, ..base(Control::Checkbox) }); | |
| 115 | } | |
| 116 | ParamKind::Enum { options, default } => defs.push(InputDef { | |
| 117 | fuid: true, | |
| 118 | default_text: default.to_owned(), | |
| 119 | entries: options.iter().map(|o| (*o).to_owned()).collect(), | |
| 120 | ..base(Control::Combo) | |
| 121 | }), | |
| 122 | ParamKind::IntEnum { options, default } => { | |
| 123 | let sequential = options.iter().enumerate().all(|(i, (code, _))| *code == i as i32); | |
| 124 | defs.push(if sequential { | |
| 125 | InputDef { | |
| 126 | default: [f64::from(default), 0.0], | |
| 127 | entries: options.iter().map(|(_, label)| (*label).to_owned()).collect(), | |
| 128 | ..base(Control::Combo) | |
| 129 | } | |
| 130 | } else { | |
| 131 | let codes = options.iter().map(|(code, _)| f64::from(*code)); | |
| 132 | let hi = codes.clone().fold(f64::MIN, f64::max); | |
| 133 | InputDef { default: [f64::from(default), 0.0], scale: [codes.fold(f64::MAX, f64::min), hi], integer: true, ..base(Control::Slider) } | |
| 134 | }); | |
| 135 | } | |
| 136 | ParamKind::Color { r, g, b, a, default } => { | |
| 137 | for (n, id) in [Some(r), Some(g), Some(b), a].into_iter().enumerate() { | |
| 138 | let Some(id) = id else { continue }; | |
| 139 | covered.insert(id.to_owned()); | |
| 140 | let name = if n == 0 { format!("{} Red", spec.label) } else { id.to_owned() }; | |
| 141 | defs.push(InputDef { | |
| 142 | default: [default[n], 0.0], | |
| 143 | group: Some((0, n as u32)), | |
| 144 | ..InputDef { page: Some("Controls".to_owned()), ..InputDef::new(id, &name, Control::Color) } | |
| 145 | }); | |
| 146 | } | |
| 147 | continue; | |
| 148 | } | |
| 149 | ParamKind::Text { default } => { | |
| 150 | defs.push(InputDef { fuid: false, default_text: default.to_owned(), ..base(Control::Text) }); | |
| 151 | } | |
| 152 | } | |
| 153 | covered.insert(spec.name.to_owned()); | |
| 154 | } | |
| 155 | Some(build_layout(kind, defs, covered)) | |
| 156 | } |
crates/app/src/inspector/edit.rs created+178| ... | ... | @@ -0,0 +1,178 @@ |
| 1 | //! Everything a row does to the comp: reading evaluated values, keyframe-aware writes with undo, | |
| 2 | //! numeric-box edit state, and keyframe toggling for single inputs and grouped channels. | |
| 3 | ||
| 4 | use super::layout::{Channel, ControlDef, Kind}; | |
| 5 | use super::widgets::{KeyframeState, keyframe_state}; | |
| 6 | use super::{InspectorAction, InspectorPalette}; | |
| 7 | use model::{Comp, CompHistory, ExprEngine, NodeId, ParamValue}; | |
| 8 | use std::time::{Duration, Instant}; | |
| 9 | ||
| 10 | /// How long a drag rests before the undo step it coalesced into closes. | |
| 11 | pub(super) const SCRUB_GRACE: Duration = Duration::from_millis(350); | |
| 12 | ||
| 13 | /// A numeric box being typed into; it commits when it loses the keys. | |
| 14 | pub(super) struct NumberEdit { | |
| 15 | pub id: ui::Id, | |
| 16 | pub buf: String, | |
| 17 | pub channel: Channel, | |
| 18 | /// `Some(0|1)` edits one axis of a Point input. | |
| 19 | pub axis: Option<usize>, | |
| 20 | } | |
| 21 | ||
| 22 | #[derive(Default)] | |
| 23 | pub(super) struct EditState { | |
| 24 | pub number: Option<NumberEdit>, | |
| 25 | pub text: Option<(ui::Id, String)>, | |
| 26 | pub last_scrub: Option<Instant>, | |
| 27 | } | |
| 28 | ||
| 29 | pub(super) struct Cx<'a> { | |
| 30 | pub comp: &'a mut Comp, | |
| 31 | pub history: &'a mut CompHistory, | |
| 32 | pub actions: &'a mut Vec<InspectorAction>, | |
| 33 | pub node: NodeId, | |
| 34 | pub frame: f64, | |
| 35 | pub now: Instant, | |
| 36 | pub p: InspectorPalette, | |
| 37 | pub expr: &'a ExprEngine, | |
| 38 | pub edit: &'a mut EditState, | |
| 39 | } | |
| 40 | ||
| 41 | impl Cx<'_> { | |
| 42 | /// A Loader without `Inputs.Loop`/`Reverse` plays whatever its clip says. | |
| 43 | pub fn default_of(&self, ch: &Channel) -> f64 { | |
| 44 | let node = self.comp.node(self.node); | |
| 45 | let clip = node.clips.first().filter(|_| node.kind == "Loader"); | |
| 46 | match (ch.id.as_str(), clip) { | |
| 47 | ("Loop", Some(c)) => f64::from(u8::from(c.loop_clip)), | |
| 48 | ("Reverse", Some(c)) => f64::from(u8::from(c.reverse)), | |
| 49 | _ => ch.default[0], | |
| 50 | } | |
| 51 | } | |
| 52 | ||
| 53 | pub fn number(&self, ch: &Channel) -> f64 { | |
| 54 | self.comp.eval_number(self.comp.node(self.node), &ch.id, self.frame, self.default_of(ch), self.expr) | |
| 55 | } | |
| 56 | ||
| 57 | pub fn point(&self, ch: &Channel) -> [f64; 2] { | |
| 58 | self.comp.eval_point(self.comp.node(self.node), &ch.id, self.frame, ch.default, self.expr) | |
| 59 | } | |
| 60 | ||
| 61 | pub fn has_expression(&self, channels: &[Channel]) -> bool { | |
| 62 | let node = self.comp.node(self.node); | |
| 63 | channels.iter().any(|ch| node.inputs.get(&ch.id).is_some_and(|b| b.expression.is_some())) | |
| 64 | } | |
| 65 | ||
| 66 | /// Every channel at a keyframe reads as on a keyframe; any animated one as animated. | |
| 67 | pub fn key_state(&self, channels: &[Channel]) -> KeyframeState { | |
| 68 | let mut states = channels.iter().map(|ch| keyframe_state(self.comp, self.node, &ch.id, self.frame)); | |
| 69 | if channels.is_empty() || states.clone().all(|s| s == KeyframeState::KeyframeAtCurrent) { | |
| 70 | return states.next().unwrap_or(KeyframeState::Static); | |
| 71 | } | |
| 72 | if states.any(|s| s != KeyframeState::Static) { | |
| 73 | KeyframeState::AnimatedOtherFrame | |
| 74 | } else { | |
| 75 | KeyframeState::Static | |
| 76 | } | |
| 77 | } | |
| 78 | ||
| 79 | /// Writes numbers, as a keyframe where the input is animated. A `drag` folds into one undo | |
| 80 | /// step per input until it rests; anything else is its own step. | |
| 81 | pub fn write_numbers(&mut self, label: &str, edits: &[(&Channel, f64)], drag: bool) { | |
| 82 | if drag { | |
| 83 | let key = format!("scrub:{}:{}", self.node.0, edits[0].0.id); | |
| 84 | self.history.push_coalesced(self.comp, format!("Adjust {label}"), key); | |
| 85 | self.edit.last_scrub = Some(self.now); | |
| 86 | } else { | |
| 87 | self.history.push_snapshot(self.comp, format!("Set {label}")); | |
| 88 | } | |
| 89 | for &(ch, value) in edits { | |
| 90 | let value = value.clamp(ch.allowed[0].unwrap_or(f64::MIN), ch.allowed[1].unwrap_or(f64::MAX)); | |
| 91 | let animated = keyframe_state(self.comp, self.node, &ch.id, self.frame) != KeyframeState::Static; | |
| 92 | if animated { | |
| 93 | let _ = self.comp.set_keyframe(self.node, &ch.id, self.frame, value); | |
| 94 | self.actions.push(InspectorAction::KeyframeEdited(self.node)); | |
| 95 | } else { | |
| 96 | self.comp.set_input_value(self.node, &ch.id, ParamValue::Number(value)); | |
| 97 | self.actions.push(InspectorAction::ParamEdited(self.node)); | |
| 98 | } | |
| 99 | } | |
| 100 | } | |
| 101 | ||
| 102 | pub fn write_value(&mut self, label: &str, id: &str, value: ParamValue) { | |
| 103 | self.history.push_snapshot(self.comp, format!("Set {label}")); | |
| 104 | self.comp.set_input_value(self.node, id, value); | |
| 105 | self.actions.push(InspectorAction::ParamEdited(self.node)); | |
| 106 | } | |
| 107 | ||
| 108 | /// Commits a numeric box once it has lost the keys. | |
| 109 | pub fn commit_number(&mut self, edit: NumberEdit) { | |
| 110 | let Ok(value) = edit.buf.trim().parse::<f64>() else { return }; | |
| 111 | if !value.is_finite() { | |
| 112 | return; | |
| 113 | } | |
| 114 | let ch = &edit.channel; | |
| 115 | match edit.axis { | |
| 116 | Some(axis) => { | |
| 117 | let mut point = self.point(ch); | |
| 118 | point[axis] = value; | |
| 119 | self.write_value(&ch.id, &ch.id, ParamValue::Point(point)); | |
| 120 | } | |
| 121 | None => self.write_numbers(&ch.id, &[(ch, value)], false), | |
| 122 | } | |
| 123 | } | |
| 124 | ||
| 125 | /// Keys every channel at the current frame, or removes those keys when all already have one. | |
| 126 | pub fn toggle_keyframes(&mut self, label: &str, channels: &[Channel], state: KeyframeState) { | |
| 127 | self.history.begin_group(self.comp, format!("Keyframe {label}")); | |
| 128 | let mut notice = None; | |
| 129 | for ch in channels { | |
| 130 | if state == KeyframeState::KeyframeAtCurrent { | |
| 131 | let spline = self.comp.node(self.node).inputs.get(&ch.id).and_then(|b| b.source_op.clone()); | |
| 132 | if spline.is_some_and(|sp| self.comp.delete_keyframe(&sp, self.frame)) { | |
| 133 | notice = Some(format!("Deleted keyframe on {label} @ f{:.0}", self.frame)); | |
| 134 | } | |
| 135 | } else { | |
| 136 | let value = self.number(ch); | |
| 137 | match self.comp.set_keyframe(self.node, &ch.id, self.frame, value) { | |
| 138 | Ok(_) => notice = Some(format!("Keyframed {label} @ f{:.0}", self.frame)), | |
| 139 | Err(e) => notice = Some(e), | |
| 140 | } | |
| 141 | } | |
| 142 | } | |
| 143 | self.history.commit_group(self.comp); | |
| 144 | if let Some(notice) = notice { | |
| 145 | self.actions.push(InspectorAction::KeyframeEdited(self.node)); | |
| 146 | self.actions.push(InspectorAction::StatusNotice(notice)); | |
| 147 | } | |
| 148 | } | |
| 149 | ||
| 150 | /// Puts every static input of `controls` back to its default; animated and expression inputs | |
| 151 | /// keep their drivers. | |
| 152 | pub fn reset_defaults<'d>(&mut self, controls: impl Iterator<Item = &'d ControlDef>) { | |
| 153 | self.history.begin_group(self.comp, "Reset to Defaults"); | |
| 154 | for def in controls { | |
| 155 | for ch in &def.channels { | |
| 156 | let binding = self.comp.node(self.node).inputs.get(&ch.id); | |
| 157 | if binding.is_some_and(|b| b.source_op.is_some() || b.expression.is_some()) { | |
| 158 | continue; | |
| 159 | } | |
| 160 | let Some(current) = binding.and_then(|b| b.value.clone()) else { continue }; | |
| 161 | let default = match def.kind { | |
| 162 | Kind::Point => ParamValue::Point(ch.default), | |
| 163 | Kind::Text if def.fuid => ParamValue::FuId(def.default_text.clone()), | |
| 164 | Kind::Text => ParamValue::Text(def.default_text.clone()), | |
| 165 | Kind::Segmented | Kind::Combo if def.fuid => ParamValue::FuId(def.entries[def.default_index].clone()), | |
| 166 | _ => ParamValue::Number(self.default_of(ch)), | |
| 167 | }; | |
| 168 | if current != default { | |
| 169 | self.comp.set_input_value(self.node, &ch.id, default); | |
| 170 | } | |
| 171 | } | |
| 172 | } | |
| 173 | if self.history.commit_group(self.comp) { | |
| 174 | self.actions.push(InspectorAction::ParamEdited(self.node)); | |
| 175 | self.actions.push(InspectorAction::StatusNotice("Reset to defaults".to_owned())); | |
| 176 | } | |
| 177 | } | |
| 178 | } |
crates/app/src/inspector/layout.rs created+254| ... | ... | @@ -0,0 +1,254 @@ |
| 1 | //! Turns a flat [`InputDef`] list into the Inspector's pages, sections and rows: sibling | |
| 2 | //! RGBA/range/toggle inputs fuse into one [`ControlDef`], pages follow Fusion's tab order. | |
| 3 | ||
| 4 | use super::catalog::{Control, InputDef}; | |
| 5 | use std::collections::HashSet; | |
| 6 | ||
| 7 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] | |
| 8 | pub enum Kind { | |
| 9 | Slider, | |
| 10 | Screw, | |
| 11 | Range, | |
| 12 | Color, | |
| 13 | Toggles, | |
| 14 | Segmented, | |
| 15 | Combo, | |
| 16 | Checkbox, | |
| 17 | Point, | |
| 18 | Text, | |
| 19 | } | |
| 20 | ||
| 21 | /// One input a row reads and writes. | |
| 22 | #[derive(Clone, Debug)] | |
| 23 | pub struct Channel { | |
| 24 | pub id: String, | |
| 25 | /// Number default in `[0]`; Point default `[x, y]`. | |
| 26 | pub default: [f64; 2], | |
| 27 | pub scale: [f64; 2], | |
| 28 | pub allowed: [Option<f64>; 2], | |
| 29 | pub integer: bool, | |
| 30 | } | |
| 31 | ||
| 32 | /// One Inspector row. | |
| 33 | #[derive(Clone, Debug)] | |
| 34 | pub struct ControlDef { | |
| 35 | pub label: String, | |
| 36 | pub kind: Kind, | |
| 37 | /// Range: start, end. Color: r, g, b[, a]. Toggles: one per button. | |
| 38 | pub channels: Vec<Channel>, | |
| 39 | /// Segmented/Combo choices, or one label per toggle button. | |
| 40 | pub entries: Vec<String>, | |
| 41 | /// Segmented/Combo/Text values are strings; choices default to `default_index`. | |
| 42 | pub fuid: bool, | |
| 43 | pub default_index: usize, | |
| 44 | pub default_text: String, | |
| 45 | } | |
| 46 | ||
| 47 | #[derive(Clone, Debug)] | |
| 48 | pub struct Section { | |
| 49 | pub title: String, | |
| 50 | pub open: bool, | |
| 51 | pub controls: Vec<ControlDef>, | |
| 52 | } | |
| 53 | ||
| 54 | #[derive(Clone, Debug)] | |
| 55 | pub struct Page { | |
| 56 | pub name: String, | |
| 57 | pub sections: Vec<Section>, | |
| 58 | } | |
| 59 | ||
| 60 | #[derive(Clone, Debug, Default)] | |
| 61 | pub struct ToolLayout { | |
| 62 | pub pages: Vec<Page>, | |
| 63 | /// Every input id the tool registers, including image and mask ports with no row. | |
| 64 | pub covered: HashSet<String>, | |
| 65 | } | |
| 66 | ||
| 67 | const SETTINGS: &str = "Settings"; | |
| 68 | ||
| 69 | /// Fusion tab order where `:GetInputList()` registration order differs. | |
| 70 | const PAGE_ORDER: &[(&str, &[&str])] = &[ | |
| 71 | ("TextPlus", &["Text", "Layout", "Transform", "Shading", "Image", SETTINGS]), | |
| 72 | ("Text3D", &["Text", "Layout", "Transform", "Shading", "3D", SETTINGS]), | |
| 73 | ]; | |
| 74 | ||
| 75 | /// Subsections Fusion draws inside a page, which the input list doesn't report: | |
| 76 | /// `(tools, first input id, title, open)`. No tools matches every tool. | |
| 77 | pub(super) const SECTIONS: &[(&[&str], &str, &str, bool)] = &[ | |
| 78 | (&["Merge", "Transform"], "Width", "Reference Size", false), | |
| 79 | (&[], "MotionBlur", "Motion Blur", true), | |
| 80 | (&["Text3D"], "ExtrusionStyle", "Extrusion", true), | |
| 81 | ]; | |
| 82 | ||
| 83 | const MAX_SEGMENTS: usize = 5; | |
| 84 | const MAX_SEGMENT_CHARS: usize = 18; | |
| 85 | ||
| 86 | pub fn build_layout(kind: &str, defs: Vec<InputDef>, covered: HashSet<String>) -> ToolLayout { | |
| 87 | let mut pages: Vec<(String, Vec<InputDef>)> = Vec::new(); | |
| 88 | for def in defs { | |
| 89 | let name = match def.page.as_deref() { | |
| 90 | None | Some("Common") => SETTINGS, | |
| 91 | Some(page) => page, | |
| 92 | }; | |
| 93 | match pages.iter_mut().find(|(n, _)| n == name) { | |
| 94 | Some((_, list)) => list.push(def), | |
| 95 | None => pages.push((name.to_owned(), vec![def])), | |
| 96 | } | |
| 97 | } | |
| 98 | let order = PAGE_ORDER.iter().find(|(k, _)| *k == kind).map(|(_, o)| *o); | |
| 99 | let rank = |name: &str| match order { | |
| 100 | Some(order) => order.iter().position(|o| *o == name), | |
| 101 | None => Some(match name { | |
| 102 | SETTINGS => 2, | |
| 103 | "Image" => 1, | |
| 104 | _ => 0, | |
| 105 | }), | |
| 106 | }; | |
| 107 | pages.sort_by_key(|(name, _)| rank(name).unwrap_or(usize::MAX)); | |
| 108 | ||
| 109 | let pages = pages | |
| 110 | .into_iter() | |
| 111 | .map(|(name, defs)| { | |
| 112 | let title = if name == SETTINGS { "Common Controls" } else { &name }; | |
| 113 | Page { sections: sections(kind, title, controls(&defs)), name } | |
| 114 | }) | |
| 115 | .collect(); | |
| 116 | ToolLayout { pages, covered } | |
| 117 | } | |
| 118 | ||
| 119 | /// A single-section page for controls that are not in the catalog (user controls, stray inputs). | |
| 120 | pub fn dynamic_page(name: &str, defs: &[InputDef]) -> Page { | |
| 121 | Page { name: name.to_owned(), sections: sections("", name, controls(defs)) } | |
| 122 | } | |
| 123 | ||
| 124 | fn sections(kind: &str, first_title: &str, controls: Vec<ControlDef>) -> Vec<Section> { | |
| 125 | let mut out = vec![Section { title: first_title.to_owned(), open: true, controls: Vec::new() }]; | |
| 126 | for control in controls { | |
| 127 | let marker = SECTIONS.iter().find(|(tools, id, ..)| { | |
| 128 | (tools.is_empty() || tools.contains(&kind)) && control.channels.first().is_some_and(|c| c.id == *id) | |
| 129 | }); | |
| 130 | if let Some(&(_, _, title, open)) = marker { | |
| 131 | out.push(Section { title: title.to_owned(), open, controls: Vec::new() }); | |
| 132 | } | |
| 133 | out.last_mut().expect("starts non-empty").controls.push(control); | |
| 134 | } | |
| 135 | out.retain(|s| !s.controls.is_empty()); | |
| 136 | out | |
| 137 | } | |
| 138 | ||
| 139 | /// How many defs from `i` form one group: same control and `IC_ControlGroup`, ascending `IC_ControlID`. | |
| 140 | fn group_len(defs: &[InputDef], i: usize) -> usize { | |
| 141 | let head = &defs[i]; | |
| 142 | let Some((group, first)) = head.group else { return 1 }; | |
| 143 | 1 + defs[i + 1..] | |
| 144 | .iter() | |
| 145 | .zip(first + 1..) | |
| 146 | .take_while(|(d, id)| d.control == head.control && d.group == Some((group, *id))) | |
| 147 | .count() | |
| 148 | } | |
| 149 | ||
| 150 | fn controls(defs: &[InputDef]) -> Vec<ControlDef> { | |
| 151 | let mut out = Vec::new(); | |
| 152 | let mut i = 0; | |
| 153 | while i < defs.len() { | |
| 154 | let head = &defs[i]; | |
| 155 | let run = group_len(defs, i); | |
| 156 | let starts_group = head.group.is_some_and(|(_, id)| id == 0); | |
| 157 | let take = match head.control { | |
| 158 | Control::Color if run >= 3 && starts_group => run.min(4), | |
| 159 | Control::Range if run >= 2 && starts_group => 2, | |
| 160 | Control::MultiButton if head.entries.len() == 1 => run, | |
| 161 | _ => 1, | |
| 162 | }; | |
| 163 | out.push(control(&defs[i..i + take])); | |
| 164 | i += take; | |
| 165 | } | |
| 166 | out | |
| 167 | } | |
| 168 | ||
| 169 | fn channel(d: &InputDef) -> Channel { | |
| 170 | Channel { id: d.id.clone(), default: d.default, scale: d.scale, allowed: d.allowed, integer: d.integer } | |
| 171 | } | |
| 172 | ||
| 173 | fn control(group: &[InputDef]) -> ControlDef { | |
| 174 | let d = &group[0]; | |
| 175 | let (kind, label, entries) = match d.control { | |
| 176 | Control::Color if group.len() >= 3 => (Kind::Color, color_label(&d.name), Vec::new()), | |
| 177 | Control::Range if group.len() == 2 => (Kind::Range, range_label(&group[0].name, &group[1].name), Vec::new()), | |
| 178 | Control::MultiButton if d.entries.len() == 1 => { | |
| 179 | let names: Vec<&str> = group.iter().map(|g| g.name.as_str()).collect(); | |
| 180 | (Kind::Toggles, common_prefix(&names).unwrap_or_else(|| if group.len() > 1 { "Channels".to_owned() } else { d.name.clone() }), group.iter().map(|g| g.entries[0].clone()).collect()) | |
| 181 | } | |
| 182 | Control::MultiButton | Control::Combo => { | |
| 183 | let chars: usize = d.entries.iter().map(String::len).sum(); | |
| 184 | let segmented = d.control == Control::MultiButton && d.entries.len() <= MAX_SEGMENTS && chars <= MAX_SEGMENT_CHARS; | |
| 185 | (if segmented { Kind::Segmented } else { Kind::Combo }, d.name.clone(), d.entries.clone()) | |
| 186 | } | |
| 187 | Control::Screw => (Kind::Screw, d.name.clone(), Vec::new()), | |
| 188 | Control::Checkbox => (Kind::Checkbox, d.name.clone(), Vec::new()), | |
| 189 | Control::Offset => (Kind::Point, d.name.clone(), Vec::new()), | |
| 190 | Control::Text => (Kind::Text, d.name.clone(), Vec::new()), | |
| 191 | Control::Slider | Control::Color | Control::Range => (Kind::Slider, d.name.clone(), Vec::new()), | |
| 192 | }; | |
| 193 | let default_index = if d.fuid { | |
| 194 | entries.iter().position(|e| *e == d.default_text).unwrap_or(0) | |
| 195 | } else { | |
| 196 | (d.default[0].max(0.0) as usize).min(entries.len().saturating_sub(1)) | |
| 197 | }; | |
| 198 | ControlDef { | |
| 199 | label, | |
| 200 | kind, | |
| 201 | channels: group.iter().map(channel).collect(), | |
| 202 | entries, | |
| 203 | fuid: d.fuid, | |
| 204 | default_index, | |
| 205 | default_text: d.default_text.clone(), | |
| 206 | } | |
| 207 | } | |
| 208 | ||
| 209 | /// `Top Left Red` -> `Top Left`; a bare channel name is just `Color`. | |
| 210 | fn color_label(first: &str) -> String { | |
| 211 | let rest: Vec<&str> = first.split_whitespace().filter(|w| *w != "Red").collect(); | |
| 212 | match rest.first() { | |
| 213 | None => "Color".to_owned(), | |
| 214 | Some(w) if w.starts_with(|c: char| c.is_ascii_digit()) => format!("Color {}", rest.join(" ")), | |
| 215 | Some(_) => rest.join(" "), | |
| 216 | } | |
| 217 | } | |
| 218 | ||
| 219 | /// `Write On Start`, `Write On End` -> `Write On Start / End`; `Low`, `High` -> `Low / High`. | |
| 220 | fn range_label(start: &str, end: &str) -> String { | |
| 221 | let (a, b): (Vec<&str>, Vec<&str>) = (start.split_whitespace().collect(), end.split_whitespace().collect()); | |
| 222 | let shared = a.iter().zip(&b).take_while(|(x, y)| x == y).count(); | |
| 223 | if shared == 0 || shared == a.len().min(b.len()) { | |
| 224 | return format!("{start} / {end}"); | |
| 225 | } | |
| 226 | format!("{} / {}", start, b[shared..].join(" ")) | |
| 227 | } | |
| 228 | ||
| 229 | /// The words every name starts with, or `None` when they share none. | |
| 230 | fn common_prefix(names: &[&str]) -> Option<String> { | |
| 231 | let first: Vec<&str> = names.first()?.split_whitespace().collect(); | |
| 232 | let shared = names | |
| 233 | .iter() | |
| 234 | .map(|n| n.split_whitespace().zip(&first).take_while(|(a, b)| a == *b).count()) | |
| 235 | .min()?; | |
| 236 | (shared > 0).then(|| first[..shared].join(" ")) | |
| 237 | } | |
| 238 | ||
| 239 | #[cfg(test)] | |
| 240 | mod tests { | |
| 241 | use super::*; | |
| 242 | ||
| 243 | #[test] | |
| 244 | fn labels() { | |
| 245 | assert_eq!(color_label("Top Left Red"), "Top Left"); | |
| 246 | assert_eq!(color_label("Red 1"), "Color 1"); | |
| 247 | assert_eq!(color_label("Red"), "Color"); | |
| 248 | assert_eq!(range_label("Write On Start", "Write On End"), "Write On Start / End"); | |
| 249 | assert_eq!(range_label("Low", "High"), "Low / High"); | |
| 250 | assert_eq!(common_prefix(&["Process Red", "Process Green"]).as_deref(), Some("Process")); | |
| 251 | assert_eq!(common_prefix(&["Flip Horizontal", "Flip Vertical"]).as_deref(), Some("Flip")); | |
| 252 | assert_eq!(common_prefix(&["Red", "Green"]), None); | |
| 253 | } | |
| 254 | } |
crates/app/src/inspector/mod.rs+144-498| ... | ... | @@ -1,24 +1,25 @@ |
| 1 | //! Inspector dock pane — Fusion 21.1 parameter editor with scrub sliders, Vec2, RGBA color groups, | |
| 2 | //! booleans, FuID enum cyclers, text fields, expression badges, and keyframe diamonds (`◆`). | |
| 3 | ||
| 1 | //! Inspector dock pane: a declarative, catalog-driven Fusion 21.1 parameter editor. Pages, groups | |
| 2 | //! and control kinds come from `scripts/tool_catalog.json`; rows are built from the Knife `ui` | |
| 3 | //! sliders, screws, range sliders, color pickers and segmented controls. | |
| 4 | ||
| 5 | mod catalog; | |
| 6 | mod chrome; | |
| 7 | mod controls; | |
| 8 | mod dynamic; | |
| 9 | mod edit; | |
| 10 | mod layout; | |
| 4 | 11 | mod schemas; |
| 5 | 12 | mod widgets; |
| 6 | 13 | |
| 7 | 14 | #[cfg(test)] |
| 8 | 15 | pub use schemas::CURATED_TOOL_KINDS; |
| 9 | #[allow(unused_imports)] | |
| 10 | pub use schemas::{ParamKind, ParamSpec, infer_float_range, schema_for_kind}; | |
| 11 | #[allow(unused_imports)] | |
| 12 | pub use widgets::{ | |
| 13 | KeyframeState, compute_scrub_value, format_param_number, keyframe_state, | |
| 14 | normalize_slider_fraction, | |
| 15 | }; | |
| 16 | pub use widgets::{KeyframeState, keyframe_state}; | |
| 16 | 17 | |
| 17 | 18 | use engine::EvalStats; |
| 18 | use model::{Comp, CompHistory, ExprEngine, NodeId, is_supported_tool}; | |
| 19 | use std::collections::{HashMap, HashSet}; | |
| 20 | use std::time::Instant; | |
| 21 | use widgets::DragState; | |
| 19 | use layout::{Page, ToolLayout}; | |
| 20 | use model::{Comp, CompHistory, ExprEngine, NodeId}; | |
| 21 | use std::collections::HashMap; | |
| 22 | use std::time::Duration; | |
| 22 | 23 | |
| 23 | 24 | #[derive(Clone, Debug)] |
| 24 | 25 | pub enum InspectorAction { |
| ... | ... | @@ -64,33 +65,43 @@ impl InspectorPalette { |
| 64 | 65 | } |
| 65 | 66 | } |
| 66 | 67 | |
| 68 | /// Pages for the selected node's own `UserControls` and stray inputs, rebuilt when the comp | |
| 69 | /// revision moves. | |
| 70 | struct NodePages { | |
| 71 | node: NodeId, | |
| 72 | revision: u64, | |
| 73 | pages: Vec<Page>, | |
| 74 | } | |
| 75 | ||
| 67 | 76 | pub struct InspectorState { |
| 68 | 77 | pub palette: InspectorPalette, |
| 69 | 78 | expr: ExprEngine, |
| 70 | /// Node name edit buffer synced with the currently selected node. | |
| 71 | name_node: Option<NodeId>, | |
| 72 | name_buf: String, | |
| 73 | /// Text parameter edit buffers keyed by `(node_id, param_name)`. | |
| 74 | text_bufs: HashMap<(usize, String), String>, | |
| 75 | /// Active scrub slider drag. | |
| 76 | drag: Option<DragState>, | |
| 77 | /// Text field that had the keys last frame, so losing them ends its coalesced undo step. | |
| 78 | text_focus: Option<ui::Id>, | |
| 79 | /// Last click timestamp per slider key for double-click reset. | |
| 80 | last_click: HashMap<String, Instant>, | |
| 79 | rename: chrome::Rename, | |
| 80 | edit: edit::EditState, | |
| 81 | /// Active page tab per node. | |
| 82 | page: HashMap<usize, usize>, | |
| 83 | /// Section open/closed overrides per `(node, page, section)`. | |
| 84 | sections: HashMap<(usize, usize, usize), bool>, | |
| 85 | node_pages: Option<NodePages>, | |
| 86 | /// Layouts of tools the catalog lacks, built from curated schemas on first sight. | |
| 87 | fallback: HashMap<String, ToolLayout>, | |
| 81 | 88 | } |
| 82 | 89 | |
| 83 | 90 | impl InspectorState { |
| 84 | 91 | pub fn new(theme: &ui::Theme) -> Self { |
| 92 | // Parse the catalog off the UI thread; frames wait on it with a placeholder. | |
| 93 | std::thread::spawn(|| { | |
| 94 | catalog::catalog(); | |
| 95 | }); | |
| 85 | 96 | Self { |
| 86 | 97 | palette: InspectorPalette::from_theme(theme), |
| 87 | 98 | expr: ExprEngine::new(), |
| 88 | name_node: None, | |
| 89 | name_buf: String::new(), | |
| 90 | text_bufs: HashMap::new(), | |
| 91 | drag: None, | |
| 92 | text_focus: None, | |
| 93 | last_click: HashMap::new(), | |
| 99 | rename: chrome::Rename::default(), | |
| 100 | edit: edit::EditState::default(), | |
| 101 | page: HashMap::new(), | |
| 102 | sections: HashMap::new(), | |
| 103 | node_pages: None, | |
| 104 | fallback: HashMap::new(), | |
| 94 | 105 | } |
| 95 | 106 | } |
| 96 | 107 | |
| ... | ... | @@ -99,11 +110,9 @@ impl InspectorState { |
| 99 | 110 | } |
| 100 | 111 | |
| 101 | 112 | pub fn reset(&mut self) { |
| 102 | self.name_node = None; | |
| 103 | self.name_buf.clear(); | |
| 104 | self.text_bufs.clear(); | |
| 105 | self.drag = None; | |
| 106 | self.text_focus = None; | |
| 113 | self.rename = chrome::Rename::default(); | |
| 114 | self.edit = edit::EditState::default(); | |
| 115 | self.node_pages = None; | |
| 107 | 116 | } |
| 108 | 117 | |
| 109 | 118 | pub fn build_ui( |
| ... | ... | @@ -121,501 +130,138 @@ impl InspectorState { |
| 121 | 130 | |
| 122 | 131 | ui.open_as( |
| 123 | 132 | pane_id, |
| 124 | ui::Spec { | |
| 125 | size: [ui::fill(), ui::fill()], | |
| 126 | axis: ui::Axis::Y, | |
| 127 | fill: Some(p.bg), | |
| 128 | ..ui::Spec::default() | |
| 129 | }, | |
| 133 | ui::Spec { size: [ui::fill(), ui::fill()], axis: ui::Axis::Y, fill: Some(p.bg), ..ui::Spec::default() }, | |
| 130 | 134 | ); |
| 131 | ||
| 132 | 135 | let Some(node_id) = selected.filter(|id| id.0 < comp.nodes.len()) else { |
| 133 | // Empty state | |
| 134 | ui.open( | |
| 135 | "insp-empty", | |
| 136 | ui::Spec { | |
| 137 | size: [ui::fill(), ui::fill()], | |
| 138 | axis: ui::Axis::Y, | |
| 139 | pad: [14.0, 18.0], | |
| 140 | gap: 8.0, | |
| 141 | ..ui::Spec::default() | |
| 142 | }, | |
| 143 | ); | |
| 144 | ui.leaf( | |
| 145 | "empty-title", | |
| 146 | ui::Spec { | |
| 147 | size: [ui::fill(), ui::px(20.0)], | |
| 148 | text: Some("No Node Selected"), | |
| 149 | font_size: Some(12.5), | |
| 150 | medium: true, | |
| 151 | color: Some(p.text), | |
| 152 | ..ui::Spec::default() | |
| 153 | }, | |
| 154 | ); | |
| 155 | ui.leaf( | |
| 156 | "empty-hint", | |
| 157 | ui::Spec { | |
| 158 | size: [ui::fill(), ui::fit()], | |
| 159 | text: Some("Select a node in the Flow graph to inspect and keyframe its parameters, or press Shift+Space to add a tool."), | |
| 160 | font_size: Some(11.0), | |
| 161 | overflow: ui::Overflow::Wrap, | |
| 162 | color: Some(p.text_dim), | |
| 163 | ..ui::Spec::default() | |
| 164 | }, | |
| 165 | ); | |
| 166 | self.render_stats_footer(ui, stats); | |
| 167 | ui.close(); | |
| 136 | chrome::empty_state(ui, p); | |
| 137 | chrome::footer(ui, p, stats); | |
| 168 | 138 | ui.close(); |
| 169 | 139 | return actions; |
| 170 | 140 | }; |
| 171 | 141 | |
| 172 | // Sync editable name buffer when selection changes or node was renamed externally (e.g. undo) | |
| 173 | let current_name = comp.node(node_id).name.clone(); | |
| 174 | let name_field_id = pane_id.child(("node-name", node_id.0)); | |
| 175 | if self.name_node != Some(node_id) | |
| 176 | || (ui.focused() != Some(name_field_id) && self.name_buf != current_name) | |
| 177 | { | |
| 178 | self.name_node = Some(node_id); | |
| 179 | self.name_buf = current_name.clone(); | |
| 180 | } | |
| 181 | ||
| 182 | // 1. Header: Node name + Class badge + Bypass toggle | |
| 183 | ui.open( | |
| 184 | "insp-header", | |
| 185 | ui::Spec { | |
| 186 | size: [ui::fill(), ui::children()], | |
| 187 | axis: ui::Axis::Y, | |
| 188 | pad: [10.0, 8.0], | |
| 189 | gap: 6.0, | |
| 190 | fill: Some(p.panel_bg), | |
| 191 | border: Some(p.rule), | |
| 192 | ..ui::Spec::default() | |
| 193 | }, | |
| 194 | ); | |
| 142 | let kind = comp.node(node_id).kind.clone(); | |
| 143 | let Some(catalog) = catalog::ready() else { | |
| 144 | ui.wake_after(Duration::from_millis(50)); | |
| 145 | return self.loading(ui, p, stats, actions); | |
| 146 | }; | |
| 147 | let layout = match catalog.get(&kind) { | |
| 148 | Some(entry) => &entry.layout, | |
| 149 | None => self | |
| 150 | .fallback | |
| 151 | .entry(kind.clone()) | |
| 152 | .or_insert_with(|| dynamic::curated_layout(&kind).unwrap_or_default()), | |
| 153 | }; | |
| 195 | 154 | |
| 196 | // Row 1: Editable name + Bypass button | |
| 197 | ui.open( | |
| 198 | "insp-name-row", | |
| 199 | ui::Spec { | |
| 200 | size: [ui::fill(), ui::px(26.0)], | |
| 201 | axis: ui::Axis::X, | |
| 202 | gap: 6.0, | |
| 203 | ..ui::Spec::default() | |
| 204 | }, | |
| 205 | ); | |
| 206 | let name_sig = ui::text_field( | |
| 207 | ui, | |
| 208 | name_field_id, | |
| 209 | &mut self.name_buf, | |
| 210 | "Node name", | |
| 211 | ui::Spec { | |
| 212 | size: [ui::fill(), ui::px(24.0)], | |
| 213 | font_size: Some(12.0), | |
| 214 | medium: true, | |
| 215 | fill: Some(p.bg), | |
| 216 | border: Some(p.rule), | |
| 217 | hover_border: Some(p.accent), | |
| 218 | radius: 4.0, | |
| 219 | pad: [6.0, 2.0], | |
| 220 | ..ui::Spec::default() | |
| 221 | }, | |
| 222 | ); | |
| 223 | let enter_pressed = name_sig.events.iter().any(|ev| { | |
| 224 | matches!( | |
| 225 | ev, | |
| 226 | ui::Event::Key { key: winit::keyboard::Key::Named(winit::keyboard::NamedKey::Enter), .. } | |
| 227 | ) | |
| 228 | }); | |
| 229 | if enter_pressed && self.name_buf.trim() != current_name { | |
| 230 | let desired = self.name_buf.trim().to_owned(); | |
| 231 | history.begin_group(comp, "Rename Node"); | |
| 232 | match comp.rename_node(node_id, &desired) { | |
| 233 | Ok(applied) => { | |
| 234 | history.commit_group(comp); | |
| 235 | self.name_buf = applied; | |
| 236 | actions.push(InspectorAction::NodeRenamed(node_id)); | |
| 237 | } | |
| 238 | Err(e) => { | |
| 239 | history.cancel_group(comp); | |
| 240 | self.name_buf = current_name.clone(); | |
| 241 | actions.push(InspectorAction::StatusNotice(e)); | |
| 242 | } | |
| 243 | } | |
| 244 | ui.set_focus(None); | |
| 155 | if self.node_pages.as_ref().is_none_or(|n| n.node != node_id || n.revision != comp.revision) { | |
| 156 | self.node_pages = Some(NodePages { node: node_id, revision: comp.revision, pages: node_pages(comp, node_id, layout) }); | |
| 245 | 157 | } |
| 246 | ||
| 247 | let bypassed = comp.node(node_id).bypassed; | |
| 248 | let pass_lbl = if bypassed { "Bypassed" } else { "Active" }; | |
| 249 | let pass_fill = if bypassed { | |
| 250 | [0.85, 0.28, 0.28, 0.28] | |
| 251 | } else { | |
| 252 | [0.24, 0.78, 0.48, 0.18] | |
| 253 | }; | |
| 254 | let pass_border = if bypassed { | |
| 255 | [0.92, 0.36, 0.36, 0.75] | |
| 256 | } else { | |
| 257 | [0.28, 0.82, 0.52, 0.55] | |
| 158 | let dynamic_pages = self.node_pages.as_ref().map_or(&[][..], |n| n.pages.as_slice()); | |
| 159 | ||
| 160 | let mut cx = edit::Cx { | |
| 161 | comp, | |
| 162 | history, | |
| 163 | actions: &mut actions, | |
| 164 | node: node_id, | |
| 165 | frame: current_frame, | |
| 166 | now: ui.now(), | |
| 167 | p, | |
| 168 | expr: &self.expr, | |
| 169 | edit: &mut self.edit, | |
| 258 | 170 | }; |
| 259 | let pass_sig = ui.leaf( | |
| 260 | ("insp-pass", node_id.0), | |
| 261 | ui::Spec { | |
| 262 | cursor: Some(winit::window::CursorIcon::Pointer), | |
| 263 | flags: ui::Flags::CLICKABLE, | |
| 264 | size: [ui::fit(), ui::px(24.0)], | |
| 265 | text: Some(pass_lbl), | |
| 266 | font_size: Some(10.5), | |
| 267 | medium: true, | |
| 268 | color: Some(p.text), | |
| 269 | fill: Some(pass_fill), | |
| 270 | border: Some(pass_border), | |
| 271 | radius: 4.0, | |
| 272 | pad: [8.0, 0.0], | |
| 273 | center: true, | |
| 274 | ..ui::Spec::default() | |
| 275 | }, | |
| 276 | ); | |
| 277 | if pass_sig.clicked { | |
| 278 | history.push_snapshot(comp, "Toggle Passthrough"); | |
| 279 | comp.toggle_passthrough(node_id); | |
| 280 | actions.push(InspectorAction::ParamEdited(node_id)); | |
| 171 | settle_edits(ui, &mut cx); | |
| 172 | ||
| 173 | let mut pages = layout.pages.iter().chain(dynamic_pages); | |
| 174 | if chrome::header(ui, pane_id, &mut self.rename, &mut cx) { | |
| 175 | cx.reset_defaults(pages.clone().flat_map(|page| page.sections.iter()).flat_map(|s| s.controls.iter())); | |
| 281 | 176 | } |
| 282 | ui.close(); // insp-name-row | |
| 283 | 177 | |
| 284 | // Row 2: Tool class badge + supported/preserved indicator + frame badge | |
| 285 | let node_kind = comp.node(node_id).kind.clone(); | |
| 286 | let supported = is_supported_tool(&node_kind); | |
| 287 | let frame_str = format!("f{:.0}", current_frame); | |
| 288 | ui.open( | |
| 289 | "insp-meta-row", | |
| 290 | ui::Spec { | |
| 291 | size: [ui::fill(), ui::px(18.0)], | |
| 292 | axis: ui::Axis::X, | |
| 293 | gap: 6.0, | |
| 294 | ..ui::Spec::default() | |
| 295 | }, | |
| 296 | ); | |
| 297 | ui.leaf( | |
| 298 | "insp-kind-badge", | |
| 299 | ui::Spec { | |
| 300 | size: [ui::fit(), ui::px(18.0)], | |
| 301 | text: Some(&node_kind), | |
| 302 | font_size: Some(10.0), | |
| 303 | medium: true, | |
| 304 | color: Some(p.accent), | |
| 305 | fill: Some([p.accent[0], p.accent[1], p.accent[2], 0.14]), | |
| 306 | border: Some([p.accent[0], p.accent[1], p.accent[2], 0.40]), | |
| 307 | radius: 3.0, | |
| 308 | pad: [6.0, 0.0], | |
| 309 | center: true, | |
| 310 | ..ui::Spec::default() | |
| 311 | }, | |
| 312 | ); | |
| 313 | if !supported { | |
| 314 | ui.leaf( | |
| 315 | "insp-preserved-badge", | |
| 316 | ui::Spec { | |
| 317 | size: [ui::fit(), ui::px(18.0)], | |
| 318 | text: Some("preserved"), | |
| 319 | font_size: Some(9.5), | |
| 320 | medium: true, | |
| 321 | color: Some([0.98, 0.78, 0.40, 1.0]), | |
| 322 | fill: Some([0.24, 0.16, 0.06, 0.85]), | |
| 323 | border: Some([0.92, 0.64, 0.24, 0.60]), | |
| 324 | radius: 3.0, | |
| 325 | pad: [5.0, 0.0], | |
| 326 | center: true, | |
| 327 | ..ui::Spec::default() | |
| 328 | }, | |
| 329 | ); | |
| 178 | let names: Vec<&str> = pages.clone().map(|page| page.name.as_str()).collect(); | |
| 179 | let active = self.page.get(&node_id.0).copied().unwrap_or(0).min(names.len().saturating_sub(1)); | |
| 180 | if let Some(next) = chrome::tabs(ui, p, &names, active) { | |
| 181 | self.page.insert(node_id.0, next); | |
| 330 | 182 | } |
| 331 | ui.leaf( | |
| 332 | "insp-spacer", | |
| 333 | ui::Spec { | |
| 334 | size: [ui::fill(), ui::px(18.0)], | |
| 335 | ..ui::Spec::default() | |
| 336 | }, | |
| 337 | ); | |
| 338 | ui.leaf( | |
| 339 | "insp-frame", | |
| 340 | ui::Spec { | |
| 341 | size: [ui::fit(), ui::px(18.0)], | |
| 342 | text: Some(&frame_str), | |
| 343 | font_size: Some(10.0), | |
| 344 | color: Some(p.text_dim), | |
| 345 | center: true, | |
| 346 | ..ui::Spec::default() | |
| 347 | }, | |
| 348 | ); | |
| 349 | ui.close(); // insp-meta-row | |
| 350 | ui.close(); // insp-header | |
| 351 | 183 | |
| 352 | // 2. Scrollable Parameter List | |
| 353 | 184 | ui.open( |
| 354 | 185 | "insp-scroll", |
| 355 | ui::Spec { | |
| 356 | flags: ui::Flags::SCROLL | ui::Flags::CLIP, | |
| 357 | size: [ui::fill(), ui::fill()], | |
| 358 | axis: ui::Axis::Y, | |
| 359 | pad: [10.0, 8.0], | |
| 360 | gap: 6.0, | |
| 361 | ..ui::Spec::default() | |
| 362 | }, | |
| 186 | ui::Spec { flags: ui::Flags::SCROLL | ui::Flags::CLIP, size: [ui::fill(), ui::fill()], axis: ui::Axis::Y, pad: [6.0, 6.0], gap: 2.0, ..ui::Spec::default() }, | |
| 363 | 187 | ); |
| 364 | ||
| 365 | let schema = schema_for_kind(&node_kind); | |
| 366 | let mut covered: HashSet<&str> = HashSet::new(); | |
| 367 | ||
| 368 | for spec in schema { | |
| 369 | covered.insert(spec.name); | |
| 370 | if let ParamKind::Color { r, g, b, a, .. } = spec.kind { | |
| 371 | covered.insert(r); | |
| 372 | covered.insert(g); | |
| 373 | covered.insert(b); | |
| 374 | if let Some(alpha_k) = a { | |
| 375 | covered.insert(alpha_k); | |
| 188 | if let Some(page) = pages.nth(active) { | |
| 189 | for (i, section) in page.sections.iter().enumerate() { | |
| 190 | let key = (node_id.0, active, i); | |
| 191 | let open = self.sections.get(&key).copied().unwrap_or(section.open); | |
| 192 | let spec = ui::CompactDisclosure { body_gap: 2.0, body_pad: [0.0, 2.0], ..ui::CompactDisclosure::new(&section.title, open) }; | |
| 193 | let toggled = ui::compact_disclosure_with(ui, ("sec", key), spec, |ui| { | |
| 194 | for def in &section.controls { | |
| 195 | controls::render(ui, &mut cx, def); | |
| 196 | } | |
| 197 | }); | |
| 198 | if toggled { | |
| 199 | self.sections.insert(key, !open); | |
| 376 | 200 | } |
| 377 | 201 | } |
| 378 | self.render_param_spec(ui, pane_id, comp, history, node_id, spec, current_frame, &mut actions); | |
| 379 | } | |
| 380 | ||
| 381 | // Fallback: list all remaining present non-image inputs on the node! | |
| 382 | let extra_keys = schemas::extra_input_keys(comp, node_id, &covered); | |
| 383 | if !extra_keys.is_empty() { | |
| 202 | } else { | |
| 384 | 203 | ui.leaf( |
| 385 | "insp-extra-hdr", | |
| 386 | ui::Spec { | |
| 387 | size: [ui::fill(), ui::px(18.0)], | |
| 388 | text: Some("OTHER INPUTS"), | |
| 389 | font_size: Some(9.5), | |
| 390 | medium: true, | |
| 391 | color: Some(p.text_dim), | |
| 392 | ..ui::Spec::default() | |
| 393 | }, | |
| 204 | "insp-no-controls", | |
| 205 | ui::Spec { size: [ui::fill(), ui::px(20.0)], text: Some("No editable inputs"), font_size: Some(11.0), color: Some(p.text_dim), ..ui::Spec::default() }, | |
| 394 | 206 | ); |
| 395 | for key in extra_keys { | |
| 396 | self.render_fallback_input(ui, pane_id, comp, history, node_id, &key, current_frame, &mut actions); | |
| 397 | } | |
| 398 | 207 | } |
| 399 | ||
| 400 | // Loader / Saver clip filename summary | |
| 401 | if matches!(node_kind.as_str(), "Loader" | "Saver") { | |
| 402 | let clip_hdr = if node_kind == "Saver" { | |
| 403 | "Output Filename" | |
| 404 | } else { | |
| 405 | "Clip Filename" | |
| 406 | }; | |
| 407 | let node_ref = comp.node(node_id); | |
| 408 | let clip_summary = node_ref | |
| 409 | .clips | |
| 410 | .first() | |
| 411 | .map(|c| c.filename.clone()) | |
| 412 | .or_else(|| { | |
| 413 | node_ref | |
| 414 | .raw | |
| 415 | .get_table("Inputs") | |
| 416 | .and_then(|i| i.get_table("Clip")) | |
| 417 | .and_then(|c| c.get_table("Value")) | |
| 418 | .and_then(|v| v.get_str("Filename")) | |
| 419 | .map(str::to_owned) | |
| 420 | }) | |
| 421 | .unwrap_or_else(|| "(no clip)".to_owned()); | |
| 422 | ui.open( | |
| 423 | "insp-loader-clip", | |
| 424 | ui::Spec { | |
| 425 | size: [ui::fill(), ui::children()], | |
| 426 | axis: ui::Axis::Y, | |
| 427 | gap: 3.0, | |
| 428 | pad: [6.0, 5.0], | |
| 429 | fill: Some(p.panel_bg), | |
| 430 | border: Some(p.rule), | |
| 431 | radius: 4.0, | |
| 432 | ..ui::Spec::default() | |
| 433 | }, | |
| 434 | ); | |
| 435 | ui.leaf( | |
| 436 | "clip-lbl", | |
| 437 | ui::Spec { | |
| 438 | size: [ui::fill(), ui::px(14.0)], | |
| 439 | text: Some(clip_hdr), | |
| 440 | font_size: Some(10.0), | |
| 441 | color: Some(p.text_dim), | |
| 442 | ..ui::Spec::default() | |
| 443 | }, | |
| 444 | ); | |
| 445 | ui.leaf( | |
| 446 | "clip-path", | |
| 447 | ui::Spec { | |
| 448 | size: [ui::fill(), ui::fit()], | |
| 449 | text: Some(&clip_summary), | |
| 450 | font_size: Some(10.5), | |
| 451 | overflow: ui::Overflow::Wrap, | |
| 452 | color: Some(p.text), | |
| 453 | ..ui::Spec::default() | |
| 454 | }, | |
| 455 | ); | |
| 456 | ui.close(); | |
| 208 | if matches!(kind.as_str(), "Loader" | "Saver") { | |
| 209 | chrome::clip_summary(ui, &cx); | |
| 457 | 210 | } |
| 458 | ||
| 459 | 211 | ui.close(); // insp-scroll |
| 460 | 212 | |
| 461 | // 3. Footer: EvalStats summary | |
| 462 | self.render_stats_footer(ui, stats); | |
| 463 | ||
| 213 | chrome::footer(ui, p, stats); | |
| 464 | 214 | ui.close(); // pane_id |
| 465 | 215 | actions |
| 466 | 216 | } |
| 467 | } | |
| 468 | ||
| 469 | #[cfg(test)] | |
| 470 | mod tests { | |
| 471 | use super::*; | |
| 472 | 217 | |
| 473 | #[test] | |
| 474 | fn curated_schemas_cover_all_major_tools() { | |
| 475 | let required = [ | |
| 476 | // Original 18 | |
| 477 | "Merge", "Transform", "Blur", "Glow", "SoftGlow", "BrightnessContrast", | |
| 478 | "ColorCorrector", "Background", "TextPlus", "EllipseMask", "RectangleMask", | |
| 479 | "Displace", "Vortex", "FastNoise", "UltraKeyer", "Loader", "Camera3D", "Shape3D", | |
| 480 | // Wave 9E additions | |
| 481 | "Dissolve", "ChannelBoolean", "Saver", "Switch", "Fuse.Switch", | |
| 482 | "TimeStretcher", "TimeSpeed", | |
| 483 | "Paint", "PaintMask", "WandMask", "BitmapMask", | |
| 484 | "Drip", "Dent", "DaySky", "GridWarp", "PerspectivePositioner", | |
| 485 | "sRender", "sEllipse", "sRectangle", "sNGon", "sBoolean", "sTransform", "sOutline", "sGrid", | |
| 486 | "MtlBlinn", "MtlPhong", "MtlCookTorrance", | |
| 487 | "LightPoint", "LightSpot", "LightDirectional", "LightAmbient", | |
| 488 | "Cube3D", "SurfaceFBXMesh", "Custom", | |
| 489 | "ErodeDilate", "DirectionalBlur", "VariBlur", "Sharpen", "Shadow", | |
| 490 | "ColorGain", "HueCurves", "GamutConvert", "FilmGrain", | |
| 491 | ]; | |
| 492 | for tool in required { | |
| 493 | assert!( | |
| 494 | CURATED_TOOL_KINDS.contains(&tool), | |
| 495 | "{tool} missing from CURATED_TOOL_KINDS" | |
| 496 | ); | |
| 497 | let s = schema_for_kind(tool); | |
| 498 | assert!(!s.is_empty(), "expected non-empty curated schema for {tool}"); | |
| 499 | } | |
| 500 | for &tool in CURATED_TOOL_KINDS { | |
| 501 | assert!( | |
| 502 | !schema_for_kind(tool).is_empty(), | |
| 503 | "CURATED_TOOL_KINDS entry {tool} has empty schema" | |
| 504 | ); | |
| 505 | } | |
| 506 | assert!(schema_for_kind("UnknownCustomTool").is_empty()); | |
| 218 | fn loading(&self, ui: &mut ui::Ui, p: InspectorPalette, stats: &EvalStats, actions: Vec<InspectorAction>) -> Vec<InspectorAction> { | |
| 219 | ui.leaf( | |
| 220 | "insp-loading", | |
| 221 | ui::Spec { size: [ui::fill(), ui::fill()], pad: [14.0, 18.0], text: Some("Loading tool catalog…"), font_size: Some(11.0), color: Some(p.text_dim), ..ui::Spec::default() }, | |
| 222 | ); | |
| 223 | chrome::footer(ui, p, stats); | |
| 224 | ui.close(); | |
| 225 | actions | |
| 507 | 226 | } |
| 227 | } | |
| 508 | 228 | |
| 509 | #[test] | |
| 510 | fn curated_schemas_have_unique_params_and_valid_bounds() { | |
| 511 | let mut seen_tools = HashSet::new(); | |
| 512 | for &tool in CURATED_TOOL_KINDS { | |
| 513 | assert!(seen_tools.insert(tool), "duplicate tool in CURATED_TOOL_KINDS: {tool}"); | |
| 514 | let schema = schema_for_kind(tool); | |
| 515 | let mut names = HashSet::new(); | |
| 516 | for spec in schema { | |
| 517 | assert!( | |
| 518 | names.insert(spec.name), | |
| 519 | "duplicate parameter `{}` in schema for `{tool}`", | |
| 520 | spec.name | |
| 521 | ); | |
| 522 | match spec.kind { | |
| 523 | ParamKind::Float { min, max, default, step } => { | |
| 524 | assert!(min.is_finite() && max.is_finite() && default.is_finite() && step.is_finite()); | |
| 525 | assert!(min <= max, "{tool}.{}: min ({min}) > max ({max})", spec.name); | |
| 526 | assert!(step > 0.0, "{tool}.{}: step ({step}) <= 0", spec.name); | |
| 527 | assert!( | |
| 528 | (min..=max).contains(&default), | |
| 529 | "{tool}.{}: default ({default}) outside [{min}, {max}]", | |
| 530 | spec.name | |
| 531 | ); | |
| 532 | } | |
| 533 | ParamKind::Vec2 { min, max, default } => { | |
| 534 | assert!(min.is_finite() && max.is_finite()); | |
| 535 | assert!(min <= max, "{tool}.{}: min ({min}) > max ({max})", spec.name); | |
| 536 | for (axis, d) in default.iter().enumerate() { | |
| 537 | assert!( | |
| 538 | d.is_finite() && (min..=max).contains(d), | |
| 539 | "{tool}.{}[{axis}]: default ({d}) outside [{min}, {max}]", | |
| 540 | spec.name | |
| 541 | ); | |
| 542 | } | |
| 543 | } | |
| 544 | ParamKind::Enum { options, default } => { | |
| 545 | assert!(!options.is_empty(), "{tool}.{}: empty Enum options", spec.name); | |
| 546 | assert!( | |
| 547 | options.contains(&default), | |
| 548 | "{tool}.{}: default `{default}` not in options {options:?}", | |
| 549 | spec.name | |
| 550 | ); | |
| 551 | } | |
| 552 | ParamKind::IntEnum { options, default } => { | |
| 553 | assert!(!options.is_empty(), "{tool}.{}: empty IntEnum options", spec.name); | |
| 554 | let mut codes = HashSet::new(); | |
| 555 | for &(code, _) in options { | |
| 556 | assert!( | |
| 557 | codes.insert(code), | |
| 558 | "{tool}.{}: duplicate IntEnum code {code}", | |
| 559 | spec.name | |
| 560 | ); | |
| 561 | } | |
| 562 | assert!( | |
| 563 | codes.contains(&default), | |
| 564 | "{tool}.{}: default {default} not in IntEnum options", | |
| 565 | spec.name | |
| 566 | ); | |
| 567 | } | |
| 568 | ParamKind::Color { r, g, b, a, default } => { | |
| 569 | for ch in [r, g, b].into_iter().chain(a) { | |
| 570 | assert!( | |
| 571 | names.insert(ch), | |
| 572 | "duplicate color channel `{ch}` in schema for `{tool}`" | |
| 573 | ); | |
| 574 | } | |
| 575 | for (idx, c) in default.iter().enumerate() { | |
| 576 | assert!( | |
| 577 | c.is_finite() && (0.0..=1.0).contains(c), | |
| 578 | "{tool}.{}[{idx}]: color default ({c}) outside [0, 1]", | |
| 579 | spec.name | |
| 580 | ); | |
| 581 | } | |
| 582 | } | |
| 583 | ParamKind::Bool { .. } | ParamKind::Text { .. } => {} | |
| 584 | } | |
| 585 | } | |
| 229 | /// Commits what loses the keys and closes a rested drag's undo step. | |
| 230 | fn settle_edits(ui: &mut ui::Ui, cx: &mut edit::Cx) { | |
| 231 | if let Some(last) = cx.edit.last_scrub { | |
| 232 | if cx.now.duration_since(last) > edit::SCRUB_GRACE { | |
| 233 | cx.history.break_coalescing(); | |
| 234 | cx.edit.last_scrub = None; | |
| 235 | } else { | |
| 236 | ui.wake_after(edit::SCRUB_GRACE); | |
| 586 | 237 | } |
| 587 | 238 | } |
| 588 | ||
| 589 | #[test] | |
| 590 | fn slider_math_and_clamping() { | |
| 591 | assert!((normalize_slider_fraction(0.5, 0.0, 1.0) - 0.5).abs() < 1e-6); | |
| 592 | assert!((normalize_slider_fraction(-5.0, 0.0, 1.0) - 0.0).abs() < 1e-6); | |
| 593 | assert!((normalize_slider_fraction(10.0, 0.0, 1.0) - 1.0).abs() < 1e-6); | |
| 594 | ||
| 595 | let v = compute_scrub_value(0.5, 50.0, 100.0, 0.0, 1.0, 1.0); | |
| 596 | assert!((v - 1.0).abs() < 1e-6); | |
| 597 | let v_fine = compute_scrub_value(0.5, 50.0, 100.0, 0.0, 1.0, 0.1); | |
| 598 | assert!((v_fine - 0.55).abs() < 1e-6); | |
| 239 | if let Some(number) = cx.edit.number.take_if(|n| ui.focused() != Some(n.id)) { | |
| 240 | cx.commit_number(number); | |
| 599 | 241 | } |
| 242 | if cx.edit.text.take_if(|(id, _)| ui.focused() != Some(*id)).is_some() { | |
| 243 | cx.history.break_coalescing(); | |
| 244 | } | |
| 245 | } | |
| 600 | 246 | |
| 601 | #[test] | |
| 602 | fn keyframe_state_transitions() { | |
| 603 | let src = r#"Composition { | |
| 604 | Tools = ordered() { | |
| 605 | BC1 = BrightnessContrast { | |
| 606 | Inputs = { Gain = Input { Value = 1.0 } }, | |
| 607 | }, | |
| 608 | }, | |
| 609 | }"#; | |
| 610 | let mut comp = Comp::from_fusion_str(src).unwrap(); | |
| 611 | let bc = comp.find_node("BC1").unwrap(); | |
| 612 | assert_eq!(keyframe_state(&comp, bc, "Gain", 10.0), KeyframeState::Static); | |
| 613 | ||
| 614 | let sp = comp.set_keyframe(bc, "Gain", 10.0, 1.5).unwrap(); | |
| 615 | assert_eq!(keyframe_state(&comp, bc, "Gain", 10.0), KeyframeState::KeyframeAtCurrent); | |
| 616 | assert_eq!(keyframe_state(&comp, bc, "Gain", 20.0), KeyframeState::AnimatedOtherFrame); | |
| 617 | ||
| 618 | assert!(comp.delete_keyframe(&sp, 10.0)); | |
| 619 | assert_eq!(keyframe_state(&comp, bc, "Gain", 10.0), KeyframeState::Static); | |
| 247 | /// The node's `UserControls` (one page per `ICS_ControlPage`) and inputs no catalog row covers. | |
| 248 | fn node_pages(comp: &Comp, node: NodeId, layout: &ToolLayout) -> Vec<Page> { | |
| 249 | let mut by_page: Vec<(String, Vec<catalog::InputDef>)> = Vec::new(); | |
| 250 | for mut def in dynamic::user_defs(&comp.node(node).raw) { | |
| 251 | let name = def.page.take().unwrap_or_default(); | |
| 252 | let name = if layout.pages.iter().any(|p| p.name == name) { "User".to_owned() } else { name }; | |
| 253 | match by_page.iter_mut().find(|(n, _)| *n == name) { | |
| 254 | Some((_, defs)) => defs.push(def), | |
| 255 | None => by_page.push((name, vec![def])), | |
| 256 | } | |
| 257 | } | |
| 258 | let user_ids: Vec<&str> = by_page.iter().flat_map(|(_, defs)| defs.iter().map(|d| d.id.as_str())).collect(); | |
| 259 | let extras = dynamic::extra_defs(comp, node, |id| layout.covered.contains(id) || user_ids.contains(&id)); | |
| 260 | if !extras.is_empty() { | |
| 261 | by_page.push(("Other".to_owned(), extras)); | |
| 620 | 262 | } |
| 263 | by_page.iter().map(|(name, defs)| layout::dynamic_page(name, defs)).collect() | |
| 621 | 264 | } |
| 265 | ||
| 266 | #[cfg(test)] | |
| 267 | mod tests; |
crates/app/src/inspector/rows.rs deleted-591| ... | ... | @@ -1,591 +0,0 @@ |
| 1 | //! Parameter row renderers for [`InspectorState`]: float, vec2, bool, enum, int-enum, | |
| 2 | //! combo, RGBA color group, and text rows. | |
| 3 | ||
| 4 | use super::super::{InspectorAction, InspectorState}; | |
| 5 | use super::{ | |
| 6 | KeyframeState, combo_cycle_index, enum_option_index, int_enum_lookup, keyframe_state, | |
| 7 | }; | |
| 8 | use model::{Comp, CompHistory, NodeId, ParamValue}; | |
| 9 | ||
| 10 | impl InspectorState { | |
| 11 | #[allow(clippy::too_many_arguments)] | |
| 12 | pub(super) fn render_float_row( | |
| 13 | &mut self, | |
| 14 | ui: &mut ui::Ui, | |
| 15 | pane_id: ui::Id, | |
| 16 | comp: &mut Comp, | |
| 17 | history: &mut CompHistory, | |
| 18 | node_id: NodeId, | |
| 19 | input_name: &str, | |
| 20 | label: &str, | |
| 21 | min: f64, | |
| 22 | max: f64, | |
| 23 | default: f64, | |
| 24 | current_frame: f64, | |
| 25 | actions: &mut Vec<InspectorAction>, | |
| 26 | ) { | |
| 27 | let cur_val = comp.eval_number(comp.node(node_id), input_name, current_frame, default, &self.expr); | |
| 28 | let has_expr = comp | |
| 29 | .node(node_id) | |
| 30 | .inputs | |
| 31 | .get(input_name) | |
| 32 | .and_then(|b| b.expression.as_ref()) | |
| 33 | .is_some(); | |
| 34 | let kf_state = keyframe_state(comp, node_id, input_name, current_frame); | |
| 35 | let p = self.palette; | |
| 36 | ||
| 37 | ui.open( | |
| 38 | ("row-f", node_id.0, input_name), | |
| 39 | ui::Spec { | |
| 40 | size: [ui::fill(), ui::px(22.0)], | |
| 41 | axis: ui::Axis::X, | |
| 42 | gap: 4.0, | |
| 43 | ..ui::Spec::default() | |
| 44 | }, | |
| 45 | ); | |
| 46 | ||
| 47 | // Label | |
| 48 | ui.leaf( | |
| 49 | "lbl", | |
| 50 | ui::Spec { | |
| 51 | size: [ui::px(86.0), ui::fill()], | |
| 52 | text: Some(label), | |
| 53 | font_size: Some(10.5), | |
| 54 | overflow: ui::Overflow::Ellipsis, | |
| 55 | color: Some(p.text_dim), | |
| 56 | ..ui::Spec::default() | |
| 57 | }, | |
| 58 | ); | |
| 59 | ||
| 60 | // Expression `=` badge if present | |
| 61 | if has_expr { | |
| 62 | render_expr_badge(ui); | |
| 63 | } | |
| 64 | ||
| 65 | // Scrub slider | |
| 66 | let slider_id = pane_id.child(("sld", node_id.0, input_name)); | |
| 67 | let drag_key = format!("{}:{input_name}", node_id.0); | |
| 68 | if let Some(new_val) = self.scrub_slider( | |
| 69 | ui, | |
| 70 | slider_id, | |
| 71 | &drag_key, | |
| 72 | node_id, | |
| 73 | cur_val, | |
| 74 | min, | |
| 75 | max, | |
| 76 | default, | |
| 77 | history, | |
| 78 | comp, | |
| 79 | input_name, | |
| 80 | ) { | |
| 81 | if kf_state != KeyframeState::Static { | |
| 82 | let _ = comp.set_keyframe(node_id, input_name, current_frame, new_val); | |
| 83 | actions.push(InspectorAction::KeyframeEdited(node_id)); | |
| 84 | } else { | |
| 85 | comp.set_input_value(node_id, input_name, ParamValue::Number(new_val)); | |
| 86 | actions.push(InspectorAction::ParamEdited(node_id)); | |
| 87 | } | |
| 88 | } | |
| 89 | ||
| 90 | // Reset button (small dot/arrow when non-default) | |
| 91 | let is_default = (cur_val - default).abs() < 1e-4; | |
| 92 | if !is_default { | |
| 93 | let rst = ui.leaf( | |
| 94 | ("rst", node_id.0, input_name), | |
| 95 | ui::Spec { | |
| 96 | cursor: Some(winit::window::CursorIcon::Pointer), | |
| 97 | flags: ui::Flags::CLICKABLE, | |
| 98 | size: [ui::px(18.0), ui::px(20.0)], | |
| 99 | text: Some("↺"), | |
| 100 | font_size: Some(10.5), | |
| 101 | color: Some(p.text_dim), | |
| 102 | hover_fill: Some(p.panel_bg), | |
| 103 | radius: 3.0, | |
| 104 | center: true, | |
| 105 | ..ui::Spec::default() | |
| 106 | }, | |
| 107 | ); | |
| 108 | if rst.clicked { | |
| 109 | history.push_snapshot(comp, format!("Reset {label}")); | |
| 110 | if kf_state != KeyframeState::Static { | |
| 111 | let _ = comp.set_keyframe(node_id, input_name, current_frame, default); | |
| 112 | actions.push(InspectorAction::KeyframeEdited(node_id)); | |
| 113 | } else { | |
| 114 | comp.set_input_value(node_id, input_name, ParamValue::Number(default)); | |
| 115 | actions.push(InspectorAction::ParamEdited(node_id)); | |
| 116 | } | |
| 117 | } | |
| 118 | } | |
| 119 | ||
| 120 | // Keyframe diamond button (`◆`) | |
| 121 | if self.keyframe_button(ui, ("kf", node_id.0, input_name), kf_state) { | |
| 122 | self.toggle_keyframe(comp, history, node_id, input_name, current_frame, cur_val, kf_state, actions); | |
| 123 | } | |
| 124 | ||
| 125 | ui.close(); | |
| 126 | } | |
| 127 | ||
| 128 | #[allow(clippy::too_many_arguments)] | |
| 129 | pub(super) fn render_vec2_row( | |
| 130 | &mut self, | |
| 131 | ui: &mut ui::Ui, | |
| 132 | pane_id: ui::Id, | |
| 133 | comp: &mut Comp, | |
| 134 | history: &mut CompHistory, | |
| 135 | node_id: NodeId, | |
| 136 | input_name: &str, | |
| 137 | label: &str, | |
| 138 | min: f64, | |
| 139 | max: f64, | |
| 140 | default: [f64; 2], | |
| 141 | current_frame: f64, | |
| 142 | actions: &mut Vec<InspectorAction>, | |
| 143 | ) { | |
| 144 | let cur = comp.eval_point(comp.node(node_id), input_name, current_frame, default, &self.expr); | |
| 145 | let has_expr = comp | |
| 146 | .node(node_id) | |
| 147 | .inputs | |
| 148 | .get(input_name) | |
| 149 | .and_then(|b| b.expression.as_ref()) | |
| 150 | .is_some(); | |
| 151 | ||
| 152 | ui.open( | |
| 153 | ("row-v2", node_id.0, input_name), | |
| 154 | ui::Spec { | |
| 155 | size: [ui::fill(), ui::px(22.0)], | |
| 156 | axis: ui::Axis::X, | |
| 157 | gap: 4.0, | |
| 158 | ..ui::Spec::default() | |
| 159 | }, | |
| 160 | ); | |
| 161 | ui.leaf( | |
| 162 | "lbl", | |
| 163 | ui::Spec { | |
| 164 | size: [ui::px(86.0), ui::fill()], | |
| 165 | text: Some(label), | |
| 166 | font_size: Some(10.5), | |
| 167 | overflow: ui::Overflow::Ellipsis, | |
| 168 | color: Some(self.palette.text_dim), | |
| 169 | ..ui::Spec::default() | |
| 170 | }, | |
| 171 | ); | |
| 172 | if has_expr { | |
| 173 | render_expr_badge(ui); | |
| 174 | } | |
| 175 | ||
| 176 | let x_id = pane_id.child(("v2x", node_id.0, input_name)); | |
| 177 | let x_key = format!("{}:{input_name}:x", node_id.0); | |
| 178 | if let Some(nx) = self.scrub_slider( | |
| 179 | ui, | |
| 180 | x_id, | |
| 181 | &x_key, | |
| 182 | node_id, | |
| 183 | cur[0], | |
| 184 | min, | |
| 185 | max, | |
| 186 | default[0], | |
| 187 | history, | |
| 188 | comp, | |
| 189 | input_name, | |
| 190 | ) { | |
| 191 | comp.set_input_value(node_id, input_name, ParamValue::Point([nx, cur[1]])); | |
| 192 | actions.push(InspectorAction::ParamEdited(node_id)); | |
| 193 | } | |
| 194 | ||
| 195 | let y_id = pane_id.child(("v2y", node_id.0, input_name)); | |
| 196 | let y_key = format!("{}:{input_name}:y", node_id.0); | |
| 197 | if let Some(ny) = self.scrub_slider( | |
| 198 | ui, | |
| 199 | y_id, | |
| 200 | &y_key, | |
| 201 | node_id, | |
| 202 | cur[1], | |
| 203 | min, | |
| 204 | max, | |
| 205 | default[1], | |
| 206 | history, | |
| 207 | comp, | |
| 208 | input_name, | |
| 209 | ) { | |
| 210 | comp.set_input_value(node_id, input_name, ParamValue::Point([cur[0], ny])); | |
| 211 | actions.push(InspectorAction::ParamEdited(node_id)); | |
| 212 | } | |
| 213 | ||
| 214 | ui.close(); | |
| 215 | } | |
| 216 | ||
| 217 | #[allow(clippy::too_many_arguments)] | |
| 218 | pub(super) fn render_bool_row( | |
| 219 | &mut self, | |
| 220 | ui: &mut ui::Ui, | |
| 221 | comp: &mut Comp, | |
| 222 | history: &mut CompHistory, | |
| 223 | node_id: NodeId, | |
| 224 | input_name: &str, | |
| 225 | label: &str, | |
| 226 | default: bool, | |
| 227 | actions: &mut Vec<InspectorAction>, | |
| 228 | ) { | |
| 229 | let checked = comp | |
| 230 | .node(node_id) | |
| 231 | .static_number(input_name) | |
| 232 | .map(|v| v >= 0.5) | |
| 233 | .unwrap_or(default); | |
| 234 | let p = self.palette; | |
| 235 | ||
| 236 | ui.open( | |
| 237 | ("row-b", node_id.0, input_name), | |
| 238 | ui::Spec { | |
| 239 | size: [ui::fill(), ui::px(22.0)], | |
| 240 | axis: ui::Axis::X, | |
| 241 | gap: 6.0, | |
| 242 | ..ui::Spec::default() | |
| 243 | }, | |
| 244 | ); | |
| 245 | ui.leaf( | |
| 246 | "lbl", | |
| 247 | ui::Spec { | |
| 248 | size: [ui::px(86.0), ui::fill()], | |
| 249 | text: Some(label), | |
| 250 | font_size: Some(10.5), | |
| 251 | overflow: ui::Overflow::Ellipsis, | |
| 252 | color: Some(p.text_dim), | |
| 253 | ..ui::Spec::default() | |
| 254 | }, | |
| 255 | ); | |
| 256 | let fill = if checked { | |
| 257 | [p.accent[0], p.accent[1], p.accent[2], 0.28] | |
| 258 | } else { | |
| 259 | p.panel_bg | |
| 260 | }; | |
| 261 | let border = if checked { p.accent } else { p.rule }; | |
| 262 | let sig = ui.leaf( | |
| 263 | ("chk", node_id.0, input_name), | |
| 264 | ui::Spec { | |
| 265 | cursor: Some(winit::window::CursorIcon::Pointer), | |
| 266 | flags: ui::Flags::CLICKABLE, | |
| 267 | size: [ui::px(54.0), ui::px(20.0)], | |
| 268 | text: Some(if checked { "✓ On" } else { "Off" }), | |
| 269 | font_size: Some(10.5), | |
| 270 | medium: checked, | |
| 271 | color: Some(if checked { p.text } else { p.text_dim }), | |
| 272 | fill: Some(fill), | |
| 273 | border: Some(border), | |
| 274 | radius: 4.0, | |
| 275 | center: true, | |
| 276 | ..ui::Spec::default() | |
| 277 | }, | |
| 278 | ); | |
| 279 | if sig.clicked { | |
| 280 | history.push_snapshot(comp, format!("Toggle {label}")); | |
| 281 | let next = if checked { 0.0 } else { 1.0 }; | |
| 282 | comp.set_input_value(node_id, input_name, ParamValue::Number(next)); | |
| 283 | actions.push(InspectorAction::ParamEdited(node_id)); | |
| 284 | } | |
| 285 | ui.close(); | |
| 286 | } | |
| 287 | ||
| 288 | #[allow(clippy::too_many_arguments)] | |
| 289 | pub(super) fn render_enum_row( | |
| 290 | &mut self, | |
| 291 | ui: &mut ui::Ui, | |
| 292 | comp: &mut Comp, | |
| 293 | history: &mut CompHistory, | |
| 294 | node_id: NodeId, | |
| 295 | input_name: &str, | |
| 296 | label: &str, | |
| 297 | options: &'static [&'static str], | |
| 298 | default: &'static str, | |
| 299 | actions: &mut Vec<InspectorAction>, | |
| 300 | ) { | |
| 301 | let cur = comp | |
| 302 | .node(node_id) | |
| 303 | .static_str(input_name) | |
| 304 | .unwrap_or(default) | |
| 305 | .to_owned(); | |
| 306 | let idx = enum_option_index(options, &cur); | |
| 307 | if let Some(next_idx) = self.render_combo_row(ui, node_id, input_name, label, &cur, idx, options.len()) { | |
| 308 | history.push_snapshot(comp, format!("Set {label}")); | |
| 309 | comp.set_input_value(node_id, input_name, ParamValue::FuId(options[next_idx].to_owned())); | |
| 310 | actions.push(InspectorAction::ParamEdited(node_id)); | |
| 311 | } | |
| 312 | } | |
| 313 | ||
| 314 | #[allow(clippy::too_many_arguments)] | |
| 315 | pub(super) fn render_int_enum_row( | |
| 316 | &mut self, | |
| 317 | ui: &mut ui::Ui, | |
| 318 | comp: &mut Comp, | |
| 319 | history: &mut CompHistory, | |
| 320 | node_id: NodeId, | |
| 321 | input_name: &str, | |
| 322 | label: &str, | |
| 323 | options: &'static [(i32, &'static str)], | |
| 324 | default: i32, | |
| 325 | actions: &mut Vec<InspectorAction>, | |
| 326 | ) { | |
| 327 | let cur_val = comp | |
| 328 | .node(node_id) | |
| 329 | .static_number(input_name) | |
| 330 | .map(|v| v.round() as i32) | |
| 331 | .unwrap_or(default); | |
| 332 | let (idx, cur_label) = int_enum_lookup(options, cur_val); | |
| 333 | if let Some(next_idx) = self.render_combo_row(ui, node_id, input_name, label, &cur_label, idx, options.len()) { | |
| 334 | history.push_snapshot(comp, format!("Set {label}")); | |
| 335 | comp.set_input_value(node_id, input_name, ParamValue::Number(f64::from(options[next_idx].0))); | |
| 336 | actions.push(InspectorAction::ParamEdited(node_id)); | |
| 337 | } | |
| 338 | } | |
| 339 | ||
| 340 | #[allow(clippy::too_many_arguments)] | |
| 341 | fn render_combo_row( | |
| 342 | &self, | |
| 343 | ui: &mut ui::Ui, | |
| 344 | node_id: NodeId, | |
| 345 | input_name: &str, | |
| 346 | label: &str, | |
| 347 | cur_label: &str, | |
| 348 | cur_idx: usize, | |
| 349 | option_count: usize, | |
| 350 | ) -> Option<usize> { | |
| 351 | let p = self.palette; | |
| 352 | ||
| 353 | ui.open( | |
| 354 | ("row-e", node_id.0, input_name), | |
| 355 | ui::Spec { | |
| 356 | size: [ui::fill(), ui::px(22.0)], | |
| 357 | axis: ui::Axis::X, | |
| 358 | gap: 6.0, | |
| 359 | ..ui::Spec::default() | |
| 360 | }, | |
| 361 | ); | |
| 362 | ui.leaf( | |
| 363 | "lbl", | |
| 364 | ui::Spec { | |
| 365 | size: [ui::px(86.0), ui::fill()], | |
| 366 | text: Some(label), | |
| 367 | font_size: Some(10.5), | |
| 368 | overflow: ui::Overflow::Ellipsis, | |
| 369 | color: Some(p.text_dim), | |
| 370 | ..ui::Spec::default() | |
| 371 | }, | |
| 372 | ); | |
| 373 | let btn_lbl = format!("{cur_label} ▾"); | |
| 374 | let sig = ui.leaf( | |
| 375 | ("enum", node_id.0, input_name), | |
| 376 | ui::Spec { | |
| 377 | cursor: Some(winit::window::CursorIcon::Pointer), | |
| 378 | flags: ui::Flags::CLICKABLE, | |
| 379 | size: [ui::fill(), ui::px(20.0)], | |
| 380 | text: Some(&btn_lbl), | |
| 381 | font_size: Some(10.5), | |
| 382 | color: Some(p.text), | |
| 383 | fill: Some(p.panel_bg), | |
| 384 | border: Some(p.rule), | |
| 385 | hover_border: Some(p.accent), | |
| 386 | radius: 4.0, | |
| 387 | pad: [6.0, 0.0], | |
| 388 | ..ui::Spec::default() | |
| 389 | }, | |
| 390 | ); | |
| 391 | let next = if sig.clicked { | |
| 392 | combo_cycle_index(cur_idx, option_count, ui.modifiers().shift_key()) | |
| 393 | } else { | |
| 394 | None | |
| 395 | }; | |
| 396 | ui.close(); | |
| 397 | next | |
| 398 | } | |
| 399 | ||
| 400 | #[allow(clippy::too_many_arguments)] | |
| 401 | pub(super) fn render_color_group( | |
| 402 | &mut self, | |
| 403 | ui: &mut ui::Ui, | |
| 404 | pane_id: ui::Id, | |
| 405 | comp: &mut Comp, | |
| 406 | history: &mut CompHistory, | |
| 407 | node_id: NodeId, | |
| 408 | label: &str, | |
| 409 | r_key: &'static str, | |
| 410 | g_key: &'static str, | |
| 411 | b_key: &'static str, | |
| 412 | a_key: Option<&'static str>, | |
| 413 | default: [f64; 4], | |
| 414 | current_frame: f64, | |
| 415 | actions: &mut Vec<InspectorAction>, | |
| 416 | ) { | |
| 417 | let rv = comp.eval_number(comp.node(node_id), r_key, current_frame, default[0], &self.expr); | |
| 418 | let gv = comp.eval_number(comp.node(node_id), g_key, current_frame, default[1], &self.expr); | |
| 419 | let bv = comp.eval_number(comp.node(node_id), b_key, current_frame, default[2], &self.expr); | |
| 420 | let _av = a_key | |
| 421 | .map(|ak| comp.eval_number(comp.node(node_id), ak, current_frame, default[3], &self.expr)) | |
| 422 | .unwrap_or(default[3]); | |
| 423 | let swatch = [ | |
| 424 | rv.clamp(0.0, 1.0) as f32, | |
| 425 | gv.clamp(0.0, 1.0) as f32, | |
| 426 | bv.clamp(0.0, 1.0) as f32, | |
| 427 | 1.0, | |
| 428 | ]; | |
| 429 | let p = self.palette; | |
| 430 | ||
| 431 | ui.open( | |
| 432 | ("grp-col", node_id.0, label), | |
| 433 | ui::Spec { | |
| 434 | size: [ui::fill(), ui::children()], | |
| 435 | axis: ui::Axis::Y, | |
| 436 | gap: 4.0, | |
| 437 | pad: [6.0, 5.0], | |
| 438 | fill: Some(p.panel_bg), | |
| 439 | border: Some(p.rule), | |
| 440 | radius: 4.0, | |
| 441 | ..ui::Spec::default() | |
| 442 | }, | |
| 443 | ); | |
| 444 | // Swatch header | |
| 445 | ui.open( | |
| 446 | "col-hdr", | |
| 447 | ui::Spec { | |
| 448 | size: [ui::fill(), ui::px(18.0)], | |
| 449 | axis: ui::Axis::X, | |
| 450 | gap: 6.0, | |
| 451 | ..ui::Spec::default() | |
| 452 | }, | |
| 453 | ); | |
| 454 | ui.leaf( | |
| 455 | "col-lbl", | |
| 456 | ui::Spec { | |
| 457 | size: [ui::px(80.0), ui::fill()], | |
| 458 | text: Some(label), | |
| 459 | font_size: Some(10.5), | |
| 460 | medium: true, | |
| 461 | color: Some(p.text), | |
| 462 | ..ui::Spec::default() | |
| 463 | }, | |
| 464 | ); | |
| 465 | ui.leaf( | |
| 466 | "col-swatch", | |
| 467 | ui::Spec { | |
| 468 | size: [ui::fill(), ui::px(16.0)], | |
| 469 | fill: Some(swatch), | |
| 470 | border: Some(p.rule), | |
| 471 | radius: 3.0, | |
| 472 | ..ui::Spec::default() | |
| 473 | }, | |
| 474 | ); | |
| 475 | ui.close(); | |
| 476 | ||
| 477 | self.render_float_row(ui, pane_id, comp, history, node_id, r_key, "Red", 0.0, 1.0, default[0], current_frame, actions); | |
| 478 | self.render_float_row(ui, pane_id, comp, history, node_id, g_key, "Green", 0.0, 1.0, default[1], current_frame, actions); | |
| 479 | self.render_float_row(ui, pane_id, comp, history, node_id, b_key, "Blue", 0.0, 1.0, default[2], current_frame, actions); | |
| 480 | if let Some(ak) = a_key { | |
| 481 | self.render_float_row(ui, pane_id, comp, history, node_id, ak, "Alpha", 0.0, 1.0, default[3], current_frame, actions); | |
| 482 | } | |
| 483 | ui.close(); | |
| 484 | } | |
| 485 | ||
| 486 | #[allow(clippy::too_many_arguments)] | |
| 487 | pub(super) fn render_text_row( | |
| 488 | &mut self, | |
| 489 | ui: &mut ui::Ui, | |
| 490 | pane_id: ui::Id, | |
| 491 | comp: &mut Comp, | |
| 492 | history: &mut CompHistory, | |
| 493 | node_id: NodeId, | |
| 494 | input_name: &str, | |
| 495 | label: &str, | |
| 496 | default: &str, | |
| 497 | actions: &mut Vec<InspectorAction>, | |
| 498 | ) { | |
| 499 | let field_id = pane_id.child(("txt", node_id.0, input_name)); | |
| 500 | if self.text_focus == Some(field_id) && ui.focused() != Some(field_id) { | |
| 501 | self.text_focus = None; | |
| 502 | history.break_coalescing(); | |
| 503 | } | |
| 504 | let key = (node_id.0, input_name.to_owned()); | |
| 505 | let model_val = comp | |
| 506 | .node(node_id) | |
| 507 | .static_str(input_name) | |
| 508 | .unwrap_or(default) | |
| 509 | .to_owned(); | |
| 510 | let p = self.palette; | |
| 511 | let buf = self.text_bufs.entry(key).or_insert_with(|| model_val.clone()); | |
| 512 | if ui.focused() != Some(field_id) && *buf != model_val { | |
| 513 | *buf = model_val.clone(); | |
| 514 | } | |
| 515 | let prev = buf.clone(); | |
| 516 | ||
| 517 | ui.open( | |
| 518 | ("row-t", node_id.0, input_name), | |
| 519 | ui::Spec { | |
| 520 | size: [ui::fill(), ui::px(24.0)], | |
| 521 | axis: ui::Axis::X, | |
| 522 | gap: 6.0, | |
| 523 | ..ui::Spec::default() | |
| 524 | }, | |
| 525 | ); | |
| 526 | ui.leaf( | |
| 527 | "lbl", | |
| 528 | ui::Spec { | |
| 529 | size: [ui::px(86.0), ui::fill()], | |
| 530 | text: Some(label), | |
| 531 | font_size: Some(10.5), | |
| 532 | overflow: ui::Overflow::Ellipsis, | |
| 533 | color: Some(p.text_dim), | |
| 534 | ..ui::Spec::default() | |
| 535 | }, | |
| 536 | ); | |
| 537 | let sig = ui::text_field( | |
| 538 | ui, | |
| 539 | field_id, | |
| 540 | buf, | |
| 541 | label, | |
| 542 | ui::Spec { | |
| 543 | size: [ui::fill(), ui::px(22.0)], | |
| 544 | font_size: Some(11.0), | |
| 545 | fill: Some(p.panel_bg), | |
| 546 | border: Some(p.rule), | |
| 547 | hover_border: Some(p.accent), | |
| 548 | radius: 4.0, | |
| 549 | pad: [6.0, 2.0], | |
| 550 | ..ui::Spec::default() | |
| 551 | }, | |
| 552 | ); | |
| 553 | if ui.focused() == Some(field_id) { | |
| 554 | self.text_focus = Some(field_id); | |
| 555 | } | |
| 556 | let committed = sig.events.iter().any(|ev| { | |
| 557 | matches!(ev, ui::Event::Key { key: winit::keyboard::Key::Named(winit::keyboard::NamedKey::Enter), .. }) | |
| 558 | }); | |
| 559 | if *buf != prev { | |
| 560 | history.push_coalesced( | |
| 561 | comp, | |
| 562 | format!("Edit {label}"), | |
| 563 | format!("text:{}:{input_name}", node_id.0), | |
| 564 | ); | |
| 565 | comp.set_input_value(node_id, input_name, ParamValue::Text(buf.clone())); | |
| 566 | actions.push(InspectorAction::ParamEdited(node_id)); | |
| 567 | } | |
| 568 | if committed { | |
| 569 | history.break_coalescing(); | |
| 570 | } | |
| 571 | ui.close(); | |
| 572 | } | |
| 573 | } | |
| 574 | ||
| 575 | fn render_expr_badge(ui: &mut ui::Ui) { | |
| 576 | ui.leaf( | |
| 577 | "expr-badge", | |
| 578 | ui::Spec { | |
| 579 | size: [ui::px(16.0), ui::px(18.0)], | |
| 580 | text: Some("="), | |
| 581 | font_size: Some(10.5), | |
| 582 | bold: true, | |
| 583 | color: Some([0.36, 0.88, 0.92, 1.0]), | |
| 584 | fill: Some([0.10, 0.24, 0.28, 0.85]), | |
| 585 | border: Some([0.32, 0.78, 0.86, 0.65]), | |
| 586 | radius: 3.0, | |
| 587 | center: true, | |
| 588 | ..ui::Spec::default() | |
| 589 | }, | |
| 590 | ); | |
| 591 | } |
crates/app/src/inspector/schemas.rs+1-32| ... | ... | @@ -1,7 +1,4 @@ |
| 1 | //! Curated Fusion 21.1 parameter schemas and fallback input discovery for the Inspector. | |
| 2 | ||
| 3 | use model::{Comp, NodeId}; | |
| 4 | use std::collections::HashSet; | |
| 1 | //! Curated Fusion 21.1 parameter schemas: the layout for tools the introspected catalog lacks. | |
| 5 | 2 | |
| 6 | 3 | #[derive(Clone, Copy, Debug, PartialEq)] |
| 7 | 4 | pub enum ParamKind { |
| ... | ... | @@ -27,34 +24,6 @@ pub struct ParamSpec { |
| 27 | 24 | pub kind: ParamKind, |
| 28 | 25 | } |
| 29 | 26 | |
| 30 | /// Collects and sorts remaining non-image inputs on `node_id` not covered by its curated schema. | |
| 31 | pub(super) fn extra_input_keys(comp: &Comp, node_id: NodeId, covered: &HashSet<&str>) -> Vec<String> { | |
| 32 | let mut extra_keys: Vec<String> = comp | |
| 33 | .node(node_id) | |
| 34 | .inputs | |
| 35 | .iter() | |
| 36 | .filter_map(|(k, b)| { | |
| 37 | if covered.contains(k.as_str()) { | |
| 38 | return None; | |
| 39 | } | |
| 40 | // Skip image/node connections unless they also have a value or spline | |
| 41 | let is_node_conn = b | |
| 42 | .source_op | |
| 43 | .as_deref() | |
| 44 | .is_some_and(|op| comp.node_by_name.contains_key(op)); | |
| 45 | if is_node_conn && b.value.is_none() { | |
| 46 | return None; | |
| 47 | } | |
| 48 | if b.value.is_none() && b.expression.is_none() && b.source_op.is_none() { | |
| 49 | return None; | |
| 50 | } | |
| 51 | Some(k.clone()) | |
| 52 | }) | |
| 53 | .collect(); | |
| 54 | extra_keys.sort(); | |
| 55 | extra_keys | |
| 56 | } | |
| 57 | ||
| 58 | 27 | pub fn infer_float_range(name: &str, val: f64) -> (f64, f64) { |
| 59 | 28 | let lower = name.to_ascii_lowercase(); |
| 60 | 29 | if lower.contains("angle") || lower.contains("rotate") { |
crates/app/src/inspector/tests.rs created+442| ... | ... | @@ -0,0 +1,442 @@ |
| 1 | //! Registry consistency: curated schemas, the parsed Fusion catalog and its grouping. | |
| 2 | ||
| 3 | use super::schemas::{ParamKind, schema_for_kind}; | |
| 4 | use super::CURATED_TOOL_KINDS; | |
| 5 | use std::collections::HashSet; | |
| 6 | ||
| 7 | #[test] | |
| 8 | fn curated_schemas_cover_all_major_tools() { | |
| 9 | let required = [ | |
| 10 | // Original 18 | |
| 11 | "Merge", "Transform", "Blur", "Glow", "SoftGlow", "BrightnessContrast", | |
| 12 | "ColorCorrector", "Background", "TextPlus", "EllipseMask", "RectangleMask", | |
| 13 | "Displace", "Vortex", "FastNoise", "UltraKeyer", "Loader", "Camera3D", "Shape3D", | |
| 14 | // Wave 9E additions | |
| 15 | "Dissolve", "ChannelBoolean", "Saver", "Switch", "Fuse.Switch", | |
| 16 | "TimeStretcher", "TimeSpeed", | |
| 17 | "Paint", "PaintMask", "WandMask", "BitmapMask", | |
| 18 | "Drip", "Dent", "DaySky", "GridWarp", "PerspectivePositioner", | |
| 19 | "sRender", "sEllipse", "sRectangle", "sNGon", "sBoolean", "sTransform", "sOutline", "sGrid", | |
| 20 | "MtlBlinn", "MtlPhong", "MtlCookTorrance", | |
| 21 | "LightPoint", "LightSpot", "LightDirectional", "LightAmbient", | |
| 22 | "Cube3D", "SurfaceFBXMesh", "Custom", | |
| 23 | "ErodeDilate", "DirectionalBlur", "VariBlur", "Sharpen", "Shadow", | |
| 24 | "ColorGain", "HueCurves", "GamutConvert", "FilmGrain", | |
| 25 | ]; | |
| 26 | for tool in required { | |
| 27 | assert!( | |
| 28 | CURATED_TOOL_KINDS.contains(&tool), | |
| 29 | "{tool} missing from CURATED_TOOL_KINDS" | |
| 30 | ); | |
| 31 | let s = schema_for_kind(tool); | |
| 32 | assert!(!s.is_empty(), "expected non-empty curated schema for {tool}"); | |
| 33 | } | |
| 34 | for &tool in CURATED_TOOL_KINDS { | |
| 35 | assert!( | |
| 36 | !schema_for_kind(tool).is_empty(), | |
| 37 | "CURATED_TOOL_KINDS entry {tool} has empty schema" | |
| 38 | ); | |
| 39 | } | |
| 40 | assert!(schema_for_kind("UnknownCustomTool").is_empty()); | |
| 41 | } | |
| 42 | ||
| 43 | #[test] | |
| 44 | fn curated_schemas_have_unique_params_and_valid_bounds() { | |
| 45 | let mut seen_tools = HashSet::new(); | |
| 46 | for &tool in CURATED_TOOL_KINDS { | |
| 47 | assert!(seen_tools.insert(tool), "duplicate tool in CURATED_TOOL_KINDS: {tool}"); | |
| 48 | let schema = schema_for_kind(tool); | |
| 49 | let mut names = HashSet::new(); | |
| 50 | for spec in schema { | |
| 51 | assert!( | |
| 52 | names.insert(spec.name), | |
| 53 | "duplicate parameter `{}` in schema for `{tool}`", | |
| 54 | spec.name | |
| 55 | ); | |
| 56 | match spec.kind { | |
| 57 | ParamKind::Float { min, max, default, step } => { | |
| 58 | assert!(min.is_finite() && max.is_finite() && default.is_finite() && step.is_finite()); | |
| 59 | assert!(min <= max, "{tool}.{}: min ({min}) > max ({max})", spec.name); | |
| 60 | assert!(step > 0.0, "{tool}.{}: step ({step}) <= 0", spec.name); | |
| 61 | assert!( | |
| 62 | (min..=max).contains(&default), | |
| 63 | "{tool}.{}: default ({default}) outside [{min}, {max}]", | |
| 64 | spec.name | |
| 65 | ); | |
| 66 | } | |
| 67 | ParamKind::Vec2 { min, max, default } => { | |
| 68 | assert!(min.is_finite() && max.is_finite()); | |
| 69 | assert!(min <= max, "{tool}.{}: min ({min}) > max ({max})", spec.name); | |
| 70 | for (axis, d) in default.iter().enumerate() { | |
| 71 | assert!( | |
| 72 | d.is_finite() && (min..=max).contains(d), | |
| 73 | "{tool}.{}[{axis}]: default ({d}) outside [{min}, {max}]", | |
| 74 | spec.name | |
| 75 | ); | |
| 76 | } | |
| 77 | } | |
| 78 | ParamKind::Enum { options, default } => { | |
| 79 | assert!(!options.is_empty(), "{tool}.{}: empty Enum options", spec.name); | |
| 80 | assert!( | |
| 81 | options.contains(&default), | |
| 82 | "{tool}.{}: default `{default}` not in options {options:?}", | |
| 83 | spec.name | |
| 84 | ); | |
| 85 | } | |
| 86 | ParamKind::IntEnum { options, default } => { | |
| 87 | assert!(!options.is_empty(), "{tool}.{}: empty IntEnum options", spec.name); | |
| 88 | let mut codes = HashSet::new(); | |
| 89 | for &(code, _) in options { | |
| 90 | assert!( | |
| 91 | codes.insert(code), | |
| 92 | "{tool}.{}: duplicate IntEnum code {code}", | |
| 93 | spec.name | |
| 94 | ); | |
| 95 | } | |
| 96 | assert!( | |
| 97 | codes.contains(&default), | |
| 98 | "{tool}.{}: default {default} not in IntEnum options", | |
| 99 | spec.name | |
| 100 | ); | |
| 101 | } | |
| 102 | ParamKind::Color { r, g, b, a, default } => { | |
| 103 | for ch in [r, g, b].into_iter().chain(a) { | |
| 104 | assert!( | |
| 105 | names.insert(ch), | |
| 106 | "duplicate color channel `{ch}` in schema for `{tool}`" | |
| 107 | ); | |
| 108 | } | |
| 109 | for (idx, c) in default.iter().enumerate() { | |
| 110 | assert!( | |
| 111 | c.is_finite() && (0.0..=1.0).contains(c), | |
| 112 | "{tool}.{}[{idx}]: color default ({c}) outside [0, 1]", | |
| 113 | spec.name | |
| 114 | ); | |
| 115 | } | |
| 116 | } | |
| 117 | ParamKind::Bool { .. } | ParamKind::Text { .. } => {} | |
| 118 | } | |
| 119 | } | |
| 120 | } | |
| 121 | } | |
| 122 | ||
| 123 | mod catalog_layout { | |
| 124 | use super::super::catalog::{self, catalog}; | |
| 125 | use super::super::layout::{ControlDef, Kind, SECTIONS, ToolLayout}; | |
| 126 | use super::super::{InspectorState, dynamic}; | |
| 127 | use super::{CURATED_TOOL_KINDS, HashSet, schema_for_kind}; | |
| 128 | use model::{Comp, CompHistory}; | |
| 129 | use std::time::Instant; | |
| 130 | ||
| 131 | fn controls(layout: &ToolLayout) -> impl Iterator<Item = &ControlDef> { | |
| 132 | layout.pages.iter().flat_map(|p| &p.sections).flat_map(|s| &s.controls) | |
| 133 | } | |
| 134 | ||
| 135 | fn find<'a>(tool: &str, first_id: &str) -> &'a ControlDef { | |
| 136 | let layout = &catalog()[tool].layout; | |
| 137 | let found = controls(layout).find(|c| c.channels[0].id == first_id); | |
| 138 | found.unwrap_or_else(|| panic!("{tool} has no row starting at {first_id}")) | |
| 139 | } | |
| 140 | ||
| 141 | fn ids(def: &ControlDef) -> Vec<&str> { | |
| 142 | def.channels.iter().map(|c| c.id.as_str()).collect() | |
| 143 | } | |
| 144 | ||
| 145 | #[test] | |
| 146 | fn catalog_has_every_introspected_tool() { | |
| 147 | let cat = catalog(); | |
| 148 | assert!(cat.len() > 100, "only {} tools", cat.len()); | |
| 149 | for tool in ["Merge", "Transform", "Background", "TextPlus", "Blur", "MacroOperator", "GroupOperator"] { | |
| 150 | assert!(cat.contains_key(tool), "{tool} missing from catalog"); | |
| 151 | } | |
| 152 | assert!(catalog::ready().is_some()); | |
| 153 | } | |
| 154 | ||
| 155 | #[test] | |
| 156 | fn rgba_color_inputs_fuse_into_one_row() { | |
| 157 | let def = find("Background", "TopLeftRed"); | |
| 158 | assert_eq!((def.kind, def.label.as_str()), (Kind::Color, "Top Left")); | |
| 159 | assert_eq!(ids(def), ["TopLeftRed", "TopLeftGreen", "TopLeftBlue", "TopLeftAlpha"]); | |
| 160 | assert_eq!(def.channels[3].default[0], 1.0); | |
| 161 | ||
| 162 | let def = find("TextPlus", "Red1"); | |
| 163 | assert_eq!((def.kind, ids(def)), (Kind::Color, vec!["Red1", "Green1", "Blue1", "Alpha1"])); | |
| 164 | ||
| 165 | // Object/Material IDs share a color group but are lone ids, not RGB. | |
| 166 | assert_eq!(find("Merge", "ObjectID").kind, Kind::Slider); | |
| 167 | } | |
| 168 | ||
| 169 | #[test] | |
| 170 | fn range_inputs_fuse_into_one_row() { | |
| 171 | let def = find("TextPlus", "Start"); | |
| 172 | assert_eq!((def.kind, ids(def)), (Kind::Range, vec!["Start", "End"])); | |
| 173 | assert_eq!(def.label, "Write On Start / End"); | |
| 174 | assert_eq!(ids(find("Merge", "MaskLow")), ["MaskLow", "MaskHigh"]); | |
| 175 | // Two Solid/Garbage ranges in one group stay two rows. | |
| 176 | let keyer = controls(&catalog()["UltraKeyer"].layout).filter(|c| c.kind == Kind::Range && c.channels[0].id.contains(".MaskLow")); | |
| 177 | assert_eq!(keyer.count(), 2); | |
| 178 | } | |
| 179 | ||
| 180 | #[test] | |
| 181 | fn angles_are_screws_and_toggles_group() { | |
| 182 | assert_eq!(find("Merge", "Angle").kind, Kind::Screw); | |
| 183 | assert_eq!(find("Transform", "Angle").kind, Kind::Screw); | |
| 184 | let process = find("Merge", "ProcessRed"); | |
| 185 | assert_eq!((process.kind, process.label.as_str()), (Kind::Toggles, "Process")); | |
| 186 | assert_eq!(process.entries, ["Red", "Green", "Blue", "Alpha"]); | |
| 187 | assert_eq!(find("Merge", "Center").kind, Kind::Point); | |
| 188 | assert_eq!(find("Merge", "ApplyMode").kind, Kind::Combo); | |
| 189 | assert!(find("Merge", "ApplyMode").fuid); | |
| 190 | assert_eq!(find("Background", "UseGPU").kind, Kind::Segmented); | |
| 191 | } | |
| 192 | ||
| 193 | #[test] | |
| 194 | fn pages_follow_fusion_tab_order() { | |
| 195 | let names = |tool: &str| -> Vec<&str> { catalog()[tool].layout.pages.iter().map(|p| p.name.as_str()).collect() }; | |
| 196 | assert_eq!(names("Merge"), ["Merge", "Channels", "Settings"]); | |
| 197 | assert_eq!(names("Transform"), ["Controls", "Settings"]); | |
| 198 | assert_eq!(names("TextPlus"), ["Text", "Layout", "Transform", "Shading", "Image", "Settings"]); | |
| 199 | let merge = &catalog()["Merge"].layout.pages[0]; | |
| 200 | assert_eq!(merge.sections.iter().map(|s| s.title.as_str()).collect::<Vec<_>>(), ["Merge", "Reference Size"]); | |
| 201 | assert!(!merge.sections[1].open); | |
| 202 | } | |
| 203 | ||
| 204 | #[test] | |
| 205 | fn section_markers_name_real_inputs() { | |
| 206 | for (tools, id, title, _) in SECTIONS { | |
| 207 | let hits = |tool: &str| controls(&catalog()[tool].layout).any(|c| c.channels[0].id == *id); | |
| 208 | if tools.is_empty() { | |
| 209 | assert!(catalog().keys().any(|t| hits(t)), "no tool has `{id}` for section `{title}`"); | |
| 210 | } | |
| 211 | for tool in *tools { | |
| 212 | assert!(hits(tool), "{tool} has no `{id}` row for section `{title}`"); | |
| 213 | } | |
| 214 | } | |
| 215 | } | |
| 216 | ||
| 217 | #[test] | |
| 218 | fn every_layout_is_well_formed() { | |
| 219 | for (tool, entry) in catalog() { | |
| 220 | let mut seen = HashSet::new(); | |
| 221 | for def in controls(&entry.layout) { | |
| 222 | for ch in &def.channels { | |
| 223 | assert!(seen.insert(ch.id.as_str()), "{tool}: `{}` appears in two rows", ch.id); | |
| 224 | assert!(entry.layout.covered.contains(&ch.id), "{tool}: `{}` not covered", ch.id); | |
| 225 | assert!(ch.scale[0] < ch.scale[1] && ch.scale.iter().all(|v| v.is_finite()), "{tool}.{} scale {:?}", ch.id, ch.scale); | |
| 226 | } | |
| 227 | if matches!(def.kind, Kind::Segmented | Kind::Combo) { | |
| 228 | assert!(def.default_index < def.entries.len(), "{tool}.{}: default index out of range", def.label); | |
| 229 | } | |
| 230 | let n = def.channels.len(); | |
| 231 | let ok = match def.kind { | |
| 232 | Kind::Range => n == 2, | |
| 233 | Kind::Color => (3..=4).contains(&n), | |
| 234 | Kind::Toggles => n == def.entries.len(), | |
| 235 | _ => n == 1, | |
| 236 | }; | |
| 237 | assert!(ok, "{tool}.{}: {n} channels", def.label); | |
| 238 | } | |
| 239 | } | |
| 240 | } | |
| 241 | ||
| 242 | #[test] | |
| 243 | fn curated_kinds_have_pages_in_catalog_or_fallback() { | |
| 244 | for &tool in CURATED_TOOL_KINDS { | |
| 245 | let layout = match catalog().get(tool) { | |
| 246 | Some(entry) => &entry.layout, | |
| 247 | None => &dynamic::curated_layout(tool).unwrap_or_else(|| panic!("{tool}: no catalog entry and no curated layout")), | |
| 248 | }; | |
| 249 | assert!(controls(layout).next().is_some(), "{tool} has no rows"); | |
| 250 | } | |
| 251 | let fallback = dynamic::curated_layout("Fuse.Switch").expect("curated fallback"); | |
| 252 | assert!(fallback.covered.contains(schema_for_kind("Fuse.Switch")[0].name)); | |
| 253 | } | |
| 254 | ||
| 255 | #[test] | |
| 256 | fn user_controls_become_rows() { | |
| 257 | let comp = Comp::from_fusion_str( | |
| 258 | r#"Composition { | |
| 259 | Tools = ordered() { | |
| 260 | Mac = MacroOperator { | |
| 261 | UserControls = ordered() { | |
| 262 | Gain = { LINKS_Name = "Gain", LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_Default = 0.5, INP_MaxScale = 4, ICS_ControlPage = "Look" }, | |
| 263 | Mode = { LINKID_DataType = "Number", INPID_InputControl = "ComboControl", INP_Default = 1, { CCS_AddString = "Off" }, { CCS_AddString = "On" } }, | |
| 264 | Spot = { LINKID_DataType = "Point", INPID_InputControl = "OffsetControl", INP_DefaultX = 0.25, INP_DefaultY = 0.75 }, | |
| 265 | }, | |
| 266 | }, | |
| 267 | }, | |
| 268 | }"#, | |
| 269 | ) | |
| 270 | .expect("comp"); | |
| 271 | let defs = dynamic::user_defs(&comp.node(comp.find_node("Mac").unwrap()).raw); | |
| 272 | assert_eq!(defs.len(), 3); | |
| 273 | assert_eq!((defs[0].page.as_deref(), defs[0].scale), (Some("Look"), [0.0, 4.0])); | |
| 274 | assert_eq!((defs[1].entries.len(), defs[1].default[0]), (2, 1.0)); | |
| 275 | assert_eq!(defs[2].default, [0.25, 0.75]); | |
| 276 | let page = super::super::layout::dynamic_page("Look", &defs); | |
| 277 | let kinds: Vec<_> = page.sections[0].controls.iter().map(|c| c.kind).collect(); | |
| 278 | assert_eq!(kinds, [Kind::Slider, Kind::Combo, Kind::Point]); | |
| 279 | } | |
| 280 | ||
| 281 | /// Every tool, every page, builds under the frame guard without panicking. | |
| 282 | #[test] | |
| 283 | fn builds_every_page_of_every_tool() { | |
| 284 | catalog(); | |
| 285 | let theme = ui::Theme::dark(); | |
| 286 | let mut state = InspectorState::new(&theme); | |
| 287 | let mut ui = ui::Ui::new(theme); | |
| 288 | let (mut history, stats) = (CompHistory::default(), engine::EvalStats::default()); | |
| 289 | for (tool, entry) in catalog() { | |
| 290 | let mut comp = Comp::from_fusion_str(&format!("Composition {{ Tools = ordered() {{ N = {tool} {{}}, }}, }}")).expect("comp"); | |
| 291 | let node = comp.find_node("N").expect("node"); | |
| 292 | for page in 0..entry.layout.pages.len().max(1) { | |
| 293 | state.page.insert(node.0, page); | |
| 294 | ui.begin([360.0, 900.0], 1.0, Instant::now()); | |
| 295 | state.build_ui(&mut ui, ui::Id::ROOT.child("pane"), &mut comp, &mut history, Some(node), 0.0, &stats); | |
| 296 | ui.end(); | |
| 297 | } | |
| 298 | } | |
| 299 | } | |
| 300 | ||
| 301 | struct Harness { | |
| 302 | ui: ui::Ui, | |
| 303 | state: InspectorState, | |
| 304 | comp: Comp, | |
| 305 | history: CompHistory, | |
| 306 | node: model::NodeId, | |
| 307 | at: Instant, | |
| 308 | } | |
| 309 | ||
| 310 | const PANE: &str = "pane"; | |
| 311 | ||
| 312 | impl Harness { | |
| 313 | fn new(tool: &str, page: usize) -> Self { | |
| 314 | catalog(); | |
| 315 | let theme = ui::Theme::dark(); | |
| 316 | let mut ui = ui::Ui::new(theme.clone()); | |
| 317 | ui.set_reduce_motion(true); | |
| 318 | let mut state = InspectorState::new(&theme); | |
| 319 | let comp = Comp::from_fusion_str(&format!("Composition {{ Tools = ordered() {{ N = {tool} {{}}, }}, }}")).expect("comp"); | |
| 320 | let node = comp.find_node("N").expect("node"); | |
| 321 | state.page.insert(node.0, page); | |
| 322 | let mut h = Self { ui, state, comp, history: CompHistory::default(), node, at: Instant::now() }; | |
| 323 | h.frame(0); | |
| 324 | h | |
| 325 | } | |
| 326 | ||
| 327 | fn frame(&mut self, advance_ms: u64) { | |
| 328 | self.at += std::time::Duration::from_millis(advance_ms); | |
| 329 | self.ui.begin([360.0, 900.0], 1.0, self.at); | |
| 330 | let pane = ui::Id::ROOT.child(PANE); | |
| 331 | self.state.build_ui(&mut self.ui, pane, &mut self.comp, &mut self.history, Some(self.node), 0.0, &engine::EvalStats::default()); | |
| 332 | self.ui.end(); | |
| 333 | } | |
| 334 | ||
| 335 | /// Where the row `key`'s child `part` sits: the first section of the active page. | |
| 336 | fn rect(&self, page: usize, key: &str, part: impl std::hash::Hash) -> [f32; 4] { | |
| 337 | let section = ui::Id::ROOT.child(PANE).child("insp-scroll").child(("sec", (self.node.0, page, 0usize))); | |
| 338 | let row = section.child("body").child(("row", self.node.0, key)); | |
| 339 | self.ui.laid_out(row.child(part)).unwrap_or_else(|| panic!("no `{key}` row in page {page}")) | |
| 340 | } | |
| 341 | ||
| 342 | fn click(&mut self, at: [f32; 2]) { | |
| 343 | use winit::event::MouseButton::Left; | |
| 344 | self.ui.event(ui::Event::PointerMoved(at)); | |
| 345 | self.ui.event(ui::Event::Button { button: Left, pressed: true, at: self.at }); | |
| 346 | self.frame(16); | |
| 347 | self.ui.event(ui::Event::Button { button: Left, pressed: false, at: self.at }); | |
| 348 | self.frame(16); | |
| 349 | self.frame(16); | |
| 350 | } | |
| 351 | ||
| 352 | fn number(&self, id: &str) -> Option<f64> { | |
| 353 | self.comp.node(self.node).static_number(id) | |
| 354 | } | |
| 355 | } | |
| 356 | ||
| 357 | fn center(r: [f32; 4]) -> [f32; 2] { | |
| 358 | [(r[0] + r[2]) / 2.0, (r[1] + r[3]) / 2.0] | |
| 359 | } | |
| 360 | ||
| 361 | #[test] | |
| 362 | fn slider_drag_edits_and_undoes_as_one_step() { | |
| 363 | let mut h = Harness::new("Merge", 2); | |
| 364 | let track = h.rect(2, "Blend", ("sld", h.node.0, "Blend")); | |
| 365 | h.click([track[0] + (track[2] - track[0]) * 0.25, (track[1] + track[3]) / 2.0]); | |
| 366 | let value = h.number("Blend").expect("slider wrote Blend"); | |
| 367 | assert!(value < 0.5, "clicking a quarter along the track set {value}"); | |
| 368 | ||
| 369 | h.frame(600); | |
| 370 | assert!(h.history.undo(&mut h.comp)); | |
| 371 | assert_eq!(h.number("Blend"), None); | |
| 372 | } | |
| 373 | ||
| 374 | #[test] | |
| 375 | fn checkbox_and_keyframe_diamond_edit_with_undo() { | |
| 376 | let mut h = Harness::new("Merge", 2); | |
| 377 | let check = h.rect(2, "ProcessWhenBlendIs00", ("chk", h.node.0, "ProcessWhenBlendIs00")); | |
| 378 | h.click(center(check)); | |
| 379 | assert_eq!(h.number("ProcessWhenBlendIs00"), Some(1.0)); | |
| 380 | ||
| 381 | let diamond = h.rect(2, "Blend", "kf"); | |
| 382 | h.click(center(diamond)); | |
| 383 | let state = |h: &Harness| super::super::keyframe_state(&h.comp, h.node, "Blend", 0.0); | |
| 384 | assert_eq!(state(&h), super::super::KeyframeState::KeyframeAtCurrent); | |
| 385 | h.click(center(diamond)); | |
| 386 | assert_eq!(state(&h), super::super::KeyframeState::Static); | |
| 387 | assert!(h.history.undo(&mut h.comp)); | |
| 388 | assert_eq!(state(&h), super::super::KeyframeState::KeyframeAtCurrent); | |
| 389 | } | |
| 390 | ||
| 391 | #[test] | |
| 392 | fn color_channel_slider_and_typed_number_commit() { | |
| 393 | let mut h = Harness::new("Background", 0); | |
| 394 | let track = h.rect(0, "TopLeftRed", ("clr-sld", h.node.0, "TopLeftRed")); | |
| 395 | h.click([track[0] + (track[2] - track[0]) * 0.75, (track[1] + track[3]) / 2.0]); | |
| 396 | let slid = h.number("TopLeftRed").expect("channel slider wrote the red channel"); | |
| 397 | assert!(slid > 0.5, "clicking three quarters along the track set {slid}"); | |
| 398 | ||
| 399 | let well = h.rect(0, "TopLeftGreen", ("num", h.node.0, "TopLeftGreen", None::<usize>)); | |
| 400 | h.click(center(well)); | |
| 401 | for ch in "0.3".chars() { | |
| 402 | let key = winit::keyboard::Key::Character(ch.to_string().into()); | |
| 403 | h.ui.event(ui::Event::Key { key, text: Some(ch.to_string()), modifiers: Default::default() }); | |
| 404 | h.frame(16); | |
| 405 | } | |
| 406 | let enter = winit::keyboard::Key::Named(winit::keyboard::NamedKey::Enter); | |
| 407 | h.ui.event(ui::Event::Key { key: enter, text: None, modifiers: Default::default() }); | |
| 408 | h.frame(16); | |
| 409 | h.frame(16); | |
| 410 | let typed = h.number("TopLeftGreen").expect("typed value committed"); | |
| 411 | assert!((typed - 0.3).abs() < 1e-9, "typed 0.3, got {typed}"); | |
| 412 | } | |
| 413 | ||
| 414 | #[test] | |
| 415 | fn reset_restores_defaults_but_keeps_animation() { | |
| 416 | let mut h = Harness::new("Merge", 2); | |
| 417 | h.comp.set_input_value(h.node, "Blend", model::ParamValue::Number(0.2)); | |
| 418 | h.comp.set_keyframe(h.node, "Gain", 0.0, 0.4).expect("keyframe"); | |
| 419 | h.comp.set_input_value(h.node, "ProcessWhenBlendIs00", model::ParamValue::Number(1.0)); | |
| 420 | let node = h.node; | |
| 421 | let pages = &catalog()["Merge"].layout.pages; | |
| 422 | let mut actions = Vec::new(); | |
| 423 | let mut edit = super::super::edit::EditState::default(); | |
| 424 | let mut cx = super::super::edit::Cx { | |
| 425 | comp: &mut h.comp, | |
| 426 | history: &mut h.history, | |
| 427 | actions: &mut actions, | |
| 428 | node, | |
| 429 | frame: 0.0, | |
| 430 | now: h.at, | |
| 431 | p: h.state.palette, | |
| 432 | expr: &h.state.expr, | |
| 433 | edit: &mut edit, | |
| 434 | }; | |
| 435 | cx.reset_defaults(pages.iter().flat_map(|p| &p.sections).flat_map(|s| &s.controls)); | |
| 436 | assert_eq!(h.number("Blend"), Some(1.0)); | |
| 437 | assert_eq!(h.number("ProcessWhenBlendIs00"), Some(0.0)); | |
| 438 | assert_eq!(super::super::keyframe_state(&h.comp, node, "Gain", 0.0), super::super::KeyframeState::KeyframeAtCurrent); | |
| 439 | assert!(h.history.undo(&mut h.comp)); | |
| 440 | assert_eq!(h.number("Blend"), Some(0.2)); | |
| 441 | } | |
| 442 | } |
crates/app/src/inspector/widgets.rs+60-504| ... | ... | @@ -1,26 +1,8 @@ |
| 1 | //! Reusable Inspector UI control builders: scrub sliders, keyframe diamonds (`◆`), | |
| 2 | //! value formatting/scrubbing math, and parameter row dispatch. | |
| 1 | //! Small Inspector widgets: the keyframe diamond (`◆`), the expression badge, and the keyframe | |
| 2 | //! state / number formatting they share. | |
| 3 | 3 | |
| 4 | #[path = "rows.rs"] | |
| 5 | mod rows; | |
| 6 | ||
| 7 | use super::schemas::{ParamKind, ParamSpec, infer_float_range}; | |
| 8 | use super::{InspectorAction, InspectorState}; | |
| 9 | use engine::EvalStats; | |
| 10 | use model::{Comp, CompHistory, NodeId, ParamValue}; | |
| 11 | use std::borrow::Cow; | |
| 12 | use std::time::{Duration, Instant}; | |
| 13 | ||
| 14 | #[derive(Clone, Debug)] | |
| 15 | pub(super) struct DragState { | |
| 16 | pub node_id: NodeId, | |
| 17 | pub key: String, | |
| 18 | pub start_x: f32, | |
| 19 | pub start_val: f64, | |
| 20 | pub min: f64, | |
| 21 | pub max: f64, | |
| 22 | pub width: f32, | |
| 23 | } | |
| 4 | use super::edit::Cx; | |
| 5 | use model::{Comp, NodeId}; | |
| 24 | 6 | |
| 25 | 7 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 26 | 8 | pub enum KeyframeState { |
| ... | ... | @@ -29,418 +11,6 @@ pub enum KeyframeState { |
| 29 | 11 | KeyframeAtCurrent, |
| 30 | 12 | } |
| 31 | 13 | |
| 32 | impl InspectorState { | |
| 33 | pub(super) fn render_stats_footer(&self, ui: &mut ui::Ui, stats: &EvalStats) { | |
| 34 | let p = self.palette; | |
| 35 | let line = format!( | |
| 36 | "Eval {:.1}ms · {} nodes · cache {}/{} · {:.0}MB", | |
| 37 | stats.eval_ms, | |
| 38 | stats.nodes_evaluated, | |
| 39 | stats.cache_hits, | |
| 40 | stats.cache_hits + stats.cache_misses, | |
| 41 | stats.cached_vram_mb, | |
| 42 | ); | |
| 43 | ui.open( | |
| 44 | "insp-footer", | |
| 45 | ui::Spec { | |
| 46 | size: [ui::fill(), ui::px(24.0)], | |
| 47 | axis: ui::Axis::X, | |
| 48 | pad: [10.0, 4.0], | |
| 49 | fill: Some(p.panel_bg), | |
| 50 | border: Some(p.rule), | |
| 51 | ..ui::Spec::default() | |
| 52 | }, | |
| 53 | ); | |
| 54 | ui.leaf( | |
| 55 | "insp-stats-txt", | |
| 56 | ui::Spec { | |
| 57 | size: [ui::fill(), ui::fill()], | |
| 58 | text: Some(&line), | |
| 59 | font_size: Some(10.0), | |
| 60 | color: Some(p.text_dim), | |
| 61 | ..ui::Spec::default() | |
| 62 | }, | |
| 63 | ); | |
| 64 | ui.close(); | |
| 65 | } | |
| 66 | ||
| 67 | #[allow(clippy::too_many_arguments)] | |
| 68 | pub(super) fn render_param_spec( | |
| 69 | &mut self, | |
| 70 | ui: &mut ui::Ui, | |
| 71 | pane_id: ui::Id, | |
| 72 | comp: &mut Comp, | |
| 73 | history: &mut CompHistory, | |
| 74 | node_id: NodeId, | |
| 75 | spec: &ParamSpec, | |
| 76 | current_frame: f64, | |
| 77 | actions: &mut Vec<InspectorAction>, | |
| 78 | ) { | |
| 79 | match spec.kind { | |
| 80 | ParamKind::Float { min, max, default, step: _ } => { | |
| 81 | self.render_float_row( | |
| 82 | ui, | |
| 83 | pane_id, | |
| 84 | comp, | |
| 85 | history, | |
| 86 | node_id, | |
| 87 | spec.name, | |
| 88 | spec.label, | |
| 89 | min, | |
| 90 | max, | |
| 91 | default, | |
| 92 | current_frame, | |
| 93 | actions, | |
| 94 | ); | |
| 95 | } | |
| 96 | ParamKind::Vec2 { min, max, default } => { | |
| 97 | self.render_vec2_row( | |
| 98 | ui, | |
| 99 | pane_id, | |
| 100 | comp, | |
| 101 | history, | |
| 102 | node_id, | |
| 103 | spec.name, | |
| 104 | spec.label, | |
| 105 | min, | |
| 106 | max, | |
| 107 | default, | |
| 108 | current_frame, | |
| 109 | actions, | |
| 110 | ); | |
| 111 | } | |
| 112 | ParamKind::Bool { default } => { | |
| 113 | // A Loader without `Inputs.Loop`/`Reverse` plays whatever its clip says. | |
| 114 | let node = comp.node(node_id); | |
| 115 | let clip = node.clips.first().filter(|_| node.kind == "Loader"); | |
| 116 | let default = match spec.name { | |
| 117 | "Loop" => clip.map_or(default, |c| c.loop_clip), | |
| 118 | "Reverse" => clip.map_or(default, |c| c.reverse), | |
| 119 | _ => default, | |
| 120 | }; | |
| 121 | self.render_bool_row(ui, comp, history, node_id, spec.name, spec.label, default, actions); | |
| 122 | } | |
| 123 | ParamKind::Enum { options, default } => { | |
| 124 | self.render_enum_row(ui, comp, history, node_id, spec.name, spec.label, options, default, actions); | |
| 125 | } | |
| 126 | ParamKind::IntEnum { options, default } => { | |
| 127 | self.render_int_enum_row(ui, comp, history, node_id, spec.name, spec.label, options, default, actions); | |
| 128 | } | |
| 129 | ParamKind::Color { r, g, b, a, default } => { | |
| 130 | self.render_color_group( | |
| 131 | ui, | |
| 132 | pane_id, | |
| 133 | comp, | |
| 134 | history, | |
| 135 | node_id, | |
| 136 | spec.label, | |
| 137 | r, | |
| 138 | g, | |
| 139 | b, | |
| 140 | a, | |
| 141 | default, | |
| 142 | current_frame, | |
| 143 | actions, | |
| 144 | ); | |
| 145 | } | |
| 146 | ParamKind::Text { default } => { | |
| 147 | self.render_text_row(ui, pane_id, comp, history, node_id, spec.name, spec.label, default, actions); | |
| 148 | } | |
| 149 | } | |
| 150 | } | |
| 151 | ||
| 152 | #[allow(clippy::too_many_arguments)] | |
| 153 | pub(super) fn render_fallback_input( | |
| 154 | &mut self, | |
| 155 | ui: &mut ui::Ui, | |
| 156 | pane_id: ui::Id, | |
| 157 | comp: &mut Comp, | |
| 158 | history: &mut CompHistory, | |
| 159 | node_id: NodeId, | |
| 160 | key: &str, | |
| 161 | current_frame: f64, | |
| 162 | actions: &mut Vec<InspectorAction>, | |
| 163 | ) { | |
| 164 | let val = comp.node(node_id).inputs.get(key).and_then(|b| b.value.clone()); | |
| 165 | match val { | |
| 166 | Some(ParamValue::Point(pt)) => { | |
| 167 | self.render_vec2_row(ui, pane_id, comp, history, node_id, key, key, -1.0, 2.0, pt, current_frame, actions); | |
| 168 | } | |
| 169 | Some(ParamValue::Text(_)) => { | |
| 170 | self.render_text_row(ui, pane_id, comp, history, node_id, key, key, "", actions); | |
| 171 | } | |
| 172 | Some(ParamValue::FuId(cur)) => { | |
| 173 | let p = self.palette; | |
| 174 | ui.open( | |
| 175 | ("fb-fuid", node_id.0, key), | |
| 176 | ui::Spec { | |
| 177 | size: [ui::fill(), ui::px(22.0)], | |
| 178 | axis: ui::Axis::X, | |
| 179 | gap: 6.0, | |
| 180 | ..ui::Spec::default() | |
| 181 | }, | |
| 182 | ); | |
| 183 | ui.leaf( | |
| 184 | "lbl", | |
| 185 | ui::Spec { | |
| 186 | size: [ui::px(92.0), ui::fill()], | |
| 187 | text: Some(key), | |
| 188 | font_size: Some(10.5), | |
| 189 | overflow: ui::Overflow::Ellipsis, | |
| 190 | color: Some(p.text_dim), | |
| 191 | ..ui::Spec::default() | |
| 192 | }, | |
| 193 | ); | |
| 194 | ui.leaf( | |
| 195 | "val", | |
| 196 | ui::Spec { | |
| 197 | size: [ui::fill(), ui::fill()], | |
| 198 | text: Some(&cur), | |
| 199 | font_size: Some(10.5), | |
| 200 | color: Some(p.text), | |
| 201 | fill: Some(p.panel_bg), | |
| 202 | border: Some(p.rule), | |
| 203 | radius: 4.0, | |
| 204 | pad: [6.0, 0.0], | |
| 205 | ..ui::Spec::default() | |
| 206 | }, | |
| 207 | ); | |
| 208 | ui.close(); | |
| 209 | } | |
| 210 | Some(ParamValue::Number(v)) => { | |
| 211 | let (min, max) = infer_float_range(key, v); | |
| 212 | self.render_float_row(ui, pane_id, comp, history, node_id, key, key, min, max, v, current_frame, actions); | |
| 213 | } | |
| 214 | None => { | |
| 215 | // Animated spline or expression-only scalar input | |
| 216 | let cur = comp.eval_number(comp.node(node_id), key, current_frame, 0.0, &self.expr); | |
| 217 | let (min, max) = infer_float_range(key, cur); | |
| 218 | self.render_float_row(ui, pane_id, comp, history, node_id, key, key, min, max, 0.0, current_frame, actions); | |
| 219 | } | |
| 220 | _ => {} | |
| 221 | } | |
| 222 | } | |
| 223 | ||
| 224 | #[allow(clippy::too_many_arguments)] | |
| 225 | pub(super) fn scrub_slider( | |
| 226 | &mut self, | |
| 227 | ui: &mut ui::Ui, | |
| 228 | slider_id: ui::Id, | |
| 229 | drag_key: &str, | |
| 230 | node_id: NodeId, | |
| 231 | value: f64, | |
| 232 | min: f64, | |
| 233 | max: f64, | |
| 234 | default: f64, | |
| 235 | history: &mut CompHistory, | |
| 236 | comp: &Comp, | |
| 237 | input_name: &str, | |
| 238 | ) -> Option<f64> { | |
| 239 | let sig = ui.signal(slider_id); | |
| 240 | let rect = ui.laid_out(slider_id); | |
| 241 | let width = rect.map(|r| (r[2] - r[0]).max(40.0)).unwrap_or(110.0); | |
| 242 | let mut updated: Option<f64> = None; | |
| 243 | ||
| 244 | if let Some(press) = sig.press { | |
| 245 | let now = Instant::now(); | |
| 246 | let is_double = self | |
| 247 | .last_click | |
| 248 | .get(drag_key) | |
| 249 | .is_some_and(|prev| now.duration_since(*prev) < Duration::from_millis(320)); | |
| 250 | self.last_click.insert(drag_key.to_owned(), now); | |
| 251 | if is_double { | |
| 252 | history.push_snapshot(comp, format!("Reset {input_name}")); | |
| 253 | self.drag = None; | |
| 254 | updated = Some(default); | |
| 255 | } else { | |
| 256 | self.drag = Some(DragState { | |
| 257 | node_id, | |
| 258 | key: drag_key.to_owned(), | |
| 259 | start_x: press[0], | |
| 260 | start_val: value, | |
| 261 | min, | |
| 262 | max, | |
| 263 | width, | |
| 264 | }); | |
| 265 | } | |
| 266 | } else if sig.dragging { | |
| 267 | if let (Some(d), Some(ptr)) = (&self.drag, ui.pointer()) { | |
| 268 | if d.key == drag_key && d.node_id == node_id { | |
| 269 | let fine = if ui.modifiers().shift_key() { 0.15 } else { 1.0 }; | |
| 270 | let next = compute_scrub_value(d.start_val, ptr[0] - d.start_x, d.width, d.min, d.max, fine); | |
| 271 | if (next - value).abs() > 1e-6 { | |
| 272 | history.push_coalesced( | |
| 273 | comp, | |
| 274 | format!("Adjust {input_name}"), | |
| 275 | format!("scrub:{drag_key}"), | |
| 276 | ); | |
| 277 | updated = Some(next); | |
| 278 | } | |
| 279 | } | |
| 280 | } | |
| 281 | } else if self.drag.as_ref().is_some_and(|d| d.key == drag_key) { | |
| 282 | self.drag = None; | |
| 283 | history.break_coalescing(); | |
| 284 | } | |
| 285 | ||
| 286 | let display_val = updated.unwrap_or(value); | |
| 287 | let frac = normalize_slider_fraction(display_val, min, max); | |
| 288 | let val_text = format_param_number(display_val); | |
| 289 | let fill_w = (width * frac).clamp(0.0, width); | |
| 290 | let active_drag = self.drag.as_ref().is_some_and(|d| d.key == drag_key); | |
| 291 | let p = self.palette; | |
| 292 | ||
| 293 | ui.open_as( | |
| 294 | slider_id, | |
| 295 | ui::Spec { | |
| 296 | cursor: Some(winit::window::CursorIcon::EwResize), | |
| 297 | flags: ui::Flags::CLICKABLE | ui::Flags::CLIP, | |
| 298 | size: [ui::fill(), ui::px(20.0)], | |
| 299 | fill: Some(p.panel_bg), | |
| 300 | border: Some(if active_drag || sig.hovered { p.accent } else { p.rule }), | |
| 301 | radius: 4.0, | |
| 302 | ..ui::Spec::default() | |
| 303 | }, | |
| 304 | ); | |
| 305 | if fill_w > 0.5 { | |
| 306 | ui.leaf( | |
| 307 | "fill", | |
| 308 | ui::Spec { | |
| 309 | flags: ui::Flags::FLOAT | ui::Flags::INERT, | |
| 310 | position: [0.0, 0.0], | |
| 311 | size: [ui::px(fill_w), ui::px(20.0)], | |
| 312 | fill: Some([p.accent[0], p.accent[1], p.accent[2], if active_drag { 0.34 } else { 0.22 }]), | |
| 313 | radius: 3.0, | |
| 314 | ..ui::Spec::default() | |
| 315 | }, | |
| 316 | ); | |
| 317 | } | |
| 318 | ui.leaf( | |
| 319 | "txt", | |
| 320 | ui::Spec { | |
| 321 | flags: ui::Flags::INERT, | |
| 322 | size: [ui::fill(), ui::fill()], | |
| 323 | text: Some(&val_text), | |
| 324 | font_size: Some(10.5), | |
| 325 | color: Some(p.text), | |
| 326 | center: true, | |
| 327 | ..ui::Spec::default() | |
| 328 | }, | |
| 329 | ); | |
| 330 | ui.close(); | |
| 331 | ||
| 332 | updated | |
| 333 | } | |
| 334 | ||
| 335 | pub(super) fn keyframe_button(&self, ui: &mut ui::Ui, part: impl std::hash::Hash, state: KeyframeState) -> bool { | |
| 336 | let (ink, fill, border) = match state { | |
| 337 | KeyframeState::KeyframeAtCurrent => ( | |
| 338 | [1.0, 0.80, 0.22, 1.0], | |
| 339 | Some([0.98, 0.72, 0.18, 0.24]), | |
| 340 | Some([0.98, 0.76, 0.20, 0.85]), | |
| 341 | ), | |
| 342 | KeyframeState::AnimatedOtherFrame => ( | |
| 343 | [0.92, 0.64, 0.24, 0.90], | |
| 344 | Some([0.92, 0.64, 0.24, 0.12]), | |
| 345 | Some([0.92, 0.64, 0.24, 0.45]), | |
| 346 | ), | |
| 347 | KeyframeState::Static => (self.palette.text_dim, None, None), | |
| 348 | }; | |
| 349 | let sig = ui.leaf( | |
| 350 | part, | |
| 351 | ui::Spec { | |
| 352 | cursor: Some(winit::window::CursorIcon::Pointer), | |
| 353 | flags: ui::Flags::CLICKABLE, | |
| 354 | size: [ui::px(20.0), ui::px(20.0)], | |
| 355 | text: Some("◆"), | |
| 356 | font_size: Some(10.5), | |
| 357 | color: Some(ink), | |
| 358 | fill, | |
| 359 | border, | |
| 360 | hover_fill: Some([0.98, 0.76, 0.22, 0.18]), | |
| 361 | radius: 4.0, | |
| 362 | center: true, | |
| 363 | ..ui::Spec::default() | |
| 364 | }, | |
| 365 | ); | |
| 366 | sig.clicked | |
| 367 | } | |
| 368 | ||
| 369 | #[allow(clippy::too_many_arguments)] | |
| 370 | pub(super) fn toggle_keyframe( | |
| 371 | &self, | |
| 372 | comp: &mut Comp, | |
| 373 | history: &mut CompHistory, | |
| 374 | node_id: NodeId, | |
| 375 | input_name: &str, | |
| 376 | current_frame: f64, | |
| 377 | cur_val: f64, | |
| 378 | state: KeyframeState, | |
| 379 | actions: &mut Vec<InspectorAction>, | |
| 380 | ) { | |
| 381 | match state { | |
| 382 | KeyframeState::KeyframeAtCurrent => { | |
| 383 | if let Some(sp_name) = comp | |
| 384 | .node(node_id) | |
| 385 | .inputs | |
| 386 | .get(input_name) | |
| 387 | .and_then(|b| b.source_op.clone()) | |
| 388 | { | |
| 389 | history.begin_group(comp, format!("Delete Keyframe {input_name}")); | |
| 390 | if comp.delete_keyframe(&sp_name, current_frame) { | |
| 391 | actions.push(InspectorAction::KeyframeEdited(node_id)); | |
| 392 | actions.push(InspectorAction::StatusNotice(format!( | |
| 393 | "Deleted keyframe on {input_name} @ f{current_frame:.0}" | |
| 394 | ))); | |
| 395 | } | |
| 396 | history.commit_group(comp); | |
| 397 | } | |
| 398 | } | |
| 399 | KeyframeState::Static | KeyframeState::AnimatedOtherFrame => { | |
| 400 | history.begin_group(comp, format!("Set Keyframe {input_name}")); | |
| 401 | let result = comp.set_keyframe(node_id, input_name, current_frame, cur_val); | |
| 402 | if result.is_ok() { | |
| 403 | history.commit_group(comp); | |
| 404 | } else { | |
| 405 | history.cancel_group(comp); | |
| 406 | } | |
| 407 | match result { | |
| 408 | Ok(_) => { | |
| 409 | actions.push(InspectorAction::KeyframeEdited(node_id)); | |
| 410 | actions.push(InspectorAction::StatusNotice(format!( | |
| 411 | "Keyframed {input_name} = {:.3} @ f{current_frame:.0}", | |
| 412 | cur_val | |
| 413 | ))); | |
| 414 | } | |
| 415 | Err(e) => actions.push(InspectorAction::StatusNotice(e)), | |
| 416 | } | |
| 417 | } | |
| 418 | } | |
| 419 | } | |
| 420 | } | |
| 421 | ||
| 422 | pub(crate) fn enum_option_index(options: &[&str], current: &str) -> usize { | |
| 423 | options.iter().position(|&o| o == current).unwrap_or(0) | |
| 424 | } | |
| 425 | ||
| 426 | pub(crate) fn int_enum_lookup<'a>(options: &[(i32, &'a str)], val: i32) -> (usize, Cow<'a, str>) { | |
| 427 | match options.iter().position(|&(v, _)| v == val) { | |
| 428 | Some(idx) => (idx, Cow::Borrowed(options[idx].1)), | |
| 429 | None => (0, Cow::Owned(val.to_string())), | |
| 430 | } | |
| 431 | } | |
| 432 | ||
| 433 | pub(crate) fn combo_cycle_index(cur_idx: usize, option_count: usize, reverse: bool) -> Option<usize> { | |
| 434 | if option_count == 0 { | |
| 435 | return None; | |
| 436 | } | |
| 437 | Some(if reverse { | |
| 438 | (cur_idx + option_count - 1) % option_count | |
| 439 | } else { | |
| 440 | (cur_idx + 1) % option_count | |
| 441 | }) | |
| 442 | } | |
| 443 | ||
| 444 | 14 | /// Computes whether an input is static, animated on another frame, or has a keyframe at `frame`. |
| 445 | 15 | pub fn keyframe_state(comp: &Comp, node_id: NodeId, input_name: &str, frame: f64) -> KeyframeState { |
| 446 | 16 | let Some(sp_name) = comp |
| ... | ... | @@ -463,17 +33,6 @@ pub fn keyframe_state(comp: &Comp, node_id: NodeId, input_name: &str, frame: f64 |
| 463 | 33 | } |
| 464 | 34 | } |
| 465 | 35 | |
| 466 | pub fn normalize_slider_fraction(value: f64, min: f64, max: f64) -> f32 { | |
| 467 | let span = (max - min).abs().max(1e-6); | |
| 468 | ((value - min) / span).clamp(0.0, 1.0) as f32 | |
| 469 | } | |
| 470 | ||
| 471 | pub fn compute_scrub_value(start_val: f64, dx: f32, width: f32, min: f64, max: f64, fine_scale: f64) -> f64 { | |
| 472 | let span = (max - min).max(1e-4); | |
| 473 | let delta = (f64::from(dx) / f64::from(width.max(40.0))) * span * fine_scale; | |
| 474 | (start_val + delta).clamp(min, max) | |
| 475 | } | |
| 476 | ||
| 477 | 36 | pub fn format_param_number(v: f64) -> String { |
| 478 | 37 | if v.abs() >= 100.0 { |
| 479 | 38 | format!("{v:.1}") |
| ... | ... | @@ -484,46 +43,67 @@ pub fn format_param_number(v: f64) -> String { |
| 484 | 43 | } |
| 485 | 44 | } |
| 486 | 45 | |
| 46 | /// The diamond column's width, kept by rows with nothing to animate so controls line up. | |
| 47 | pub(super) const MARK_W: f32 = 18.0; | |
| 48 | ||
| 49 | /// Whether the diamond was clicked. | |
| 50 | pub(super) fn keyframe_button(ui: &mut ui::Ui, cx: &Cx, state: KeyframeState) -> bool { | |
| 51 | let (ink, fill, border) = match state { | |
| 52 | KeyframeState::KeyframeAtCurrent => ( | |
| 53 | [1.0, 0.80, 0.22, 1.0], | |
| 54 | Some([0.98, 0.72, 0.18, 0.24]), | |
| 55 | Some([0.98, 0.76, 0.20, 0.85]), | |
| 56 | ), | |
| 57 | KeyframeState::AnimatedOtherFrame => ( | |
| 58 | [0.92, 0.64, 0.24, 0.90], | |
| 59 | Some([0.92, 0.64, 0.24, 0.12]), | |
| 60 | Some([0.92, 0.64, 0.24, 0.45]), | |
| 61 | ), | |
| 62 | KeyframeState::Static => (cx.p.text_dim, None, None), | |
| 63 | }; | |
| 64 | ui.leaf( | |
| 65 | "kf", | |
| 66 | ui::Spec { | |
| 67 | cursor: Some(winit::window::CursorIcon::Pointer), | |
| 68 | flags: ui::Flags::CLICKABLE, | |
| 69 | size: [ui::px(MARK_W), ui::px(20.0)], | |
| 70 | text: Some("◆"), | |
| 71 | font_size: Some(10.0), | |
| 72 | color: Some(ink), | |
| 73 | fill, | |
| 74 | border, | |
| 75 | hover_fill: Some([0.98, 0.76, 0.22, 0.18]), | |
| 76 | radius: 4.0, | |
| 77 | center: true, | |
| 78 | ..ui::Spec::default() | |
| 79 | }, | |
| 80 | ) | |
| 81 | .clicked | |
| 82 | } | |
| 83 | ||
| 84 | pub(super) fn expression_badge(ui: &mut ui::Ui) { | |
| 85 | ui.leaf( | |
| 86 | "expr", | |
| 87 | ui::Spec { | |
| 88 | size: [ui::px(16.0), ui::px(18.0)], | |
| 89 | text: Some("="), | |
| 90 | font_size: Some(10.5), | |
| 91 | bold: true, | |
| 92 | color: Some([0.36, 0.88, 0.92, 1.0]), | |
| 93 | fill: Some([0.10, 0.24, 0.28, 0.85]), | |
| 94 | border: Some([0.32, 0.78, 0.86, 0.65]), | |
| 95 | radius: 3.0, | |
| 96 | center: true, | |
| 97 | ..ui::Spec::default() | |
| 98 | }, | |
| 99 | ); | |
| 100 | } | |
| 101 | ||
| 487 | 102 | #[cfg(test)] |
| 488 | 103 | mod tests { |
| 489 | 104 | use super::*; |
| 490 | 105 | use model::{BezierSpline, Comp, Keyframe}; |
| 491 | 106 | |
| 492 | #[test] | |
| 493 | fn int_enum_lookup_and_cycling_with_unknown_fallback() { | |
| 494 | const OPTS: &[(i32, &str)] = &[(0, "Normal"), (2, "Screen"), (5, "Multiply")]; | |
| 495 | ||
| 496 | let (idx, lbl) = int_enum_lookup(OPTS, 2); | |
| 497 | assert_eq!(idx, 1); | |
| 498 | assert_eq!(lbl.as_ref(), "Screen"); | |
| 499 | ||
| 500 | // Forward and reverse cycling wrap around | |
| 501 | assert_eq!(combo_cycle_index(idx, OPTS.len(), false), Some(2)); | |
| 502 | assert_eq!(combo_cycle_index(idx, OPTS.len(), true), Some(0)); | |
| 503 | assert_eq!(combo_cycle_index(0, OPTS.len(), true), Some(2)); | |
| 504 | assert_eq!(combo_cycle_index(2, OPTS.len(), false), Some(0)); | |
| 505 | ||
| 506 | // Unknown integer code falls back to index 0 and stringified code | |
| 507 | let (idx, lbl) = int_enum_lookup(OPTS, 99); | |
| 508 | assert_eq!(idx, 0); | |
| 509 | assert_eq!(lbl.as_ref(), "99"); | |
| 510 | assert_eq!(combo_cycle_index(idx, OPTS.len(), false), Some(1)); | |
| 511 | } | |
| 512 | ||
| 513 | #[test] | |
| 514 | fn combo_option_lookup_and_cycling() { | |
| 515 | const OPTS: &[&str] = &["Nearest", "Linear", "Cubic"]; | |
| 516 | ||
| 517 | assert_eq!(enum_option_index(OPTS, "Linear"), 1); | |
| 518 | assert_eq!(enum_option_index(OPTS, "Missing"), 0); | |
| 519 | ||
| 520 | assert_eq!(combo_cycle_index(0, OPTS.len(), false), Some(1)); | |
| 521 | assert_eq!(combo_cycle_index(2, OPTS.len(), false), Some(0)); | |
| 522 | assert_eq!(combo_cycle_index(0, OPTS.len(), true), Some(2)); | |
| 523 | assert_eq!(combo_cycle_index(1, OPTS.len(), true), Some(0)); | |
| 524 | assert_eq!(combo_cycle_index(0, 0, false), None); | |
| 525 | } | |
| 526 | ||
| 527 | 107 | #[test] |
| 528 | 108 | fn format_param_number_uses_magnitude_precision() { |
| 529 | 109 | assert_eq!(format_param_number(0.12345), "0.123"); |
| ... | ... | @@ -534,30 +114,6 @@ mod tests { |
| 534 | 114 | assert_eq!(format_param_number(-1234.56), "-1234.6"); |
| 535 | 115 | } |
| 536 | 116 | |
| 537 | #[test] | |
| 538 | fn compute_scrub_value_normal_and_fine_shift_precision() { | |
| 539 | // Full width drag of 100px over [0, 10] adds 10.0 normally, 1.5 with Shift (0.15) | |
| 540 | let normal = compute_scrub_value(2.0, 50.0, 100.0, 0.0, 10.0, 1.0); | |
| 541 | assert!((normal - 7.0).abs() < 1e-9); | |
| 542 | ||
| 543 | let fine = compute_scrub_value(2.0, 50.0, 100.0, 0.0, 10.0, 0.15); | |
| 544 | assert!((fine - 2.75).abs() < 1e-9); | |
| 545 | ||
| 546 | // Clamps to [min, max] and enforces minimum 40px width denominator | |
| 547 | assert_eq!(compute_scrub_value(8.0, 200.0, 100.0, 0.0, 10.0, 1.0), 10.0); | |
| 548 | assert_eq!(compute_scrub_value(1.0, -200.0, 100.0, 0.0, 10.0, 1.0), 0.0); | |
| 549 | let narrow = compute_scrub_value(0.0, 20.0, 10.0, 0.0, 10.0, 1.0); | |
| 550 | assert!((narrow - 5.0).abs() < 1e-9); | |
| 551 | } | |
| 552 | ||
| 553 | #[test] | |
| 554 | fn normalize_slider_fraction_clamps_and_handles_degenerate_span() { | |
| 555 | assert_eq!(normalize_slider_fraction(5.0, 0.0, 10.0), 0.5); | |
| 556 | assert_eq!(normalize_slider_fraction(-5.0, 0.0, 10.0), 0.0); | |
| 557 | assert_eq!(normalize_slider_fraction(25.0, 0.0, 10.0), 1.0); | |
| 558 | assert_eq!(normalize_slider_fraction(0.0, 1.0, 1.0), 0.0); | |
| 559 | } | |
| 560 | ||
| 561 | 117 | #[test] |
| 562 | 118 | fn keyframe_state_respects_epsilon() { |
| 563 | 119 | let mut comp = Comp::from_fusion_str( |