| 1 | //! The Inspector's frame: header (bypass, name, reset), page tabs, clip summary, stats footer. |
| 2 | |
| 3 | use super::edit::Cx; |
| 4 | use super::{InspectorAction, InspectorPalette}; |
| 5 | use engine::EvalStats; |
| 6 | use model::is_supported_tool; |
| 7 | use ui::{Spec, Ui, fill, fit, px}; |
| 8 | use winit::keyboard::{Key, NamedKey}; |
| 9 | |
| 10 | /// The node-name edit buffer, synced with the selected node. |
| 11 | #[derive(Default)] |
| 12 | pub(super) struct Rename { |
| 13 | pub node: Option<model::NodeId>, |
| 14 | pub buf: String, |
| 15 | } |
| 16 | |
| 17 | pub(super) fn empty_state(ui: &mut Ui, p: InspectorPalette) { |
| 18 | ui.open( |
| 19 | "insp-empty", |
| 20 | Spec { size: [fill(), fill()], axis: ui::Axis::Y, pad: [14.0, 18.0], gap: 8.0, ..Spec::default() }, |
| 21 | ); |
| 22 | ui.leaf( |
| 23 | "empty-title", |
| 24 | Spec { size: [fill(), px(20.0)], text: Some("No Node Selected"), font_size: Some(12.5), medium: true, color: Some(p.text), ..Spec::default() }, |
| 25 | ); |
| 26 | ui.leaf( |
| 27 | "empty-hint", |
| 28 | Spec { |
| 29 | size: [fill(), fit()], |
| 30 | text: Some("Select a node in the Flow graph to inspect and keyframe its parameters, or press Shift+Space to add a tool."), |
| 31 | font_size: Some(11.0), |
| 32 | overflow: ui::Overflow::Wrap, |
| 33 | color: Some(p.text_dim), |
| 34 | ..Spec::default() |
| 35 | }, |
| 36 | ); |
| 37 | ui.close(); |
| 38 | } |
| 39 | |
| 40 | /// Bypass pill, name field and reset action; below them the tool badge and frame number. |
| 41 | /// Returns whether reset-to-defaults was clicked. |
| 42 | pub(super) fn header(ui: &mut Ui, pane_id: ui::Id, rename: &mut Rename, cx: &mut Cx) -> bool { |
| 43 | let p = cx.p; |
| 44 | let node_id = cx.node; |
| 45 | let current_name = cx.comp.node(node_id).name.clone(); |
| 46 | let name_field = pane_id.child(("node-name", node_id.0)); |
| 47 | if rename.node != Some(node_id) || (ui.focused() != Some(name_field) && rename.buf != current_name) { |
| 48 | rename.node = Some(node_id); |
| 49 | rename.buf = current_name.clone(); |
| 50 | } |
| 51 | |
| 52 | ui.open( |
| 53 | "insp-header", |
| 54 | Spec { size: [fill(), ui::children()], axis: ui::Axis::Y, pad: [10.0, 8.0], gap: 6.0, fill: Some(p.panel_bg), border: Some(p.rule), ..Spec::default() }, |
| 55 | ); |
| 56 | ui.open("insp-name-row", Spec { size: [fill(), px(26.0)], axis: ui::Axis::X, gap: 6.0, ..Spec::default() }); |
| 57 | |
| 58 | let bypassed = cx.comp.node(node_id).bypassed; |
| 59 | let (fill_c, border_c) = if bypassed { |
| 60 | ([0.85, 0.28, 0.28, 0.28], [0.92, 0.36, 0.36, 0.75]) |
| 61 | } else { |
| 62 | ([0.24, 0.78, 0.48, 0.18], [0.28, 0.82, 0.52, 0.55]) |
| 63 | }; |
| 64 | let pill = ui.leaf( |
| 65 | ("insp-pass", node_id.0), |
| 66 | Spec { |
| 67 | cursor: Some(winit::window::CursorIcon::Pointer), |
| 68 | flags: ui::Flags::CLICKABLE, |
| 69 | size: [px(64.0), px(24.0)], |
| 70 | text: Some(if bypassed { "Bypassed" } else { "Active" }), |
| 71 | font_size: Some(10.5), |
| 72 | medium: true, |
| 73 | color: Some(p.text), |
| 74 | fill: Some(fill_c), |
| 75 | border: Some(border_c), |
| 76 | radius: 12.0, |
| 77 | center: true, |
| 78 | ..Spec::default() |
| 79 | }, |
| 80 | ); |
| 81 | if pill.clicked { |
| 82 | cx.history.push_snapshot(cx.comp, "Toggle Passthrough"); |
| 83 | cx.comp.toggle_passthrough(node_id); |
| 84 | cx.actions.push(InspectorAction::ParamEdited(node_id)); |
| 85 | } |
| 86 | |
| 87 | let name_sig = ui::text_field( |
| 88 | ui, |
| 89 | name_field, |
| 90 | &mut rename.buf, |
| 91 | "Node name", |
| 92 | Spec { |
| 93 | size: [fill(), px(24.0)], |
| 94 | font_size: Some(12.0), |
| 95 | medium: true, |
| 96 | fill: Some(p.bg), |
| 97 | border: Some(p.rule), |
| 98 | hover_border: Some(p.accent), |
| 99 | radius: 4.0, |
| 100 | pad: [6.0, 2.0], |
| 101 | ..Spec::default() |
| 102 | }, |
| 103 | ); |
| 104 | let entered = name_sig |
| 105 | .events |
| 106 | .iter() |
| 107 | .any(|ev| matches!(ev, ui::Event::Key { key: Key::Named(NamedKey::Enter), .. })); |
| 108 | if entered && rename.buf.trim() != current_name { |
| 109 | let desired = rename.buf.trim().to_owned(); |
| 110 | cx.history.begin_group(cx.comp, "Rename Node"); |
| 111 | match cx.comp.rename_node(node_id, &desired) { |
| 112 | Ok(applied) => { |
| 113 | cx.history.commit_group(cx.comp); |
| 114 | rename.buf = applied; |
| 115 | cx.actions.push(InspectorAction::NodeRenamed(node_id)); |
| 116 | } |
| 117 | Err(e) => { |
| 118 | cx.history.cancel_group(cx.comp); |
| 119 | rename.buf = current_name; |
| 120 | cx.actions.push(InspectorAction::StatusNotice(e)); |
| 121 | } |
| 122 | } |
| 123 | ui.set_focus(None); |
| 124 | } |
| 125 | |
| 126 | let reset = ui |
| 127 | .leaf( |
| 128 | ("insp-reset", node_id.0), |
| 129 | Spec { |
| 130 | cursor: Some(winit::window::CursorIcon::Pointer), |
| 131 | flags: ui::Flags::CLICKABLE, |
| 132 | size: [px(24.0), px(24.0)], |
| 133 | text: Some("↺"), |
| 134 | font_size: Some(13.0), |
| 135 | color: Some(p.text_dim), |
| 136 | hover_fill: Some(p.bg), |
| 137 | radius: 4.0, |
| 138 | center: true, |
| 139 | ..Spec::default() |
| 140 | }, |
| 141 | ) |
| 142 | .clicked; |
| 143 | ui.close(); |
| 144 | |
| 145 | let kind = cx.comp.node(node_id).kind.as_str(); |
| 146 | ui.open("insp-meta-row", Spec { size: [fill(), px(18.0)], axis: ui::Axis::X, gap: 6.0, ..Spec::default() }); |
| 147 | ui.leaf( |
| 148 | "insp-kind-badge", |
| 149 | Spec { |
| 150 | size: [fit(), px(18.0)], |
| 151 | text: Some(kind), |
| 152 | font_size: Some(10.0), |
| 153 | medium: true, |
| 154 | color: Some(p.accent), |
| 155 | fill: Some([p.accent[0], p.accent[1], p.accent[2], 0.14]), |
| 156 | border: Some([p.accent[0], p.accent[1], p.accent[2], 0.40]), |
| 157 | radius: 3.0, |
| 158 | pad: [6.0, 0.0], |
| 159 | center: true, |
| 160 | ..Spec::default() |
| 161 | }, |
| 162 | ); |
| 163 | if !is_supported_tool(kind) { |
| 164 | ui.leaf( |
| 165 | "insp-preserved-badge", |
| 166 | Spec { |
| 167 | size: [fit(), px(18.0)], |
| 168 | text: Some("preserved"), |
| 169 | font_size: Some(9.5), |
| 170 | medium: true, |
| 171 | color: Some([0.98, 0.78, 0.40, 1.0]), |
| 172 | fill: Some([0.24, 0.16, 0.06, 0.85]), |
| 173 | border: Some([0.92, 0.64, 0.24, 0.60]), |
| 174 | radius: 3.0, |
| 175 | pad: [5.0, 0.0], |
| 176 | center: true, |
| 177 | ..Spec::default() |
| 178 | }, |
| 179 | ); |
| 180 | } |
| 181 | ui.leaf("insp-spacer", Spec { size: [fill(), px(18.0)], ..Spec::default() }); |
| 182 | ui.leaf( |
| 183 | "insp-frame", |
| 184 | Spec { size: [fit(), px(18.0)], text: Some(&format!("f{:.0}", cx.frame)), font_size: Some(10.0), color: Some(p.text_dim), center: true, ..Spec::default() }, |
| 185 | ); |
| 186 | ui.close(); |
| 187 | ui.close(); |
| 188 | reset |
| 189 | } |
| 190 | |
| 191 | /// Underlined page tabs; returns the tab clicked. |
| 192 | pub(super) fn tabs(ui: &mut Ui, p: InspectorPalette, names: &[&str], active: usize) -> Option<usize> { |
| 193 | ui.open( |
| 194 | "insp-tabs", |
| 195 | Spec { size: [fill(), px(28.0)], axis: ui::Axis::X, flags: ui::Flags::CLIP, pad: [6.0, 0.0], border: Some(p.rule), ..Spec::default() }, |
| 196 | ); |
| 197 | let mut clicked = None; |
| 198 | for (i, name) in names.iter().enumerate() { |
| 199 | let on = i == active; |
| 200 | ui.open(("tab", i), Spec { size: [ui::children(), fill()], axis: ui::Axis::Y, ..Spec::default() }); |
| 201 | let signal = ui.leaf( |
| 202 | "label", |
| 203 | Spec { |
| 204 | cursor: Some(winit::window::CursorIcon::Pointer), |
| 205 | flags: ui::Flags::CLICKABLE, |
| 206 | size: [fit(), fill()], |
| 207 | text: Some(name), |
| 208 | font_size: Some(11.0), |
| 209 | medium: on, |
| 210 | color: Some(if on { p.text } else { p.text_dim }), |
| 211 | hover_fill: Some(p.panel_bg), |
| 212 | pad: [8.0, 0.0], |
| 213 | center: true, |
| 214 | ..Spec::default() |
| 215 | }, |
| 216 | ); |
| 217 | ui.leaf("rule", Spec { size: [fill(), px(2.0)], fill: on.then_some(p.accent), ..Spec::default() }); |
| 218 | ui.close(); |
| 219 | if signal.clicked { |
| 220 | clicked = Some(i); |
| 221 | } |
| 222 | } |
| 223 | ui.close(); |
| 224 | clicked |
| 225 | } |
| 226 | |
| 227 | /// The Loader/Saver's first clip path. |
| 228 | pub(super) fn clip_summary(ui: &mut Ui, cx: &Cx) { |
| 229 | let node = cx.comp.node(cx.node); |
| 230 | let heading = if node.kind == "Saver" { "Output Filename" } else { "Clip Filename" }; |
| 231 | let path = node |
| 232 | .clips |
| 233 | .first() |
| 234 | .map(|c| c.filename.as_str()) |
| 235 | .or_else(|| { |
| 236 | node.raw |
| 237 | .get_table("Inputs")? |
| 238 | .get_table("Clip")? |
| 239 | .get_table("Value")? |
| 240 | .get_str("Filename") |
| 241 | }) |
| 242 | .unwrap_or("(no clip)"); |
| 243 | let p = cx.p; |
| 244 | ui.open( |
| 245 | "insp-loader-clip", |
| 246 | Spec { size: [fill(), ui::children()], axis: ui::Axis::Y, gap: 3.0, pad: [6.0, 5.0], fill: Some(p.panel_bg), border: Some(p.rule), radius: 4.0, ..Spec::default() }, |
| 247 | ); |
| 248 | ui.leaf("clip-lbl", Spec { size: [fill(), px(14.0)], text: Some(heading), font_size: Some(10.0), color: Some(p.text_dim), ..Spec::default() }); |
| 249 | ui.leaf( |
| 250 | "clip-path", |
| 251 | Spec { size: [fill(), fit()], text: Some(path), font_size: Some(10.5), overflow: ui::Overflow::Wrap, color: Some(p.text), ..Spec::default() }, |
| 252 | ); |
| 253 | ui.close(); |
| 254 | } |
| 255 | |
| 256 | pub(super) fn footer(ui: &mut Ui, p: InspectorPalette, stats: &EvalStats) { |
| 257 | let line = format!( |
| 258 | "Eval {:.1}ms · {} nodes · cache {}/{} · {:.0}MB", |
| 259 | stats.eval_ms, |
| 260 | stats.nodes_evaluated, |
| 261 | stats.cache_hits, |
| 262 | stats.cache_hits + stats.cache_misses, |
| 263 | stats.cached_vram_mb, |
| 264 | ); |
| 265 | ui.open( |
| 266 | "insp-footer", |
| 267 | Spec { size: [fill(), px(24.0)], axis: ui::Axis::X, pad: [10.0, 4.0], fill: Some(p.panel_bg), border: Some(p.rule), ..Spec::default() }, |
| 268 | ); |
| 269 | ui.leaf("insp-stats-txt", Spec { size: [fill(), fill()], text: Some(&line), font_size: Some(10.0), color: Some(p.text_dim), ..Spec::default() }); |
| 270 | ui.close(); |
| 271 | } |