| author | |
| committer | |
| log | 76545ca44fc6ea68304c7bd900bf449842534b23 |
| tree | 585e0ddb1aa303459a8b15b836fb92e8065830a3 |
| parent | df2e366bf9ed831fec49c63c19a3f1efa4e24550 |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
4 files changed, 1828 insertions(+), 1802 deletions(-)
crates/app/src/inspector.rs deleted-1802| ... | @@ -1,1802 +0,0 @@ | ||
| 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 | |||
| 4 | use engine::EvalStats; | ||
| 5 | use model::{Comp, CompHistory, ExprEngine, NodeId, ParamValue, is_supported_tool}; | ||
| 6 | use std::collections::{HashMap, HashSet}; | ||
| 7 | use std::time::{Duration, Instant}; | ||
| 8 | |||
| 9 | #[derive(Clone, Copy, Debug, PartialEq)] | ||
| 10 | pub enum ParamKind { | ||
| 11 | Float { min: f64, max: f64, default: f64, step: f64 }, | ||
| 12 | Vec2 { min: f64, max: f64, default: [f64; 2] }, | ||
| 13 | Bool { default: bool }, | ||
| 14 | Enum { options: &'static [&'static str], default: &'static str }, | ||
| 15 | Color { | ||
| 16 | r: &'static str, | ||
| 17 | g: &'static str, | ||
| 18 | b: &'static str, | ||
| 19 | a: Option<&'static str>, | ||
| 20 | default: [f64; 4], | ||
| 21 | }, | ||
| 22 | Text { default: &'static str }, | ||
| 23 | } | ||
| 24 | |||
| 25 | #[derive(Clone, Copy, Debug)] | ||
| 26 | pub struct ParamSpec { | ||
| 27 | pub name: &'static str, | ||
| 28 | pub label: &'static str, | ||
| 29 | pub kind: ParamKind, | ||
| 30 | } | ||
| 31 | |||
| 32 | #[derive(Clone, Debug)] | ||
| 33 | pub enum InspectorAction { | ||
| 34 | /// A parameter or node property changed; bust subtree & re-render viewers. | ||
| 35 | ParamEdited(NodeId), | ||
| 36 | /// A keyframe was added or deleted; refresh spline editor + bust subtree. | ||
| 37 | KeyframeEdited(NodeId), | ||
| 38 | /// Node was renamed. | ||
| 39 | NodeRenamed(NodeId), | ||
| 40 | /// Status notice to show in window title. | ||
| 41 | StatusNotice(String), | ||
| 42 | } | ||
| 43 | |||
| 44 | #[derive(Clone, Debug)] | ||
| 45 | struct DragState { | ||
| 46 | node_id: NodeId, | ||
| 47 | key: String, | ||
| 48 | start_x: f32, | ||
| 49 | start_val: f64, | ||
| 50 | min: f64, | ||
| 51 | max: f64, | ||
| 52 | width: f32, | ||
| 53 | } | ||
| 54 | |||
| 55 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
| 56 | pub enum KeyframeState { | ||
| 57 | Static, | ||
| 58 | AnimatedOtherFrame, | ||
| 59 | KeyframeAtCurrent, | ||
| 60 | } | ||
| 61 | |||
| 62 | pub struct InspectorState { | ||
| 63 | pub bg: [f32; 4], | ||
| 64 | pub panel_bg: [f32; 4], | ||
| 65 | pub rule: [f32; 4], | ||
| 66 | pub text: [f32; 4], | ||
| 67 | pub text_dim: [f32; 4], | ||
| 68 | pub accent: [f32; 4], | ||
| 69 | 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 | /// Last click timestamp per slider key for double-click reset. | ||
| 78 | last_click: HashMap<String, Instant>, | ||
| 79 | } | ||
| 80 | |||
| 81 | impl InspectorState { | ||
| 82 | pub fn new(theme: &ui::Theme) -> Self { | ||
| 83 | let b = theme.base; | ||
| 84 | let lift = |c: [f32; 4], d: f32| { | ||
| 85 | [ | ||
| 86 | (c[0] + d).clamp(0.0, 1.0), | ||
| 87 | (c[1] + d).clamp(0.0, 1.0), | ||
| 88 | (c[2] + d).clamp(0.0, 1.0), | ||
| 89 | 1.0, | ||
| 90 | ] | ||
| 91 | }; | ||
| 92 | Self { | ||
| 93 | bg: b, | ||
| 94 | panel_bg: lift(b, 0.020), | ||
| 95 | rule: theme.rule, | ||
| 96 | text: theme.text, | ||
| 97 | text_dim: theme.text_dim, | ||
| 98 | accent: theme.accent, | ||
| 99 | expr: ExprEngine::new(), | ||
| 100 | name_node: None, | ||
| 101 | name_buf: String::new(), | ||
| 102 | text_bufs: HashMap::new(), | ||
| 103 | drag: None, | ||
| 104 | last_click: HashMap::new(), | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | pub fn background(&self) -> [f32; 4] { | ||
| 109 | self.bg | ||
| 110 | } | ||
| 111 | |||
| 112 | pub fn reset(&mut self) { | ||
| 113 | self.name_node = None; | ||
| 114 | self.name_buf.clear(); | ||
| 115 | self.text_bufs.clear(); | ||
| 116 | self.drag = None; | ||
| 117 | } | ||
| 118 | |||
| 119 | pub fn build_ui( | ||
| 120 | &mut self, | ||
| 121 | ui: &mut ui::Ui, | ||
| 122 | pane_id: ui::Id, | ||
| 123 | comp: &mut Comp, | ||
| 124 | history: &mut CompHistory, | ||
| 125 | selected: Option<NodeId>, | ||
| 126 | current_frame: f64, | ||
| 127 | stats: &EvalStats, | ||
| 128 | ) -> Vec<InspectorAction> { | ||
| 129 | let mut actions = Vec::new(); | ||
| 130 | let bg = self.bg; | ||
| 131 | let panel_bg = self.panel_bg; | ||
| 132 | let rule = self.rule; | ||
| 133 | let text_col = self.text; | ||
| 134 | let text_dim = self.text_dim; | ||
| 135 | let accent = self.accent; | ||
| 136 | |||
| 137 | ui.open_as( | ||
| 138 | pane_id, | ||
| 139 | ui::Spec { | ||
| 140 | size: [ui::fill(), ui::fill()], | ||
| 141 | axis: ui::Axis::Y, | ||
| 142 | fill: Some(bg), | ||
| 143 | ..ui::Spec::default() | ||
| 144 | }, | ||
| 145 | ); | ||
| 146 | |||
| 147 | let Some(node_id) = selected.filter(|id| id.0 < comp.nodes.len()) else { | ||
| 148 | // Empty state | ||
| 149 | ui.open( | ||
| 150 | "insp-empty", | ||
| 151 | ui::Spec { | ||
| 152 | size: [ui::fill(), ui::fill()], | ||
| 153 | axis: ui::Axis::Y, | ||
| 154 | pad: [14.0, 18.0], | ||
| 155 | gap: 8.0, | ||
| 156 | ..ui::Spec::default() | ||
| 157 | }, | ||
| 158 | ); | ||
| 159 | ui.leaf( | ||
| 160 | "empty-title", | ||
| 161 | ui::Spec { | ||
| 162 | size: [ui::fill(), ui::px(20.0)], | ||
| 163 | text: Some("No Node Selected"), | ||
| 164 | font_size: Some(12.5), | ||
| 165 | medium: true, | ||
| 166 | color: Some(text_col), | ||
| 167 | ..ui::Spec::default() | ||
| 168 | }, | ||
| 169 | ); | ||
| 170 | ui.leaf( | ||
| 171 | "empty-hint", | ||
| 172 | ui::Spec { | ||
| 173 | size: [ui::fill(), ui::fit()], | ||
| 174 | text: Some("Select a node in the Flow graph to inspect and keyframe its parameters, or press Shift+Space to add a tool."), | ||
| 175 | font_size: Some(11.0), | ||
| 176 | overflow: ui::Overflow::Wrap, | ||
| 177 | color: Some(text_dim), | ||
| 178 | ..ui::Spec::default() | ||
| 179 | }, | ||
| 180 | ); | ||
| 181 | self.render_stats_footer(ui, stats, panel_bg, rule, text_dim); | ||
| 182 | ui.close(); | ||
| 183 | ui.close(); | ||
| 184 | return actions; | ||
| 185 | }; | ||
| 186 | |||
| 187 | // Sync editable name buffer when selection changes or node was renamed externally (e.g. undo) | ||
| 188 | let current_name = comp.node(node_id).name.clone(); | ||
| 189 | let name_field_id = pane_id.child(("node-name", node_id.0)); | ||
| 190 | if self.name_node != Some(node_id) | ||
| 191 | || (ui.focused() != Some(name_field_id) && self.name_buf != current_name) | ||
| 192 | { | ||
| 193 | self.name_node = Some(node_id); | ||
| 194 | self.name_buf = current_name.clone(); | ||
| 195 | } | ||
| 196 | |||
| 197 | // 1. Header: Node name + Class badge + Bypass toggle | ||
| 198 | ui.open( | ||
| 199 | "insp-header", | ||
| 200 | ui::Spec { | ||
| 201 | size: [ui::fill(), ui::children()], | ||
| 202 | axis: ui::Axis::Y, | ||
| 203 | pad: [10.0, 8.0], | ||
| 204 | gap: 6.0, | ||
| 205 | fill: Some(panel_bg), | ||
| 206 | border: Some(rule), | ||
| 207 | ..ui::Spec::default() | ||
| 208 | }, | ||
| 209 | ); | ||
| 210 | |||
| 211 | // Row 1: Editable name + Bypass button | ||
| 212 | ui.open( | ||
| 213 | "insp-name-row", | ||
| 214 | ui::Spec { | ||
| 215 | size: [ui::fill(), ui::px(26.0)], | ||
| 216 | axis: ui::Axis::X, | ||
| 217 | gap: 6.0, | ||
| 218 | ..ui::Spec::default() | ||
| 219 | }, | ||
| 220 | ); | ||
| 221 | let name_sig = ui::text_field( | ||
| 222 | ui, | ||
| 223 | name_field_id, | ||
| 224 | &mut self.name_buf, | ||
| 225 | "Node name", | ||
| 226 | ui::Spec { | ||
| 227 | size: [ui::fill(), ui::px(24.0)], | ||
| 228 | font_size: Some(12.0), | ||
| 229 | medium: true, | ||
| 230 | fill: Some(bg), | ||
| 231 | border: Some(rule), | ||
| 232 | hover_border: Some(accent), | ||
| 233 | radius: 4.0, | ||
| 234 | pad: [6.0, 2.0], | ||
| 235 | ..ui::Spec::default() | ||
| 236 | }, | ||
| 237 | ); | ||
| 238 | let enter_pressed = name_sig.events.iter().any(|ev| { | ||
| 239 | matches!( | ||
| 240 | ev, | ||
| 241 | ui::Event::Key { key: winit::keyboard::Key::Named(winit::keyboard::NamedKey::Enter), .. } | ||
| 242 | ) | ||
| 243 | }); | ||
| 244 | if enter_pressed && self.name_buf.trim() != current_name { | ||
| 245 | let desired = self.name_buf.trim().to_owned(); | ||
| 246 | history.push_snapshot(comp, "Rename Node"); | ||
| 247 | match comp.rename_node(node_id, &desired) { | ||
| 248 | Ok(applied) => { | ||
| 249 | self.name_buf = applied; | ||
| 250 | actions.push(InspectorAction::NodeRenamed(node_id)); | ||
| 251 | } | ||
| 252 | Err(e) => { | ||
| 253 | self.name_buf = current_name.clone(); | ||
| 254 | actions.push(InspectorAction::StatusNotice(e)); | ||
| 255 | } | ||
| 256 | } | ||
| 257 | ui.set_focus(None); | ||
| 258 | } | ||
| 259 | |||
| 260 | let bypassed = comp.node(node_id).bypassed; | ||
| 261 | let pass_lbl = if bypassed { "Bypassed" } else { "Active" }; | ||
| 262 | let pass_fill = if bypassed { | ||
| 263 | [0.85, 0.28, 0.28, 0.28] | ||
| 264 | } else { | ||
| 265 | [0.24, 0.78, 0.48, 0.18] | ||
| 266 | }; | ||
| 267 | let pass_border = if bypassed { | ||
| 268 | [0.92, 0.36, 0.36, 0.75] | ||
| 269 | } else { | ||
| 270 | [0.28, 0.82, 0.52, 0.55] | ||
| 271 | }; | ||
| 272 | let pass_sig = ui.leaf( | ||
| 273 | ("insp-pass", node_id.0), | ||
| 274 | ui::Spec { | ||
| 275 | cursor: Some(winit::window::CursorIcon::Pointer), | ||
| 276 | flags: ui::Flags::CLICKABLE, | ||
| 277 | size: [ui::fit(), ui::px(24.0)], | ||
| 278 | text: Some(pass_lbl), | ||
| 279 | font_size: Some(10.5), | ||
| 280 | medium: true, | ||
| 281 | color: Some(text_col), | ||
| 282 | fill: Some(pass_fill), | ||
| 283 | border: Some(pass_border), | ||
| 284 | radius: 4.0, | ||
| 285 | pad: [8.0, 0.0], | ||
| 286 | center: true, | ||
| 287 | ..ui::Spec::default() | ||
| 288 | }, | ||
| 289 | ); | ||
| 290 | if pass_sig.clicked { | ||
| 291 | history.push_snapshot(comp, "Toggle Passthrough"); | ||
| 292 | comp.toggle_passthrough(node_id); | ||
| 293 | actions.push(InspectorAction::ParamEdited(node_id)); | ||
| 294 | } | ||
| 295 | ui.close(); // insp-name-row | ||
| 296 | |||
| 297 | // Row 2: Tool class badge + supported/preserved indicator + frame badge | ||
| 298 | let node_kind = comp.node(node_id).kind.clone(); | ||
| 299 | let supported = is_supported_tool(&node_kind); | ||
| 300 | let frame_str = format!("f{:.0}", current_frame); | ||
| 301 | ui.open( | ||
| 302 | "insp-meta-row", | ||
| 303 | ui::Spec { | ||
| 304 | size: [ui::fill(), ui::px(18.0)], | ||
| 305 | axis: ui::Axis::X, | ||
| 306 | gap: 6.0, | ||
| 307 | ..ui::Spec::default() | ||
| 308 | }, | ||
| 309 | ); | ||
| 310 | ui.leaf( | ||
| 311 | "insp-kind-badge", | ||
| 312 | ui::Spec { | ||
| 313 | size: [ui::fit(), ui::px(18.0)], | ||
| 314 | text: Some(&node_kind), | ||
| 315 | font_size: Some(10.0), | ||
| 316 | medium: true, | ||
| 317 | color: Some(accent), | ||
| 318 | fill: Some([accent[0], accent[1], accent[2], 0.14]), | ||
| 319 | border: Some([accent[0], accent[1], accent[2], 0.40]), | ||
| 320 | radius: 3.0, | ||
| 321 | pad: [6.0, 0.0], | ||
| 322 | center: true, | ||
| 323 | ..ui::Spec::default() | ||
| 324 | }, | ||
| 325 | ); | ||
| 326 | if !supported { | ||
| 327 | ui.leaf( | ||
| 328 | "insp-preserved-badge", | ||
| 329 | ui::Spec { | ||
| 330 | size: [ui::fit(), ui::px(18.0)], | ||
| 331 | text: Some("preserved"), | ||
| 332 | font_size: Some(9.5), | ||
| 333 | medium: true, | ||
| 334 | color: Some([0.98, 0.78, 0.40, 1.0]), | ||
| 335 | fill: Some([0.24, 0.16, 0.06, 0.85]), | ||
| 336 | border: Some([0.92, 0.64, 0.24, 0.60]), | ||
| 337 | radius: 3.0, | ||
| 338 | pad: [5.0, 0.0], | ||
| 339 | center: true, | ||
| 340 | ..ui::Spec::default() | ||
| 341 | }, | ||
| 342 | ); | ||
| 343 | } | ||
| 344 | ui.leaf( | ||
| 345 | "insp-spacer", | ||
| 346 | ui::Spec { | ||
| 347 | size: [ui::fill(), ui::px(18.0)], | ||
| 348 | ..ui::Spec::default() | ||
| 349 | }, | ||
| 350 | ); | ||
| 351 | ui.leaf( | ||
| 352 | "insp-frame", | ||
| 353 | ui::Spec { | ||
| 354 | size: [ui::fit(), ui::px(18.0)], | ||
| 355 | text: Some(&frame_str), | ||
| 356 | font_size: Some(10.0), | ||
| 357 | color: Some(text_dim), | ||
| 358 | center: true, | ||
| 359 | ..ui::Spec::default() | ||
| 360 | }, | ||
| 361 | ); | ||
| 362 | ui.close(); // insp-meta-row | ||
| 363 | ui.close(); // insp-header | ||
| 364 | |||
| 365 | // 2. Scrollable Parameter List | ||
| 366 | ui.open( | ||
| 367 | "insp-scroll", | ||
| 368 | ui::Spec { | ||
| 369 | flags: ui::Flags::SCROLL | ui::Flags::CLIP, | ||
| 370 | size: [ui::fill(), ui::fill()], | ||
| 371 | axis: ui::Axis::Y, | ||
| 372 | pad: [10.0, 8.0], | ||
| 373 | gap: 6.0, | ||
| 374 | ..ui::Spec::default() | ||
| 375 | }, | ||
| 376 | ); | ||
| 377 | |||
| 378 | let schema = schema_for_kind(&node_kind); | ||
| 379 | let mut covered: HashSet<&str> = HashSet::new(); | ||
| 380 | |||
| 381 | for spec in schema { | ||
| 382 | covered.insert(spec.name); | ||
| 383 | if let ParamKind::Color { r, g, b, a, .. } = spec.kind { | ||
| 384 | covered.insert(r); | ||
| 385 | covered.insert(g); | ||
| 386 | covered.insert(b); | ||
| 387 | if let Some(alpha_k) = a { | ||
| 388 | covered.insert(alpha_k); | ||
| 389 | } | ||
| 390 | } | ||
| 391 | self.render_param_spec(ui, pane_id, comp, history, node_id, spec, current_frame, &mut actions); | ||
| 392 | } | ||
| 393 | |||
| 394 | // Fallback: list all remaining present non-image inputs on the node! | ||
| 395 | let mut extra_keys: Vec<String> = comp | ||
| 396 | .node(node_id) | ||
| 397 | .inputs | ||
| 398 | .iter() | ||
| 399 | .filter_map(|(k, b)| { | ||
| 400 | if covered.contains(k.as_str()) { | ||
| 401 | return None; | ||
| 402 | } | ||
| 403 | // Skip image/node connections unless they also have a value or spline | ||
| 404 | let is_node_conn = b | ||
| 405 | .source_op | ||
| 406 | .as_deref() | ||
| 407 | .is_some_and(|op| comp.node_by_name.contains_key(op)); | ||
| 408 | if is_node_conn && b.value.is_none() { | ||
| 409 | return None; | ||
| 410 | } | ||
| 411 | if b.value.is_none() && b.expression.is_none() && b.source_op.is_none() { | ||
| 412 | return None; | ||
| 413 | } | ||
| 414 | Some(k.clone()) | ||
| 415 | }) | ||
| 416 | .collect(); | ||
| 417 | extra_keys.sort(); | ||
| 418 | |||
| 419 | if !extra_keys.is_empty() { | ||
| 420 | ui.leaf( | ||
| 421 | "insp-extra-hdr", | ||
| 422 | ui::Spec { | ||
| 423 | size: [ui::fill(), ui::px(18.0)], | ||
| 424 | text: Some("OTHER INPUTS"), | ||
| 425 | font_size: Some(9.5), | ||
| 426 | medium: true, | ||
| 427 | color: Some(text_dim), | ||
| 428 | ..ui::Spec::default() | ||
| 429 | }, | ||
| 430 | ); | ||
| 431 | for key in extra_keys { | ||
| 432 | self.render_fallback_input(ui, pane_id, comp, history, node_id, &key, current_frame, &mut actions); | ||
| 433 | } | ||
| 434 | } | ||
| 435 | |||
| 436 | // Loader clip info if Loader node | ||
| 437 | if node_kind == "Loader" { | ||
| 438 | let clip_summary = comp | ||
| 439 | .node(node_id) | ||
| 440 | .clips | ||
| 441 | .first() | ||
| 442 | .map(|c| c.filename.clone()) | ||
| 443 | .unwrap_or_else(|| "(no clip)".to_owned()); | ||
| 444 | ui.open( | ||
| 445 | "insp-loader-clip", | ||
| 446 | ui::Spec { | ||
| 447 | size: [ui::fill(), ui::children()], | ||
| 448 | axis: ui::Axis::Y, | ||
| 449 | gap: 3.0, | ||
| 450 | pad: [6.0, 5.0], | ||
| 451 | fill: Some(panel_bg), | ||
| 452 | border: Some(rule), | ||
| 453 | radius: 4.0, | ||
| 454 | ..ui::Spec::default() | ||
| 455 | }, | ||
| 456 | ); | ||
| 457 | ui.leaf( | ||
| 458 | "clip-lbl", | ||
| 459 | ui::Spec { | ||
| 460 | size: [ui::fill(), ui::px(14.0)], | ||
| 461 | text: Some("Clip Filename"), | ||
| 462 | font_size: Some(10.0), | ||
| 463 | color: Some(text_dim), | ||
| 464 | ..ui::Spec::default() | ||
| 465 | }, | ||
| 466 | ); | ||
| 467 | ui.leaf( | ||
| 468 | "clip-path", | ||
| 469 | ui::Spec { | ||
| 470 | size: [ui::fill(), ui::fit()], | ||
| 471 | text: Some(&clip_summary), | ||
| 472 | font_size: Some(10.5), | ||
| 473 | overflow: ui::Overflow::Wrap, | ||
| 474 | color: Some(text_col), | ||
| 475 | ..ui::Spec::default() | ||
| 476 | }, | ||
| 477 | ); | ||
| 478 | ui.close(); | ||
| 479 | } | ||
| 480 | |||
| 481 | ui.close(); // insp-scroll | ||
| 482 | |||
| 483 | // 3. Footer: EvalStats summary | ||
| 484 | self.render_stats_footer(ui, stats, panel_bg, rule, text_dim); | ||
| 485 | |||
| 486 | ui.close(); // pane_id | ||
| 487 | actions | ||
| 488 | } | ||
| 489 | |||
| 490 | fn render_stats_footer( | ||
| 491 | &self, | ||
| 492 | ui: &mut ui::Ui, | ||
| 493 | stats: &EvalStats, | ||
| 494 | panel_bg: [f32; 4], | ||
| 495 | rule: [f32; 4], | ||
| 496 | text_dim: [f32; 4], | ||
| 497 | ) { | ||
| 498 | let line = format!( | ||
| 499 | "Eval {:.1}ms · {} nodes · cache {}/{} · {:.0}MB", | ||
| 500 | stats.eval_ms, | ||
| 501 | stats.nodes_evaluated, | ||
| 502 | stats.cache_hits, | ||
| 503 | stats.cache_hits + stats.cache_misses, | ||
| 504 | stats.cached_vram_mb, | ||
| 505 | ); | ||
| 506 | ui.open( | ||
| 507 | "insp-footer", | ||
| 508 | ui::Spec { | ||
| 509 | size: [ui::fill(), ui::px(24.0)], | ||
| 510 | axis: ui::Axis::X, | ||
| 511 | pad: [10.0, 4.0], | ||
| 512 | fill: Some(panel_bg), | ||
| 513 | border: Some(rule), | ||
| 514 | ..ui::Spec::default() | ||
| 515 | }, | ||
| 516 | ); | ||
| 517 | ui.leaf( | ||
| 518 | "insp-stats-txt", | ||
| 519 | ui::Spec { | ||
| 520 | size: [ui::fill(), ui::fill()], | ||
| 521 | text: Some(&line), | ||
| 522 | font_size: Some(10.0), | ||
| 523 | color: Some(text_dim), | ||
| 524 | ..ui::Spec::default() | ||
| 525 | }, | ||
| 526 | ); | ||
| 527 | ui.close(); | ||
| 528 | } | ||
| 529 | |||
| 530 | #[allow(clippy::too_many_arguments)] | ||
| 531 | fn render_param_spec( | ||
| 532 | &mut self, | ||
| 533 | ui: &mut ui::Ui, | ||
| 534 | pane_id: ui::Id, | ||
| 535 | comp: &mut Comp, | ||
| 536 | history: &mut CompHistory, | ||
| 537 | node_id: NodeId, | ||
| 538 | spec: &ParamSpec, | ||
| 539 | current_frame: f64, | ||
| 540 | actions: &mut Vec<InspectorAction>, | ||
| 541 | ) { | ||
| 542 | match spec.kind { | ||
| 543 | ParamKind::Float { min, max, default, step: _ } => { | ||
| 544 | self.render_float_row( | ||
| 545 | ui, | ||
| 546 | pane_id, | ||
| 547 | comp, | ||
| 548 | history, | ||
| 549 | node_id, | ||
| 550 | spec.name, | ||
| 551 | spec.label, | ||
| 552 | min, | ||
| 553 | max, | ||
| 554 | default, | ||
| 555 | current_frame, | ||
| 556 | actions, | ||
| 557 | ); | ||
| 558 | } | ||
| 559 | ParamKind::Vec2 { min, max, default } => { | ||
| 560 | self.render_vec2_row( | ||
| 561 | ui, | ||
| 562 | pane_id, | ||
| 563 | comp, | ||
| 564 | history, | ||
| 565 | node_id, | ||
| 566 | spec.name, | ||
| 567 | spec.label, | ||
| 568 | min, | ||
| 569 | max, | ||
| 570 | default, | ||
| 571 | current_frame, | ||
| 572 | actions, | ||
| 573 | ); | ||
| 574 | } | ||
| 575 | ParamKind::Bool { default } => { | ||
| 576 | self.render_bool_row(ui, comp, history, node_id, spec.name, spec.label, default, actions); | ||
| 577 | } | ||
| 578 | ParamKind::Enum { options, default } => { | ||
| 579 | self.render_enum_row(ui, comp, history, node_id, spec.name, spec.label, options, default, actions); | ||
| 580 | } | ||
| 581 | ParamKind::Color { r, g, b, a, default } => { | ||
| 582 | self.render_color_group( | ||
| 583 | ui, | ||
| 584 | pane_id, | ||
| 585 | comp, | ||
| 586 | history, | ||
| 587 | node_id, | ||
| 588 | spec.label, | ||
| 589 | r, | ||
| 590 | g, | ||
| 591 | b, | ||
| 592 | a, | ||
| 593 | default, | ||
| 594 | current_frame, | ||
| 595 | actions, | ||
| 596 | ); | ||
| 597 | } | ||
| 598 | ParamKind::Text { default } => { | ||
| 599 | self.render_text_row(ui, pane_id, comp, history, node_id, spec.name, spec.label, default, actions); | ||
| 600 | } | ||
| 601 | } | ||
| 602 | } | ||
| 603 | |||
| 604 | #[allow(clippy::too_many_arguments)] | ||
| 605 | fn render_fallback_input( | ||
| 606 | &mut self, | ||
| 607 | ui: &mut ui::Ui, | ||
| 608 | pane_id: ui::Id, | ||
| 609 | comp: &mut Comp, | ||
| 610 | history: &mut CompHistory, | ||
| 611 | node_id: NodeId, | ||
| 612 | key: &str, | ||
| 613 | current_frame: f64, | ||
| 614 | actions: &mut Vec<InspectorAction>, | ||
| 615 | ) { | ||
| 616 | let val = comp.node(node_id).inputs.get(key).and_then(|b| b.value.clone()); | ||
| 617 | match val { | ||
| 618 | Some(ParamValue::Point(pt)) => { | ||
| 619 | self.render_vec2_row(ui, pane_id, comp, history, node_id, key, key, -1.0, 2.0, pt, current_frame, actions); | ||
| 620 | } | ||
| 621 | Some(ParamValue::Text(_)) => { | ||
| 622 | self.render_text_row(ui, pane_id, comp, history, node_id, key, key, "", actions); | ||
| 623 | } | ||
| 624 | Some(ParamValue::FuId(cur)) => { | ||
| 625 | let text_dim = self.text_dim; | ||
| 626 | let text_col = self.text; | ||
| 627 | let panel_bg = self.panel_bg; | ||
| 628 | let rule = self.rule; | ||
| 629 | ui.open( | ||
| 630 | ("fb-fuid", node_id.0, key), | ||
| 631 | ui::Spec { | ||
| 632 | size: [ui::fill(), ui::px(22.0)], | ||
| 633 | axis: ui::Axis::X, | ||
| 634 | gap: 6.0, | ||
| 635 | ..ui::Spec::default() | ||
| 636 | }, | ||
| 637 | ); | ||
| 638 | ui.leaf( | ||
| 639 | "lbl", | ||
| 640 | ui::Spec { | ||
| 641 | size: [ui::px(92.0), ui::fill()], | ||
| 642 | text: Some(key), | ||
| 643 | font_size: Some(10.5), | ||
| 644 | overflow: ui::Overflow::Ellipsis, | ||
| 645 | color: Some(text_dim), | ||
| 646 | ..ui::Spec::default() | ||
| 647 | }, | ||
| 648 | ); | ||
| 649 | ui.leaf( | ||
| 650 | "val", | ||
| 651 | ui::Spec { | ||
| 652 | size: [ui::fill(), ui::fill()], | ||
| 653 | text: Some(&cur), | ||
| 654 | font_size: Some(10.5), | ||
| 655 | color: Some(text_col), | ||
| 656 | fill: Some(panel_bg), | ||
| 657 | border: Some(rule), | ||
| 658 | radius: 4.0, | ||
| 659 | pad: [6.0, 0.0], | ||
| 660 | ..ui::Spec::default() | ||
| 661 | }, | ||
| 662 | ); | ||
| 663 | ui.close(); | ||
| 664 | } | ||
| 665 | Some(ParamValue::Number(v)) => { | ||
| 666 | let (min, max) = infer_float_range(key, v); | ||
| 667 | self.render_float_row(ui, pane_id, comp, history, node_id, key, key, min, max, v, current_frame, actions); | ||
| 668 | } | ||
| 669 | None => { | ||
| 670 | // Animated spline or expression-only scalar input | ||
| 671 | let cur = comp.eval_number(comp.node(node_id), key, current_frame, 0.0, &self.expr); | ||
| 672 | let (min, max) = infer_float_range(key, cur); | ||
| 673 | self.render_float_row(ui, pane_id, comp, history, node_id, key, key, min, max, 0.0, current_frame, actions); | ||
| 674 | } | ||
| 675 | _ => {} | ||
| 676 | } | ||
| 677 | } | ||
| 678 | |||
| 679 | #[allow(clippy::too_many_arguments)] | ||
| 680 | fn render_float_row( | ||
| 681 | &mut self, | ||
| 682 | ui: &mut ui::Ui, | ||
| 683 | pane_id: ui::Id, | ||
| 684 | comp: &mut Comp, | ||
| 685 | history: &mut CompHistory, | ||
| 686 | node_id: NodeId, | ||
| 687 | input_name: &str, | ||
| 688 | label: &str, | ||
| 689 | min: f64, | ||
| 690 | max: f64, | ||
| 691 | default: f64, | ||
| 692 | current_frame: f64, | ||
| 693 | actions: &mut Vec<InspectorAction>, | ||
| 694 | ) { | ||
| 695 | let cur_val = comp.eval_number(comp.node(node_id), input_name, current_frame, default, &self.expr); | ||
| 696 | let has_expr = comp | ||
| 697 | .node(node_id) | ||
| 698 | .inputs | ||
| 699 | .get(input_name) | ||
| 700 | .and_then(|b| b.expression.as_ref()) | ||
| 701 | .is_some(); | ||
| 702 | let kf_state = keyframe_state(comp, node_id, input_name, current_frame); | ||
| 703 | |||
| 704 | ui.open( | ||
| 705 | ("row-f", node_id.0, input_name), | ||
| 706 | ui::Spec { | ||
| 707 | size: [ui::fill(), ui::px(22.0)], | ||
| 708 | axis: ui::Axis::X, | ||
| 709 | gap: 4.0, | ||
| 710 | ..ui::Spec::default() | ||
| 711 | }, | ||
| 712 | ); | ||
| 713 | |||
| 714 | // Label | ||
| 715 | ui.leaf( | ||
| 716 | "lbl", | ||
| 717 | ui::Spec { | ||
| 718 | size: [ui::px(86.0), ui::fill()], | ||
| 719 | text: Some(label), | ||
| 720 | font_size: Some(10.5), | ||
| 721 | overflow: ui::Overflow::Ellipsis, | ||
| 722 | color: Some(self.text_dim), | ||
| 723 | ..ui::Spec::default() | ||
| 724 | }, | ||
| 725 | ); | ||
| 726 | |||
| 727 | // Expression `=` badge if present | ||
| 728 | if has_expr { | ||
| 729 | ui.leaf( | ||
| 730 | "expr-badge", | ||
| 731 | ui::Spec { | ||
| 732 | size: [ui::px(16.0), ui::px(18.0)], | ||
| 733 | text: Some("="), | ||
| 734 | font_size: Some(10.5), | ||
| 735 | bold: true, | ||
| 736 | color: Some([0.36, 0.88, 0.92, 1.0]), | ||
| 737 | fill: Some([0.10, 0.24, 0.28, 0.85]), | ||
| 738 | border: Some([0.32, 0.78, 0.86, 0.65]), | ||
| 739 | radius: 3.0, | ||
| 740 | center: true, | ||
| 741 | ..ui::Spec::default() | ||
| 742 | }, | ||
| 743 | ); | ||
| 744 | } | ||
| 745 | |||
| 746 | // Scrub slider | ||
| 747 | let slider_id = pane_id.child(("sld", node_id.0, input_name)); | ||
| 748 | let drag_key = format!("{}:{input_name}", node_id.0); | ||
| 749 | if let Some(new_val) = self.scrub_slider( | ||
| 750 | ui, | ||
| 751 | slider_id, | ||
| 752 | &drag_key, | ||
| 753 | node_id, | ||
| 754 | cur_val, | ||
| 755 | min, | ||
| 756 | max, | ||
| 757 | default, | ||
| 758 | history, | ||
| 759 | comp, | ||
| 760 | input_name, | ||
| 761 | ) { | ||
| 762 | if kf_state != KeyframeState::Static { | ||
| 763 | let _ = comp.set_keyframe(node_id, input_name, current_frame, new_val); | ||
| 764 | actions.push(InspectorAction::KeyframeEdited(node_id)); | ||
| 765 | } else { | ||
| 766 | comp.set_input_value(node_id, input_name, ParamValue::Number(new_val)); | ||
| 767 | actions.push(InspectorAction::ParamEdited(node_id)); | ||
| 768 | } | ||
| 769 | } | ||
| 770 | |||
| 771 | // Reset button (small dot/arrow when non-default) | ||
| 772 | let is_default = (cur_val - default).abs() < 1e-4; | ||
| 773 | if !is_default { | ||
| 774 | let rst = ui.leaf( | ||
| 775 | ("rst", node_id.0, input_name), | ||
| 776 | ui::Spec { | ||
| 777 | cursor: Some(winit::window::CursorIcon::Pointer), | ||
| 778 | flags: ui::Flags::CLICKABLE, | ||
| 779 | size: [ui::px(18.0), ui::px(20.0)], | ||
| 780 | text: Some("↺"), | ||
| 781 | font_size: Some(10.5), | ||
| 782 | color: Some(self.text_dim), | ||
| 783 | hover_fill: Some(self.panel_bg), | ||
| 784 | radius: 3.0, | ||
| 785 | center: true, | ||
| 786 | ..ui::Spec::default() | ||
| 787 | }, | ||
| 788 | ); | ||
| 789 | if rst.clicked { | ||
| 790 | history.push_snapshot(comp, format!("Reset {label}")); | ||
| 791 | if kf_state != KeyframeState::Static { | ||
| 792 | let _ = comp.set_keyframe(node_id, input_name, current_frame, default); | ||
| 793 | actions.push(InspectorAction::KeyframeEdited(node_id)); | ||
| 794 | } else { | ||
| 795 | comp.set_input_value(node_id, input_name, ParamValue::Number(default)); | ||
| 796 | actions.push(InspectorAction::ParamEdited(node_id)); | ||
| 797 | } | ||
| 798 | } | ||
| 799 | } | ||
| 800 | |||
| 801 | // Keyframe diamond button (`◆`) | ||
| 802 | if self.keyframe_button(ui, ("kf", node_id.0, input_name), kf_state) { | ||
| 803 | self.toggle_keyframe(comp, history, node_id, input_name, current_frame, cur_val, kf_state, actions); | ||
| 804 | } | ||
| 805 | |||
| 806 | ui.close(); | ||
| 807 | } | ||
| 808 | |||
| 809 | #[allow(clippy::too_many_arguments)] | ||
| 810 | fn render_vec2_row( | ||
| 811 | &mut self, | ||
| 812 | ui: &mut ui::Ui, | ||
| 813 | pane_id: ui::Id, | ||
| 814 | comp: &mut Comp, | ||
| 815 | history: &mut CompHistory, | ||
| 816 | node_id: NodeId, | ||
| 817 | input_name: &str, | ||
| 818 | label: &str, | ||
| 819 | min: f64, | ||
| 820 | max: f64, | ||
| 821 | default: [f64; 2], | ||
| 822 | current_frame: f64, | ||
| 823 | actions: &mut Vec<InspectorAction>, | ||
| 824 | ) { | ||
| 825 | let cur = comp.eval_point(comp.node(node_id), input_name, current_frame, default, &self.expr); | ||
| 826 | let has_expr = comp | ||
| 827 | .node(node_id) | ||
| 828 | .inputs | ||
| 829 | .get(input_name) | ||
| 830 | .and_then(|b| b.expression.as_ref()) | ||
| 831 | .is_some(); | ||
| 832 | |||
| 833 | ui.open( | ||
| 834 | ("row-v2", node_id.0, input_name), | ||
| 835 | ui::Spec { | ||
| 836 | size: [ui::fill(), ui::px(22.0)], | ||
| 837 | axis: ui::Axis::X, | ||
| 838 | gap: 4.0, | ||
| 839 | ..ui::Spec::default() | ||
| 840 | }, | ||
| 841 | ); | ||
| 842 | ui.leaf( | ||
| 843 | "lbl", | ||
| 844 | ui::Spec { | ||
| 845 | size: [ui::px(86.0), ui::fill()], | ||
| 846 | text: Some(label), | ||
| 847 | font_size: Some(10.5), | ||
| 848 | overflow: ui::Overflow::Ellipsis, | ||
| 849 | color: Some(self.text_dim), | ||
| 850 | ..ui::Spec::default() | ||
| 851 | }, | ||
| 852 | ); | ||
| 853 | if has_expr { | ||
| 854 | ui.leaf( | ||
| 855 | "expr-badge", | ||
| 856 | ui::Spec { | ||
| 857 | size: [ui::px(16.0), ui::px(18.0)], | ||
| 858 | text: Some("="), | ||
| 859 | font_size: Some(10.5), | ||
| 860 | bold: true, | ||
| 861 | color: Some([0.36, 0.88, 0.92, 1.0]), | ||
| 862 | fill: Some([0.10, 0.24, 0.28, 0.85]), | ||
| 863 | border: Some([0.32, 0.78, 0.86, 0.65]), | ||
| 864 | radius: 3.0, | ||
| 865 | center: true, | ||
| 866 | ..ui::Spec::default() | ||
| 867 | }, | ||
| 868 | ); | ||
| 869 | } | ||
| 870 | |||
| 871 | let x_id = pane_id.child(("v2x", node_id.0, input_name)); | ||
| 872 | let x_key = format!("{}:{input_name}:x", node_id.0); | ||
| 873 | if let Some(nx) = self.scrub_slider( | ||
| 874 | ui, | ||
| 875 | x_id, | ||
| 876 | &x_key, | ||
| 877 | node_id, | ||
| 878 | cur[0], | ||
| 879 | min, | ||
| 880 | max, | ||
| 881 | default[0], | ||
| 882 | history, | ||
| 883 | comp, | ||
| 884 | input_name, | ||
| 885 | ) { | ||
| 886 | comp.set_input_value(node_id, input_name, ParamValue::Point([nx, cur[1]])); | ||
| 887 | actions.push(InspectorAction::ParamEdited(node_id)); | ||
| 888 | } | ||
| 889 | |||
| 890 | let y_id = pane_id.child(("v2y", node_id.0, input_name)); | ||
| 891 | let y_key = format!("{}:{input_name}:y", node_id.0); | ||
| 892 | if let Some(ny) = self.scrub_slider( | ||
| 893 | ui, | ||
| 894 | y_id, | ||
| 895 | &y_key, | ||
| 896 | node_id, | ||
| 897 | cur[1], | ||
| 898 | min, | ||
| 899 | max, | ||
| 900 | default[1], | ||
| 901 | history, | ||
| 902 | comp, | ||
| 903 | input_name, | ||
| 904 | ) { | ||
| 905 | comp.set_input_value(node_id, input_name, ParamValue::Point([cur[0], ny])); | ||
| 906 | actions.push(InspectorAction::ParamEdited(node_id)); | ||
| 907 | } | ||
| 908 | |||
| 909 | ui.close(); | ||
| 910 | } | ||
| 911 | |||
| 912 | #[allow(clippy::too_many_arguments)] | ||
| 913 | fn render_bool_row( | ||
| 914 | &mut self, | ||
| 915 | ui: &mut ui::Ui, | ||
| 916 | comp: &mut Comp, | ||
| 917 | history: &mut CompHistory, | ||
| 918 | node_id: NodeId, | ||
| 919 | input_name: &str, | ||
| 920 | label: &str, | ||
| 921 | default: bool, | ||
| 922 | actions: &mut Vec<InspectorAction>, | ||
| 923 | ) { | ||
| 924 | let checked = comp | ||
| 925 | .node(node_id) | ||
| 926 | .static_number(input_name) | ||
| 927 | .map(|v| v >= 0.5) | ||
| 928 | .unwrap_or(default); | ||
| 929 | |||
| 930 | ui.open( | ||
| 931 | ("row-b", node_id.0, input_name), | ||
| 932 | ui::Spec { | ||
| 933 | size: [ui::fill(), ui::px(22.0)], | ||
| 934 | axis: ui::Axis::X, | ||
| 935 | gap: 6.0, | ||
| 936 | ..ui::Spec::default() | ||
| 937 | }, | ||
| 938 | ); | ||
| 939 | ui.leaf( | ||
| 940 | "lbl", | ||
| 941 | ui::Spec { | ||
| 942 | size: [ui::px(86.0), ui::fill()], | ||
| 943 | text: Some(label), | ||
| 944 | font_size: Some(10.5), | ||
| 945 | overflow: ui::Overflow::Ellipsis, | ||
| 946 | color: Some(self.text_dim), | ||
| 947 | ..ui::Spec::default() | ||
| 948 | }, | ||
| 949 | ); | ||
| 950 | let fill = if checked { | ||
| 951 | [self.accent[0], self.accent[1], self.accent[2], 0.28] | ||
| 952 | } else { | ||
| 953 | self.panel_bg | ||
| 954 | }; | ||
| 955 | let border = if checked { self.accent } else { self.rule }; | ||
| 956 | let sig = ui.leaf( | ||
| 957 | ("chk", node_id.0, input_name), | ||
| 958 | ui::Spec { | ||
| 959 | cursor: Some(winit::window::CursorIcon::Pointer), | ||
| 960 | flags: ui::Flags::CLICKABLE, | ||
| 961 | size: [ui::px(54.0), ui::px(20.0)], | ||
| 962 | text: Some(if checked { "✓ On" } else { "Off" }), | ||
| 963 | font_size: Some(10.5), | ||
| 964 | medium: checked, | ||
| 965 | color: Some(if checked { self.text } else { self.text_dim }), | ||
| 966 | fill: Some(fill), | ||
| 967 | border: Some(border), | ||
| 968 | radius: 4.0, | ||
| 969 | center: true, | ||
| 970 | ..ui::Spec::default() | ||
| 971 | }, | ||
| 972 | ); | ||
| 973 | if sig.clicked { | ||
| 974 | history.push_snapshot(comp, format!("Toggle {label}")); | ||
| 975 | let next = if checked { 0.0 } else { 1.0 }; | ||
| 976 | comp.set_input_value(node_id, input_name, ParamValue::Number(next)); | ||
| 977 | actions.push(InspectorAction::ParamEdited(node_id)); | ||
| 978 | } | ||
| 979 | ui.close(); | ||
| 980 | } | ||
| 981 | |||
| 982 | #[allow(clippy::too_many_arguments)] | ||
| 983 | fn render_enum_row( | ||
| 984 | &mut self, | ||
| 985 | ui: &mut ui::Ui, | ||
| 986 | comp: &mut Comp, | ||
| 987 | history: &mut CompHistory, | ||
| 988 | node_id: NodeId, | ||
| 989 | input_name: &str, | ||
| 990 | label: &str, | ||
| 991 | options: &'static [&'static str], | ||
| 992 | default: &'static str, | ||
| 993 | actions: &mut Vec<InspectorAction>, | ||
| 994 | ) { | ||
| 995 | let cur = comp | ||
| 996 | .node(node_id) | ||
| 997 | .static_str(input_name) | ||
| 998 | .unwrap_or(default) | ||
| 999 | .to_owned(); | ||
| 1000 | |||
| 1001 | ui.open( | ||
| 1002 | ("row-e", node_id.0, input_name), | ||
| 1003 | ui::Spec { | ||
| 1004 | size: [ui::fill(), ui::px(22.0)], | ||
| 1005 | axis: ui::Axis::X, | ||
| 1006 | gap: 6.0, | ||
| 1007 | ..ui::Spec::default() | ||
| 1008 | }, | ||
| 1009 | ); | ||
| 1010 | ui.leaf( | ||
| 1011 | "lbl", | ||
| 1012 | ui::Spec { | ||
| 1013 | size: [ui::px(86.0), ui::fill()], | ||
| 1014 | text: Some(label), | ||
| 1015 | font_size: Some(10.5), | ||
| 1016 | overflow: ui::Overflow::Ellipsis, | ||
| 1017 | color: Some(self.text_dim), | ||
| 1018 | ..ui::Spec::default() | ||
| 1019 | }, | ||
| 1020 | ); | ||
| 1021 | let btn_lbl = format!("{cur} ▾"); | ||
| 1022 | let sig = ui.leaf( | ||
| 1023 | ("enum", node_id.0, input_name), | ||
| 1024 | ui::Spec { | ||
| 1025 | cursor: Some(winit::window::CursorIcon::Pointer), | ||
| 1026 | flags: ui::Flags::CLICKABLE, | ||
| 1027 | size: [ui::fill(), ui::px(20.0)], | ||
| 1028 | text: Some(&btn_lbl), | ||
| 1029 | font_size: Some(10.5), | ||
| 1030 | color: Some(self.text), | ||
| 1031 | fill: Some(self.panel_bg), | ||
| 1032 | border: Some(self.rule), | ||
| 1033 | hover_border: Some(self.accent), | ||
| 1034 | radius: 4.0, | ||
| 1035 | pad: [6.0, 0.0], | ||
| 1036 | ..ui::Spec::default() | ||
| 1037 | }, | ||
| 1038 | ); | ||
| 1039 | if sig.clicked && !options.is_empty() { | ||
| 1040 | let idx = options.iter().position(|&o| o == cur).unwrap_or(0); | ||
| 1041 | let next_idx = if ui.modifiers().shift_key() { | ||
| 1042 | (idx + options.len() - 1) % options.len() | ||
| 1043 | } else { | ||
| 1044 | (idx + 1) % options.len() | ||
| 1045 | }; | ||
| 1046 | history.push_snapshot(comp, format!("Set {label}")); | ||
| 1047 | comp.set_input_value(node_id, input_name, ParamValue::FuId(options[next_idx].to_owned())); | ||
| 1048 | actions.push(InspectorAction::ParamEdited(node_id)); | ||
| 1049 | } | ||
| 1050 | ui.close(); | ||
| 1051 | } | ||
| 1052 | |||
| 1053 | #[allow(clippy::too_many_arguments)] | ||
| 1054 | fn render_color_group( | ||
| 1055 | &mut self, | ||
| 1056 | ui: &mut ui::Ui, | ||
| 1057 | pane_id: ui::Id, | ||
| 1058 | comp: &mut Comp, | ||
| 1059 | history: &mut CompHistory, | ||
| 1060 | node_id: NodeId, | ||
| 1061 | label: &str, | ||
| 1062 | r_key: &'static str, | ||
| 1063 | g_key: &'static str, | ||
| 1064 | b_key: &'static str, | ||
| 1065 | a_key: Option<&'static str>, | ||
| 1066 | default: [f64; 4], | ||
| 1067 | current_frame: f64, | ||
| 1068 | actions: &mut Vec<InspectorAction>, | ||
| 1069 | ) { | ||
| 1070 | let rv = comp.eval_number(comp.node(node_id), r_key, current_frame, default[0], &self.expr); | ||
| 1071 | let gv = comp.eval_number(comp.node(node_id), g_key, current_frame, default[1], &self.expr); | ||
| 1072 | let bv = comp.eval_number(comp.node(node_id), b_key, current_frame, default[2], &self.expr); | ||
| 1073 | let _av = a_key | ||
| 1074 | .map(|ak| comp.eval_number(comp.node(node_id), ak, current_frame, default[3], &self.expr)) | ||
| 1075 | .unwrap_or(default[3]); | ||
| 1076 | let swatch = [ | ||
| 1077 | rv.clamp(0.0, 1.0) as f32, | ||
| 1078 | gv.clamp(0.0, 1.0) as f32, | ||
| 1079 | bv.clamp(0.0, 1.0) as f32, | ||
| 1080 | 1.0, | ||
| 1081 | ]; | ||
| 1082 | |||
| 1083 | ui.open( | ||
| 1084 | ("grp-col", node_id.0, label), | ||
| 1085 | ui::Spec { | ||
| 1086 | size: [ui::fill(), ui::children()], | ||
| 1087 | axis: ui::Axis::Y, | ||
| 1088 | gap: 4.0, | ||
| 1089 | pad: [6.0, 5.0], | ||
| 1090 | fill: Some(self.panel_bg), | ||
| 1091 | border: Some(self.rule), | ||
| 1092 | radius: 4.0, | ||
| 1093 | ..ui::Spec::default() | ||
| 1094 | }, | ||
| 1095 | ); | ||
| 1096 | // Swatch header | ||
| 1097 | ui.open( | ||
| 1098 | "col-hdr", | ||
| 1099 | ui::Spec { | ||
| 1100 | size: [ui::fill(), ui::px(18.0)], | ||
| 1101 | axis: ui::Axis::X, | ||
| 1102 | gap: 6.0, | ||
| 1103 | ..ui::Spec::default() | ||
| 1104 | }, | ||
| 1105 | ); | ||
| 1106 | ui.leaf( | ||
| 1107 | "col-lbl", | ||
| 1108 | ui::Spec { | ||
| 1109 | size: [ui::px(80.0), ui::fill()], | ||
| 1110 | text: Some(label), | ||
| 1111 | font_size: Some(10.5), | ||
| 1112 | medium: true, | ||
| 1113 | color: Some(self.text), | ||
| 1114 | ..ui::Spec::default() | ||
| 1115 | }, | ||
| 1116 | ); | ||
| 1117 | ui.leaf( | ||
| 1118 | "col-swatch", | ||
| 1119 | ui::Spec { | ||
| 1120 | size: [ui::fill(), ui::px(16.0)], | ||
| 1121 | fill: Some(swatch), | ||
| 1122 | border: Some(self.rule), | ||
| 1123 | radius: 3.0, | ||
| 1124 | ..ui::Spec::default() | ||
| 1125 | }, | ||
| 1126 | ); | ||
| 1127 | ui.close(); | ||
| 1128 | |||
| 1129 | self.render_float_row(ui, pane_id, comp, history, node_id, r_key, "Red", 0.0, 1.0, default[0], current_frame, actions); | ||
| 1130 | self.render_float_row(ui, pane_id, comp, history, node_id, g_key, "Green", 0.0, 1.0, default[1], current_frame, actions); | ||
| 1131 | self.render_float_row(ui, pane_id, comp, history, node_id, b_key, "Blue", 0.0, 1.0, default[2], current_frame, actions); | ||
| 1132 | if let Some(ak) = a_key { | ||
| 1133 | self.render_float_row(ui, pane_id, comp, history, node_id, ak, "Alpha", 0.0, 1.0, default[3], current_frame, actions); | ||
| 1134 | } | ||
| 1135 | ui.close(); | ||
| 1136 | } | ||
| 1137 | |||
| 1138 | #[allow(clippy::too_many_arguments)] | ||
| 1139 | fn render_text_row( | ||
| 1140 | &mut self, | ||
| 1141 | ui: &mut ui::Ui, | ||
| 1142 | pane_id: ui::Id, | ||
| 1143 | comp: &mut Comp, | ||
| 1144 | history: &mut CompHistory, | ||
| 1145 | node_id: NodeId, | ||
| 1146 | input_name: &str, | ||
| 1147 | label: &str, | ||
| 1148 | default: &str, | ||
| 1149 | actions: &mut Vec<InspectorAction>, | ||
| 1150 | ) { | ||
| 1151 | let field_id = pane_id.child(("txt", node_id.0, input_name)); | ||
| 1152 | let key = (node_id.0, input_name.to_owned()); | ||
| 1153 | let model_val = comp | ||
| 1154 | .node(node_id) | ||
| 1155 | .static_str(input_name) | ||
| 1156 | .unwrap_or(default) | ||
| 1157 | .to_owned(); | ||
| 1158 | let buf = self.text_bufs.entry(key).or_insert_with(|| model_val.clone()); | ||
| 1159 | if ui.focused() != Some(field_id) && *buf != model_val { | ||
| 1160 | *buf = model_val.clone(); | ||
| 1161 | } | ||
| 1162 | let prev = buf.clone(); | ||
| 1163 | |||
| 1164 | ui.open( | ||
| 1165 | ("row-t", node_id.0, input_name), | ||
| 1166 | ui::Spec { | ||
| 1167 | size: [ui::fill(), ui::px(24.0)], | ||
| 1168 | axis: ui::Axis::X, | ||
| 1169 | gap: 6.0, | ||
| 1170 | ..ui::Spec::default() | ||
| 1171 | }, | ||
| 1172 | ); | ||
| 1173 | ui.leaf( | ||
| 1174 | "lbl", | ||
| 1175 | ui::Spec { | ||
| 1176 | size: [ui::px(86.0), ui::fill()], | ||
| 1177 | text: Some(label), | ||
| 1178 | font_size: Some(10.5), | ||
| 1179 | overflow: ui::Overflow::Ellipsis, | ||
| 1180 | color: Some(self.text_dim), | ||
| 1181 | ..ui::Spec::default() | ||
| 1182 | }, | ||
| 1183 | ); | ||
| 1184 | ui::text_field( | ||
| 1185 | ui, | ||
| 1186 | field_id, | ||
| 1187 | buf, | ||
| 1188 | label, | ||
| 1189 | ui::Spec { | ||
| 1190 | size: [ui::fill(), ui::px(22.0)], | ||
| 1191 | font_size: Some(11.0), | ||
| 1192 | fill: Some(self.panel_bg), | ||
| 1193 | border: Some(self.rule), | ||
| 1194 | hover_border: Some(self.accent), | ||
| 1195 | radius: 4.0, | ||
| 1196 | pad: [6.0, 2.0], | ||
| 1197 | ..ui::Spec::default() | ||
| 1198 | }, | ||
| 1199 | ); | ||
| 1200 | if *buf != prev { | ||
| 1201 | history.push_coalesced( | ||
| 1202 | comp, | ||
| 1203 | format!("Edit {label}"), | ||
| 1204 | format!("text:{}:{input_name}", node_id.0), | ||
| 1205 | ); | ||
| 1206 | comp.set_input_value(node_id, input_name, ParamValue::Text(buf.clone())); | ||
| 1207 | actions.push(InspectorAction::ParamEdited(node_id)); | ||
| 1208 | } | ||
| 1209 | ui.close(); | ||
| 1210 | } | ||
| 1211 | |||
| 1212 | #[allow(clippy::too_many_arguments)] | ||
| 1213 | fn scrub_slider( | ||
| 1214 | &mut self, | ||
| 1215 | ui: &mut ui::Ui, | ||
| 1216 | slider_id: ui::Id, | ||
| 1217 | drag_key: &str, | ||
| 1218 | node_id: NodeId, | ||
| 1219 | value: f64, | ||
| 1220 | min: f64, | ||
| 1221 | max: f64, | ||
| 1222 | default: f64, | ||
| 1223 | history: &mut CompHistory, | ||
| 1224 | comp: &Comp, | ||
| 1225 | input_name: &str, | ||
| 1226 | ) -> Option<f64> { | ||
| 1227 | let sig = ui.signal(slider_id); | ||
| 1228 | let rect = ui.laid_out(slider_id); | ||
| 1229 | let width = rect.map(|r| (r[2] - r[0]).max(40.0)).unwrap_or(110.0); | ||
| 1230 | let mut updated: Option<f64> = None; | ||
| 1231 | |||
| 1232 | if let Some(press) = sig.press { | ||
| 1233 | let now = Instant::now(); | ||
| 1234 | let is_double = self | ||
| 1235 | .last_click | ||
| 1236 | .get(drag_key) | ||
| 1237 | .is_some_and(|prev| now.duration_since(*prev) < Duration::from_millis(320)); | ||
| 1238 | self.last_click.insert(drag_key.to_owned(), now); | ||
| 1239 | if is_double { | ||
| 1240 | history.push_snapshot(comp, format!("Reset {input_name}")); | ||
| 1241 | self.drag = None; | ||
| 1242 | updated = Some(default); | ||
| 1243 | } else { | ||
| 1244 | self.drag = Some(DragState { | ||
| 1245 | node_id, | ||
| 1246 | key: drag_key.to_owned(), | ||
| 1247 | start_x: press[0], | ||
| 1248 | start_val: value, | ||
| 1249 | min, | ||
| 1250 | max, | ||
| 1251 | width, | ||
| 1252 | }); | ||
| 1253 | } | ||
| 1254 | } else if sig.dragging { | ||
| 1255 | if let (Some(d), Some(ptr)) = (&self.drag, ui.pointer()) { | ||
| 1256 | if d.key == drag_key && d.node_id == node_id { | ||
| 1257 | let fine = if ui.modifiers().shift_key() { 0.15 } else { 1.0 }; | ||
| 1258 | let next = compute_scrub_value(d.start_val, ptr[0] - d.start_x, d.width, d.min, d.max, fine); | ||
| 1259 | if (next - value).abs() > 1e-6 { | ||
| 1260 | history.push_coalesced( | ||
| 1261 | comp, | ||
| 1262 | format!("Adjust {input_name}"), | ||
| 1263 | format!("scrub:{drag_key}"), | ||
| 1264 | ); | ||
| 1265 | updated = Some(next); | ||
| 1266 | } | ||
| 1267 | } | ||
| 1268 | } | ||
| 1269 | } else if self.drag.as_ref().is_some_and(|d| d.key == drag_key) { | ||
| 1270 | self.drag = None; | ||
| 1271 | history.break_coalescing(); | ||
| 1272 | } | ||
| 1273 | |||
| 1274 | let display_val = updated.unwrap_or(value); | ||
| 1275 | let frac = normalize_slider_fraction(display_val, min, max); | ||
| 1276 | let val_text = format_param_number(display_val); | ||
| 1277 | let fill_w = (width * frac).clamp(0.0, width); | ||
| 1278 | let active_drag = self.drag.as_ref().is_some_and(|d| d.key == drag_key); | ||
| 1279 | |||
| 1280 | ui.open_as( | ||
| 1281 | slider_id, | ||
| 1282 | ui::Spec { | ||
| 1283 | cursor: Some(winit::window::CursorIcon::EwResize), | ||
| 1284 | flags: ui::Flags::CLICKABLE | ui::Flags::CLIP, | ||
| 1285 | size: [ui::fill(), ui::px(20.0)], | ||
| 1286 | fill: Some(self.panel_bg), | ||
| 1287 | border: Some(if active_drag || sig.hovered { self.accent } else { self.rule }), | ||
| 1288 | radius: 4.0, | ||
| 1289 | ..ui::Spec::default() | ||
| 1290 | }, | ||
| 1291 | ); | ||
| 1292 | if fill_w > 0.5 { | ||
| 1293 | ui.leaf( | ||
| 1294 | "fill", | ||
| 1295 | ui::Spec { | ||
| 1296 | flags: ui::Flags::FLOAT | ui::Flags::INERT, | ||
| 1297 | position: [0.0, 0.0], | ||
| 1298 | size: [ui::px(fill_w), ui::px(20.0)], | ||
| 1299 | fill: Some([self.accent[0], self.accent[1], self.accent[2], if active_drag { 0.34 } else { 0.22 }]), | ||
| 1300 | radius: 3.0, | ||
| 1301 | ..ui::Spec::default() | ||
| 1302 | }, | ||
| 1303 | ); | ||
| 1304 | } | ||
| 1305 | ui.leaf( | ||
| 1306 | "txt", | ||
| 1307 | ui::Spec { | ||
| 1308 | flags: ui::Flags::INERT, | ||
| 1309 | size: [ui::fill(), ui::fill()], | ||
| 1310 | text: Some(&val_text), | ||
| 1311 | font_size: Some(10.5), | ||
| 1312 | color: Some(self.text), | ||
| 1313 | center: true, | ||
| 1314 | ..ui::Spec::default() | ||
| 1315 | }, | ||
| 1316 | ); | ||
| 1317 | ui.close(); | ||
| 1318 | |||
| 1319 | updated | ||
| 1320 | } | ||
| 1321 | |||
| 1322 | fn keyframe_button(&self, ui: &mut ui::Ui, part: impl std::hash::Hash, state: KeyframeState) -> bool { | ||
| 1323 | let (ink, fill, border) = match state { | ||
| 1324 | KeyframeState::KeyframeAtCurrent => ( | ||
| 1325 | [1.0, 0.80, 0.22, 1.0], | ||
| 1326 | Some([0.98, 0.72, 0.18, 0.24]), | ||
| 1327 | Some([0.98, 0.76, 0.20, 0.85]), | ||
| 1328 | ), | ||
| 1329 | KeyframeState::AnimatedOtherFrame => ( | ||
| 1330 | [0.92, 0.64, 0.24, 0.90], | ||
| 1331 | Some([0.92, 0.64, 0.24, 0.12]), | ||
| 1332 | Some([0.92, 0.64, 0.24, 0.45]), | ||
| 1333 | ), | ||
| 1334 | KeyframeState::Static => (self.text_dim, None, None), | ||
| 1335 | }; | ||
| 1336 | let sig = ui.leaf( | ||
| 1337 | part, | ||
| 1338 | ui::Spec { | ||
| 1339 | cursor: Some(winit::window::CursorIcon::Pointer), | ||
| 1340 | flags: ui::Flags::CLICKABLE, | ||
| 1341 | size: [ui::px(20.0), ui::px(20.0)], | ||
| 1342 | text: Some("◆"), | ||
| 1343 | font_size: Some(10.5), | ||
| 1344 | color: Some(ink), | ||
| 1345 | fill, | ||
| 1346 | border, | ||
| 1347 | hover_fill: Some([0.98, 0.76, 0.22, 0.18]), | ||
| 1348 | radius: 4.0, | ||
| 1349 | center: true, | ||
| 1350 | ..ui::Spec::default() | ||
| 1351 | }, | ||
| 1352 | ); | ||
| 1353 | sig.clicked | ||
| 1354 | } | ||
| 1355 | |||
| 1356 | #[allow(clippy::too_many_arguments)] | ||
| 1357 | fn toggle_keyframe( | ||
| 1358 | &self, | ||
| 1359 | comp: &mut Comp, | ||
| 1360 | history: &mut CompHistory, | ||
| 1361 | node_id: NodeId, | ||
| 1362 | input_name: &str, | ||
| 1363 | current_frame: f64, | ||
| 1364 | cur_val: f64, | ||
| 1365 | state: KeyframeState, | ||
| 1366 | actions: &mut Vec<InspectorAction>, | ||
| 1367 | ) { | ||
| 1368 | match state { | ||
| 1369 | KeyframeState::KeyframeAtCurrent => { | ||
| 1370 | if let Some(sp_name) = comp | ||
| 1371 | .node(node_id) | ||
| 1372 | .inputs | ||
| 1373 | .get(input_name) | ||
| 1374 | .and_then(|b| b.source_op.clone()) | ||
| 1375 | { | ||
| 1376 | history.push_snapshot(comp, format!("Delete Keyframe {input_name}")); | ||
| 1377 | if comp.delete_keyframe(&sp_name, current_frame) { | ||
| 1378 | actions.push(InspectorAction::KeyframeEdited(node_id)); | ||
| 1379 | actions.push(InspectorAction::StatusNotice(format!( | ||
| 1380 | "Deleted keyframe on {input_name} @ f{current_frame:.0}" | ||
| 1381 | ))); | ||
| 1382 | } | ||
| 1383 | } | ||
| 1384 | } | ||
| 1385 | KeyframeState::Static | KeyframeState::AnimatedOtherFrame => { | ||
| 1386 | history.push_snapshot(comp, format!("Set Keyframe {input_name}")); | ||
| 1387 | match comp.set_keyframe(node_id, input_name, current_frame, cur_val) { | ||
| 1388 | Ok(_) => { | ||
| 1389 | actions.push(InspectorAction::KeyframeEdited(node_id)); | ||
| 1390 | actions.push(InspectorAction::StatusNotice(format!( | ||
| 1391 | "Keyframed {input_name} = {:.3} @ f{current_frame:.0}", | ||
| 1392 | cur_val | ||
| 1393 | ))); | ||
| 1394 | } | ||
| 1395 | Err(e) => actions.push(InspectorAction::StatusNotice(e)), | ||
| 1396 | } | ||
| 1397 | } | ||
| 1398 | } | ||
| 1399 | } | ||
| 1400 | } | ||
| 1401 | |||
| 1402 | /// Computes whether an input is static, animated on another frame, or has a keyframe at `frame`. | ||
| 1403 | pub fn keyframe_state(comp: &Comp, node_id: NodeId, input_name: &str, frame: f64) -> KeyframeState { | ||
| 1404 | let Some(sp_name) = comp | ||
| 1405 | .node(node_id) | ||
| 1406 | .inputs | ||
| 1407 | .get(input_name) | ||
| 1408 | .and_then(|b| b.source_op.as_deref()) | ||
| 1409 | else { | ||
| 1410 | return KeyframeState::Static; | ||
| 1411 | }; | ||
| 1412 | let Some(spline) = comp.splines.get(sp_name) else { | ||
| 1413 | return KeyframeState::Static; | ||
| 1414 | }; | ||
| 1415 | if spline.keyframes.iter().any(|kf| (kf.time - frame).abs() < 1e-4) { | ||
| 1416 | KeyframeState::KeyframeAtCurrent | ||
| 1417 | } else if !spline.keyframes.is_empty() { | ||
| 1418 | KeyframeState::AnimatedOtherFrame | ||
| 1419 | } else { | ||
| 1420 | KeyframeState::Static | ||
| 1421 | } | ||
| 1422 | } | ||
| 1423 | |||
| 1424 | pub fn normalize_slider_fraction(value: f64, min: f64, max: f64) -> f32 { | ||
| 1425 | let span = (max - min).abs().max(1e-6); | ||
| 1426 | ((value - min) / span).clamp(0.0, 1.0) as f32 | ||
| 1427 | } | ||
| 1428 | |||
| 1429 | pub fn compute_scrub_value(start_val: f64, dx: f32, width: f32, min: f64, max: f64, fine_scale: f64) -> f64 { | ||
| 1430 | let span = (max - min).max(1e-4); | ||
| 1431 | let delta = (f64::from(dx) / f64::from(width.max(40.0))) * span * fine_scale; | ||
| 1432 | (start_val + delta).clamp(min, max) | ||
| 1433 | } | ||
| 1434 | |||
| 1435 | pub fn format_param_number(v: f64) -> String { | ||
| 1436 | if v.abs() >= 100.0 { | ||
| 1437 | format!("{v:.1}") | ||
| 1438 | } else if v.abs() >= 10.0 { | ||
| 1439 | format!("{v:.2}") | ||
| 1440 | } else { | ||
| 1441 | format!("{v:.3}") | ||
| 1442 | } | ||
| 1443 | } | ||
| 1444 | |||
| 1445 | pub fn infer_float_range(name: &str, val: f64) -> (f64, f64) { | ||
| 1446 | let lower = name.to_ascii_lowercase(); | ||
| 1447 | if lower.contains("angle") || lower.contains("rotate") { | ||
| 1448 | (-360.0, 360.0) | ||
| 1449 | } else if lower.contains("width") || lower.contains("height") { | ||
| 1450 | if val > 2.0 { | ||
| 1451 | (1.0, (val * 2.0).max(4096.0)) | ||
| 1452 | } else { | ||
| 1453 | (0.0, 2.0) | ||
| 1454 | } | ||
| 1455 | } else if lower.contains("blend") || lower.contains("alpha") || lower.contains("opacity") { | ||
| 1456 | (0.0, 1.0) | ||
| 1457 | } else if lower.contains("size") || lower.contains("blur") || lower.contains("glow") { | ||
| 1458 | (0.0, (val.abs() * 2.0).max(50.0)) | ||
| 1459 | } else if val < 0.0 || val > 1.0 { | ||
| 1460 | let hi = (val.abs() * 2.0).max(10.0); | ||
| 1461 | (-hi, hi) | ||
| 1462 | } else { | ||
| 1463 | (0.0, 1.0) | ||
| 1464 | } | ||
| 1465 | } | ||
| 1466 | |||
| 1467 | const APPLY_MODES: &[&str] = &[ | ||
| 1468 | "Normal", | ||
| 1469 | "Screen", | ||
| 1470 | "Multiply", | ||
| 1471 | "Overlay", | ||
| 1472 | "Soft Light", | ||
| 1473 | "Hard Light", | ||
| 1474 | "Color Dodge", | ||
| 1475 | "Color Burn", | ||
| 1476 | "Darken", | ||
| 1477 | "Lighten", | ||
| 1478 | "Difference", | ||
| 1479 | "Exclusion", | ||
| 1480 | "Hue", | ||
| 1481 | "Saturation", | ||
| 1482 | "Color", | ||
| 1483 | "Luminosity", | ||
| 1484 | ]; | ||
| 1485 | |||
| 1486 | const BLUR_FILTERS: &[&str] = &["Fast Gaussian", "Gaussian", "Box", "Bartlett", "Multi-box"]; | ||
| 1487 | const CLIPPING_MODES: &[&str] = &["Frame", "Domain", "None"]; | ||
| 1488 | const EDGES_MODES: &[&str] = &["Canvas", "Wrap", "Duplicate", "Mirror"]; | ||
| 1489 | const SHAPE3D_TYPES: &[&str] = &[ | ||
| 1490 | "SurfacePlaneInputs", | ||
| 1491 | "SurfaceSphereInputs", | ||
| 1492 | "SurfaceCubeInputs", | ||
| 1493 | "SurfaceCylinderInputs", | ||
| 1494 | "SurfaceConeInputs", | ||
| 1495 | "SurfaceTorusInputs", | ||
| 1496 | ]; | ||
| 1497 | |||
| 1498 | const fn flt(name: &'static str, label: &'static str, min: f64, max: f64, default: f64) -> ParamSpec { | ||
| 1499 | ParamSpec { | ||
| 1500 | name, | ||
| 1501 | label, | ||
| 1502 | kind: ParamKind::Float { min, max, default, step: 0.01 }, | ||
| 1503 | } | ||
| 1504 | } | ||
| 1505 | |||
| 1506 | const fn v2(name: &'static str, label: &'static str, min: f64, max: f64, default: [f64; 2]) -> ParamSpec { | ||
| 1507 | ParamSpec { | ||
| 1508 | name, | ||
| 1509 | label, | ||
| 1510 | kind: ParamKind::Vec2 { min, max, default }, | ||
| 1511 | } | ||
| 1512 | } | ||
| 1513 | |||
| 1514 | const fn boolean(name: &'static str, label: &'static str, default: bool) -> ParamSpec { | ||
| 1515 | ParamSpec { | ||
| 1516 | name, | ||
| 1517 | label, | ||
| 1518 | kind: ParamKind::Bool { default }, | ||
| 1519 | } | ||
| 1520 | } | ||
| 1521 | |||
| 1522 | const fn fuid( | ||
| 1523 | name: &'static str, | ||
| 1524 | label: &'static str, | ||
| 1525 | options: &'static [&'static str], | ||
| 1526 | default: &'static str, | ||
| 1527 | ) -> ParamSpec { | ||
| 1528 | ParamSpec { | ||
| 1529 | name, | ||
| 1530 | label, | ||
| 1531 | kind: ParamKind::Enum { options, default }, | ||
| 1532 | } | ||
| 1533 | } | ||
| 1534 | |||
| 1535 | /// Curated Fusion 21.1 parameter schemas for major compositor tools. | ||
| 1536 | pub fn schema_for_kind(kind: &str) -> &'static [ParamSpec] { | ||
| 1537 | match kind { | ||
| 1538 | "Merge" => const { &[ | ||
| 1539 | fuid("ApplyMode", "Apply Mode", APPLY_MODES, "Normal"), | ||
| 1540 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 1541 | flt("SubMerge", "Subtractive", 0.0, 1.0, 0.0), | ||
| 1542 | v2("Center", "Center", -1.0, 2.0, [0.5, 0.5]), | ||
| 1543 | flt("Size", "Size", 0.0, 5.0, 1.0), | ||
| 1544 | flt("Angle", "Angle", -360.0, 360.0, 0.0), | ||
| 1545 | boolean("FlipHoriz", "Flip Horiz", false), | ||
| 1546 | boolean("FlipVert", "Flip Vert", false), | ||
| 1547 | fuid("Edges", "Edges", EDGES_MODES, "Canvas"), | ||
| 1548 | boolean("PerformDepthMerge", "Depth Merge", false), | ||
| 1549 | ] }, | ||
| 1550 | "Transform" => const { &[ | ||
| 1551 | v2("Center", "Center", -1.0, 2.0, [0.5, 0.5]), | ||
| 1552 | v2("Pivot", "Pivot", -1.0, 2.0, [0.5, 0.5]), | ||
| 1553 | flt("Size", "Size", 0.0, 5.0, 1.0), | ||
| 1554 | flt("Aspect", "Aspect", 0.1, 4.0, 1.0), | ||
| 1555 | flt("Angle", "Angle", -360.0, 360.0, 0.0), | ||
| 1556 | boolean("FlipHoriz", "Flip Horiz", false), | ||
| 1557 | boolean("FlipVert", "Flip Vert", false), | ||
| 1558 | fuid("Edges", "Edges", EDGES_MODES, "Canvas"), | ||
| 1559 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 1560 | ] }, | ||
| 1561 | "Blur" => const { &[ | ||
| 1562 | fuid("Filter", "Filter", BLUR_FILTERS, "Fast Gaussian"), | ||
| 1563 | boolean("LockXY", "Lock X/Y", true), | ||
| 1564 | flt("XBlurSize", "Blur Size", 0.0, 100.0, 1.0), | ||
| 1565 | flt("YBlurSize", "Y Blur Size", 0.0, 100.0, 1.0), | ||
| 1566 | fuid("ClippingMode", "Clipping", CLIPPING_MODES, "Frame"), | ||
| 1567 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 1568 | ] }, | ||
| 1569 | "Glow" => const { &[ | ||
| 1570 | flt("XGlowSize", "Glow Size", 0.0, 100.0, 10.0), | ||
| 1571 | flt("Glow", "Glow", 0.0, 2.0, 0.8), | ||
| 1572 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 1573 | fuid("Filter", "Filter", BLUR_FILTERS, "Fast Gaussian"), | ||
| 1574 | ] }, | ||
| 1575 | "SoftGlow" => const { &[ | ||
| 1576 | fuid("Filter", "Filter", BLUR_FILTERS, "Fast Gaussian"), | ||
| 1577 | flt("Threshold", "Threshold", 0.0, 1.0, 0.0), | ||
| 1578 | flt("Gain", "Gain", 0.0, 5.0, 2.0), | ||
| 1579 | flt("XGlowSize", "Glow Size", 0.0, 100.0, 10.0), | ||
| 1580 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 1581 | ] }, | ||
| 1582 | "BrightnessContrast" => const { &[ | ||
| 1583 | flt("Gain", "Gain", 0.0, 5.0, 1.0), | ||
| 1584 | flt("Lift", "Lift", -1.0, 1.0, 0.0), | ||
| 1585 | flt("Gamma", "Gamma", 0.05, 5.0, 1.0), | ||
| 1586 | flt("Contrast", "Contrast", -1.0, 1.0, 0.0), | ||
| 1587 | flt("Brightness", "Brightness", -1.0, 1.0, 0.0), | ||
| 1588 | flt("Saturation", "Saturation", 0.0, 4.0, 1.0), | ||
| 1589 | boolean("PreDividePostMultiply", "Pre-Div/Post", false), | ||
| 1590 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 1591 | ] }, | ||
| 1592 | "ColorCorrector" => const { &[ | ||
| 1593 | flt("WheelSaturation1", "Saturation", 0.0, 4.0, 1.0), | ||
| 1594 | flt("WheelHue1", "Hue", -1.0, 1.0, 0.0), | ||
| 1595 | flt("MasterRGBGain", "Gain", 0.0, 5.0, 1.0), | ||
| 1596 | flt("MasterRGBGamma", "Gamma", 0.05, 5.0, 1.0), | ||
| 1597 | flt("MasterRGBLift", "Lift", -1.0, 1.0, 0.0), | ||
| 1598 | flt("MasterRGBContrast", "Contrast", 0.0, 3.0, 1.0), | ||
| 1599 | flt("MasterRGBBrightness", "Brightness", -1.0, 1.0, 0.0), | ||
| 1600 | boolean("PreDividePostMultiply", "Pre-Div/Post", false), | ||
| 1601 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 1602 | ] }, | ||
| 1603 | "Background" => const { &[ | ||
| 1604 | ParamSpec { | ||
| 1605 | name: "TopLeftColor", | ||
| 1606 | label: "Color", | ||
| 1607 | kind: ParamKind::Color { | ||
| 1608 | r: "TopLeftRed", | ||
| 1609 | g: "TopLeftGreen", | ||
| 1610 | b: "TopLeftBlue", | ||
| 1611 | a: Some("TopLeftAlpha"), | ||
| 1612 | default: [0.0, 0.0, 0.0, 1.0], | ||
| 1613 | }, | ||
| 1614 | }, | ||
| 1615 | flt("Width", "Width", 1.0, 7680.0, 1920.0), | ||
| 1616 | flt("Height", "Height", 1.0, 4320.0, 1080.0), | ||
| 1617 | ] }, | ||
| 1618 | "TextPlus" => const { &[ | ||
| 1619 | ParamSpec { | ||
| 1620 | name: "StyledText", | ||
| 1621 | label: "Styled Text", | ||
| 1622 | kind: ParamKind::Text { default: "" }, | ||
| 1623 | }, | ||
| 1624 | ParamSpec { | ||
| 1625 | name: "Font", | ||
| 1626 | label: "Font", | ||
| 1627 | kind: ParamKind::Text { default: "Open Sans" }, | ||
| 1628 | }, | ||
| 1629 | flt("Size", "Size", 0.005, 1.0, 0.08), | ||
| 1630 | flt("Tracking", "Tracking", 0.0, 4.0, 1.0), | ||
| 1631 | v2("Center", "Center", -1.0, 2.0, [0.5, 0.5]), | ||
| 1632 | ParamSpec { | ||
| 1633 | name: "TextColor", | ||
| 1634 | label: "Text Color", | ||
| 1635 | kind: ParamKind::Color { | ||
| 1636 | r: "Red1", | ||
| 1637 | g: "Green1", | ||
| 1638 | b: "Blue1", | ||
| 1639 | a: Some("Alpha1"), | ||
| 1640 | default: [1.0, 1.0, 1.0, 1.0], | ||
| 1641 | }, | ||
| 1642 | }, | ||
| 1643 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 1644 | ] }, | ||
| 1645 | "EllipseMask" => const { &[ | ||
| 1646 | flt("Level", "Level", 0.0, 1.0, 1.0), | ||
| 1647 | flt("SoftEdge", "Soft Edge", 0.0, 0.5, 0.0), | ||
| 1648 | flt("BorderWidth", "Border", -0.2, 0.2, 0.0), | ||
| 1649 | boolean("Solid", "Solid", true), | ||
| 1650 | boolean("Invert", "Invert", false), | ||
| 1651 | v2("Center", "Center", -0.5, 1.5, [0.5, 0.5]), | ||
| 1652 | flt("Width", "Width", 0.0, 2.0, 0.5), | ||
| 1653 | flt("Height", "Height", 0.0, 2.0, 0.5), | ||
| 1654 | flt("Angle", "Angle", -360.0, 360.0, 0.0), | ||
| 1655 | ] }, | ||
| 1656 | "RectangleMask" => const { &[ | ||
| 1657 | flt("Level", "Level", 0.0, 1.0, 1.0), | ||
| 1658 | flt("SoftEdge", "Soft Edge", 0.0, 0.5, 0.0), | ||
| 1659 | flt("CornerRadius", "Corner", 0.0, 1.0, 0.0), | ||
| 1660 | boolean("Solid", "Solid", true), | ||
| 1661 | boolean("Invert", "Invert", false), | ||
| 1662 | v2("Center", "Center", -0.5, 1.5, [0.5, 0.5]), | ||
| 1663 | flt("Width", "Width", 0.0, 2.0, 0.5), | ||
| 1664 | flt("Height", "Height", 0.0, 2.0, 0.5), | ||
| 1665 | flt("Angle", "Angle", -360.0, 360.0, 0.0), | ||
| 1666 | ] }, | ||
| 1667 | "Displace" => const { &[ | ||
| 1668 | flt("XRefraction", "X Refract", -1.0, 1.0, 0.0), | ||
| 1669 | flt("YRefraction", "Y Refract", -1.0, 1.0, 0.0), | ||
| 1670 | flt("RefractionStrength", "Strength", -2.0, 2.0, 0.0), | ||
| 1671 | flt("LightAngle", "Light Angle", -360.0, 360.0, 0.0), | ||
| 1672 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 1673 | ] }, | ||
| 1674 | "Vortex" => const { &[ | ||
| 1675 | v2("Center", "Center", -0.5, 1.5, [0.5, 0.5]), | ||
| 1676 | flt("Size", "Size", 0.0, 2.0, 0.5), | ||
| 1677 | flt("Angle", "Angle", -720.0, 720.0, 90.0), | ||
| 1678 | flt("Power", "Power", 0.1, 5.0, 1.0), | ||
| 1679 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 1680 | ] }, | ||
| 1681 | "FastNoise" => const { &[ | ||
| 1682 | flt("Detail", "Detail", 0.0, 10.0, 2.0), | ||
| 1683 | flt("Contrast", "Contrast", 0.0, 5.0, 1.0), | ||
| 1684 | flt("Brightness", "Brightness", -1.0, 1.0, 0.0), | ||
| 1685 | flt("XScale", "Scale", 0.01, 50.0, 2.0), | ||
| 1686 | flt("Seethe", "Seethe", 0.0, 100.0, 0.0), | ||
| 1687 | flt("SeetheRate", "Seethe Rate", 0.0, 2.0, 0.0), | ||
| 1688 | v2("Center", "Center", -2.0, 3.0, [0.5, 0.5]), | ||
| 1689 | ] }, | ||
| 1690 | "UltraKeyer" => const { &[ | ||
| 1691 | ParamSpec { | ||
| 1692 | name: "KeyColor", | ||
| 1693 | label: "Key Color", | ||
| 1694 | kind: ParamKind::Color { | ||
| 1695 | r: "BackgroundRed", | ||
| 1696 | g: "BackgroundGreen", | ||
| 1697 | b: "BackgroundBlue", | ||
| 1698 | a: None, | ||
| 1699 | default: [0.0, 1.0, 0.0, 1.0], | ||
| 1700 | }, | ||
| 1701 | }, | ||
| 1702 | flt("MatteThresholdLow", "Matte Low", 0.0, 1.0, 0.0), | ||
| 1703 | flt("MatteThresholdHigh", "Matte High", 0.0, 1.0, 1.0), | ||
| 1704 | flt("SpillSuppression", "Spill", 0.0, 1.0, 0.0), | ||
| 1705 | boolean("PostMultiplyImage", "Post-Multiply", true), | ||
| 1706 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 1707 | ] }, | ||
| 1708 | "Loader" => const { &[ | ||
| 1709 | flt("GlobalIn", "Global In", 0.0, 10000.0, 0.0), | ||
| 1710 | flt("GlobalOut", "Global Out", 0.0, 10000.0, 100.0), | ||
| 1711 | boolean("Loop", "Loop", false), | ||
| 1712 | boolean("Reverse", "Reverse", false), | ||
| 1713 | ] }, | ||
| 1714 | "Camera3D" => const { &[ | ||
| 1715 | flt("FLength", "Focal Len", 5.0, 200.0, 24.0), | ||
| 1716 | flt("PlaneOfFocus", "Focus Dist", 0.1, 100.0, 5.0), | ||
| 1717 | flt("Transform3DOp.Translate.X", "Trans X", -50.0, 50.0, 0.0), | ||
| 1718 | flt("Transform3DOp.Translate.Y", "Trans Y", -50.0, 50.0, 0.0), | ||
| 1719 | flt("Transform3DOp.Translate.Z", "Trans Z", -50.0, 50.0, 5.0), | ||
| 1720 | flt("Transform3DOp.Rotate.X", "Rot X", -180.0, 180.0, 0.0), | ||
| 1721 | flt("Transform3DOp.Rotate.Y", "Rot Y", -180.0, 180.0, 0.0), | ||
| 1722 | flt("Transform3DOp.Rotate.Z", "Rot Z", -180.0, 180.0, 0.0), | ||
| 1723 | ] }, | ||
| 1724 | "Shape3D" => const { &[ | ||
| 1725 | fuid("Shape", "Shape", SHAPE3D_TYPES, "SurfacePlaneInputs"), | ||
| 1726 | flt("SurfacePlaneInputs.Width", "Width", 0.01, 20.0, 1.0), | ||
| 1727 | flt("SurfacePlaneInputs.Height", "Height", 0.01, 20.0, 1.0), | ||
| 1728 | flt("Transform3DOp.Translate.X", "Trans X", -50.0, 50.0, 0.0), | ||
| 1729 | flt("Transform3DOp.Translate.Y", "Trans Y", -50.0, 50.0, 0.0), | ||
| 1730 | flt("Transform3DOp.Translate.Z", "Trans Z", -50.0, 50.0, 0.0), | ||
| 1731 | flt("Transform3DOp.Scale.X", "Scale", 0.01, 20.0, 1.0), | ||
| 1732 | ] }, | ||
| 1733 | _ => &[], | ||
| 1734 | } | ||
| 1735 | } | ||
| 1736 | |||
| 1737 | #[cfg(test)] | ||
| 1738 | mod tests { | ||
| 1739 | use super::*; | ||
| 1740 | |||
| 1741 | #[test] | ||
| 1742 | fn curated_schemas_cover_all_major_tools() { | ||
| 1743 | let major = [ | ||
| 1744 | "Merge", | ||
| 1745 | "Transform", | ||
| 1746 | "Blur", | ||
| 1747 | "Glow", | ||
| 1748 | "SoftGlow", | ||
| 1749 | "BrightnessContrast", | ||
| 1750 | "ColorCorrector", | ||
| 1751 | "Background", | ||
| 1752 | "TextPlus", | ||
| 1753 | "EllipseMask", | ||
| 1754 | "RectangleMask", | ||
| 1755 | "Displace", | ||
| 1756 | "Vortex", | ||
| 1757 | "FastNoise", | ||
| 1758 | "UltraKeyer", | ||
| 1759 | "Loader", | ||
| 1760 | "Camera3D", | ||
| 1761 | "Shape3D", | ||
| 1762 | ]; | ||
| 1763 | for tool in major { | ||
| 1764 | let s = schema_for_kind(tool); | ||
| 1765 | assert!(!s.is_empty(), "expected non-empty curated schema for {tool}"); | ||
| 1766 | } | ||
| 1767 | assert!(schema_for_kind("UnknownCustomTool").is_empty()); | ||
| 1768 | } | ||
| 1769 | |||
| 1770 | #[test] | ||
| 1771 | fn slider_math_and_clamping() { | ||
| 1772 | assert!((normalize_slider_fraction(0.5, 0.0, 1.0) - 0.5).abs() < 1e-6); | ||
| 1773 | assert!((normalize_slider_fraction(-5.0, 0.0, 1.0) - 0.0).abs() < 1e-6); | ||
| 1774 | assert!((normalize_slider_fraction(10.0, 0.0, 1.0) - 1.0).abs() < 1e-6); | ||
| 1775 | |||
| 1776 | let v = compute_scrub_value(0.5, 50.0, 100.0, 0.0, 1.0, 1.0); | ||
| 1777 | assert!((v - 1.0).abs() < 1e-6); | ||
| 1778 | let v_fine = compute_scrub_value(0.5, 50.0, 100.0, 0.0, 1.0, 0.1); | ||
| 1779 | assert!((v_fine - 0.55).abs() < 1e-6); | ||
| 1780 | } | ||
| 1781 | |||
| 1782 | #[test] | ||
| 1783 | fn keyframe_state_transitions() { | ||
| 1784 | let src = r#"Composition { | ||
| 1785 | Tools = ordered() { | ||
| 1786 | BC1 = BrightnessContrast { | ||
| 1787 | Inputs = { Gain = Input { Value = 1.0 } }, | ||
| 1788 | }, | ||
| 1789 | }, | ||
| 1790 | }"#; | ||
| 1791 | let mut comp = Comp::from_fusion_str(src).unwrap(); | ||
| 1792 | let bc = comp.find_node("BC1").unwrap(); | ||
| 1793 | assert_eq!(keyframe_state(&comp, bc, "Gain", 10.0), KeyframeState::Static); | ||
| 1794 | |||
| 1795 | let sp = comp.set_keyframe(bc, "Gain", 10.0, 1.5).unwrap(); | ||
| 1796 | assert_eq!(keyframe_state(&comp, bc, "Gain", 10.0), KeyframeState::KeyframeAtCurrent); | ||
| 1797 | assert_eq!(keyframe_state(&comp, bc, "Gain", 20.0), KeyframeState::AnimatedOtherFrame); | ||
| 1798 | |||
| 1799 | assert!(comp.delete_keyframe(&sp, 10.0)); | ||
| 1800 | assert_eq!(keyframe_state(&comp, bc, "Gain", 10.0), KeyframeState::Static); | ||
| 1801 | } | ||
| 1802 | } | ||
crates/app/src/inspector/mod.rs created+512| ... | @@ -0,0 +1,512 @@ | ||
| 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 | |||
| 4 | mod schemas; | ||
| 5 | mod widgets; | ||
| 6 | |||
| 7 | #[allow(unused_imports)] | ||
| 8 | pub use schemas::{ParamKind, ParamSpec, infer_float_range, schema_for_kind}; | ||
| 9 | #[allow(unused_imports)] | ||
| 10 | pub use widgets::{ | ||
| 11 | KeyframeState, compute_scrub_value, format_param_number, keyframe_state, | ||
| 12 | normalize_slider_fraction, | ||
| 13 | }; | ||
| 14 | |||
| 15 | use engine::EvalStats; | ||
| 16 | use model::{Comp, CompHistory, ExprEngine, NodeId, is_supported_tool}; | ||
| 17 | use std::collections::{HashMap, HashSet}; | ||
| 18 | use std::time::Instant; | ||
| 19 | use widgets::DragState; | ||
| 20 | |||
| 21 | #[derive(Clone, Debug)] | ||
| 22 | pub enum InspectorAction { | ||
| 23 | /// A parameter or node property changed; bust subtree & re-render viewers. | ||
| 24 | ParamEdited(NodeId), | ||
| 25 | /// A keyframe was added or deleted; refresh spline editor + bust subtree. | ||
| 26 | KeyframeEdited(NodeId), | ||
| 27 | /// Node was renamed. | ||
| 28 | NodeRenamed(NodeId), | ||
| 29 | /// Status notice to show in window title. | ||
| 30 | StatusNotice(String), | ||
| 31 | } | ||
| 32 | |||
| 33 | #[derive(Clone, Copy, Debug)] | ||
| 34 | pub struct InspectorPalette { | ||
| 35 | pub bg: [f32; 4], | ||
| 36 | pub panel_bg: [f32; 4], | ||
| 37 | pub rule: [f32; 4], | ||
| 38 | pub text: [f32; 4], | ||
| 39 | pub text_dim: [f32; 4], | ||
| 40 | pub accent: [f32; 4], | ||
| 41 | } | ||
| 42 | |||
| 43 | impl InspectorPalette { | ||
| 44 | pub fn from_theme(theme: &ui::Theme) -> Self { | ||
| 45 | let b = theme.base; | ||
| 46 | let lift = |c: [f32; 4], d: f32| { | ||
| 47 | [ | ||
| 48 | (c[0] + d).clamp(0.0, 1.0), | ||
| 49 | (c[1] + d).clamp(0.0, 1.0), | ||
| 50 | (c[2] + d).clamp(0.0, 1.0), | ||
| 51 | 1.0, | ||
| 52 | ] | ||
| 53 | }; | ||
| 54 | Self { | ||
| 55 | bg: b, | ||
| 56 | panel_bg: lift(b, 0.020), | ||
| 57 | rule: theme.rule, | ||
| 58 | text: theme.text, | ||
| 59 | text_dim: theme.text_dim, | ||
| 60 | accent: theme.accent, | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | pub struct InspectorState { | ||
| 66 | pub palette: InspectorPalette, | ||
| 67 | expr: ExprEngine, | ||
| 68 | /// Node name edit buffer synced with the currently selected node. | ||
| 69 | name_node: Option<NodeId>, | ||
| 70 | name_buf: String, | ||
| 71 | /// Text parameter edit buffers keyed by `(node_id, param_name)`. | ||
| 72 | text_bufs: HashMap<(usize, String), String>, | ||
| 73 | /// Active scrub slider drag. | ||
| 74 | drag: Option<DragState>, | ||
| 75 | /// Last click timestamp per slider key for double-click reset. | ||
| 76 | last_click: HashMap<String, Instant>, | ||
| 77 | } | ||
| 78 | |||
| 79 | impl InspectorState { | ||
| 80 | pub fn new(theme: &ui::Theme) -> Self { | ||
| 81 | Self { | ||
| 82 | palette: InspectorPalette::from_theme(theme), | ||
| 83 | expr: ExprEngine::new(), | ||
| 84 | name_node: None, | ||
| 85 | name_buf: String::new(), | ||
| 86 | text_bufs: HashMap::new(), | ||
| 87 | drag: None, | ||
| 88 | last_click: HashMap::new(), | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | pub fn background(&self) -> [f32; 4] { | ||
| 93 | self.palette.bg | ||
| 94 | } | ||
| 95 | |||
| 96 | pub fn reset(&mut self) { | ||
| 97 | self.name_node = None; | ||
| 98 | self.name_buf.clear(); | ||
| 99 | self.text_bufs.clear(); | ||
| 100 | self.drag = None; | ||
| 101 | } | ||
| 102 | |||
| 103 | pub fn build_ui( | ||
| 104 | &mut self, | ||
| 105 | ui: &mut ui::Ui, | ||
| 106 | pane_id: ui::Id, | ||
| 107 | comp: &mut Comp, | ||
| 108 | history: &mut CompHistory, | ||
| 109 | selected: Option<NodeId>, | ||
| 110 | current_frame: f64, | ||
| 111 | stats: &EvalStats, | ||
| 112 | ) -> Vec<InspectorAction> { | ||
| 113 | let mut actions = Vec::new(); | ||
| 114 | let p = self.palette; | ||
| 115 | |||
| 116 | ui.open_as( | ||
| 117 | pane_id, | ||
| 118 | ui::Spec { | ||
| 119 | size: [ui::fill(), ui::fill()], | ||
| 120 | axis: ui::Axis::Y, | ||
| 121 | fill: Some(p.bg), | ||
| 122 | ..ui::Spec::default() | ||
| 123 | }, | ||
| 124 | ); | ||
| 125 | |||
| 126 | let Some(node_id) = selected.filter(|id| id.0 < comp.nodes.len()) else { | ||
| 127 | // Empty state | ||
| 128 | ui.open( | ||
| 129 | "insp-empty", | ||
| 130 | ui::Spec { | ||
| 131 | size: [ui::fill(), ui::fill()], | ||
| 132 | axis: ui::Axis::Y, | ||
| 133 | pad: [14.0, 18.0], | ||
| 134 | gap: 8.0, | ||
| 135 | ..ui::Spec::default() | ||
| 136 | }, | ||
| 137 | ); | ||
| 138 | ui.leaf( | ||
| 139 | "empty-title", | ||
| 140 | ui::Spec { | ||
| 141 | size: [ui::fill(), ui::px(20.0)], | ||
| 142 | text: Some("No Node Selected"), | ||
| 143 | font_size: Some(12.5), | ||
| 144 | medium: true, | ||
| 145 | color: Some(p.text), | ||
| 146 | ..ui::Spec::default() | ||
| 147 | }, | ||
| 148 | ); | ||
| 149 | ui.leaf( | ||
| 150 | "empty-hint", | ||
| 151 | ui::Spec { | ||
| 152 | size: [ui::fill(), ui::fit()], | ||
| 153 | text: Some("Select a node in the Flow graph to inspect and keyframe its parameters, or press Shift+Space to add a tool."), | ||
| 154 | font_size: Some(11.0), | ||
| 155 | overflow: ui::Overflow::Wrap, | ||
| 156 | color: Some(p.text_dim), | ||
| 157 | ..ui::Spec::default() | ||
| 158 | }, | ||
| 159 | ); | ||
| 160 | self.render_stats_footer(ui, stats); | ||
| 161 | ui.close(); | ||
| 162 | ui.close(); | ||
| 163 | return actions; | ||
| 164 | }; | ||
| 165 | |||
| 166 | // Sync editable name buffer when selection changes or node was renamed externally (e.g. undo) | ||
| 167 | let current_name = comp.node(node_id).name.clone(); | ||
| 168 | let name_field_id = pane_id.child(("node-name", node_id.0)); | ||
| 169 | if self.name_node != Some(node_id) | ||
| 170 | || (ui.focused() != Some(name_field_id) && self.name_buf != current_name) | ||
| 171 | { | ||
| 172 | self.name_node = Some(node_id); | ||
| 173 | self.name_buf = current_name.clone(); | ||
| 174 | } | ||
| 175 | |||
| 176 | // 1. Header: Node name + Class badge + Bypass toggle | ||
| 177 | ui.open( | ||
| 178 | "insp-header", | ||
| 179 | ui::Spec { | ||
| 180 | size: [ui::fill(), ui::children()], | ||
| 181 | axis: ui::Axis::Y, | ||
| 182 | pad: [10.0, 8.0], | ||
| 183 | gap: 6.0, | ||
| 184 | fill: Some(p.panel_bg), | ||
| 185 | border: Some(p.rule), | ||
| 186 | ..ui::Spec::default() | ||
| 187 | }, | ||
| 188 | ); | ||
| 189 | |||
| 190 | // Row 1: Editable name + Bypass button | ||
| 191 | ui.open( | ||
| 192 | "insp-name-row", | ||
| 193 | ui::Spec { | ||
| 194 | size: [ui::fill(), ui::px(26.0)], | ||
| 195 | axis: ui::Axis::X, | ||
| 196 | gap: 6.0, | ||
| 197 | ..ui::Spec::default() | ||
| 198 | }, | ||
| 199 | ); | ||
| 200 | let name_sig = ui::text_field( | ||
| 201 | ui, | ||
| 202 | name_field_id, | ||
| 203 | &mut self.name_buf, | ||
| 204 | "Node name", | ||
| 205 | ui::Spec { | ||
| 206 | size: [ui::fill(), ui::px(24.0)], | ||
| 207 | font_size: Some(12.0), | ||
| 208 | medium: true, | ||
| 209 | fill: Some(p.bg), | ||
| 210 | border: Some(p.rule), | ||
| 211 | hover_border: Some(p.accent), | ||
| 212 | radius: 4.0, | ||
| 213 | pad: [6.0, 2.0], | ||
| 214 | ..ui::Spec::default() | ||
| 215 | }, | ||
| 216 | ); | ||
| 217 | let enter_pressed = name_sig.events.iter().any(|ev| { | ||
| 218 | matches!( | ||
| 219 | ev, | ||
| 220 | ui::Event::Key { key: winit::keyboard::Key::Named(winit::keyboard::NamedKey::Enter), .. } | ||
| 221 | ) | ||
| 222 | }); | ||
| 223 | if enter_pressed && self.name_buf.trim() != current_name { | ||
| 224 | let desired = self.name_buf.trim().to_owned(); | ||
| 225 | history.push_snapshot(comp, "Rename Node"); | ||
| 226 | match comp.rename_node(node_id, &desired) { | ||
| 227 | Ok(applied) => { | ||
| 228 | self.name_buf = applied; | ||
| 229 | actions.push(InspectorAction::NodeRenamed(node_id)); | ||
| 230 | } | ||
| 231 | Err(e) => { | ||
| 232 | self.name_buf = current_name.clone(); | ||
| 233 | actions.push(InspectorAction::StatusNotice(e)); | ||
| 234 | } | ||
| 235 | } | ||
| 236 | ui.set_focus(None); | ||
| 237 | } | ||
| 238 | |||
| 239 | let bypassed = comp.node(node_id).bypassed; | ||
| 240 | let pass_lbl = if bypassed { "Bypassed" } else { "Active" }; | ||
| 241 | let pass_fill = if bypassed { | ||
| 242 | [0.85, 0.28, 0.28, 0.28] | ||
| 243 | } else { | ||
| 244 | [0.24, 0.78, 0.48, 0.18] | ||
| 245 | }; | ||
| 246 | let pass_border = if bypassed { | ||
| 247 | [0.92, 0.36, 0.36, 0.75] | ||
| 248 | } else { | ||
| 249 | [0.28, 0.82, 0.52, 0.55] | ||
| 250 | }; | ||
| 251 | let pass_sig = ui.leaf( | ||
| 252 | ("insp-pass", node_id.0), | ||
| 253 | ui::Spec { | ||
| 254 | cursor: Some(winit::window::CursorIcon::Pointer), | ||
| 255 | flags: ui::Flags::CLICKABLE, | ||
| 256 | size: [ui::fit(), ui::px(24.0)], | ||
| 257 | text: Some(pass_lbl), | ||
| 258 | font_size: Some(10.5), | ||
| 259 | medium: true, | ||
| 260 | color: Some(p.text), | ||
| 261 | fill: Some(pass_fill), | ||
| 262 | border: Some(pass_border), | ||
| 263 | radius: 4.0, | ||
| 264 | pad: [8.0, 0.0], | ||
| 265 | center: true, | ||
| 266 | ..ui::Spec::default() | ||
| 267 | }, | ||
| 268 | ); | ||
| 269 | if pass_sig.clicked { | ||
| 270 | history.push_snapshot(comp, "Toggle Passthrough"); | ||
| 271 | comp.toggle_passthrough(node_id); | ||
| 272 | actions.push(InspectorAction::ParamEdited(node_id)); | ||
| 273 | } | ||
| 274 | ui.close(); // insp-name-row | ||
| 275 | |||
| 276 | // Row 2: Tool class badge + supported/preserved indicator + frame badge | ||
| 277 | let node_kind = comp.node(node_id).kind.clone(); | ||
| 278 | let supported = is_supported_tool(&node_kind); | ||
| 279 | let frame_str = format!("f{:.0}", current_frame); | ||
| 280 | ui.open( | ||
| 281 | "insp-meta-row", | ||
| 282 | ui::Spec { | ||
| 283 | size: [ui::fill(), ui::px(18.0)], | ||
| 284 | axis: ui::Axis::X, | ||
| 285 | gap: 6.0, | ||
| 286 | ..ui::Spec::default() | ||
| 287 | }, | ||
| 288 | ); | ||
| 289 | ui.leaf( | ||
| 290 | "insp-kind-badge", | ||
| 291 | ui::Spec { | ||
| 292 | size: [ui::fit(), ui::px(18.0)], | ||
| 293 | text: Some(&node_kind), | ||
| 294 | font_size: Some(10.0), | ||
| 295 | medium: true, | ||
| 296 | color: Some(p.accent), | ||
| 297 | fill: Some([p.accent[0], p.accent[1], p.accent[2], 0.14]), | ||
| 298 | border: Some([p.accent[0], p.accent[1], p.accent[2], 0.40]), | ||
| 299 | radius: 3.0, | ||
| 300 | pad: [6.0, 0.0], | ||
| 301 | center: true, | ||
| 302 | ..ui::Spec::default() | ||
| 303 | }, | ||
| 304 | ); | ||
| 305 | if !supported { | ||
| 306 | ui.leaf( | ||
| 307 | "insp-preserved-badge", | ||
| 308 | ui::Spec { | ||
| 309 | size: [ui::fit(), ui::px(18.0)], | ||
| 310 | text: Some("preserved"), | ||
| 311 | font_size: Some(9.5), | ||
| 312 | medium: true, | ||
| 313 | color: Some([0.98, 0.78, 0.40, 1.0]), | ||
| 314 | fill: Some([0.24, 0.16, 0.06, 0.85]), | ||
| 315 | border: Some([0.92, 0.64, 0.24, 0.60]), | ||
| 316 | radius: 3.0, | ||
| 317 | pad: [5.0, 0.0], | ||
| 318 | center: true, | ||
| 319 | ..ui::Spec::default() | ||
| 320 | }, | ||
| 321 | ); | ||
| 322 | } | ||
| 323 | ui.leaf( | ||
| 324 | "insp-spacer", | ||
| 325 | ui::Spec { | ||
| 326 | size: [ui::fill(), ui::px(18.0)], | ||
| 327 | ..ui::Spec::default() | ||
| 328 | }, | ||
| 329 | ); | ||
| 330 | ui.leaf( | ||
| 331 | "insp-frame", | ||
| 332 | ui::Spec { | ||
| 333 | size: [ui::fit(), ui::px(18.0)], | ||
| 334 | text: Some(&frame_str), | ||
| 335 | font_size: Some(10.0), | ||
| 336 | color: Some(p.text_dim), | ||
| 337 | center: true, | ||
| 338 | ..ui::Spec::default() | ||
| 339 | }, | ||
| 340 | ); | ||
| 341 | ui.close(); // insp-meta-row | ||
| 342 | ui.close(); // insp-header | ||
| 343 | |||
| 344 | // 2. Scrollable Parameter List | ||
| 345 | ui.open( | ||
| 346 | "insp-scroll", | ||
| 347 | ui::Spec { | ||
| 348 | flags: ui::Flags::SCROLL | ui::Flags::CLIP, | ||
| 349 | size: [ui::fill(), ui::fill()], | ||
| 350 | axis: ui::Axis::Y, | ||
| 351 | pad: [10.0, 8.0], | ||
| 352 | gap: 6.0, | ||
| 353 | ..ui::Spec::default() | ||
| 354 | }, | ||
| 355 | ); | ||
| 356 | |||
| 357 | let schema = schema_for_kind(&node_kind); | ||
| 358 | let mut covered: HashSet<&str> = HashSet::new(); | ||
| 359 | |||
| 360 | for spec in schema { | ||
| 361 | covered.insert(spec.name); | ||
| 362 | if let ParamKind::Color { r, g, b, a, .. } = spec.kind { | ||
| 363 | covered.insert(r); | ||
| 364 | covered.insert(g); | ||
| 365 | covered.insert(b); | ||
| 366 | if let Some(alpha_k) = a { | ||
| 367 | covered.insert(alpha_k); | ||
| 368 | } | ||
| 369 | } | ||
| 370 | self.render_param_spec(ui, pane_id, comp, history, node_id, spec, current_frame, &mut actions); | ||
| 371 | } | ||
| 372 | |||
| 373 | // Fallback: list all remaining present non-image inputs on the node! | ||
| 374 | let extra_keys = schemas::extra_input_keys(comp, node_id, &covered); | ||
| 375 | if !extra_keys.is_empty() { | ||
| 376 | ui.leaf( | ||
| 377 | "insp-extra-hdr", | ||
| 378 | ui::Spec { | ||
| 379 | size: [ui::fill(), ui::px(18.0)], | ||
| 380 | text: Some("OTHER INPUTS"), | ||
| 381 | font_size: Some(9.5), | ||
| 382 | medium: true, | ||
| 383 | color: Some(p.text_dim), | ||
| 384 | ..ui::Spec::default() | ||
| 385 | }, | ||
| 386 | ); | ||
| 387 | for key in extra_keys { | ||
| 388 | self.render_fallback_input(ui, pane_id, comp, history, node_id, &key, current_frame, &mut actions); | ||
| 389 | } | ||
| 390 | } | ||
| 391 | |||
| 392 | // Loader clip info if Loader node | ||
| 393 | if node_kind == "Loader" { | ||
| 394 | let clip_summary = comp | ||
| 395 | .node(node_id) | ||
| 396 | .clips | ||
| 397 | .first() | ||
| 398 | .map(|c| c.filename.clone()) | ||
| 399 | .unwrap_or_else(|| "(no clip)".to_owned()); | ||
| 400 | ui.open( | ||
| 401 | "insp-loader-clip", | ||
| 402 | ui::Spec { | ||
| 403 | size: [ui::fill(), ui::children()], | ||
| 404 | axis: ui::Axis::Y, | ||
| 405 | gap: 3.0, | ||
| 406 | pad: [6.0, 5.0], | ||
| 407 | fill: Some(p.panel_bg), | ||
| 408 | border: Some(p.rule), | ||
| 409 | radius: 4.0, | ||
| 410 | ..ui::Spec::default() | ||
| 411 | }, | ||
| 412 | ); | ||
| 413 | ui.leaf( | ||
| 414 | "clip-lbl", | ||
| 415 | ui::Spec { | ||
| 416 | size: [ui::fill(), ui::px(14.0)], | ||
| 417 | text: Some("Clip Filename"), | ||
| 418 | font_size: Some(10.0), | ||
| 419 | color: Some(p.text_dim), | ||
| 420 | ..ui::Spec::default() | ||
| 421 | }, | ||
| 422 | ); | ||
| 423 | ui.leaf( | ||
| 424 | "clip-path", | ||
| 425 | ui::Spec { | ||
| 426 | size: [ui::fill(), ui::fit()], | ||
| 427 | text: Some(&clip_summary), | ||
| 428 | font_size: Some(10.5), | ||
| 429 | overflow: ui::Overflow::Wrap, | ||
| 430 | color: Some(p.text), | ||
| 431 | ..ui::Spec::default() | ||
| 432 | }, | ||
| 433 | ); | ||
| 434 | ui.close(); | ||
| 435 | } | ||
| 436 | |||
| 437 | ui.close(); // insp-scroll | ||
| 438 | |||
| 439 | // 3. Footer: EvalStats summary | ||
| 440 | self.render_stats_footer(ui, stats); | ||
| 441 | |||
| 442 | ui.close(); // pane_id | ||
| 443 | actions | ||
| 444 | } | ||
| 445 | } | ||
| 446 | |||
| 447 | #[cfg(test)] | ||
| 448 | mod tests { | ||
| 449 | use super::*; | ||
| 450 | |||
| 451 | #[test] | ||
| 452 | fn curated_schemas_cover_all_major_tools() { | ||
| 453 | let major = [ | ||
| 454 | "Merge", | ||
| 455 | "Transform", | ||
| 456 | "Blur", | ||
| 457 | "Glow", | ||
| 458 | "SoftGlow", | ||
| 459 | "BrightnessContrast", | ||
| 460 | "ColorCorrector", | ||
| 461 | "Background", | ||
| 462 | "TextPlus", | ||
| 463 | "EllipseMask", | ||
| 464 | "RectangleMask", | ||
| 465 | "Displace", | ||
| 466 | "Vortex", | ||
| 467 | "FastNoise", | ||
| 468 | "UltraKeyer", | ||
| 469 | "Loader", | ||
| 470 | "Camera3D", | ||
| 471 | "Shape3D", | ||
| 472 | ]; | ||
| 473 | for tool in major { | ||
| 474 | let s = schema_for_kind(tool); | ||
| 475 | assert!(!s.is_empty(), "expected non-empty curated schema for {tool}"); | ||
| 476 | } | ||
| 477 | assert!(schema_for_kind("UnknownCustomTool").is_empty()); | ||
| 478 | } | ||
| 479 | |||
| 480 | #[test] | ||
| 481 | fn slider_math_and_clamping() { | ||
| 482 | assert!((normalize_slider_fraction(0.5, 0.0, 1.0) - 0.5).abs() < 1e-6); | ||
| 483 | assert!((normalize_slider_fraction(-5.0, 0.0, 1.0) - 0.0).abs() < 1e-6); | ||
| 484 | assert!((normalize_slider_fraction(10.0, 0.0, 1.0) - 1.0).abs() < 1e-6); | ||
| 485 | |||
| 486 | let v = compute_scrub_value(0.5, 50.0, 100.0, 0.0, 1.0, 1.0); | ||
| 487 | assert!((v - 1.0).abs() < 1e-6); | ||
| 488 | let v_fine = compute_scrub_value(0.5, 50.0, 100.0, 0.0, 1.0, 0.1); | ||
| 489 | assert!((v_fine - 0.55).abs() < 1e-6); | ||
| 490 | } | ||
| 491 | |||
| 492 | #[test] | ||
| 493 | fn keyframe_state_transitions() { | ||
| 494 | let src = r#"Composition { | ||
| 495 | Tools = ordered() { | ||
| 496 | BC1 = BrightnessContrast { | ||
| 497 | Inputs = { Gain = Input { Value = 1.0 } }, | ||
| 498 | }, | ||
| 499 | }, | ||
| 500 | }"#; | ||
| 501 | let mut comp = Comp::from_fusion_str(src).unwrap(); | ||
| 502 | let bc = comp.find_node("BC1").unwrap(); | ||
| 503 | assert_eq!(keyframe_state(&comp, bc, "Gain", 10.0), KeyframeState::Static); | ||
| 504 | |||
| 505 | let sp = comp.set_keyframe(bc, "Gain", 10.0, 1.5).unwrap(); | ||
| 506 | assert_eq!(keyframe_state(&comp, bc, "Gain", 10.0), KeyframeState::KeyframeAtCurrent); | ||
| 507 | assert_eq!(keyframe_state(&comp, bc, "Gain", 20.0), KeyframeState::AnimatedOtherFrame); | ||
| 508 | |||
| 509 | assert!(comp.delete_keyframe(&sp, 10.0)); | ||
| 510 | assert_eq!(keyframe_state(&comp, bc, "Gain", 10.0), KeyframeState::Static); | ||
| 511 | } | ||
| 512 | } | ||
crates/app/src/inspector/schemas.rs created+347| ... | @@ -0,0 +1,347 @@ | ||
| 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; | ||
| 5 | |||
| 6 | #[derive(Clone, Copy, Debug, PartialEq)] | ||
| 7 | pub enum ParamKind { | ||
| 8 | Float { min: f64, max: f64, default: f64, step: f64 }, | ||
| 9 | Vec2 { min: f64, max: f64, default: [f64; 2] }, | ||
| 10 | Bool { default: bool }, | ||
| 11 | Enum { options: &'static [&'static str], default: &'static str }, | ||
| 12 | Color { | ||
| 13 | r: &'static str, | ||
| 14 | g: &'static str, | ||
| 15 | b: &'static str, | ||
| 16 | a: Option<&'static str>, | ||
| 17 | default: [f64; 4], | ||
| 18 | }, | ||
| 19 | Text { default: &'static str }, | ||
| 20 | } | ||
| 21 | |||
| 22 | #[derive(Clone, Copy, Debug)] | ||
| 23 | pub struct ParamSpec { | ||
| 24 | pub name: &'static str, | ||
| 25 | pub label: &'static str, | ||
| 26 | pub kind: ParamKind, | ||
| 27 | } | ||
| 28 | |||
| 29 | /// Collects and sorts remaining non-image inputs on `node_id` not covered by its curated schema. | ||
| 30 | pub(super) fn extra_input_keys(comp: &Comp, node_id: NodeId, covered: &HashSet<&str>) -> Vec<String> { | ||
| 31 | let mut extra_keys: Vec<String> = comp | ||
| 32 | .node(node_id) | ||
| 33 | .inputs | ||
| 34 | .iter() | ||
| 35 | .filter_map(|(k, b)| { | ||
| 36 | if covered.contains(k.as_str()) { | ||
| 37 | return None; | ||
| 38 | } | ||
| 39 | // Skip image/node connections unless they also have a value or spline | ||
| 40 | let is_node_conn = b | ||
| 41 | .source_op | ||
| 42 | .as_deref() | ||
| 43 | .is_some_and(|op| comp.node_by_name.contains_key(op)); | ||
| 44 | if is_node_conn && b.value.is_none() { | ||
| 45 | return None; | ||
| 46 | } | ||
| 47 | if b.value.is_none() && b.expression.is_none() && b.source_op.is_none() { | ||
| 48 | return None; | ||
| 49 | } | ||
| 50 | Some(k.clone()) | ||
| 51 | }) | ||
| 52 | .collect(); | ||
| 53 | extra_keys.sort(); | ||
| 54 | extra_keys | ||
| 55 | } | ||
| 56 | |||
| 57 | pub fn infer_float_range(name: &str, val: f64) -> (f64, f64) { | ||
| 58 | let lower = name.to_ascii_lowercase(); | ||
| 59 | if lower.contains("angle") || lower.contains("rotate") { | ||
| 60 | (-360.0, 360.0) | ||
| 61 | } else if lower.contains("width") || lower.contains("height") { | ||
| 62 | if val > 2.0 { | ||
| 63 | (1.0, (val * 2.0).max(4096.0)) | ||
| 64 | } else { | ||
| 65 | (0.0, 2.0) | ||
| 66 | } | ||
| 67 | } else if lower.contains("blend") || lower.contains("alpha") || lower.contains("opacity") { | ||
| 68 | (0.0, 1.0) | ||
| 69 | } else if lower.contains("size") || lower.contains("blur") || lower.contains("glow") { | ||
| 70 | (0.0, (val.abs() * 2.0).max(50.0)) | ||
| 71 | } else if val < 0.0 || val > 1.0 { | ||
| 72 | let hi = (val.abs() * 2.0).max(10.0); | ||
| 73 | (-hi, hi) | ||
| 74 | } else { | ||
| 75 | (0.0, 1.0) | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 | const APPLY_MODES: &[&str] = &[ | ||
| 80 | "Normal", | ||
| 81 | "Screen", | ||
| 82 | "Multiply", | ||
| 83 | "Overlay", | ||
| 84 | "Soft Light", | ||
| 85 | "Hard Light", | ||
| 86 | "Color Dodge", | ||
| 87 | "Color Burn", | ||
| 88 | "Darken", | ||
| 89 | "Lighten", | ||
| 90 | "Difference", | ||
| 91 | "Exclusion", | ||
| 92 | "Hue", | ||
| 93 | "Saturation", | ||
| 94 | "Color", | ||
| 95 | "Luminosity", | ||
| 96 | ]; | ||
| 97 | |||
| 98 | const BLUR_FILTERS: &[&str] = &["Fast Gaussian", "Gaussian", "Box", "Bartlett", "Multi-box"]; | ||
| 99 | const CLIPPING_MODES: &[&str] = &["Frame", "Domain", "None"]; | ||
| 100 | const EDGES_MODES: &[&str] = &["Canvas", "Wrap", "Duplicate", "Mirror"]; | ||
| 101 | const SHAPE3D_TYPES: &[&str] = &[ | ||
| 102 | "SurfacePlaneInputs", | ||
| 103 | "SurfaceSphereInputs", | ||
| 104 | "SurfaceCubeInputs", | ||
| 105 | "SurfaceCylinderInputs", | ||
| 106 | "SurfaceConeInputs", | ||
| 107 | "SurfaceTorusInputs", | ||
| 108 | ]; | ||
| 109 | |||
| 110 | const fn flt(name: &'static str, label: &'static str, min: f64, max: f64, default: f64) -> ParamSpec { | ||
| 111 | ParamSpec { | ||
| 112 | name, | ||
| 113 | label, | ||
| 114 | kind: ParamKind::Float { min, max, default, step: 0.01 }, | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | const fn v2(name: &'static str, label: &'static str, min: f64, max: f64, default: [f64; 2]) -> ParamSpec { | ||
| 119 | ParamSpec { | ||
| 120 | name, | ||
| 121 | label, | ||
| 122 | kind: ParamKind::Vec2 { min, max, default }, | ||
| 123 | } | ||
| 124 | } | ||
| 125 | |||
| 126 | const fn boolean(name: &'static str, label: &'static str, default: bool) -> ParamSpec { | ||
| 127 | ParamSpec { | ||
| 128 | name, | ||
| 129 | label, | ||
| 130 | kind: ParamKind::Bool { default }, | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | const fn fuid( | ||
| 135 | name: &'static str, | ||
| 136 | label: &'static str, | ||
| 137 | options: &'static [&'static str], | ||
| 138 | default: &'static str, | ||
| 139 | ) -> ParamSpec { | ||
| 140 | ParamSpec { | ||
| 141 | name, | ||
| 142 | label, | ||
| 143 | kind: ParamKind::Enum { options, default }, | ||
| 144 | } | ||
| 145 | } | ||
| 146 | |||
| 147 | /// Curated Fusion 21.1 parameter schemas for major compositor tools. | ||
| 148 | pub fn schema_for_kind(kind: &str) -> &'static [ParamSpec] { | ||
| 149 | match kind { | ||
| 150 | "Merge" => const { &[ | ||
| 151 | fuid("ApplyMode", "Apply Mode", APPLY_MODES, "Normal"), | ||
| 152 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 153 | flt("SubMerge", "Subtractive", 0.0, 1.0, 0.0), | ||
| 154 | v2("Center", "Center", -1.0, 2.0, [0.5, 0.5]), | ||
| 155 | flt("Size", "Size", 0.0, 5.0, 1.0), | ||
| 156 | flt("Angle", "Angle", -360.0, 360.0, 0.0), | ||
| 157 | boolean("FlipHoriz", "Flip Horiz", false), | ||
| 158 | boolean("FlipVert", "Flip Vert", false), | ||
| 159 | fuid("Edges", "Edges", EDGES_MODES, "Canvas"), | ||
| 160 | boolean("PerformDepthMerge", "Depth Merge", false), | ||
| 161 | ] }, | ||
| 162 | "Transform" => const { &[ | ||
| 163 | v2("Center", "Center", -1.0, 2.0, [0.5, 0.5]), | ||
| 164 | v2("Pivot", "Pivot", -1.0, 2.0, [0.5, 0.5]), | ||
| 165 | flt("Size", "Size", 0.0, 5.0, 1.0), | ||
| 166 | flt("Aspect", "Aspect", 0.1, 4.0, 1.0), | ||
| 167 | flt("Angle", "Angle", -360.0, 360.0, 0.0), | ||
| 168 | boolean("FlipHoriz", "Flip Horiz", false), | ||
| 169 | boolean("FlipVert", "Flip Vert", false), | ||
| 170 | fuid("Edges", "Edges", EDGES_MODES, "Canvas"), | ||
| 171 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 172 | ] }, | ||
| 173 | "Blur" => const { &[ | ||
| 174 | fuid("Filter", "Filter", BLUR_FILTERS, "Fast Gaussian"), | ||
| 175 | boolean("LockXY", "Lock X/Y", true), | ||
| 176 | flt("XBlurSize", "Blur Size", 0.0, 100.0, 1.0), | ||
| 177 | flt("YBlurSize", "Y Blur Size", 0.0, 100.0, 1.0), | ||
| 178 | fuid("ClippingMode", "Clipping", CLIPPING_MODES, "Frame"), | ||
| 179 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 180 | ] }, | ||
| 181 | "Glow" => const { &[ | ||
| 182 | flt("XGlowSize", "Glow Size", 0.0, 100.0, 10.0), | ||
| 183 | flt("Glow", "Glow", 0.0, 2.0, 0.8), | ||
| 184 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 185 | fuid("Filter", "Filter", BLUR_FILTERS, "Fast Gaussian"), | ||
| 186 | ] }, | ||
| 187 | "SoftGlow" => const { &[ | ||
| 188 | fuid("Filter", "Filter", BLUR_FILTERS, "Fast Gaussian"), | ||
| 189 | flt("Threshold", "Threshold", 0.0, 1.0, 0.0), | ||
| 190 | flt("Gain", "Gain", 0.0, 5.0, 2.0), | ||
| 191 | flt("XGlowSize", "Glow Size", 0.0, 100.0, 10.0), | ||
| 192 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 193 | ] }, | ||
| 194 | "BrightnessContrast" => const { &[ | ||
| 195 | flt("Gain", "Gain", 0.0, 5.0, 1.0), | ||
| 196 | flt("Lift", "Lift", -1.0, 1.0, 0.0), | ||
| 197 | flt("Gamma", "Gamma", 0.05, 5.0, 1.0), | ||
| 198 | flt("Contrast", "Contrast", -1.0, 1.0, 0.0), | ||
| 199 | flt("Brightness", "Brightness", -1.0, 1.0, 0.0), | ||
| 200 | flt("Saturation", "Saturation", 0.0, 4.0, 1.0), | ||
| 201 | boolean("PreDividePostMultiply", "Pre-Div/Post", false), | ||
| 202 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 203 | ] }, | ||
| 204 | "ColorCorrector" => const { &[ | ||
| 205 | flt("WheelSaturation1", "Saturation", 0.0, 4.0, 1.0), | ||
| 206 | flt("WheelHue1", "Hue", -1.0, 1.0, 0.0), | ||
| 207 | flt("MasterRGBGain", "Gain", 0.0, 5.0, 1.0), | ||
| 208 | flt("MasterRGBGamma", "Gamma", 0.05, 5.0, 1.0), | ||
| 209 | flt("MasterRGBLift", "Lift", -1.0, 1.0, 0.0), | ||
| 210 | flt("MasterRGBContrast", "Contrast", 0.0, 3.0, 1.0), | ||
| 211 | flt("MasterRGBBrightness", "Brightness", -1.0, 1.0, 0.0), | ||
| 212 | boolean("PreDividePostMultiply", "Pre-Div/Post", false), | ||
| 213 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 214 | ] }, | ||
| 215 | "Background" => const { &[ | ||
| 216 | ParamSpec { | ||
| 217 | name: "TopLeftColor", | ||
| 218 | label: "Color", | ||
| 219 | kind: ParamKind::Color { | ||
| 220 | r: "TopLeftRed", | ||
| 221 | g: "TopLeftGreen", | ||
| 222 | b: "TopLeftBlue", | ||
| 223 | a: Some("TopLeftAlpha"), | ||
| 224 | default: [0.0, 0.0, 0.0, 1.0], | ||
| 225 | }, | ||
| 226 | }, | ||
| 227 | flt("Width", "Width", 1.0, 7680.0, 1920.0), | ||
| 228 | flt("Height", "Height", 1.0, 4320.0, 1080.0), | ||
| 229 | ] }, | ||
| 230 | "TextPlus" => const { &[ | ||
| 231 | ParamSpec { | ||
| 232 | name: "StyledText", | ||
| 233 | label: "Styled Text", | ||
| 234 | kind: ParamKind::Text { default: "" }, | ||
| 235 | }, | ||
| 236 | ParamSpec { | ||
| 237 | name: "Font", | ||
| 238 | label: "Font", | ||
| 239 | kind: ParamKind::Text { default: "Open Sans" }, | ||
| 240 | }, | ||
| 241 | flt("Size", "Size", 0.005, 1.0, 0.08), | ||
| 242 | flt("Tracking", "Tracking", 0.0, 4.0, 1.0), | ||
| 243 | v2("Center", "Center", -1.0, 2.0, [0.5, 0.5]), | ||
| 244 | ParamSpec { | ||
| 245 | name: "TextColor", | ||
| 246 | label: "Text Color", | ||
| 247 | kind: ParamKind::Color { | ||
| 248 | r: "Red1", | ||
| 249 | g: "Green1", | ||
| 250 | b: "Blue1", | ||
| 251 | a: Some("Alpha1"), | ||
| 252 | default: [1.0, 1.0, 1.0, 1.0], | ||
| 253 | }, | ||
| 254 | }, | ||
| 255 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 256 | ] }, | ||
| 257 | "EllipseMask" => const { &[ | ||
| 258 | flt("Level", "Level", 0.0, 1.0, 1.0), | ||
| 259 | flt("SoftEdge", "Soft Edge", 0.0, 0.5, 0.0), | ||
| 260 | flt("BorderWidth", "Border", -0.2, 0.2, 0.0), | ||
| 261 | boolean("Solid", "Solid", true), | ||
| 262 | boolean("Invert", "Invert", false), | ||
| 263 | v2("Center", "Center", -0.5, 1.5, [0.5, 0.5]), | ||
| 264 | flt("Width", "Width", 0.0, 2.0, 0.5), | ||
| 265 | flt("Height", "Height", 0.0, 2.0, 0.5), | ||
| 266 | flt("Angle", "Angle", -360.0, 360.0, 0.0), | ||
| 267 | ] }, | ||
| 268 | "RectangleMask" => const { &[ | ||
| 269 | flt("Level", "Level", 0.0, 1.0, 1.0), | ||
| 270 | flt("SoftEdge", "Soft Edge", 0.0, 0.5, 0.0), | ||
| 271 | flt("CornerRadius", "Corner", 0.0, 1.0, 0.0), | ||
| 272 | boolean("Solid", "Solid", true), | ||
| 273 | boolean("Invert", "Invert", false), | ||
| 274 | v2("Center", "Center", -0.5, 1.5, [0.5, 0.5]), | ||
| 275 | flt("Width", "Width", 0.0, 2.0, 0.5), | ||
| 276 | flt("Height", "Height", 0.0, 2.0, 0.5), | ||
| 277 | flt("Angle", "Angle", -360.0, 360.0, 0.0), | ||
| 278 | ] }, | ||
| 279 | "Displace" => const { &[ | ||
| 280 | flt("XRefraction", "X Refract", -1.0, 1.0, 0.0), | ||
| 281 | flt("YRefraction", "Y Refract", -1.0, 1.0, 0.0), | ||
| 282 | flt("RefractionStrength", "Strength", -2.0, 2.0, 0.0), | ||
| 283 | flt("LightAngle", "Light Angle", -360.0, 360.0, 0.0), | ||
| 284 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 285 | ] }, | ||
| 286 | "Vortex" => const { &[ | ||
| 287 | v2("Center", "Center", -0.5, 1.5, [0.5, 0.5]), | ||
| 288 | flt("Size", "Size", 0.0, 2.0, 0.5), | ||
| 289 | flt("Angle", "Angle", -720.0, 720.0, 90.0), | ||
| 290 | flt("Power", "Power", 0.1, 5.0, 1.0), | ||
| 291 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 292 | ] }, | ||
| 293 | "FastNoise" => const { &[ | ||
| 294 | flt("Detail", "Detail", 0.0, 10.0, 2.0), | ||
| 295 | flt("Contrast", "Contrast", 0.0, 5.0, 1.0), | ||
| 296 | flt("Brightness", "Brightness", -1.0, 1.0, 0.0), | ||
| 297 | flt("XScale", "Scale", 0.01, 50.0, 2.0), | ||
| 298 | flt("Seethe", "Seethe", 0.0, 100.0, 0.0), | ||
| 299 | flt("SeetheRate", "Seethe Rate", 0.0, 2.0, 0.0), | ||
| 300 | v2("Center", "Center", -2.0, 3.0, [0.5, 0.5]), | ||
| 301 | ] }, | ||
| 302 | "UltraKeyer" => const { &[ | ||
| 303 | ParamSpec { | ||
| 304 | name: "KeyColor", | ||
| 305 | label: "Key Color", | ||
| 306 | kind: ParamKind::Color { | ||
| 307 | r: "BackgroundRed", | ||
| 308 | g: "BackgroundGreen", | ||
| 309 | b: "BackgroundBlue", | ||
| 310 | a: None, | ||
| 311 | default: [0.0, 1.0, 0.0, 1.0], | ||
| 312 | }, | ||
| 313 | }, | ||
| 314 | flt("MatteThresholdLow", "Matte Low", 0.0, 1.0, 0.0), | ||
| 315 | flt("MatteThresholdHigh", "Matte High", 0.0, 1.0, 1.0), | ||
| 316 | flt("SpillSuppression", "Spill", 0.0, 1.0, 0.0), | ||
| 317 | boolean("PostMultiplyImage", "Post-Multiply", true), | ||
| 318 | flt("Blend", "Blend", 0.0, 1.0, 1.0), | ||
| 319 | ] }, | ||
| 320 | "Loader" => const { &[ | ||
| 321 | flt("GlobalIn", "Global In", 0.0, 10000.0, 0.0), | ||
| 322 | flt("GlobalOut", "Global Out", 0.0, 10000.0, 100.0), | ||
| 323 | boolean("Loop", "Loop", false), | ||
| 324 | boolean("Reverse", "Reverse", false), | ||
| 325 | ] }, | ||
| 326 | "Camera3D" => const { &[ | ||
| 327 | flt("FLength", "Focal Len", 5.0, 200.0, 24.0), | ||
| 328 | flt("PlaneOfFocus", "Focus Dist", 0.1, 100.0, 5.0), | ||
| 329 | flt("Transform3DOp.Translate.X", "Trans X", -50.0, 50.0, 0.0), | ||
| 330 | flt("Transform3DOp.Translate.Y", "Trans Y", -50.0, 50.0, 0.0), | ||
| 331 | flt("Transform3DOp.Translate.Z", "Trans Z", -50.0, 50.0, 5.0), | ||
| 332 | flt("Transform3DOp.Rotate.X", "Rot X", -180.0, 180.0, 0.0), | ||
| 333 | flt("Transform3DOp.Rotate.Y", "Rot Y", -180.0, 180.0, 0.0), | ||
| 334 | flt("Transform3DOp.Rotate.Z", "Rot Z", -180.0, 180.0, 0.0), | ||
| 335 | ] }, | ||
| 336 | "Shape3D" => const { &[ | ||
| 337 | fuid("Shape", "Shape", SHAPE3D_TYPES, "SurfacePlaneInputs"), | ||
| 338 | flt("SurfacePlaneInputs.Width", "Width", 0.01, 20.0, 1.0), | ||
| 339 | flt("SurfacePlaneInputs.Height", "Height", 0.01, 20.0, 1.0), | ||
| 340 | flt("Transform3DOp.Translate.X", "Trans X", -50.0, 50.0, 0.0), | ||
| 341 | flt("Transform3DOp.Translate.Y", "Trans Y", -50.0, 50.0, 0.0), | ||
| 342 | flt("Transform3DOp.Translate.Z", "Trans Z", -50.0, 50.0, 0.0), | ||
| 343 | flt("Transform3DOp.Scale.X", "Scale", 0.01, 20.0, 1.0), | ||
| 344 | ] }, | ||
| 345 | _ => &[], | ||
| 346 | } | ||
| 347 | } | ||
crates/app/src/inspector/widgets.rs created+969| ... | @@ -0,0 +1,969 @@ | ||
| 1 | //! Reusable Inspector UI control builders: scrub sliders, Vec2, RGBA color groups, | ||
| 2 | //! booleans, FuID enum cyclers, text fields, expression badges, and keyframe diamonds (`◆`). | ||
| 3 | |||
| 4 | use super::schemas::{ParamKind, ParamSpec, infer_float_range}; | ||
| 5 | use super::{InspectorAction, InspectorState}; | ||
| 6 | use engine::EvalStats; | ||
| 7 | use model::{Comp, CompHistory, NodeId, ParamValue}; | ||
| 8 | use std::time::{Duration, Instant}; | ||
| 9 | |||
| 10 | #[derive(Clone, Debug)] | ||
| 11 | pub(super) struct DragState { | ||
| 12 | pub node_id: NodeId, | ||
| 13 | pub key: String, | ||
| 14 | pub start_x: f32, | ||
| 15 | pub start_val: f64, | ||
| 16 | pub min: f64, | ||
| 17 | pub max: f64, | ||
| 18 | pub width: f32, | ||
| 19 | } | ||
| 20 | |||
| 21 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
| 22 | pub enum KeyframeState { | ||
| 23 | Static, | ||
| 24 | AnimatedOtherFrame, | ||
| 25 | KeyframeAtCurrent, | ||
| 26 | } | ||
| 27 | |||
| 28 | impl InspectorState { | ||
| 29 | pub(super) fn render_stats_footer(&self, ui: &mut ui::Ui, stats: &EvalStats) { | ||
| 30 | let p = self.palette; | ||
| 31 | let line = format!( | ||
| 32 | "Eval {:.1}ms · {} nodes · cache {}/{} · {:.0}MB", | ||
| 33 | stats.eval_ms, | ||
| 34 | stats.nodes_evaluated, | ||
| 35 | stats.cache_hits, | ||
| 36 | stats.cache_hits + stats.cache_misses, | ||
| 37 | stats.cached_vram_mb, | ||
| 38 | ); | ||
| 39 | ui.open( | ||
| 40 | "insp-footer", | ||
| 41 | ui::Spec { | ||
| 42 | size: [ui::fill(), ui::px(24.0)], | ||
| 43 | axis: ui::Axis::X, | ||
| 44 | pad: [10.0, 4.0], | ||
| 45 | fill: Some(p.panel_bg), | ||
| 46 | border: Some(p.rule), | ||
| 47 | ..ui::Spec::default() | ||
| 48 | }, | ||
| 49 | ); | ||
| 50 | ui.leaf( | ||
| 51 | "insp-stats-txt", | ||
| 52 | ui::Spec { | ||
| 53 | size: [ui::fill(), ui::fill()], | ||
| 54 | text: Some(&line), | ||
| 55 | font_size: Some(10.0), | ||
| 56 | color: Some(p.text_dim), | ||
| 57 | ..ui::Spec::default() | ||
| 58 | }, | ||
| 59 | ); | ||
| 60 | ui.close(); | ||
| 61 | } | ||
| 62 | |||
| 63 | #[allow(clippy::too_many_arguments)] | ||
| 64 | pub(super) fn render_param_spec( | ||
| 65 | &mut self, | ||
| 66 | ui: &mut ui::Ui, | ||
| 67 | pane_id: ui::Id, | ||
| 68 | comp: &mut Comp, | ||
| 69 | history: &mut CompHistory, | ||
| 70 | node_id: NodeId, | ||
| 71 | spec: &ParamSpec, | ||
| 72 | current_frame: f64, | ||
| 73 | actions: &mut Vec<InspectorAction>, | ||
| 74 | ) { | ||
| 75 | match spec.kind { | ||
| 76 | ParamKind::Float { min, max, default, step: _ } => { | ||
| 77 | self.render_float_row( | ||
| 78 | ui, | ||
| 79 | pane_id, | ||
| 80 | comp, | ||
| 81 | history, | ||
| 82 | node_id, | ||
| 83 | spec.name, | ||
| 84 | spec.label, | ||
| 85 | min, | ||
| 86 | max, | ||
| 87 | default, | ||
| 88 | current_frame, | ||
| 89 | actions, | ||
| 90 | ); | ||
| 91 | } | ||
| 92 | ParamKind::Vec2 { min, max, default } => { | ||
| 93 | self.render_vec2_row( | ||
| 94 | ui, | ||
| 95 | pane_id, | ||
| 96 | comp, | ||
| 97 | history, | ||
| 98 | node_id, | ||
| 99 | spec.name, | ||
| 100 | spec.label, | ||
| 101 | min, | ||
| 102 | max, | ||
| 103 | default, | ||
| 104 | current_frame, | ||
| 105 | actions, | ||
| 106 | ); | ||
| 107 | } | ||
| 108 | ParamKind::Bool { default } => { | ||
| 109 | self.render_bool_row(ui, comp, history, node_id, spec.name, spec.label, default, actions); | ||
| 110 | } | ||
| 111 | ParamKind::Enum { options, default } => { | ||
| 112 | self.render_enum_row(ui, comp, history, node_id, spec.name, spec.label, options, default, actions); | ||
| 113 | } | ||
| 114 | ParamKind::Color { r, g, b, a, default } => { | ||
| 115 | self.render_color_group( | ||
| 116 | ui, | ||
| 117 | pane_id, | ||
| 118 | comp, | ||
| 119 | history, | ||
| 120 | node_id, | ||
| 121 | spec.label, | ||
| 122 | r, | ||
| 123 | g, | ||
| 124 | b, | ||
| 125 | a, | ||
| 126 | default, | ||
| 127 | current_frame, | ||
| 128 | actions, | ||
| 129 | ); | ||
| 130 | } | ||
| 131 | ParamKind::Text { default } => { | ||
| 132 | self.render_text_row(ui, pane_id, comp, history, node_id, spec.name, spec.label, default, actions); | ||
| 133 | } | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | #[allow(clippy::too_many_arguments)] | ||
| 138 | pub(super) fn render_fallback_input( | ||
| 139 | &mut self, | ||
| 140 | ui: &mut ui::Ui, | ||
| 141 | pane_id: ui::Id, | ||
| 142 | comp: &mut Comp, | ||
| 143 | history: &mut CompHistory, | ||
| 144 | node_id: NodeId, | ||
| 145 | key: &str, | ||
| 146 | current_frame: f64, | ||
| 147 | actions: &mut Vec<InspectorAction>, | ||
| 148 | ) { | ||
| 149 | let val = comp.node(node_id).inputs.get(key).and_then(|b| b.value.clone()); | ||
| 150 | match val { | ||
| 151 | Some(ParamValue::Point(pt)) => { | ||
| 152 | self.render_vec2_row(ui, pane_id, comp, history, node_id, key, key, -1.0, 2.0, pt, current_frame, actions); | ||
| 153 | } | ||
| 154 | Some(ParamValue::Text(_)) => { | ||
| 155 | self.render_text_row(ui, pane_id, comp, history, node_id, key, key, "", actions); | ||
| 156 | } | ||
| 157 | Some(ParamValue::FuId(cur)) => { | ||
| 158 | let p = self.palette; | ||
| 159 | ui.open( | ||
| 160 | ("fb-fuid", node_id.0, key), | ||
| 161 | ui::Spec { | ||
| 162 | size: [ui::fill(), ui::px(22.0)], | ||
| 163 | axis: ui::Axis::X, | ||
| 164 | gap: 6.0, | ||
| 165 | ..ui::Spec::default() | ||
| 166 | }, | ||
| 167 | ); | ||
| 168 | ui.leaf( | ||
| 169 | "lbl", | ||
| 170 | ui::Spec { | ||
| 171 | size: [ui::px(92.0), ui::fill()], | ||
| 172 | text: Some(key), | ||
| 173 | font_size: Some(10.5), | ||
| 174 | overflow: ui::Overflow::Ellipsis, | ||
| 175 | color: Some(p.text_dim), | ||
| 176 | ..ui::Spec::default() | ||
| 177 | }, | ||
| 178 | ); | ||
| 179 | ui.leaf( | ||
| 180 | "val", | ||
| 181 | ui::Spec { | ||
| 182 | size: [ui::fill(), ui::fill()], | ||
| 183 | text: Some(&cur), | ||
| 184 | font_size: Some(10.5), | ||
| 185 | color: Some(p.text), | ||
| 186 | fill: Some(p.panel_bg), | ||
| 187 | border: Some(p.rule), | ||
| 188 | radius: 4.0, | ||
| 189 | pad: [6.0, 0.0], | ||
| 190 | ..ui::Spec::default() | ||
| 191 | }, | ||
| 192 | ); | ||
| 193 | ui.close(); | ||
| 194 | } | ||
| 195 | Some(ParamValue::Number(v)) => { | ||
| 196 | let (min, max) = infer_float_range(key, v); | ||
| 197 | self.render_float_row(ui, pane_id, comp, history, node_id, key, key, min, max, v, current_frame, actions); | ||
| 198 | } | ||
| 199 | None => { | ||
| 200 | // Animated spline or expression-only scalar input | ||
| 201 | let cur = comp.eval_number(comp.node(node_id), key, current_frame, 0.0, &self.expr); | ||
| 202 | let (min, max) = infer_float_range(key, cur); | ||
| 203 | self.render_float_row(ui, pane_id, comp, history, node_id, key, key, min, max, 0.0, current_frame, actions); | ||
| 204 | } | ||
| 205 | _ => {} | ||
| 206 | } | ||
| 207 | } | ||
| 208 | |||
| 209 | #[allow(clippy::too_many_arguments)] | ||
| 210 | fn render_float_row( | ||
| 211 | &mut self, | ||
| 212 | ui: &mut ui::Ui, | ||
| 213 | pane_id: ui::Id, | ||
| 214 | comp: &mut Comp, | ||
| 215 | history: &mut CompHistory, | ||
| 216 | node_id: NodeId, | ||
| 217 | input_name: &str, | ||
| 218 | label: &str, | ||
| 219 | min: f64, | ||
| 220 | max: f64, | ||
| 221 | default: f64, | ||
| 222 | current_frame: f64, | ||
| 223 | actions: &mut Vec<InspectorAction>, | ||
| 224 | ) { | ||
| 225 | let cur_val = comp.eval_number(comp.node(node_id), input_name, current_frame, default, &self.expr); | ||
| 226 | let has_expr = comp | ||
| 227 | .node(node_id) | ||
| 228 | .inputs | ||
| 229 | .get(input_name) | ||
| 230 | .and_then(|b| b.expression.as_ref()) | ||
| 231 | .is_some(); | ||
| 232 | let kf_state = keyframe_state(comp, node_id, input_name, current_frame); | ||
| 233 | let p = self.palette; | ||
| 234 | |||
| 235 | ui.open( | ||
| 236 | ("row-f", node_id.0, input_name), | ||
| 237 | ui::Spec { | ||
| 238 | size: [ui::fill(), ui::px(22.0)], | ||
| 239 | axis: ui::Axis::X, | ||
| 240 | gap: 4.0, | ||
| 241 | ..ui::Spec::default() | ||
| 242 | }, | ||
| 243 | ); | ||
| 244 | |||
| 245 | // Label | ||
| 246 | ui.leaf( | ||
| 247 | "lbl", | ||
| 248 | ui::Spec { | ||
| 249 | size: [ui::px(86.0), ui::fill()], | ||
| 250 | text: Some(label), | ||
| 251 | font_size: Some(10.5), | ||
| 252 | overflow: ui::Overflow::Ellipsis, | ||
| 253 | color: Some(p.text_dim), | ||
| 254 | ..ui::Spec::default() | ||
| 255 | }, | ||
| 256 | ); | ||
| 257 | |||
| 258 | // Expression `=` badge if present | ||
| 259 | if has_expr { | ||
| 260 | render_expr_badge(ui); | ||
| 261 | } | ||
| 262 | |||
| 263 | // Scrub slider | ||
| 264 | let slider_id = pane_id.child(("sld", node_id.0, input_name)); | ||
| 265 | let drag_key = format!("{}:{input_name}", node_id.0); | ||
| 266 | if let Some(new_val) = self.scrub_slider( | ||
| 267 | ui, | ||
| 268 | slider_id, | ||
| 269 | &drag_key, | ||
| 270 | node_id, | ||
| 271 | cur_val, | ||
| 272 | min, | ||
| 273 | max, | ||
| 274 | default, | ||
| 275 | history, | ||
| 276 | comp, | ||
| 277 | input_name, | ||
| 278 | ) { | ||
| 279 | if kf_state != KeyframeState::Static { | ||
| 280 | let _ = comp.set_keyframe(node_id, input_name, current_frame, new_val); | ||
| 281 | actions.push(InspectorAction::KeyframeEdited(node_id)); | ||
| 282 | } else { | ||
| 283 | comp.set_input_value(node_id, input_name, ParamValue::Number(new_val)); | ||
| 284 | actions.push(InspectorAction::ParamEdited(node_id)); | ||
| 285 | } | ||
| 286 | } | ||
| 287 | |||
| 288 | // Reset button (small dot/arrow when non-default) | ||
| 289 | let is_default = (cur_val - default).abs() < 1e-4; | ||
| 290 | if !is_default { | ||
| 291 | let rst = ui.leaf( | ||
| 292 | ("rst", node_id.0, input_name), | ||
| 293 | ui::Spec { | ||
| 294 | cursor: Some(winit::window::CursorIcon::Pointer), | ||
| 295 | flags: ui::Flags::CLICKABLE, | ||
| 296 | size: [ui::px(18.0), ui::px(20.0)], | ||
| 297 | text: Some("↺"), | ||
| 298 | font_size: Some(10.5), | ||
| 299 | color: Some(p.text_dim), | ||
| 300 | hover_fill: Some(p.panel_bg), | ||
| 301 | radius: 3.0, | ||
| 302 | center: true, | ||
| 303 | ..ui::Spec::default() | ||
| 304 | }, | ||
| 305 | ); | ||
| 306 | if rst.clicked { | ||
| 307 | history.push_snapshot(comp, format!("Reset {label}")); | ||
| 308 | if kf_state != KeyframeState::Static { | ||
| 309 | let _ = comp.set_keyframe(node_id, input_name, current_frame, default); | ||
| 310 | actions.push(InspectorAction::KeyframeEdited(node_id)); | ||
| 311 | } else { | ||
| 312 | comp.set_input_value(node_id, input_name, ParamValue::Number(default)); | ||
| 313 | actions.push(InspectorAction::ParamEdited(node_id)); | ||
| 314 | } | ||
| 315 | } | ||
| 316 | } | ||
| 317 | |||
| 318 | // Keyframe diamond button (`◆`) | ||
| 319 | if self.keyframe_button(ui, ("kf", node_id.0, input_name), kf_state) { | ||
| 320 | self.toggle_keyframe(comp, history, node_id, input_name, current_frame, cur_val, kf_state, actions); | ||
| 321 | } | ||
| 322 | |||
| 323 | ui.close(); | ||
| 324 | } | ||
| 325 | |||
| 326 | #[allow(clippy::too_many_arguments)] | ||
| 327 | fn render_vec2_row( | ||
| 328 | &mut self, | ||
| 329 | ui: &mut ui::Ui, | ||
| 330 | pane_id: ui::Id, | ||
| 331 | comp: &mut Comp, | ||
| 332 | history: &mut CompHistory, | ||
| 333 | node_id: NodeId, | ||
| 334 | input_name: &str, | ||
| 335 | label: &str, | ||
| 336 | min: f64, | ||
| 337 | max: f64, | ||
| 338 | default: [f64; 2], | ||
| 339 | current_frame: f64, | ||
| 340 | actions: &mut Vec<InspectorAction>, | ||
| 341 | ) { | ||
| 342 | let cur = comp.eval_point(comp.node(node_id), input_name, current_frame, default, &self.expr); | ||
| 343 | let has_expr = comp | ||
| 344 | .node(node_id) | ||
| 345 | .inputs | ||
| 346 | .get(input_name) | ||
| 347 | .and_then(|b| b.expression.as_ref()) | ||
| 348 | .is_some(); | ||
| 349 | |||
| 350 | ui.open( | ||
| 351 | ("row-v2", node_id.0, input_name), | ||
| 352 | ui::Spec { | ||
| 353 | size: [ui::fill(), ui::px(22.0)], | ||
| 354 | axis: ui::Axis::X, | ||
| 355 | gap: 4.0, | ||
| 356 | ..ui::Spec::default() | ||
| 357 | }, | ||
| 358 | ); | ||
| 359 | ui.leaf( | ||
| 360 | "lbl", | ||
| 361 | ui::Spec { | ||
| 362 | size: [ui::px(86.0), ui::fill()], | ||
| 363 | text: Some(label), | ||
| 364 | font_size: Some(10.5), | ||
| 365 | overflow: ui::Overflow::Ellipsis, | ||
| 366 | color: Some(self.palette.text_dim), | ||
| 367 | ..ui::Spec::default() | ||
| 368 | }, | ||
| 369 | ); | ||
| 370 | if has_expr { | ||
| 371 | render_expr_badge(ui); | ||
| 372 | } | ||
| 373 | |||
| 374 | let x_id = pane_id.child(("v2x", node_id.0, input_name)); | ||
| 375 | let x_key = format!("{}:{input_name}:x", node_id.0); | ||
| 376 | if let Some(nx) = self.scrub_slider( | ||
| 377 | ui, | ||
| 378 | x_id, | ||
| 379 | &x_key, | ||
| 380 | node_id, | ||
| 381 | cur[0], | ||
| 382 | min, | ||
| 383 | max, | ||
| 384 | default[0], | ||
| 385 | history, | ||
| 386 | comp, | ||
| 387 | input_name, | ||
| 388 | ) { | ||
| 389 | comp.set_input_value(node_id, input_name, ParamValue::Point([nx, cur[1]])); | ||
| 390 | actions.push(InspectorAction::ParamEdited(node_id)); | ||
| 391 | } | ||
| 392 | |||
| 393 | let y_id = pane_id.child(("v2y", node_id.0, input_name)); | ||
| 394 | let y_key = format!("{}:{input_name}:y", node_id.0); | ||
| 395 | if let Some(ny) = self.scrub_slider( | ||
| 396 | ui, | ||
| 397 | y_id, | ||
| 398 | &y_key, | ||
| 399 | node_id, | ||
| 400 | cur[1], | ||
| 401 | min, | ||
| 402 | max, | ||
| 403 | default[1], | ||
| 404 | history, | ||
| 405 | comp, | ||
| 406 | input_name, | ||
| 407 | ) { | ||
| 408 | comp.set_input_value(node_id, input_name, ParamValue::Point([cur[0], ny])); | ||
| 409 | actions.push(InspectorAction::ParamEdited(node_id)); | ||
| 410 | } | ||
| 411 | |||
| 412 | ui.close(); | ||
| 413 | } | ||
| 414 | |||
| 415 | #[allow(clippy::too_many_arguments)] | ||
| 416 | fn render_bool_row( | ||
| 417 | &mut self, | ||
| 418 | ui: &mut ui::Ui, | ||
| 419 | comp: &mut Comp, | ||
| 420 | history: &mut CompHistory, | ||
| 421 | node_id: NodeId, | ||
| 422 | input_name: &str, | ||
| 423 | label: &str, | ||
| 424 | default: bool, | ||
| 425 | actions: &mut Vec<InspectorAction>, | ||
| 426 | ) { | ||
| 427 | let checked = comp | ||
| 428 | .node(node_id) | ||
| 429 | .static_number(input_name) | ||
| 430 | .map(|v| v >= 0.5) | ||
| 431 | .unwrap_or(default); | ||
| 432 | let p = self.palette; | ||
| 433 | |||
| 434 | ui.open( | ||
| 435 | ("row-b", node_id.0, input_name), | ||
| 436 | ui::Spec { | ||
| 437 | size: [ui::fill(), ui::px(22.0)], | ||
| 438 | axis: ui::Axis::X, | ||
| 439 | gap: 6.0, | ||
| 440 | ..ui::Spec::default() | ||
| 441 | }, | ||
| 442 | ); | ||
| 443 | ui.leaf( | ||
| 444 | "lbl", | ||
| 445 | ui::Spec { | ||
| 446 | size: [ui::px(86.0), ui::fill()], | ||
| 447 | text: Some(label), | ||
| 448 | font_size: Some(10.5), | ||
| 449 | overflow: ui::Overflow::Ellipsis, | ||
| 450 | color: Some(p.text_dim), | ||
| 451 | ..ui::Spec::default() | ||
| 452 | }, | ||
| 453 | ); | ||
| 454 | let fill = if checked { | ||
| 455 | [p.accent[0], p.accent[1], p.accent[2], 0.28] | ||
| 456 | } else { | ||
| 457 | p.panel_bg | ||
| 458 | }; | ||
| 459 | let border = if checked { p.accent } else { p.rule }; | ||
| 460 | let sig = ui.leaf( | ||
| 461 | ("chk", node_id.0, input_name), | ||
| 462 | ui::Spec { | ||
| 463 | cursor: Some(winit::window::CursorIcon::Pointer), | ||
| 464 | flags: ui::Flags::CLICKABLE, | ||
| 465 | size: [ui::px(54.0), ui::px(20.0)], | ||
| 466 | text: Some(if checked { "✓ On" } else { "Off" }), | ||
| 467 | font_size: Some(10.5), | ||
| 468 | medium: checked, | ||
| 469 | color: Some(if checked { p.text } else { p.text_dim }), | ||
| 470 | fill: Some(fill), | ||
| 471 | border: Some(border), | ||
| 472 | radius: 4.0, | ||
| 473 | center: true, | ||
| 474 | ..ui::Spec::default() | ||
| 475 | }, | ||
| 476 | ); | ||
| 477 | if sig.clicked { | ||
| 478 | history.push_snapshot(comp, format!("Toggle {label}")); | ||
| 479 | let next = if checked { 0.0 } else { 1.0 }; | ||
| 480 | comp.set_input_value(node_id, input_name, ParamValue::Number(next)); | ||
| 481 | actions.push(InspectorAction::ParamEdited(node_id)); | ||
| 482 | } | ||
| 483 | ui.close(); | ||
| 484 | } | ||
| 485 | |||
| 486 | #[allow(clippy::too_many_arguments)] | ||
| 487 | fn render_enum_row( | ||
| 488 | &mut self, | ||
| 489 | ui: &mut ui::Ui, | ||
| 490 | comp: &mut Comp, | ||
| 491 | history: &mut CompHistory, | ||
| 492 | node_id: NodeId, | ||
| 493 | input_name: &str, | ||
| 494 | label: &str, | ||
| 495 | options: &'static [&'static str], | ||
| 496 | default: &'static str, | ||
| 497 | actions: &mut Vec<InspectorAction>, | ||
| 498 | ) { | ||
| 499 | let cur = comp | ||
| 500 | .node(node_id) | ||
| 501 | .static_str(input_name) | ||
| 502 | .unwrap_or(default) | ||
| 503 | .to_owned(); | ||
| 504 | let p = self.palette; | ||
| 505 | |||
| 506 | ui.open( | ||
| 507 | ("row-e", node_id.0, input_name), | ||
| 508 | ui::Spec { | ||
| 509 | size: [ui::fill(), ui::px(22.0)], | ||
| 510 | axis: ui::Axis::X, | ||
| 511 | gap: 6.0, | ||
| 512 | ..ui::Spec::default() | ||
| 513 | }, | ||
| 514 | ); | ||
| 515 | ui.leaf( | ||
| 516 | "lbl", | ||
| 517 | ui::Spec { | ||
| 518 | size: [ui::px(86.0), ui::fill()], | ||
| 519 | text: Some(label), | ||
| 520 | font_size: Some(10.5), | ||
| 521 | overflow: ui::Overflow::Ellipsis, | ||
| 522 | color: Some(p.text_dim), | ||
| 523 | ..ui::Spec::default() | ||
| 524 | }, | ||
| 525 | ); | ||
| 526 | let btn_lbl = format!("{cur} ▾"); | ||
| 527 | let sig = ui.leaf( | ||
| 528 | ("enum", node_id.0, input_name), | ||
| 529 | ui::Spec { | ||
| 530 | cursor: Some(winit::window::CursorIcon::Pointer), | ||
| 531 | flags: ui::Flags::CLICKABLE, | ||
| 532 | size: [ui::fill(), ui::px(20.0)], | ||
| 533 | text: Some(&btn_lbl), | ||
| 534 | font_size: Some(10.5), | ||
| 535 | color: Some(p.text), | ||
| 536 | fill: Some(p.panel_bg), | ||
| 537 | border: Some(p.rule), | ||
| 538 | hover_border: Some(p.accent), | ||
| 539 | radius: 4.0, | ||
| 540 | pad: [6.0, 0.0], | ||
| 541 | ..ui::Spec::default() | ||
| 542 | }, | ||
| 543 | ); | ||
| 544 | if sig.clicked && !options.is_empty() { | ||
| 545 | let idx = options.iter().position(|&o| o == cur).unwrap_or(0); | ||
| 546 | let next_idx = if ui.modifiers().shift_key() { | ||
| 547 | (idx + options.len() - 1) % options.len() | ||
| 548 | } else { | ||
| 549 | (idx + 1) % options.len() | ||
| 550 | }; | ||
| 551 | history.push_snapshot(comp, format!("Set {label}")); | ||
| 552 | comp.set_input_value(node_id, input_name, ParamValue::FuId(options[next_idx].to_owned())); | ||
| 553 | actions.push(InspectorAction::ParamEdited(node_id)); | ||
| 554 | } | ||
| 555 | ui.close(); | ||
| 556 | } | ||
| 557 | |||
| 558 | #[allow(clippy::too_many_arguments)] | ||
| 559 | fn render_color_group( | ||
| 560 | &mut self, | ||
| 561 | ui: &mut ui::Ui, | ||
| 562 | pane_id: ui::Id, | ||
| 563 | comp: &mut Comp, | ||
| 564 | history: &mut CompHistory, | ||
| 565 | node_id: NodeId, | ||
| 566 | label: &str, | ||
| 567 | r_key: &'static str, | ||
| 568 | g_key: &'static str, | ||
| 569 | b_key: &'static str, | ||
| 570 | a_key: Option<&'static str>, | ||
| 571 | default: [f64; 4], | ||
| 572 | current_frame: f64, | ||
| 573 | actions: &mut Vec<InspectorAction>, | ||
| 574 | ) { | ||
| 575 | let rv = comp.eval_number(comp.node(node_id), r_key, current_frame, default[0], &self.expr); | ||
| 576 | let gv = comp.eval_number(comp.node(node_id), g_key, current_frame, default[1], &self.expr); | ||
| 577 | let bv = comp.eval_number(comp.node(node_id), b_key, current_frame, default[2], &self.expr); | ||
| 578 | let _av = a_key | ||
| 579 | .map(|ak| comp.eval_number(comp.node(node_id), ak, current_frame, default[3], &self.expr)) | ||
| 580 | .unwrap_or(default[3]); | ||
| 581 | let swatch = [ | ||
| 582 | rv.clamp(0.0, 1.0) as f32, | ||
| 583 | gv.clamp(0.0, 1.0) as f32, | ||
| 584 | bv.clamp(0.0, 1.0) as f32, | ||
| 585 | 1.0, | ||
| 586 | ]; | ||
| 587 | let p = self.palette; | ||
| 588 | |||
| 589 | ui.open( | ||
| 590 | ("grp-col", node_id.0, label), | ||
| 591 | ui::Spec { | ||
| 592 | size: [ui::fill(), ui::children()], | ||
| 593 | axis: ui::Axis::Y, | ||
| 594 | gap: 4.0, | ||
| 595 | pad: [6.0, 5.0], | ||
| 596 | fill: Some(p.panel_bg), | ||
| 597 | border: Some(p.rule), | ||
| 598 | radius: 4.0, | ||
| 599 | ..ui::Spec::default() | ||
| 600 | }, | ||
| 601 | ); | ||
| 602 | // Swatch header | ||
| 603 | ui.open( | ||
| 604 | "col-hdr", | ||
| 605 | ui::Spec { | ||
| 606 | size: [ui::fill(), ui::px(18.0)], | ||
| 607 | axis: ui::Axis::X, | ||
| 608 | gap: 6.0, | ||
| 609 | ..ui::Spec::default() | ||
| 610 | }, | ||
| 611 | ); | ||
| 612 | ui.leaf( | ||
| 613 | "col-lbl", | ||
| 614 | ui::Spec { | ||
| 615 | size: [ui::px(80.0), ui::fill()], | ||
| 616 | text: Some(label), | ||
| 617 | font_size: Some(10.5), | ||
| 618 | medium: true, | ||
| 619 | color: Some(p.text), | ||
| 620 | ..ui::Spec::default() | ||
| 621 | }, | ||
| 622 | ); | ||
| 623 | ui.leaf( | ||
| 624 | "col-swatch", | ||
| 625 | ui::Spec { | ||
| 626 | size: [ui::fill(), ui::px(16.0)], | ||
| 627 | fill: Some(swatch), | ||
| 628 | border: Some(p.rule), | ||
| 629 | radius: 3.0, | ||
| 630 | ..ui::Spec::default() | ||
| 631 | }, | ||
| 632 | ); | ||
| 633 | ui.close(); | ||
| 634 | |||
| 635 | self.render_float_row(ui, pane_id, comp, history, node_id, r_key, "Red", 0.0, 1.0, default[0], current_frame, actions); | ||
| 636 | self.render_float_row(ui, pane_id, comp, history, node_id, g_key, "Green", 0.0, 1.0, default[1], current_frame, actions); | ||
| 637 | self.render_float_row(ui, pane_id, comp, history, node_id, b_key, "Blue", 0.0, 1.0, default[2], current_frame, actions); | ||
| 638 | if let Some(ak) = a_key { | ||
| 639 | self.render_float_row(ui, pane_id, comp, history, node_id, ak, "Alpha", 0.0, 1.0, default[3], current_frame, actions); | ||
| 640 | } | ||
| 641 | ui.close(); | ||
| 642 | } | ||
| 643 | |||
| 644 | #[allow(clippy::too_many_arguments)] | ||
| 645 | fn render_text_row( | ||
| 646 | &mut self, | ||
| 647 | ui: &mut ui::Ui, | ||
| 648 | pane_id: ui::Id, | ||
| 649 | comp: &mut Comp, | ||
| 650 | history: &mut CompHistory, | ||
| 651 | node_id: NodeId, | ||
| 652 | input_name: &str, | ||
| 653 | label: &str, | ||
| 654 | default: &str, | ||
| 655 | actions: &mut Vec<InspectorAction>, | ||
| 656 | ) { | ||
| 657 | let field_id = pane_id.child(("txt", node_id.0, input_name)); | ||
| 658 | let key = (node_id.0, input_name.to_owned()); | ||
| 659 | let model_val = comp | ||
| 660 | .node(node_id) | ||
| 661 | .static_str(input_name) | ||
| 662 | .unwrap_or(default) | ||
| 663 | .to_owned(); | ||
| 664 | let p = self.palette; | ||
| 665 | let buf = self.text_bufs.entry(key).or_insert_with(|| model_val.clone()); | ||
| 666 | if ui.focused() != Some(field_id) && *buf != model_val { | ||
| 667 | *buf = model_val.clone(); | ||
| 668 | } | ||
| 669 | let prev = buf.clone(); | ||
| 670 | |||
| 671 | ui.open( | ||
| 672 | ("row-t", node_id.0, input_name), | ||
| 673 | ui::Spec { | ||
| 674 | size: [ui::fill(), ui::px(24.0)], | ||
| 675 | axis: ui::Axis::X, | ||
| 676 | gap: 6.0, | ||
| 677 | ..ui::Spec::default() | ||
| 678 | }, | ||
| 679 | ); | ||
| 680 | ui.leaf( | ||
| 681 | "lbl", | ||
| 682 | ui::Spec { | ||
| 683 | size: [ui::px(86.0), ui::fill()], | ||
| 684 | text: Some(label), | ||
| 685 | font_size: Some(10.5), | ||
| 686 | overflow: ui::Overflow::Ellipsis, | ||
| 687 | color: Some(p.text_dim), | ||
| 688 | ..ui::Spec::default() | ||
| 689 | }, | ||
| 690 | ); | ||
| 691 | ui::text_field( | ||
| 692 | ui, | ||
| 693 | field_id, | ||
| 694 | buf, | ||
| 695 | label, | ||
| 696 | ui::Spec { | ||
| 697 | size: [ui::fill(), ui::px(22.0)], | ||
| 698 | font_size: Some(11.0), | ||
| 699 | fill: Some(p.panel_bg), | ||
| 700 | border: Some(p.rule), | ||
| 701 | hover_border: Some(p.accent), | ||
| 702 | radius: 4.0, | ||
| 703 | pad: [6.0, 2.0], | ||
| 704 | ..ui::Spec::default() | ||
| 705 | }, | ||
| 706 | ); | ||
| 707 | if *buf != prev { | ||
| 708 | history.push_coalesced( | ||
| 709 | comp, | ||
| 710 | format!("Edit {label}"), | ||
| 711 | format!("text:{}:{input_name}", node_id.0), | ||
| 712 | ); | ||
| 713 | comp.set_input_value(node_id, input_name, ParamValue::Text(buf.clone())); | ||
| 714 | actions.push(InspectorAction::ParamEdited(node_id)); | ||
| 715 | } | ||
| 716 | ui.close(); | ||
| 717 | } | ||
| 718 | |||
| 719 | #[allow(clippy::too_many_arguments)] | ||
| 720 | fn scrub_slider( | ||
| 721 | &mut self, | ||
| 722 | ui: &mut ui::Ui, | ||
| 723 | slider_id: ui::Id, | ||
| 724 | drag_key: &str, | ||
| 725 | node_id: NodeId, | ||
| 726 | value: f64, | ||
| 727 | min: f64, | ||
| 728 | max: f64, | ||
| 729 | default: f64, | ||
| 730 | history: &mut CompHistory, | ||
| 731 | comp: &Comp, | ||
| 732 | input_name: &str, | ||
| 733 | ) -> Option<f64> { | ||
| 734 | let sig = ui.signal(slider_id); | ||
| 735 | let rect = ui.laid_out(slider_id); | ||
| 736 | let width = rect.map(|r| (r[2] - r[0]).max(40.0)).unwrap_or(110.0); | ||
| 737 | let mut updated: Option<f64> = None; | ||
| 738 | |||
| 739 | if let Some(press) = sig.press { | ||
| 740 | let now = Instant::now(); | ||
| 741 | let is_double = self | ||
| 742 | .last_click | ||
| 743 | .get(drag_key) | ||
| 744 | .is_some_and(|prev| now.duration_since(*prev) < Duration::from_millis(320)); | ||
| 745 | self.last_click.insert(drag_key.to_owned(), now); | ||
| 746 | if is_double { | ||
| 747 | history.push_snapshot(comp, format!("Reset {input_name}")); | ||
| 748 | self.drag = None; | ||
| 749 | updated = Some(default); | ||
| 750 | } else { | ||
| 751 | self.drag = Some(DragState { | ||
| 752 | node_id, | ||
| 753 | key: drag_key.to_owned(), | ||
| 754 | start_x: press[0], | ||
| 755 | start_val: value, | ||
| 756 | min, | ||
| 757 | max, | ||
| 758 | width, | ||
| 759 | }); | ||
| 760 | } | ||
| 761 | } else if sig.dragging { | ||
| 762 | if let (Some(d), Some(ptr)) = (&self.drag, ui.pointer()) { | ||
| 763 | if d.key == drag_key && d.node_id == node_id { | ||
| 764 | let fine = if ui.modifiers().shift_key() { 0.15 } else { 1.0 }; | ||
| 765 | let next = compute_scrub_value(d.start_val, ptr[0] - d.start_x, d.width, d.min, d.max, fine); | ||
| 766 | if (next - value).abs() > 1e-6 { | ||
| 767 | history.push_coalesced( | ||
| 768 | comp, | ||
| 769 | format!("Adjust {input_name}"), | ||
| 770 | format!("scrub:{drag_key}"), | ||
| 771 | ); | ||
| 772 | updated = Some(next); | ||
| 773 | } | ||
| 774 | } | ||
| 775 | } | ||
| 776 | } else if self.drag.as_ref().is_some_and(|d| d.key == drag_key) { | ||
| 777 | self.drag = None; | ||
| 778 | history.break_coalescing(); | ||
| 779 | } | ||
| 780 | |||
| 781 | let display_val = updated.unwrap_or(value); | ||
| 782 | let frac = normalize_slider_fraction(display_val, min, max); | ||
| 783 | let val_text = format_param_number(display_val); | ||
| 784 | let fill_w = (width * frac).clamp(0.0, width); | ||
| 785 | let active_drag = self.drag.as_ref().is_some_and(|d| d.key == drag_key); | ||
| 786 | let p = self.palette; | ||
| 787 | |||
| 788 | ui.open_as( | ||
| 789 | slider_id, | ||
| 790 | ui::Spec { | ||
| 791 | cursor: Some(winit::window::CursorIcon::EwResize), | ||
| 792 | flags: ui::Flags::CLICKABLE | ui::Flags::CLIP, | ||
| 793 | size: [ui::fill(), ui::px(20.0)], | ||
| 794 | fill: Some(p.panel_bg), | ||
| 795 | border: Some(if active_drag || sig.hovered { p.accent } else { p.rule }), | ||
| 796 | radius: 4.0, | ||
| 797 | ..ui::Spec::default() | ||
| 798 | }, | ||
| 799 | ); | ||
| 800 | if fill_w > 0.5 { | ||
| 801 | ui.leaf( | ||
| 802 | "fill", | ||
| 803 | ui::Spec { | ||
| 804 | flags: ui::Flags::FLOAT | ui::Flags::INERT, | ||
| 805 | position: [0.0, 0.0], | ||
| 806 | size: [ui::px(fill_w), ui::px(20.0)], | ||
| 807 | fill: Some([p.accent[0], p.accent[1], p.accent[2], if active_drag { 0.34 } else { 0.22 }]), | ||
| 808 | radius: 3.0, | ||
| 809 | ..ui::Spec::default() | ||
| 810 | }, | ||
| 811 | ); | ||
| 812 | } | ||
| 813 | ui.leaf( | ||
| 814 | "txt", | ||
| 815 | ui::Spec { | ||
| 816 | flags: ui::Flags::INERT, | ||
| 817 | size: [ui::fill(), ui::fill()], | ||
| 818 | text: Some(&val_text), | ||
| 819 | font_size: Some(10.5), | ||
| 820 | color: Some(p.text), | ||
| 821 | center: true, | ||
| 822 | ..ui::Spec::default() | ||
| 823 | }, | ||
| 824 | ); | ||
| 825 | ui.close(); | ||
| 826 | |||
| 827 | updated | ||
| 828 | } | ||
| 829 | |||
| 830 | fn keyframe_button(&self, ui: &mut ui::Ui, part: impl std::hash::Hash, state: KeyframeState) -> bool { | ||
| 831 | let (ink, fill, border) = match state { | ||
| 832 | KeyframeState::KeyframeAtCurrent => ( | ||
| 833 | [1.0, 0.80, 0.22, 1.0], | ||
| 834 | Some([0.98, 0.72, 0.18, 0.24]), | ||
| 835 | Some([0.98, 0.76, 0.20, 0.85]), | ||
| 836 | ), | ||
| 837 | KeyframeState::AnimatedOtherFrame => ( | ||
| 838 | [0.92, 0.64, 0.24, 0.90], | ||
| 839 | Some([0.92, 0.64, 0.24, 0.12]), | ||
| 840 | Some([0.92, 0.64, 0.24, 0.45]), | ||
| 841 | ), | ||
| 842 | KeyframeState::Static => (self.palette.text_dim, None, None), | ||
| 843 | }; | ||
| 844 | let sig = ui.leaf( | ||
| 845 | part, | ||
| 846 | ui::Spec { | ||
| 847 | cursor: Some(winit::window::CursorIcon::Pointer), | ||
| 848 | flags: ui::Flags::CLICKABLE, | ||
| 849 | size: [ui::px(20.0), ui::px(20.0)], | ||
| 850 | text: Some("◆"), | ||
| 851 | font_size: Some(10.5), | ||
| 852 | color: Some(ink), | ||
| 853 | fill, | ||
| 854 | border, | ||
| 855 | hover_fill: Some([0.98, 0.76, 0.22, 0.18]), | ||
| 856 | radius: 4.0, | ||
| 857 | center: true, | ||
| 858 | ..ui::Spec::default() | ||
| 859 | }, | ||
| 860 | ); | ||
| 861 | sig.clicked | ||
| 862 | } | ||
| 863 | |||
| 864 | #[allow(clippy::too_many_arguments)] | ||
| 865 | fn toggle_keyframe( | ||
| 866 | &self, | ||
| 867 | comp: &mut Comp, | ||
| 868 | history: &mut CompHistory, | ||
| 869 | node_id: NodeId, | ||
| 870 | input_name: &str, | ||
| 871 | current_frame: f64, | ||
| 872 | cur_val: f64, | ||
| 873 | state: KeyframeState, | ||
| 874 | actions: &mut Vec<InspectorAction>, | ||
| 875 | ) { | ||
| 876 | match state { | ||
| 877 | KeyframeState::KeyframeAtCurrent => { | ||
| 878 | if let Some(sp_name) = comp | ||
| 879 | .node(node_id) | ||
| 880 | .inputs | ||
| 881 | .get(input_name) | ||
| 882 | .and_then(|b| b.source_op.clone()) | ||
| 883 | { | ||
| 884 | history.push_snapshot(comp, format!("Delete Keyframe {input_name}")); | ||
| 885 | if comp.delete_keyframe(&sp_name, current_frame) { | ||
| 886 | actions.push(InspectorAction::KeyframeEdited(node_id)); | ||
| 887 | actions.push(InspectorAction::StatusNotice(format!( | ||
| 888 | "Deleted keyframe on {input_name} @ f{current_frame:.0}" | ||
| 889 | ))); | ||
| 890 | } | ||
| 891 | } | ||
| 892 | } | ||
| 893 | KeyframeState::Static | KeyframeState::AnimatedOtherFrame => { | ||
| 894 | history.push_snapshot(comp, format!("Set Keyframe {input_name}")); | ||
| 895 | match comp.set_keyframe(node_id, input_name, current_frame, cur_val) { | ||
| 896 | Ok(_) => { | ||
| 897 | actions.push(InspectorAction::KeyframeEdited(node_id)); | ||
| 898 | actions.push(InspectorAction::StatusNotice(format!( | ||
| 899 | "Keyframed {input_name} = {:.3} @ f{current_frame:.0}", | ||
| 900 | cur_val | ||
| 901 | ))); | ||
| 902 | } | ||
| 903 | Err(e) => actions.push(InspectorAction::StatusNotice(e)), | ||
| 904 | } | ||
| 905 | } | ||
| 906 | } | ||
| 907 | } | ||
| 908 | } | ||
| 909 | |||
| 910 | fn render_expr_badge(ui: &mut ui::Ui) { | ||
| 911 | ui.leaf( | ||
| 912 | "expr-badge", | ||
| 913 | ui::Spec { | ||
| 914 | size: [ui::px(16.0), ui::px(18.0)], | ||
| 915 | text: Some("="), | ||
| 916 | font_size: Some(10.5), | ||
| 917 | bold: true, | ||
| 918 | color: Some([0.36, 0.88, 0.92, 1.0]), | ||
| 919 | fill: Some([0.10, 0.24, 0.28, 0.85]), | ||
| 920 | border: Some([0.32, 0.78, 0.86, 0.65]), | ||
| 921 | radius: 3.0, | ||
| 922 | center: true, | ||
| 923 | ..ui::Spec::default() | ||
| 924 | }, | ||
| 925 | ); | ||
| 926 | } | ||
| 927 | |||
| 928 | /// Computes whether an input is static, animated on another frame, or has a keyframe at `frame`. | ||
| 929 | pub fn keyframe_state(comp: &Comp, node_id: NodeId, input_name: &str, frame: f64) -> KeyframeState { | ||
| 930 | let Some(sp_name) = comp | ||
| 931 | .node(node_id) | ||
| 932 | .inputs | ||
| 933 | .get(input_name) | ||
| 934 | .and_then(|b| b.source_op.as_deref()) | ||
| 935 | else { | ||
| 936 | return KeyframeState::Static; | ||
| 937 | }; | ||
| 938 | let Some(spline) = comp.splines.get(sp_name) else { | ||
| 939 | return KeyframeState::Static; | ||
| 940 | }; | ||
| 941 | if spline.keyframes.iter().any(|kf| (kf.time - frame).abs() < 1e-4) { | ||
| 942 | KeyframeState::KeyframeAtCurrent | ||
| 943 | } else if !spline.keyframes.is_empty() { | ||
| 944 | KeyframeState::AnimatedOtherFrame | ||
| 945 | } else { | ||
| 946 | KeyframeState::Static | ||
| 947 | } | ||
| 948 | } | ||
| 949 | |||
| 950 | pub fn normalize_slider_fraction(value: f64, min: f64, max: f64) -> f32 { | ||
| 951 | let span = (max - min).abs().max(1e-6); | ||
| 952 | ((value - min) / span).clamp(0.0, 1.0) as f32 | ||
| 953 | } | ||
| 954 | |||
| 955 | pub fn compute_scrub_value(start_val: f64, dx: f32, width: f32, min: f64, max: f64, fine_scale: f64) -> f64 { | ||
| 956 | let span = (max - min).max(1e-4); | ||
| 957 | let delta = (f64::from(dx) / f64::from(width.max(40.0))) * span * fine_scale; | ||
| 958 | (start_val + delta).clamp(min, max) | ||
| 959 | } | ||
| 960 | |||
| 961 | pub fn format_param_number(v: f64) -> String { | ||
| 962 | if v.abs() >= 100.0 { | ||
| 963 | format!("{v:.1}") | ||
| 964 | } else if v.abs() >= 10.0 { | ||
| 965 | format!("{v:.2}") | ||
| 966 | } else { | ||
| 967 | format!("{v:.3}") | ||
| 968 | } | ||
| 969 | } | ||