| ... | @@ -4,17 +4,27 @@ | ... | @@ -4,17 +4,27 @@ |
| 4 | //! - Crisp straight lines by default (clean in any build orientation: L->R, T->B, B->T, diagonal) | 4 | //! - Crisp straight lines by default (clean in any build orientation: L->R, T->B, B->T, diagonal) |
| 5 | //! - Day-1 Blender `G`/`R`/`S` modal transforms + `X`/`Y` axis locks | 5 | //! - Day-1 Blender `G`/`R`/`S` modal transforms + `X`/`Y` axis locks |
| 6 | //! - `1`/`2` multi-viewer routing, `Cmd+F` / Numpad `.` fit-to-view, `P` bypass, drag-onto-wire insert. | 6 | //! - `1`/`2` multi-viewer routing, `Cmd+F` / Numpad `.` fit-to-view, `P` bypass, drag-onto-wire insert. |
| | 7 | //! - `Cmd+C` / `Cmd+V` node clipboard requests, double-click into Macro/Group subgraphs, `Esc` back out. |
| | 8 | |
| | 9 | mod scope; |
| 7 | | 10 | |
| 8 | use draw::{Glyphs, PathStyle, Primitive}; | 11 | use draw::{Glyphs, PathStyle, Primitive}; |
| 9 | use model::{Comp, CompHistory, NodeId, PortRole, default_main_input_port, is_supported_tool}; | 12 | use model::{Comp, CompHistory, NodeId, PortRole, default_main_input_port, is_supported_tool}; |
| | 13 | use scope::Scope; |
| | 14 | pub use scope::group_children; |
| 10 | use std::collections::{HashMap, HashSet}; | 15 | use std::collections::{HashMap, HashSet}; |
| 11 | use std::sync::Arc; | 16 | use std::sync::Arc; |
| | 17 | use std::time::{Duration, Instant}; |
| 12 | use winit::event::{ElementState, MouseButton}; | 18 | use winit::event::{ElementState, MouseButton}; |
| 13 | use winit::keyboard::{Key, KeyCode, ModifiersState, NamedKey, PhysicalKey}; | 19 | use winit::keyboard::{Key, KeyCode, ModifiersState, NamedKey, PhysicalKey}; |
| 14 | | 20 | |
| 15 | // Exact 1:1 match to Fusion's 110×33 flow grid cells (leaving crisp 26px X / 12px Y gaps for □──▶ wires). | 21 | // Exact 1:1 match to Fusion's 110×33 flow grid cells (leaving crisp 26px X / 12px Y gaps for □──▶ wires). |
| 16 | const NODE_W: f32 = 84.0; | 22 | const NODE_W: f32 = 84.0; |
| 17 | const NODE_H: f32 = 21.0; | 23 | const NODE_H: f32 = 21.0; |
| | 24 | const DOUBLE_CLICK: Duration = Duration::from_millis(400); |
| | 25 | |
| | 26 | const HUD_ROOT: &str = "Shift+Space: Add Tool G/R/S: Transform Shift+Drag: Splice Del: Delete Cmd+C/V: Copy/Paste Cmd+D: Dup F2: Rename Ctrl+P: Bypass 1/2: Viewer Dbl-click group: Enter"; |
| | 27 | const HUD_GROUP: &str = "Group contents are read-only Dbl-click nested group: Enter Cmd+C: Copy 1/2: Viewer F: Fit Esc: Back"; |
| 18 | | 28 | |
| 19 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] | 29 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 20 | pub enum TransformMode { | 30 | pub enum TransformMode { |
| ... | @@ -98,6 +108,12 @@ pub enum FlowAction { | ... | @@ -98,6 +108,12 @@ pub enum FlowAction { |
| 98 | RequestRename(NodeId), | 108 | RequestRename(NodeId), |
| 99 | /// Transient feedback message (e.g., cycle rejected). | 109 | /// Transient feedback message (e.g., cycle rejected). |
| 100 | StatusNotice(String), | 110 | StatusNotice(String), |
| | 111 | /// `Cmd+C`: serialize these nodes to the system clipboard. |
| | 112 | CopyNodes(Vec<NodeId>), |
| | 113 | /// `Cmd+V`: paste the system clipboard at the root graph. |
| | 114 | PasteNodes, |
| | 115 | /// A Macro/Group was entered or left; selection was reset to the new level. |
| | 116 | ScopeChanged, |
| 101 | } | 117 | } |
| 102 | | 118 | |
| 103 | #[derive(Clone, Debug)] | 119 | #[derive(Clone, Debug)] |
| ... | @@ -159,6 +175,8 @@ pub struct FlowView { | ... | @@ -159,6 +175,8 @@ pub struct FlowView { |
| 159 | panning: Option<([f32; 2], [f32; 2])>, | 175 | panning: Option<([f32; 2], [f32; 2])>, |
| 160 | lmb_drag_node: Option<(NodeId, [f32; 2], bool)>, | 176 | lmb_drag_node: Option<(NodeId, [f32; 2], bool)>, |
| 161 | pointer_local: [f32; 2], | 177 | pointer_local: [f32; 2], |
| | 178 | scope: Scope, |
| | 179 | last_click: Option<(Instant, NodeId)>, |
| 162 | label_cache: HashMap<String, text::Layout>, | 180 | label_cache: HashMap<String, text::Layout>, |
| 163 | badge_cache: HashMap<String, text::Layout>, | 181 | badge_cache: HashMap<String, text::Layout>, |
| 164 | fitted_once: bool, | 182 | fitted_once: bool, |
| ... | @@ -182,6 +200,8 @@ impl FlowView { | ... | @@ -182,6 +200,8 @@ impl FlowView { |
| 182 | panning: None, | 200 | panning: None, |
| 183 | lmb_drag_node: None, | 201 | lmb_drag_node: None, |
| 184 | pointer_local: [0.0, 0.0], | 202 | pointer_local: [0.0, 0.0], |
| | 203 | scope: Scope::default(), |
| | 204 | last_click: None, |
| 185 | label_cache: HashMap::new(), | 205 | label_cache: HashMap::new(), |
| 186 | badge_cache: HashMap::new(), | 206 | badge_cache: HashMap::new(), |
| 187 | fitted_once: false, | 207 | fitted_once: false, |
| ... | @@ -207,16 +227,63 @@ impl FlowView { | ... | @@ -207,16 +227,63 @@ impl FlowView { |
| 207 | self.box_select = None; | 227 | self.box_select = None; |
| 208 | self.panning = None; | 228 | self.panning = None; |
| 209 | self.lmb_drag_node = None; | 229 | self.lmb_drag_node = None; |
| | 230 | self.last_click = None; |
| | 231 | self.scope = Scope::default(); |
| 210 | self.label_cache.clear(); | 232 | self.label_cache.clear(); |
| 211 | self.fitted_once = false; | 233 | self.fitted_once = false; |
| 212 | self.fit_comp(comp); | 234 | self.fit_comp(comp); |
| 213 | } | 235 | } |
| 214 | | 236 | |
| | 237 | /// Groups entered from the root, outermost first; empty at the root graph. |
| | 238 | pub fn scope_path(&self) -> &[NodeId] { |
| | 239 | self.scope.path() |
| | 240 | } |
| | 241 | |
| | 242 | /// Shows the inside of Macro/Group `id`, which must be visible at the current level. |
| | 243 | pub fn enter_group(&mut self, comp: &Comp, id: NodeId) -> bool { |
| | 244 | if !self.scope.enter(comp, id) { |
| | 245 | return false; |
| | 246 | } |
| | 247 | self.scope_switched(comp, None); |
| | 248 | true |
| | 249 | } |
| | 250 | |
| | 251 | /// Keeps the outermost `depth` groups (`0` = root) and selects the group just left. |
| | 252 | pub fn exit_to_depth(&mut self, comp: &Comp, depth: usize) -> bool { |
| | 253 | let Some(left) = self.scope.truncate(comp, depth) else { |
| | 254 | return false; |
| | 255 | }; |
| | 256 | self.scope_switched(comp, Some(left)); |
| | 257 | true |
| | 258 | } |
| | 259 | |
| | 260 | /// Leaves the innermost group. |
| | 261 | pub fn exit_group(&mut self, comp: &Comp) -> bool { |
| | 262 | self.scope.path().len().checked_sub(1).is_some_and(|d| self.exit_to_depth(comp, d)) |
| | 263 | } |
| | 264 | |
| | 265 | fn scope_switched(&mut self, comp: &Comp, select: Option<NodeId>) { |
| | 266 | self.selected.clear(); |
| | 267 | self.selected.extend(select); |
| | 268 | self.primary = select; |
| | 269 | self.hovered_node = None; |
| | 270 | self.hovered_wire = None; |
| | 271 | self.modal = None; |
| | 272 | self.wire_drag = None; |
| | 273 | self.box_select = None; |
| | 274 | self.lmb_drag_node = None; |
| | 275 | self.last_click = None; |
| | 276 | self.fit_comp(comp); |
| | 277 | } |
| | 278 | |
| 215 | /// Removes any stale `NodeId`s from selection/viewed_nodes after undo/redo or deletion. | 279 | /// Removes any stale `NodeId`s from selection/viewed_nodes after undo/redo or deletion. |
| 216 | pub fn sanitize_ids(&mut self, comp: &Comp) { | 280 | pub fn sanitize_ids(&mut self, comp: &Comp) { |
| 217 | let len = comp.nodes.len(); | 281 | let len = comp.nodes.len(); |
| 218 | self.selected.retain(|id| id.0 < len && !comp.nodes[id.0].internal); | 282 | if self.scope.refresh(comp) { |
| 219 | if self.primary.is_some_and(|id| id.0 >= len || comp.nodes[id.0].internal) { | 283 | self.fitted_once = false; |
| | 284 | } |
| | 285 | self.selected.retain(|id| id.0 < len && self.scope.shows(comp.node(*id))); |
| | 286 | if self.primary.is_some_and(|id| id.0 >= len || !self.scope.shows(comp.node(id))) { |
| 220 | self.primary = self.selected.iter().copied().next(); | 287 | self.primary = self.selected.iter().copied().next(); |
| 221 | } | 288 | } |
| 222 | for slot in &mut self.viewed_nodes { | 289 | for slot in &mut self.viewed_nodes { |
| ... | @@ -231,6 +298,7 @@ impl FlowView { | ... | @@ -231,6 +298,7 @@ impl FlowView { |
| 231 | self.modal = None; | 298 | self.modal = None; |
| 232 | self.wire_drag = None; | 299 | self.wire_drag = None; |
| 233 | self.lmb_drag_node = None; | 300 | self.lmb_drag_node = None; |
| | 301 | self.last_click = None; |
| 234 | } | 302 | } |
| 235 | | 303 | |
| 236 | /// Computes a clean world-space spawn position for a newly added node. | 304 | /// Computes a clean world-space spawn position for a newly added node. |
| ... | @@ -251,13 +319,13 @@ impl FlowView { | ... | @@ -251,13 +319,13 @@ impl FlowView { |
| 251 | let ids: Vec<NodeId> = if !self.selected.is_empty() { | 319 | let ids: Vec<NodeId> = if !self.selected.is_empty() { |
| 252 | self.selected.iter().copied().collect() | 320 | self.selected.iter().copied().collect() |
| 253 | } else { | 321 | } else { |
| 254 | comp.nodes.iter().filter(|n| !n.internal).map(|n| n.id).collect() | 322 | self.scope.visible(comp) |
| 255 | }; | 323 | }; |
| 256 | self.fit_ids(comp, ids); | 324 | self.fit_ids(comp, ids); |
| 257 | } | 325 | } |
| 258 | | 326 | |
| 259 | pub fn fit_comp(&mut self, comp: &Comp) { | 327 | pub fn fit_comp(&mut self, comp: &Comp) { |
| 260 | let ids: Vec<NodeId> = comp.nodes.iter().filter(|n| !n.internal).map(|n| n.id).collect(); | 328 | let ids = self.scope.visible(comp); |
| 261 | self.fit_ids(comp, ids); | 329 | self.fit_ids(comp, ids); |
| 262 | } | 330 | } |
| 263 | | 331 | |
| ... | @@ -339,7 +407,7 @@ impl FlowView { | ... | @@ -339,7 +407,7 @@ impl FlowView { |
| 339 | let mut sx = 0.0_f32; | 407 | let mut sx = 0.0_f32; |
| 340 | let mut sy = 0.0_f32; | 408 | let mut sy = 0.0_f32; |
| 341 | let mut count = 0; | 409 | let mut count = 0; |
| 342 | for other in &comp.nodes { | 410 | for other in comp.nodes.iter().filter(|n| self.scope.shows(n)) { |
| 343 | for binding in other.inputs.values() { | 411 | for binding in other.inputs.values() { |
| 344 | if binding.source_op.as_deref() == Some(name.as_str()) { | 412 | if binding.source_op.as_deref() == Some(name.as_str()) { |
| 345 | let dx = other.pos[0] - sp[0]; | 413 | let dx = other.pos[0] - sp[0]; |
| ... | @@ -360,7 +428,7 @@ impl FlowView { | ... | @@ -360,7 +428,7 @@ impl FlowView { |
| 360 | | 428 | |
| 361 | fn hit_node(&self, comp: &Comp, local: [f32; 2]) -> Option<NodeId> { | 429 | fn hit_node(&self, comp: &Comp, local: [f32; 2]) -> Option<NodeId> { |
| 362 | for n in comp.nodes.iter().rev() { | 430 | for n in comp.nodes.iter().rev() { |
| 363 | if n.internal { continue; } | 431 | if !self.scope.shows(n) { continue; } |
| 364 | let r = self.node_rect_local(n.pos); | 432 | let r = self.node_rect_local(n.pos); |
| 365 | if local[0] >= r[0] && local[0] <= r[2] && local[1] >= r[1] && local[1] <= r[3] { | 433 | if local[0] >= r[0] && local[0] <= r[2] && local[1] >= r[1] && local[1] <= r[3] { |
| 366 | return Some(n.id); | 434 | return Some(n.id); |
| ... | @@ -371,7 +439,7 @@ impl FlowView { | ... | @@ -371,7 +439,7 @@ impl FlowView { |
| 371 | | 439 | |
| 372 | fn hit_output_port(&self, comp: &Comp, local: [f32; 2]) -> Option<NodeId> { | 440 | fn hit_output_port(&self, comp: &Comp, local: [f32; 2]) -> Option<NodeId> { |
| 373 | for n in comp.nodes.iter().rev() { | 441 | for n in comp.nodes.iter().rev() { |
| 374 | if n.internal { continue; } | 442 | if !self.scope.shows(n) { continue; } |
| 375 | let r = self.node_rect_local(n.pos); | 443 | let r = self.node_rect_local(n.pos); |
| 376 | let edge = self.node_output_edge(comp, n.id); | 444 | let edge = self.node_output_edge(comp, n.id); |
| 377 | let nrm = edge.normal(); | 445 | let nrm = edge.normal(); |
| ... | @@ -388,7 +456,7 @@ impl FlowView { | ... | @@ -388,7 +456,7 @@ impl FlowView { |
| 388 | | 456 | |
| 389 | fn hit_input_port(&self, comp: &Comp, local: [f32; 2]) -> Option<(NodeId, &'static str)> { | 457 | fn hit_input_port(&self, comp: &Comp, local: [f32; 2]) -> Option<(NodeId, &'static str)> { |
| 390 | for n in comp.nodes.iter().rev() { | 458 | for n in comp.nodes.iter().rev() { |
| 391 | if n.internal { continue; } | 459 | if !self.scope.shows(n) { continue; } |
| 392 | let r = self.node_rect_local(n.pos); | 460 | let r = self.node_rect_local(n.pos); |
| 393 | if local[0] >= r[0] - 10.0 && local[0] <= r[2] + 10.0 && local[1] >= r[1] - 10.0 && local[1] <= r[3] + 10.0 { | 461 | if local[0] >= r[0] - 10.0 && local[0] <= r[2] + 10.0 && local[1] >= r[1] - 10.0 && local[1] <= r[3] + 10.0 { |
| 394 | // Pick Background/Foreground/Mask cleanly based on approach edge for Merge/Displace! | 462 | // Pick Background/Foreground/Mask cleanly based on approach edge for Merge/Displace! |
| ... | @@ -417,10 +485,10 @@ impl FlowView { | ... | @@ -417,10 +485,10 @@ impl FlowView { |
| 417 | fn hit_connected_input_port(&self, comp: &Comp, local: [f32; 2]) -> Option<(NodeId, String, NodeId)> { | 485 | fn hit_connected_input_port(&self, comp: &Comp, local: [f32; 2]) -> Option<(NodeId, String, NodeId)> { |
| 418 | let hit_r2 = 10.5_f32 * 10.5_f32; | 486 | let hit_r2 = 10.5_f32 * 10.5_f32; |
| 419 | for dst in comp.nodes.iter().rev() { | 487 | for dst in comp.nodes.iter().rev() { |
| 420 | if dst.internal { continue; } | 488 | if !self.scope.shows(dst) { continue; } |
| 421 | for (port, binding) in &dst.inputs { | 489 | for (port, binding) in &dst.inputs { |
| 422 | let Some(src_name) = &binding.source_op else { continue }; | 490 | let Some(src_name) = &binding.source_op else { continue }; |
| 423 | let Some(src_id) = comp.find_node(src_name) else { continue }; | 491 | let Some(src_id) = self.scope.resolve(comp, src_name) else { continue }; |
| 424 | let role = PortRole::from_input_name(port); | 492 | let role = PortRole::from_input_name(port); |
| 425 | let (_a, _ae, b, be) = self.wire_endpoints(comp, src_id, dst.id, role); | 493 | let (_a, _ae, b, be) = self.wire_endpoints(comp, src_id, dst.id, role); |
| 426 | let bn = be.normal(); | 494 | let bn = be.normal(); |
| ... | @@ -437,13 +505,13 @@ impl FlowView { | ... | @@ -437,13 +505,13 @@ impl FlowView { |
| 437 | | 505 | |
| 438 | fn hit_wire(&self, comp: &Comp, local: [f32; 2], ignore_node: Option<NodeId>) -> Option<WireRef> { | 506 | fn hit_wire(&self, comp: &Comp, local: [f32; 2], ignore_node: Option<NodeId>) -> Option<WireRef> { |
| 439 | let mut best: Option<(f32, WireRef)> = None; | 507 | let mut best: Option<(f32, WireRef)> = None; |
| 440 | for dst in &comp.nodes { | 508 | for dst in comp.nodes.iter().filter(|n| self.scope.shows(n)) { |
| 441 | if Some(dst.id) == ignore_node { | 509 | if Some(dst.id) == ignore_node { |
| 442 | continue; | 510 | continue; |
| 443 | } | 511 | } |
| 444 | for (port, binding) in &dst.inputs { | 512 | for (port, binding) in &dst.inputs { |
| 445 | let Some(src_name) = &binding.source_op else { continue }; | 513 | let Some(src_name) = &binding.source_op else { continue }; |
| 446 | let Some(src_id) = comp.find_node(src_name) else { continue }; | 514 | let Some(src_id) = self.scope.resolve(comp, src_name) else { continue }; |
| 447 | if Some(src_id) == ignore_node { | 515 | if Some(src_id) == ignore_node { |
| 448 | continue; | 516 | continue; |
| 449 | } | 517 | } |
| ... | @@ -618,10 +686,15 @@ impl FlowView { | ... | @@ -618,10 +686,15 @@ impl FlowView { |
| 618 | let cmd = kmod.super_key() || kmod.control_key(); | 686 | let cmd = kmod.super_key() || kmod.control_key(); |
| 619 | match key { | 687 | match key { |
| 620 | Key::Named(NamedKey::Escape) => { | 688 | Key::Named(NamedKey::Escape) => { |
| 621 | if self.modal.is_some() { | 689 | if self.modal.is_some() || self.wire_drag.is_some() { |
| 622 | self.cancel_modal(comp, history); | 690 | if self.modal.is_some() { |
| | 691 | self.cancel_modal(comp, history); |
| | 692 | } |
| | 693 | self.wire_drag = None; |
| | 694 | } else if self.exit_group(comp) { |
| | 695 | actions.push(FlowAction::SelectionChanged(self.primary)); |
| | 696 | actions.push(FlowAction::ScopeChanged); |
| 623 | } | 697 | } |
| 624 | self.wire_drag = None; | | |
| 625 | } | 698 | } |
| 626 | Key::Named(NamedKey::Enter) => { | 699 | Key::Named(NamedKey::Enter) => { |
| 627 | if self.modal.is_some() { | 700 | if self.modal.is_some() { |
| ... | @@ -629,7 +702,9 @@ impl FlowView { | ... | @@ -629,7 +702,9 @@ impl FlowView { |
| 629 | } | 702 | } |
| 630 | } | 703 | } |
| 631 | Key::Named(NamedKey::Delete) | Key::Named(NamedKey::Backspace) => { | 704 | Key::Named(NamedKey::Delete) | Key::Named(NamedKey::Backspace) => { |
| 632 | if !self.selected.is_empty() { | 705 | if !self.scope.is_root() { |
| | 706 | read_only_notice(actions); |
| | 707 | } else if !self.selected.is_empty() { |
| 633 | let ids: Vec<NodeId> = self.selected.iter().copied().collect(); | 708 | let ids: Vec<NodeId> = self.selected.iter().copied().collect(); |
| 634 | history.push_snapshot(comp, "Delete Nodes"); | 709 | history.push_snapshot(comp, "Delete Nodes"); |
| 635 | let deleted = comp.delete_nodes(&ids); | 710 | let deleted = comp.delete_nodes(&ids); |
| ... | @@ -648,7 +723,9 @@ impl FlowView { | ... | @@ -648,7 +723,9 @@ impl FlowView { |
| 648 | } | 723 | } |
| 649 | } | 724 | } |
| 650 | Key::Named(NamedKey::F2) => { | 725 | Key::Named(NamedKey::F2) => { |
| 651 | if let Some(id) = self.primary { | 726 | if !self.scope.is_root() { |
| | 727 | read_only_notice(actions); |
| | 728 | } else if let Some(id) = self.primary { |
| 652 | actions.push(FlowAction::RequestRename(id)); | 729 | actions.push(FlowAction::RequestRename(id)); |
| 653 | } | 730 | } |
| 654 | } | 731 | } |
| ... | @@ -657,6 +734,15 @@ impl FlowView { | ... | @@ -657,6 +734,15 @@ impl FlowView { |
| 657 | self.viewed_nodes = [None, None]; | 734 | self.viewed_nodes = [None, None]; |
| 658 | actions.push(FlowAction::ClearViewers); | 735 | actions.push(FlowAction::ClearViewers); |
| 659 | } | 736 | } |
| | 737 | "c" if cmd && !kmod.shift_key() => { |
| | 738 | if !self.selected.is_empty() { |
| | 739 | let mut ids: Vec<NodeId> = self.selected.iter().copied().collect(); |
| | 740 | ids.sort_unstable_by_key(|id| id.0); |
| | 741 | actions.push(FlowAction::CopyNodes(ids)); |
| | 742 | } |
| | 743 | } |
| | 744 | "v" if cmd && !kmod.shift_key() => actions.push(FlowAction::PasteNodes), |
| | 745 | "d" if cmd && !kmod.shift_key() && !self.scope.is_root() => read_only_notice(actions), |
| 660 | "d" if cmd && !kmod.shift_key() => { | 746 | "d" if cmd && !kmod.shift_key() => { |
| 661 | if !self.selected.is_empty() { | 747 | if !self.selected.is_empty() { |
| 662 | let ids: Vec<NodeId> = self.selected.iter().copied().collect(); | 748 | let ids: Vec<NodeId> = self.selected.iter().copied().collect(); |
| ... | @@ -681,12 +767,15 @@ impl FlowView { | ... | @@ -681,12 +767,15 @@ impl FlowView { |
| 681 | "f" if kmod.super_key() => self.fit_all(comp), | 767 | "f" if kmod.super_key() => self.fit_all(comp), |
| 682 | "f" if !kmod.super_key() => self.fit_all(comp), | 768 | "f" if !kmod.super_key() => self.fit_all(comp), |
| 683 | "." if !kmod.super_key() => self.fit_all(comp), | 769 | "." if !kmod.super_key() => self.fit_all(comp), |
| | 770 | "g" if !cmd && self.modal.is_none() && !self.scope.is_root() => read_only_notice(actions), |
| 684 | "g" if !cmd && self.modal.is_none() => { | 771 | "g" if !cmd && self.modal.is_none() => { |
| 685 | self.begin_modal(comp, history, TransformMode::Grab); | 772 | self.begin_modal(comp, history, TransformMode::Grab); |
| 686 | } | 773 | } |
| | 774 | "r" if !cmd && self.modal.is_none() && !self.scope.is_root() => read_only_notice(actions), |
| 687 | "r" if !cmd && self.modal.is_none() => { | 775 | "r" if !cmd && self.modal.is_none() => { |
| 688 | self.begin_modal(comp, history, TransformMode::Rotate); | 776 | self.begin_modal(comp, history, TransformMode::Rotate); |
| 689 | } | 777 | } |
| | 778 | "s" if !cmd && self.modal.is_none() && !self.scope.is_root() => read_only_notice(actions), |
| 690 | "s" if !cmd && self.modal.is_none() => { | 779 | "s" if !cmd && self.modal.is_none() => { |
| 691 | self.begin_modal(comp, history, TransformMode::Scale); | 780 | self.begin_modal(comp, history, TransformMode::Scale); |
| 692 | } | 781 | } |
| ... | @@ -703,7 +792,7 @@ impl FlowView { | ... | @@ -703,7 +792,7 @@ impl FlowView { |
| 703 | self.apply_modal(comp, kmod.shift_key()); | 792 | self.apply_modal(comp, kmod.shift_key()); |
| 704 | } | 793 | } |
| 705 | "a" if !kmod.super_key() => { | 794 | "a" if !kmod.super_key() => { |
| 706 | let visible: Vec<NodeId> = comp.nodes.iter().filter(|n| !n.internal).map(|n| n.id).collect(); | 795 | let visible = self.scope.visible(comp); |
| 707 | if self.selected.len() == visible.len() { | 796 | if self.selected.len() == visible.len() { |
| 708 | self.selected.clear(); | 797 | self.selected.clear(); |
| 709 | self.primary = None; | 798 | self.primary = None; |
| ... | @@ -725,6 +814,7 @@ impl FlowView { | ... | @@ -725,6 +814,7 @@ impl FlowView { |
| 725 | actions.push(FlowAction::ViewNode(1, id)); | 814 | actions.push(FlowAction::ViewNode(1, id)); |
| 726 | } | 815 | } |
| 727 | } | 816 | } |
| | 817 | "p" if !kmod.super_key() && !self.scope.is_root() => read_only_notice(actions), |
| 728 | "p" if !kmod.super_key() => { | 818 | "p" if !kmod.super_key() => { |
| 729 | if !self.selected.is_empty() { | 819 | if !self.selected.is_empty() { |
| 730 | let ids: Vec<NodeId> = self.selected.iter().copied().collect(); | 820 | let ids: Vec<NodeId> = self.selected.iter().copied().collect(); |
| ... | @@ -797,7 +887,7 @@ impl FlowView { | ... | @@ -797,7 +887,7 @@ impl FlowView { |
| 797 | }; | 887 | }; |
| 798 | } | 888 | } |
| 799 | } | 889 | } |
| 800 | ui::Event::Button { button, pressed, .. } => { | 890 | ui::Event::Button { button, pressed, at } => { |
| 801 | if button == MouseButton::Middle || (button == MouseButton::Left && modifiers.alt_key()) { | 891 | if button == MouseButton::Middle || (button == MouseButton::Left && modifiers.alt_key()) { |
| 802 | if pressed { | 892 | if pressed { |
| 803 | self.panning = Some((self.pointer_local, self.pan)); | 893 | self.panning = Some((self.pointer_local, self.pan)); |
| ... | @@ -811,7 +901,9 @@ impl FlowView { | ... | @@ -811,7 +901,9 @@ impl FlowView { |
| 811 | self.wire_drag = None; | 901 | self.wire_drag = None; |
| 812 | } else if pressed { | 902 | } else if pressed { |
| 813 | // Right-click a hovered wire or connected input port to disconnect it! | 903 | // Right-click a hovered wire or connected input port to disconnect it! |
| 814 | if let Some(w) = self.hit_wire(comp, self.pointer_local, None) { | 904 | if !self.scope.is_root() { |
| | 905 | read_only_notice(&mut actions); |
| | 906 | } else if let Some(w) = self.hit_wire(comp, self.pointer_local, None) { |
| 815 | history.push_snapshot(comp, "Disconnect"); | 907 | history.push_snapshot(comp, "Disconnect"); |
| 816 | if comp.disconnect(w.dst, &w.port) { | 908 | if comp.disconnect(w.dst, &w.port) { |
| 817 | self.hovered_wire = None; | 909 | self.hovered_wire = None; |
| ... | @@ -828,14 +920,14 @@ impl FlowView { | ... | @@ -828,14 +920,14 @@ impl FlowView { |
| 828 | if pressed { | 920 | if pressed { |
| 829 | if self.modal.is_some() { | 921 | if self.modal.is_some() { |
| 830 | self.confirm_modal(comp, history, &mut actions); | 922 | self.confirm_modal(comp, history, &mut actions); |
| 831 | } else if let Some(src) = self.hit_output_port(comp, self.pointer_local) { | 923 | } else if let Some(src) = self.hit_output_port(comp, self.pointer_local).filter(|_| self.scope.is_root()) { |
| 832 | self.wire_drag = Some(WireDrag { | 924 | self.wire_drag = Some(WireDrag { |
| 833 | src, | 925 | src, |
| 834 | cursor_local: self.pointer_local, | 926 | cursor_local: self.pointer_local, |
| 835 | target: None, | 927 | target: None, |
| 836 | detached_from: None, | 928 | detached_from: None, |
| 837 | }); | 929 | }); |
| 838 | } else if let Some((dst, port, src)) = self.hit_connected_input_port(comp, self.pointer_local) { | 930 | } else if let Some((dst, port, src)) = self.hit_connected_input_port(comp, self.pointer_local).filter(|_| self.scope.is_root()) { |
| 839 | // Dragging an existing input port detaches it so user can drop to disconnect or rewire! | 931 | // Dragging an existing input port detaches it so user can drop to disconnect or rewire! |
| 840 | history.push_snapshot(comp, "Disconnect"); | 932 | history.push_snapshot(comp, "Disconnect"); |
| 841 | comp.disconnect(dst, &port); | 933 | comp.disconnect(dst, &port); |
| ... | @@ -847,6 +939,13 @@ impl FlowView { | ... | @@ -847,6 +939,13 @@ impl FlowView { |
| 847 | detached_from: Some((dst, port)), | 939 | detached_from: Some((dst, port)), |
| 848 | }); | 940 | }); |
| 849 | } else if let Some(nid) = self.hit_node(comp, self.pointer_local) { | 941 | } else if let Some(nid) = self.hit_node(comp, self.pointer_local) { |
| | 942 | let double = self.last_click.is_some_and(|(t, prev)| prev == nid && at.duration_since(t) <= DOUBLE_CLICK); |
| | 943 | self.last_click = Some((at, nid)); |
| | 944 | if double && !modifiers.shift_key() && self.enter_group(comp, nid) { |
| | 945 | actions.push(FlowAction::SelectionChanged(None)); |
| | 946 | actions.push(FlowAction::ScopeChanged); |
| | 947 | return actions; |
| | 948 | } |
| 850 | if modifiers.shift_key() { | 949 | if modifiers.shift_key() { |
| 851 | if !self.selected.remove(&nid) { | 950 | if !self.selected.remove(&nid) { |
| 852 | self.selected.insert(nid); | 951 | self.selected.insert(nid); |
| ... | @@ -862,7 +961,9 @@ impl FlowView { | ... | @@ -862,7 +961,9 @@ impl FlowView { |
| 862 | self.primary = Some(nid); | 961 | self.primary = Some(nid); |
| 863 | } | 962 | } |
| 864 | actions.push(FlowAction::SelectionChanged(self.primary)); | 963 | actions.push(FlowAction::SelectionChanged(self.primary)); |
| 865 | self.lmb_drag_node = Some((nid, self.pointer_local, false)); | 964 | if self.scope.is_root() { |
| | 965 | self.lmb_drag_node = Some((nid, self.pointer_local, false)); |
| | 966 | } |
| 866 | } else { | 967 | } else { |
| 867 | if !modifiers.shift_key() { | 968 | if !modifiers.shift_key() { |
| 868 | self.selected.clear(); | 969 | self.selected.clear(); |
| ... | @@ -913,8 +1014,7 @@ impl FlowView { | ... | @@ -913,8 +1014,7 @@ impl FlowView { |
| 913 | let y0 = bs.start_local[1].min(bs.cur_local[1]); | 1014 | let y0 = bs.start_local[1].min(bs.cur_local[1]); |
| 914 | let y1 = bs.start_local[1].max(bs.cur_local[1]); | 1015 | let y1 = bs.start_local[1].max(bs.cur_local[1]); |
| 915 | if (x1 - x0) > 4.0 || (y1 - y0) > 4.0 { | 1016 | if (x1 - x0) > 4.0 || (y1 - y0) > 4.0 { |
| 916 | for n in &comp.nodes { | 1017 | for n in comp.nodes.iter().filter(|n| self.scope.shows(n)) { |
| 917 | if n.internal { continue; } | | |
| 918 | let c = self.world_to_local(n.pos); | 1018 | let c = self.world_to_local(n.pos); |
| 919 | if c[0] >= x0 && c[0] <= x1 && c[1] >= y0 && c[1] <= y1 { | 1019 | if c[0] >= x0 && c[0] <= x1 && c[1] >= y0 && c[1] <= y1 { |
| 920 | self.selected.insert(n.id); | 1020 | self.selected.insert(n.id); |
| ... | @@ -1005,7 +1105,8 @@ impl FlowView { | ... | @@ -1005,7 +1105,8 @@ impl FlowView { |
| 1005 | .entry("cycle!".to_owned()) | 1105 | .entry("cycle!".to_owned()) |
| 1006 | .or_insert_with(|| make_layout("cycle!", &tiny_font)); | 1106 | .or_insert_with(|| make_layout("cycle!", &tiny_font)); |
| 1007 | for key in [ | 1107 | for key in [ |
| 1008 | "Shift+Space: Add Tool G/R/S: Transform Shift+Drag: Splice Del: Delete Cmd+D: Dup F2: Rename Ctrl+P: Bypass 1/2: Viewer", | 1108 | HUD_ROOT, |
| | 1109 | HUD_GROUP, |
| 1009 | "GRAB [LMB/Enter confirm, RMB/Esc cancel, X/Y axis, Shift: Splice]", | 1110 | "GRAB [LMB/Enter confirm, RMB/Esc cancel, X/Y axis, Shift: Splice]", |
| 1010 | "ROTATE [LMB/Enter confirm, RMB/Esc cancel]", | 1111 | "ROTATE [LMB/Enter confirm, RMB/Esc cancel]", |
| 1011 | "SCALE [LMB/Enter confirm, RMB/Esc cancel, X/Y axis]", | 1112 | "SCALE [LMB/Enter confirm, RMB/Esc cancel, X/Y axis]", |
| ... | @@ -1066,8 +1167,7 @@ impl FlowView { | ... | @@ -1066,8 +1167,7 @@ impl FlowView { |
| 1066 | let out_gap = if large_ports { 2.2 } else { 1.5 }; | 1167 | let out_gap = if large_ports { 2.2 } else { 1.5 }; |
| 1067 | let port_outline = [0.04, 0.04, 0.06, 0.92]; | 1168 | let port_outline = [0.04, 0.04, 0.06, 0.92]; |
| 1068 | | 1169 | |
| 1069 | for dst in &comp.nodes { | 1170 | for dst in comp.nodes.iter().filter(|n| self.scope.shows(n)) { |
| 1070 | if dst.internal { continue; } | | |
| 1071 | // Track used edges on `dst` so multiple inputs on the same edge spread cleanly instead of overlapping | 1171 | // Track used edges on `dst` so multiple inputs on the same edge spread cleanly instead of overlapping |
| 1072 | let mut used_edges: HashMap<u8, usize> = HashMap::new(); | 1172 | let mut used_edges: HashMap<u8, usize> = HashMap::new(); |
| 1073 | let mut sorted_ports: Vec<(&String, &model::InputBinding)> = dst.inputs.iter().collect(); | 1173 | let mut sorted_ports: Vec<(&String, &model::InputBinding)> = dst.inputs.iter().collect(); |
| ... | @@ -1080,7 +1180,7 @@ impl FlowView { | ... | @@ -1080,7 +1180,7 @@ impl FlowView { |
| 1080 | }); | 1180 | }); |
| 1081 | for (port, binding) in sorted_ports { | 1181 | for (port, binding) in sorted_ports { |
| 1082 | let Some(src_name) = &binding.source_op else { continue }; | 1182 | let Some(src_name) = &binding.source_op else { continue }; |
| 1083 | let Some(src_id) = comp.find_node(src_name) else { continue }; | 1183 | let Some(src_id) = self.scope.resolve(comp, src_name) else { continue }; |
| 1084 | let role = PortRole::from_input_name(port); | 1184 | let role = PortRole::from_input_name(port); |
| 1085 | let (a, ae, mut b, mut be) = self.wire_endpoints(comp, src_id, dst.id, role); | 1185 | let (a, ae, mut b, mut be) = self.wire_endpoints(comp, src_id, dst.id, role); |
| 1086 | let ekey = |e: Edge| match e { Edge::Left => 0u8, Edge::Right => 1, Edge::Top => 2, Edge::Bottom => 3 }; | 1186 | let ekey = |e: Edge| match e { Edge::Left => 0u8, Edge::Right => 1, Edge::Top => 2, Edge::Bottom => 3 }; |
| ... | @@ -1212,8 +1312,7 @@ impl FlowView { | ... | @@ -1212,8 +1312,7 @@ impl FlowView { |
| 1212 | } | 1312 | } |
| 1213 | | 1313 | |
| 1214 | // 4. Sleek Thin Fusion-Style Node Bars (color line along BOTTOM!) | 1314 | // 4. Sleek Thin Fusion-Style Node Bars (color line along BOTTOM!) |
| 1215 | for n in &comp.nodes { | 1315 | for n in comp.nodes.iter().filter(|n| self.scope.shows(n)) { |
| 1216 | if n.internal { continue; } | | |
| 1217 | let r = self.node_rect_local(n.pos); | 1316 | let r = self.node_rect_local(n.pos); |
| 1218 | if r[2] < -20.0 || r[0] > w + 20.0 || r[3] < -20.0 || r[1] > h + 20.0 { | 1317 | if r[2] < -20.0 || r[0] > w + 20.0 || r[3] < -20.0 || r[1] > h + 20.0 { |
| 1219 | continue; | 1318 | continue; |
| ... | @@ -1394,7 +1493,8 @@ impl FlowView { | ... | @@ -1394,7 +1493,8 @@ impl FlowView { |
| 1394 | Some(TransformMode::Grab) => "GRAB [LMB/Enter confirm, RMB/Esc cancel, X/Y axis, Shift: Splice]", | 1493 | Some(TransformMode::Grab) => "GRAB [LMB/Enter confirm, RMB/Esc cancel, X/Y axis, Shift: Splice]", |
| 1395 | Some(TransformMode::Rotate) => "ROTATE [LMB/Enter confirm, RMB/Esc cancel]", | 1494 | Some(TransformMode::Rotate) => "ROTATE [LMB/Enter confirm, RMB/Esc cancel]", |
| 1396 | Some(TransformMode::Scale) => "SCALE [LMB/Enter confirm, RMB/Esc cancel, X/Y axis]", | 1495 | Some(TransformMode::Scale) => "SCALE [LMB/Enter confirm, RMB/Esc cancel, X/Y axis]", |
| 1397 | None => "Shift+Space: Add Tool G/R/S: Transform Shift+Drag: Splice Del: Delete Cmd+D: Dup F2: Rename Ctrl+P: Bypass 1/2: Viewer", | 1496 | None if !self.scope.is_root() => HUD_GROUP, |
| | 1497 | None => HUD_ROOT, |
| 1398 | }; | 1498 | }; |
| 1399 | if let Some(l) = self.badge_cache.get(hud_key) { | 1499 | if let Some(l) = self.badge_cache.get(hud_key) { |
| 1400 | let pill_h = 20.0; | 1500 | let pill_h = 20.0; |
| ... | @@ -1416,6 +1516,10 @@ impl FlowView { | ... | @@ -1416,6 +1516,10 @@ impl FlowView { |
| 1416 | } | 1516 | } |
| 1417 | } | 1517 | } |
| 1418 | | 1518 | |
| | 1519 | fn read_only_notice(actions: &mut Vec<FlowAction>) { |
| | 1520 | actions.push(FlowAction::StatusNotice("Group contents are read-only; press Esc to leave the group".to_owned())); |
| | 1521 | } |
| | 1522 | |
| 1419 | /// Static SVG triangles pointing INTO the node edge (`origin` sits flush on the node border). | 1523 | /// Static SVG triangles pointing INTO the node edge (`origin` sits flush on the node border). |
| 1420 | fn input_arrow_svg(edge: Edge, large: bool) -> &'static str { | 1524 | fn input_arrow_svg(edge: Edge, large: bool) -> &'static str { |
| 1421 | match (edge, large) { | 1525 | match (edge, large) { |
| ... | @@ -1605,4 +1709,224 @@ mod tests { | ... | @@ -1605,4 +1709,224 @@ mod tests { |
| 1605 | assert!(p_eff[0] > comp.node(bg).pos[0]); | 1709 | assert!(p_eff[0] > comp.node(bg).pos[0]); |
| 1606 | assert!(p_gen[1] < comp.node(bg).pos[1]); | 1710 | assert!(p_gen[1] < comp.node(bg).pos[1]); |
| 1607 | } | 1711 | } |
| | 1712 | |
| | 1713 | const GROUP_COMP: &str = r#"Composition { |
| | 1714 | Tools = ordered() { |
| | 1715 | BG1 = Background { ViewInfo = OperatorInfo { Pos = { 0, 0 } }, }, |
| | 1716 | Outer = GroupOperator { |
| | 1717 | Outputs = { Output1 = InstanceOutput { SourceOp = "Mid", Source = "Output" }, }, |
| | 1718 | ViewInfo = GroupInfo { Pos = { 200, 0 } }, |
| | 1719 | Tools = ordered() { |
| | 1720 | A = Blur { ViewInfo = OperatorInfo { Pos = { 0, 100 } }, }, |
| | 1721 | ASpline = BezierSpline { KeyFrames = { [0] = { 1, Flags = { Linear = true } } }, }, |
| | 1722 | Mid = Merge { |
| | 1723 | Inputs = { Background = Input { SourceOp = "A", Source = "Output" }, }, |
| | 1724 | ViewInfo = OperatorInfo { Pos = { 110, 100 } }, |
| | 1725 | }, |
| | 1726 | Inner = GroupOperator { |
| | 1727 | ViewInfo = GroupInfo { Pos = { 220, 100 } }, |
| | 1728 | Tools = ordered() { |
| | 1729 | Deep = Blur { ViewInfo = OperatorInfo { Pos = { 0, 50 } }, }, |
| | 1730 | }, |
| | 1731 | }, |
| | 1732 | }, |
| | 1733 | }, |
| | 1734 | A = Background { ViewInfo = OperatorInfo { Pos = { 400, 0 } }, }, |
| | 1735 | }, |
| | 1736 | }"#; |
| | 1737 | |
| | 1738 | fn group_flow() -> (Comp, FlowView) { |
| | 1739 | let comp = Comp::from_fusion_str(GROUP_COMP).expect("parse group comp"); |
| | 1740 | let theme = ui::Theme::new(&theme::KNIFE, true); |
| | 1741 | let mut flow = FlowView::new(&theme); |
| | 1742 | flow.size = [800.0, 600.0]; |
| | 1743 | flow.reset_for_comp(&comp); |
| | 1744 | flow.pan = [0.0, 0.0]; |
| | 1745 | flow.zoom = 1.0; |
| | 1746 | (comp, flow) |
| | 1747 | } |
| | 1748 | |
| | 1749 | fn id(comp: &Comp, name: &str) -> NodeId { |
| | 1750 | comp.find_node(name).unwrap() |
| | 1751 | } |
| | 1752 | |
| | 1753 | fn press(flow: &mut FlowView, comp: &mut Comp, history: &mut CompHistory, at: Instant, node: NodeId) -> Vec<FlowAction> { |
| | 1754 | let local = flow.world_to_local(comp.node(node).pos); |
| | 1755 | flow.input( |
| | 1756 | comp, |
| | 1757 | history, |
| | 1758 | ui::Event::Button { button: MouseButton::Left, pressed: true, at }, |
| | 1759 | [0.0, 0.0, 800.0, 600.0], |
| | 1760 | local, |
| | 1761 | ModifiersState::empty(), |
| | 1762 | ) |
| | 1763 | } |
| | 1764 | |
| | 1765 | fn key(flow: &mut FlowView, comp: &mut Comp, history: &mut CompHistory, key: Key, modifiers: ModifiersState) -> Vec<FlowAction> { |
| | 1766 | flow.input( |
| | 1767 | comp, |
| | 1768 | history, |
| | 1769 | ui::Event::Key { key, text: None, modifiers }, |
| | 1770 | [0.0, 0.0, 800.0, 600.0], |
| | 1771 | [0.0, 0.0], |
| | 1772 | modifiers, |
| | 1773 | ) |
| | 1774 | } |
| | 1775 | |
| | 1776 | #[test] |
| | 1777 | fn group_children_are_direct_tools_only() { |
| | 1778 | let (comp, _) = group_flow(); |
| | 1779 | let names = |g: &str| -> Vec<&str> { |
| | 1780 | group_children(&comp, id(&comp, g)).into_iter().map(|c| comp.node(c).name.as_str()).collect() |
| | 1781 | }; |
| | 1782 | assert_eq!(names("Outer"), ["A", "Mid", "Inner"]); |
| | 1783 | assert_eq!(names("Inner"), ["Deep"]); |
| | 1784 | assert!(group_children(&comp, id(&comp, "BG1")).is_empty()); |
| | 1785 | } |
| | 1786 | |
| | 1787 | #[test] |
| | 1788 | fn enter_and_exit_group_filter_visible_nodes() { |
| | 1789 | let (comp, mut flow) = group_flow(); |
| | 1790 | let (bg, outer, inner) = (id(&comp, "BG1"), id(&comp, "Outer"), id(&comp, "Inner")); |
| | 1791 | let (mid, deep) = (id(&comp, "Mid"), id(&comp, "Deep")); |
| | 1792 | flow.selected.insert(bg); |
| | 1793 | flow.primary = Some(bg); |
| | 1794 | |
| | 1795 | // Root shows only top-level tools; internal tools are not enterable from the root. |
| | 1796 | assert_eq!(flow.hit_node(&comp, flow.world_to_local(comp.node(bg).pos)), Some(bg)); |
| | 1797 | assert_eq!(flow.hit_node(&comp, flow.world_to_local(comp.node(mid).pos)), None); |
| | 1798 | assert!(!flow.enter_group(&comp, mid)); |
| | 1799 | assert!(!flow.enter_group(&comp, bg)); |
| | 1800 | assert!(flow.scope_path().is_empty()); |
| | 1801 | |
| | 1802 | assert!(flow.enter_group(&comp, outer)); |
| | 1803 | assert_eq!(flow.scope_path(), [outer]); |
| | 1804 | assert!(flow.selected.is_empty() && flow.primary.is_none()); |
| | 1805 | assert_eq!(flow.hit_node(&comp, flow.world_to_local(comp.node(mid).pos)), Some(mid)); |
| | 1806 | assert_eq!(flow.hit_node(&comp, flow.world_to_local(comp.node(bg).pos)), None); |
| | 1807 | assert_eq!(flow.hit_node(&comp, flow.world_to_local(comp.node(deep).pos)), None); |
| | 1808 | |
| | 1809 | // Nested group, then back out one level at a time; leaving selects the group left. |
| | 1810 | assert!(flow.enter_group(&comp, inner)); |
| | 1811 | assert_eq!(flow.scope_path(), [outer, inner]); |
| | 1812 | assert_eq!(flow.hit_node(&comp, flow.world_to_local(comp.node(deep).pos)), Some(deep)); |
| | 1813 | assert!(flow.exit_group(&comp)); |
| | 1814 | assert_eq!(flow.scope_path(), [outer]); |
| | 1815 | assert_eq!(flow.primary, Some(inner)); |
| | 1816 | assert!(flow.exit_to_depth(&comp, 0)); |
| | 1817 | assert!(flow.scope_path().is_empty()); |
| | 1818 | assert_eq!(flow.primary, Some(outer)); |
| | 1819 | assert_eq!(flow.selected, HashSet::from([outer])); |
| | 1820 | assert!(!flow.exit_group(&comp)); |
| | 1821 | } |
| | 1822 | |
| | 1823 | #[test] |
| | 1824 | fn wires_resolve_within_the_shown_level() { |
| | 1825 | let (comp, mut flow) = group_flow(); |
| | 1826 | let outer = id(&comp, "Outer"); |
| | 1827 | let (inner_a, root_a) = (comp.nodes.iter().find(|n| n.internal && n.name == "A").unwrap().id, id(&comp, "A")); |
| | 1828 | assert_ne!(inner_a, root_a); |
| | 1829 | assert_eq!(flow.scope.resolve(&comp, "A"), Some(root_a)); |
| | 1830 | flow.enter_group(&comp, outer); |
| | 1831 | assert_eq!(flow.scope.resolve(&comp, "A"), Some(inner_a)); |
| | 1832 | assert_eq!(flow.scope.resolve(&comp, "BG1"), None); |
| | 1833 | |
| | 1834 | // Mid's wire from A is hittable between the two inner nodes. |
| | 1835 | let mid = id(&comp, "Mid"); |
| | 1836 | let mid_pos = comp.node(mid).pos; |
| | 1837 | let a_pos = comp.node(inner_a).pos; |
| | 1838 | let midpoint = [(mid_pos[0] + a_pos[0]) * 0.5, (mid_pos[1] + a_pos[1]) * 0.5]; |
| | 1839 | let wire = flow.hit_wire(&comp, flow.world_to_local(midpoint), None).expect("wire"); |
| | 1840 | assert_eq!((wire.src, wire.dst), (inner_a, mid)); |
| | 1841 | } |
| | 1842 | |
| | 1843 | #[test] |
| | 1844 | fn double_click_enters_group_and_escape_leaves() { |
| | 1845 | let (mut comp, mut flow) = group_flow(); |
| | 1846 | let mut history = CompHistory::new(); |
| | 1847 | let (bg, outer) = (id(&comp, "BG1"), id(&comp, "Outer")); |
| | 1848 | let t0 = Instant::now(); |
| | 1849 | |
| | 1850 | // Double-clicking a plain tool, or two slow clicks on a group, never enters. |
| | 1851 | press(&mut flow, &mut comp, &mut history, t0, bg); |
| | 1852 | press(&mut flow, &mut comp, &mut history, t0 + Duration::from_millis(100), bg); |
| | 1853 | assert!(flow.scope_path().is_empty()); |
| | 1854 | press(&mut flow, &mut comp, &mut history, t0, outer); |
| | 1855 | press(&mut flow, &mut comp, &mut history, t0 + Duration::from_millis(900), outer); |
| | 1856 | assert!(flow.scope_path().is_empty()); |
| | 1857 | |
| | 1858 | let acts = press(&mut flow, &mut comp, &mut history, t0 + Duration::from_millis(1000), outer); |
| | 1859 | assert_eq!(flow.scope_path(), [outer]); |
| | 1860 | assert!(acts.iter().any(|a| matches!(a, FlowAction::ScopeChanged))); |
| | 1861 | |
| | 1862 | let acts = key(&mut flow, &mut comp, &mut history, Key::Named(NamedKey::Escape), ModifiersState::empty()); |
| | 1863 | assert!(flow.scope_path().is_empty()); |
| | 1864 | assert!(acts.iter().any(|a| matches!(a, FlowAction::ScopeChanged))); |
| | 1865 | assert_eq!(flow.primary, Some(outer)); |
| | 1866 | |
| | 1867 | // Escape at the root does nothing. |
| | 1868 | let acts = key(&mut flow, &mut comp, &mut history, Key::Named(NamedKey::Escape), ModifiersState::empty()); |
| | 1869 | assert!(acts.is_empty()); |
| | 1870 | } |
| | 1871 | |
| | 1872 | #[test] |
| | 1873 | fn group_view_is_read_only_but_copyable() { |
| | 1874 | let (mut comp, mut flow) = group_flow(); |
| | 1875 | let mut history = CompHistory::new(); |
| | 1876 | let (outer, mid) = (id(&comp, "Outer"), id(&comp, "Mid")); |
| | 1877 | flow.enter_group(&comp, outer); |
| | 1878 | flow.selected.insert(mid); |
| | 1879 | flow.primary = Some(mid); |
| | 1880 | let nodes = comp.nodes.len(); |
| | 1881 | |
| | 1882 | for k in ["g", "p"] { |
| | 1883 | let acts = key(&mut flow, &mut comp, &mut history, Key::Character(k.into()), ModifiersState::empty()); |
| | 1884 | assert!(matches!(acts.as_slice(), [FlowAction::StatusNotice(_)]), "{k}"); |
| | 1885 | } |
| | 1886 | let acts = key(&mut flow, &mut comp, &mut history, Key::Named(NamedKey::Delete), ModifiersState::empty()); |
| | 1887 | assert!(matches!(acts.as_slice(), [FlowAction::StatusNotice(_)])); |
| | 1888 | let acts = key(&mut flow, &mut comp, &mut history, Key::Character("d".into()), ModifiersState::SUPER); |
| | 1889 | assert!(matches!(acts.as_slice(), [FlowAction::StatusNotice(_)])); |
| | 1890 | assert_eq!(comp.nodes.len(), nodes); |
| | 1891 | assert!(!comp.node(mid).bypassed); |
| | 1892 | assert!(!history.can_undo()); |
| | 1893 | |
| | 1894 | let acts = key(&mut flow, &mut comp, &mut history, Key::Character("c".into()), ModifiersState::SUPER); |
| | 1895 | assert!(matches!(acts.as_slice(), [FlowAction::CopyNodes(ids)] if ids == &[mid])); |
| | 1896 | } |
| | 1897 | |
| | 1898 | #[test] |
| | 1899 | fn copy_and_paste_shortcuts_emit_requests() { |
| | 1900 | let (mut comp, mut flow) = group_flow(); |
| | 1901 | let mut history = CompHistory::new(); |
| | 1902 | let bg = id(&comp, "BG1"); |
| | 1903 | |
| | 1904 | let none = key(&mut flow, &mut comp, &mut history, Key::Character("c".into()), ModifiersState::SUPER); |
| | 1905 | assert!(none.is_empty(), "nothing selected, nothing to copy"); |
| | 1906 | |
| | 1907 | flow.selected.insert(bg); |
| | 1908 | flow.primary = Some(bg); |
| | 1909 | let acts = key(&mut flow, &mut comp, &mut history, Key::Character("c".into()), ModifiersState::SUPER); |
| | 1910 | assert!(matches!(acts.as_slice(), [FlowAction::CopyNodes(ids)] if ids == &[bg])); |
| | 1911 | let acts = key(&mut flow, &mut comp, &mut history, Key::Character("v".into()), ModifiersState::SUPER); |
| | 1912 | assert!(matches!(acts.as_slice(), [FlowAction::PasteNodes])); |
| | 1913 | // Plain `c` / `v` are not shortcuts. |
| | 1914 | let acts = key(&mut flow, &mut comp, &mut history, Key::Character("v".into()), ModifiersState::empty()); |
| | 1915 | assert!(acts.is_empty()); |
| | 1916 | } |
| | 1917 | |
| | 1918 | #[test] |
| | 1919 | fn sanitize_drops_scope_levels_that_no_longer_exist() { |
| | 1920 | let (comp, mut flow) = group_flow(); |
| | 1921 | let (outer, inner) = (id(&comp, "Outer"), id(&comp, "Inner")); |
| | 1922 | flow.enter_group(&comp, outer); |
| | 1923 | flow.enter_group(&comp, inner); |
| | 1924 | flow.sanitize_ids(&comp); |
| | 1925 | assert_eq!(flow.scope_path(), [outer, inner]); |
| | 1926 | |
| | 1927 | let flat = test_comp(); |
| | 1928 | flow.sanitize_ids(&flat); |
| | 1929 | assert!(flow.scope_path().is_empty()); |
| | 1930 | assert!(flow.selected.is_empty()); |
| | 1931 | } |
| 1608 | } | 1932 | } |