miroiu / nodify

Highly performant and modular controls for node-based editors designed for data-binding and MVVM.
https://miroiu.github.io/nodify
MIT License
1.38k stars 224 forks source link

Allow changing editor gestures at runtime #104

Closed miroiu closed 6 months ago

miroiu commented 6 months ago

📝 Description of the Change

This PR aims to provide more options for customizing the editor gestures at runtime (see the Playground app for a simple example).

The EditorGestures class is now a singleton and can be accessed through EditorGestures.Mappings which allows customizing the editor gestures in a couple of ways:

// multiple gestures EditorGestures.Mappings.Editor.Selection.Apply(new SelectionGestures(MouseAction.RightClick)); EditorGestures.Mappings.ItemContainer.Apply(new ItemContainerGestures());

- define templates that you can apply to the EditorGestures.Mappings 
```csharp
public class Blender3DInputMappings : EditorGestures
{
    public Blender3DInputMappings()
    {
        Editor.Pan.Value = new AnyGesture(new MouseGesture(MouseAction.LeftClick), new MouseGesture(MouseAction.MiddleClick));
        Editor.Selection.Apply(new SelectionGestures(MouseAction.RightClick));
        ItemContainer.Selection.Apply(Editor.Selection);
    }
}

// apply custom gesture mappings
EditorGestures.Mappings.Apply(new Blender3DInputMappings());

// note that you can reset the gestures as follows
EditorGestures.Mappings.Apply(new EditorGestures());

You can also inherit from SelectionGestures, ItemContainerGestures, NodifyEditorGestures, ConnectorGestures, ConnectionGestures, and GroupingNodeGestures or simply create an instance and customize it. These can be applied in the same way:

EditorGestures.Mappings.ItemContainer.Apply(new ItemContainerGestures());