-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
WIP: add gizmo registry with lookup for all 6 shape node types #4143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Ayush2k02
wants to merge
6
commits into
GraphiteEditor:master
Choose a base branch
from
Ayush2k02:feature/gizmo-registry
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
81a1328
Add gizmo registry with lookup for all 6 shape node types
Ayush2k02 249267f
Refactor get_gizmo_info to deduplicate GizmoInfo construction
Ayush2k02 9d32423
Replace hardcoded input indices with generated INDEX constants
Ayush2k02 f6bc465
Expand slider min validation test to cover arc and spiral
Ayush2k02 d1088c5
Remove unused NodeInputDecleration import
Ayush2k02 49695b2
Restore NodeInputDecleration import needed for INDEX trait
Ayush2k02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
358 changes: 358 additions & 0 deletions
358
editor/src/messages/tool/common_functionality/gizmos/gizmo_registry.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,358 @@ | ||
| use crate::messages::portfolio::document::node_graph::document_node_definitions::DefinitionIdentifier; | ||
| use graphene_std::{NodeInputDecleration, ProtoNodeIdentifier}; | ||
|
|
||
| /// Describes how a gizmo handle should be positioned relative to the shape. | ||
| #[derive(Clone, Debug, PartialEq)] | ||
| pub enum PositionHint { | ||
| /// Positioned at the center of the shape's bounding box. | ||
| BoundingBoxCenter, | ||
| /// Positioned at the edge of the shape's bounding box (e.g., midpoint of a side). | ||
| BoundingBoxEdge, | ||
| /// Positioned at a corner of the shape's bounding box. | ||
| BoundingBoxCorner, | ||
| /// Position derived from a specific parameter value (e.g., a radius endpoint). | ||
| /// The `usize` refers to the input index whose value determines the position. | ||
| ParameterDerived(usize), | ||
| } | ||
|
|
||
| /// The kind of interactive control a gizmo provides. | ||
| #[derive(Clone, Debug, PartialEq)] | ||
| pub enum GizmoType { | ||
| /// A linear slider controlling an `f64` parameter (e.g., radius, blur amount). | ||
| Slider, | ||
| /// A circular dial controlling a `u32` parameter (e.g., number of sides/points). | ||
| Dial, | ||
| /// A 2D position handle controlling a `DVec2` parameter (e.g., offset, center). | ||
| Position, | ||
| /// A rotary handle controlling an angle in degrees (`f64`). | ||
| Angle, | ||
| } | ||
|
|
||
| /// Metadata describing a single gizmo-enabled parameter on a node. | ||
| #[derive(Clone, Debug, PartialEq)] | ||
| pub struct GizmoParameterInfo { | ||
| /// Human-readable name of the parameter (e.g., "Radius", "Sides"). | ||
| pub name: &'static str, | ||
| /// The node input index this gizmo controls. | ||
| pub input_index: usize, | ||
| /// What kind of gizmo to display. | ||
| pub gizmo_type: GizmoType, | ||
| /// Where to position the gizmo handle on the canvas. | ||
| pub position_hint: PositionHint, | ||
| /// Optional minimum value constraint. | ||
| pub min: Option<f64>, | ||
| /// Optional maximum value constraint. | ||
| pub max: Option<f64>, | ||
| } | ||
|
|
||
| /// All gizmo information for a particular node type. | ||
| #[derive(Clone, Debug, PartialEq)] | ||
| pub struct GizmoInfo { | ||
| /// The node identifier this info applies to. | ||
| pub node_identifier: ProtoNodeIdentifier, | ||
| /// The gizmo-enabled parameters for this node. | ||
| pub parameters: Vec<GizmoParameterInfo>, | ||
| } | ||
|
|
||
| /// Returns gizmo metadata for a given node type, if it has gizmo-enabled parameters. | ||
| /// | ||
| /// This is the central registry that maps node types to their interactive gizmo descriptions. | ||
| /// When a new node should support gizmos, add an entry here. | ||
| pub fn get_gizmo_info(identifier: &DefinitionIdentifier) -> Option<GizmoInfo> { | ||
| let DefinitionIdentifier::ProtoNode(proto_id) = identifier else { | ||
| return None; | ||
| }; | ||
|
|
||
| if *proto_id == graphene_std::vector::generator_nodes::star::IDENTIFIER { | ||
| return Some(GizmoInfo { | ||
| node_identifier: proto_id.clone(), | ||
| parameters: vec![ | ||
| GizmoParameterInfo { | ||
| name: "Sides", | ||
| input_index: 1, | ||
| gizmo_type: GizmoType::Dial, | ||
| position_hint: PositionHint::BoundingBoxCenter, | ||
| min: Some(3.0), | ||
| max: None, | ||
| }, | ||
| GizmoParameterInfo { | ||
| name: "Outer Radius", | ||
| input_index: 2, | ||
| gizmo_type: GizmoType::Slider, | ||
| position_hint: PositionHint::ParameterDerived(2), | ||
| min: Some(0.0), | ||
| max: None, | ||
| }, | ||
| GizmoParameterInfo { | ||
| name: "Inner Radius", | ||
| input_index: 3, | ||
| gizmo_type: GizmoType::Slider, | ||
| position_hint: PositionHint::ParameterDerived(3), | ||
| min: Some(0.0), | ||
| max: None, | ||
| }, | ||
| ], | ||
| }); | ||
| } | ||
|
Ayush2k02 marked this conversation as resolved.
Outdated
|
||
|
|
||
| if *proto_id == graphene_std::vector::generator_nodes::regular_polygon::IDENTIFIER { | ||
| return Some(GizmoInfo { | ||
| node_identifier: proto_id.clone(), | ||
| parameters: vec![ | ||
| GizmoParameterInfo { | ||
| name: "Sides", | ||
| input_index: 1, | ||
| gizmo_type: GizmoType::Dial, | ||
| position_hint: PositionHint::BoundingBoxCenter, | ||
| min: Some(3.0), | ||
| max: None, | ||
| }, | ||
| GizmoParameterInfo { | ||
| name: "Radius", | ||
| input_index: 2, | ||
| gizmo_type: GizmoType::Slider, | ||
| position_hint: PositionHint::ParameterDerived(2), | ||
| min: Some(0.0), | ||
| max: None, | ||
| }, | ||
| ], | ||
| }); | ||
| } | ||
|
|
||
| if *proto_id == graphene_std::vector::generator_nodes::arc::IDENTIFIER { | ||
| return Some(GizmoInfo { | ||
| node_identifier: proto_id.clone(), | ||
| parameters: vec![ | ||
| GizmoParameterInfo { | ||
| name: "Radius", | ||
| input_index: 1, | ||
| gizmo_type: GizmoType::Slider, | ||
| position_hint: PositionHint::ParameterDerived(1), | ||
| min: Some(0.0), | ||
| max: None, | ||
| }, | ||
| GizmoParameterInfo { | ||
| name: "Start Angle", | ||
| input_index: 2, | ||
| gizmo_type: GizmoType::Angle, | ||
| position_hint: PositionHint::ParameterDerived(2), | ||
| min: Some(0.0), | ||
| max: Some(360.0), | ||
| }, | ||
| GizmoParameterInfo { | ||
| name: "Sweep Angle", | ||
| input_index: 3, | ||
| gizmo_type: GizmoType::Angle, | ||
| position_hint: PositionHint::ParameterDerived(3), | ||
| min: Some(-360.0), | ||
| max: Some(360.0), | ||
| }, | ||
| ], | ||
| }); | ||
| } | ||
|
|
||
| if *proto_id == graphene_std::vector::generator_nodes::circle::IDENTIFIER { | ||
| return Some(GizmoInfo { | ||
| node_identifier: proto_id.clone(), | ||
| parameters: vec![GizmoParameterInfo { | ||
| name: "Radius", | ||
| input_index: 1, | ||
| gizmo_type: GizmoType::Slider, | ||
| position_hint: PositionHint::ParameterDerived(1), | ||
| min: Some(0.0), | ||
| max: None, | ||
| }], | ||
| }); | ||
| } | ||
|
|
||
| if *proto_id == graphene_std::vector::generator_nodes::grid::IDENTIFIER { | ||
| use graphene_std::vector::generator_nodes::grid::*; | ||
| return Some(GizmoInfo { | ||
| node_identifier: proto_id.clone(), | ||
| parameters: vec![ | ||
| GizmoParameterInfo { | ||
| name: "Columns", | ||
| input_index: ColumnsInput::INDEX, | ||
| gizmo_type: GizmoType::Dial, | ||
| position_hint: PositionHint::BoundingBoxEdge, | ||
| min: Some(1.0), | ||
| max: None, | ||
| }, | ||
| GizmoParameterInfo { | ||
| name: "Rows", | ||
| input_index: RowsInput::INDEX, | ||
| gizmo_type: GizmoType::Dial, | ||
| position_hint: PositionHint::BoundingBoxEdge, | ||
| min: Some(1.0), | ||
| max: None, | ||
| }, | ||
| ], | ||
| }); | ||
| } | ||
|
|
||
| if *proto_id == graphene_std::vector::generator_nodes::spiral::IDENTIFIER { | ||
| use graphene_std::vector::generator_nodes::spiral::*; | ||
| return Some(GizmoInfo { | ||
| node_identifier: proto_id.clone(), | ||
| parameters: vec![ | ||
| GizmoParameterInfo { | ||
| name: "Turns", | ||
| input_index: TurnsInput::INDEX, | ||
| gizmo_type: GizmoType::Slider, | ||
| position_hint: PositionHint::ParameterDerived(TurnsInput::INDEX), | ||
| min: Some(0.0), | ||
| max: None, | ||
| }, | ||
| GizmoParameterInfo { | ||
| name: "Outer Radius", | ||
| input_index: OuterRadiusInput::INDEX, | ||
| gizmo_type: GizmoType::Slider, | ||
| position_hint: PositionHint::ParameterDerived(OuterRadiusInput::INDEX), | ||
| min: Some(0.0), | ||
| max: None, | ||
| }, | ||
| ], | ||
| }); | ||
| } | ||
|
|
||
| None | ||
| } | ||
|
Ayush2k02 marked this conversation as resolved.
|
||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| fn def_id(proto: &ProtoNodeIdentifier) -> DefinitionIdentifier { | ||
| DefinitionIdentifier::ProtoNode(proto.clone()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn star_registry_entry_exists() { | ||
| let info = get_gizmo_info(&def_id(&graphene_std::vector::generator_nodes::star::IDENTIFIER)); | ||
| assert!(info.is_some(), "Star should have a registry entry"); | ||
| let info = info.unwrap(); | ||
| assert_eq!(info.parameters.len(), 3); | ||
| assert_eq!(info.parameters[0].name, "Sides"); | ||
| assert_eq!(info.parameters[0].gizmo_type, GizmoType::Dial); | ||
| assert_eq!(info.parameters[1].name, "Outer Radius"); | ||
| assert_eq!(info.parameters[1].gizmo_type, GizmoType::Slider); | ||
| assert_eq!(info.parameters[2].name, "Inner Radius"); | ||
| assert_eq!(info.parameters[2].input_index, 3); | ||
| } | ||
|
|
||
| #[test] | ||
| fn polygon_registry_entry_exists() { | ||
| let info = get_gizmo_info(&def_id(&graphene_std::vector::generator_nodes::regular_polygon::IDENTIFIER)); | ||
| assert!(info.is_some(), "Polygon should have a registry entry"); | ||
| let info = info.unwrap(); | ||
| assert_eq!(info.parameters.len(), 2); | ||
| assert_eq!(info.parameters[0].name, "Sides"); | ||
| assert_eq!(info.parameters[0].min, Some(3.0)); | ||
| assert_eq!(info.parameters[1].name, "Radius"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn arc_registry_entry_exists() { | ||
| let info = get_gizmo_info(&def_id(&graphene_std::vector::generator_nodes::arc::IDENTIFIER)); | ||
| assert!(info.is_some(), "Arc should have a registry entry"); | ||
| let info = info.unwrap(); | ||
| assert_eq!(info.parameters.len(), 3); | ||
| assert_eq!(info.parameters[0].name, "Radius"); | ||
| assert_eq!(info.parameters[0].gizmo_type, GizmoType::Slider); | ||
| assert_eq!(info.parameters[1].name, "Start Angle"); | ||
| assert_eq!(info.parameters[1].gizmo_type, GizmoType::Angle); | ||
| assert_eq!(info.parameters[2].name, "Sweep Angle"); | ||
| assert_eq!(info.parameters[2].gizmo_type, GizmoType::Angle); | ||
| assert_eq!(info.parameters[2].min, Some(-360.0)); | ||
| assert_eq!(info.parameters[2].max, Some(360.0)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn circle_registry_entry_exists() { | ||
| let info = get_gizmo_info(&def_id(&graphene_std::vector::generator_nodes::circle::IDENTIFIER)); | ||
| assert!(info.is_some(), "Circle should have a registry entry"); | ||
| let info = info.unwrap(); | ||
| assert_eq!(info.parameters.len(), 1); | ||
| assert_eq!(info.parameters[0].name, "Radius"); | ||
| assert_eq!(info.parameters[0].min, Some(0.0)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn grid_registry_entry_exists() { | ||
| let info = get_gizmo_info(&def_id(&graphene_std::vector::generator_nodes::grid::IDENTIFIER)); | ||
| assert!(info.is_some(), "Grid should have a registry entry"); | ||
| let info = info.unwrap(); | ||
| assert_eq!(info.parameters.len(), 2); | ||
| assert_eq!(info.parameters[0].name, "Columns"); | ||
| assert_eq!(info.parameters[0].gizmo_type, GizmoType::Dial); | ||
| assert_eq!(info.parameters[1].name, "Rows"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn spiral_registry_entry_exists() { | ||
| let info = get_gizmo_info(&def_id(&graphene_std::vector::generator_nodes::spiral::IDENTIFIER)); | ||
| assert!(info.is_some(), "Spiral should have a registry entry"); | ||
| let info = info.unwrap(); | ||
| assert_eq!(info.parameters.len(), 2); | ||
| assert_eq!(info.parameters[0].name, "Turns"); | ||
| assert_eq!(info.parameters[1].name, "Outer Radius"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn unknown_node_returns_none() { | ||
| let fake_id = ProtoNodeIdentifier::new("fake::nonexistent::node"); | ||
| let info = get_gizmo_info(&def_id(&fake_id)); | ||
| assert!(info.is_none(), "Unknown node should return None"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn all_six_shapes_registered() { | ||
| let identifiers = [ | ||
| graphene_std::vector::generator_nodes::star::IDENTIFIER, | ||
| graphene_std::vector::generator_nodes::regular_polygon::IDENTIFIER, | ||
| graphene_std::vector::generator_nodes::arc::IDENTIFIER, | ||
| graphene_std::vector::generator_nodes::circle::IDENTIFIER, | ||
| graphene_std::vector::generator_nodes::grid::IDENTIFIER, | ||
| graphene_std::vector::generator_nodes::spiral::IDENTIFIER, | ||
| ]; | ||
| for id in &identifiers { | ||
| assert!(get_gizmo_info(&def_id(&*id)).is_some(), "Shape with identifier {:?} should be registered", id); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn parameter_indices_are_valid() { | ||
| // Verify no parameter has input_index 0 (which is typically the primary input, not a parameter) | ||
| let identifiers = [ | ||
| graphene_std::vector::generator_nodes::star::IDENTIFIER, | ||
| graphene_std::vector::generator_nodes::regular_polygon::IDENTIFIER, | ||
| graphene_std::vector::generator_nodes::arc::IDENTIFIER, | ||
| graphene_std::vector::generator_nodes::circle::IDENTIFIER, | ||
| graphene_std::vector::generator_nodes::grid::IDENTIFIER, | ||
| graphene_std::vector::generator_nodes::spiral::IDENTIFIER, | ||
| ]; | ||
| for id in &identifiers { | ||
| let info = get_gizmo_info(&def_id(&*id)).unwrap(); | ||
| for param in &info.parameters { | ||
| assert!(param.input_index >= 1, "Parameter '{}' has input_index 0, which is typically the primary input", param.name); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn slider_gizmos_have_non_negative_min() { | ||
| let identifiers = [ | ||
| graphene_std::vector::generator_nodes::star::IDENTIFIER, | ||
| graphene_std::vector::generator_nodes::regular_polygon::IDENTIFIER, | ||
| graphene_std::vector::generator_nodes::circle::IDENTIFIER, | ||
| ]; | ||
|
Ayush2k02 marked this conversation as resolved.
|
||
| for id in &identifiers { | ||
| let info = get_gizmo_info(&def_id(&*id)).unwrap(); | ||
| for param in &info.parameters { | ||
| if param.gizmo_type == GizmoType::Slider { | ||
| assert!(param.min.unwrap_or(0.0) >= 0.0, "Slider '{}' should have non-negative min", param.name); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| pub mod gizmo_manager; | ||
| pub mod gizmo_registry; | ||
| pub mod shape_gizmos; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.