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

[Feature] Allow more complexe gestures #146

Open ndegheselle opened 1 week ago

ndegheselle commented 1 week ago

Hi, would like to have more customizable / complexe gestures for states.

Problem : Users are used to the navigation of softwares like photoshop or paint.net and want the same feel (Ctrl + Scroll = zoom, Left Click + Space = Pan, Scroll = Pan vertically, Scroll + Shift = Pan horizontally).

Solution : Allow more complexe gestures on states :

Here is a fork feature/extended-gestures where I did one possible implementation of that, there is still some things that could be checked :

Unrelated in the fork : I also added custom cursors for panning which is unrelated but would be cool

miroiu commented 1 week ago

Hi, the following code allows zooming with Ctrl + Scroll and panning with Space + Left Click in the playground app:

Click to expand code block ```csharp public partial class NodifyEditorView : UserControl { public NodifyEditor EditorInstance => Editor; private EditorGestures DefaultEditorGestures { get; set; } public NodifyEditorView() { InitializeComponent(); DefaultEditorGestures = new EditorGestures(); DefaultEditorGestures.Editor.ZoomModifierKey = ModifierKeys.Control; EditorGestures.Mappings.Apply(DefaultEditorGestures); } private void Minimap_Zoom(object sender, ZoomEventArgs e) { EditorInstance.ZoomAtPosition(e.Zoom, e.Location); } protected override void OnKeyDown(KeyEventArgs e) { if (e.Key == Key.Space) { EditorGestures.Mappings.Apply(PanningGestureMappings.Instance); Cursor = Cursors.Hand; } } protected override void OnKeyUp(KeyEventArgs e) { if (e.Key == Key.Space) { EditorGestures.Mappings.Apply(DefaultEditorGestures); Cursor = Cursors.Arrow; } } } internal class PanningGestureMappings : EditorGestures { public static readonly PanningGestureMappings Instance = new PanningGestureMappings(); public PanningGestureMappings() { Editor.Pan.Value = new AnyGesture(new MouseGesture(MouseAction.LeftClick)); Editor.Selection.Apply(SelectionGestures.None); Editor.Cutting.Value = MultiGesture.None; ItemContainer.Selection.Apply(SelectionGestures.None); ItemContainer.Drag.Value = MultiGesture.None; Connector.Connect.Value = MultiGesture.None; } } ```

Things I need to think about: