33
44namespace Nodify
55{
6+ /// <summary>
7+ /// Represents an abstract base class for managing drag operations within a UI element.
8+ /// Provides a framework for handling input gestures such as starting, canceling, and completing drag operations.
9+ /// </summary>
10+ /// <typeparam name="TElement">The type of <see cref="FrameworkElement"/> that owns the state.</typeparam>
611 public abstract class DragState < TElement > : InputElementState < TElement > , IInputHandler
712 where TElement : FrameworkElement
813 {
14+ /// <summary>
15+ /// Gets the gesture used to cancel the drag operation, if defined.
16+ /// </summary>
917 protected InputGesture ? CancelGesture { get ; }
18+
19+ /// <summary>
20+ /// Gets the gesture used to begin the drag operation.
21+ /// </summary>
1022 protected InputGesture BeginGesture { get ; }
1123
24+ /// <summary>
25+ /// Indicates whether the element has a context menu associated with it.
26+ /// </summary>
27+ /// <remarks>This property is used to suppress the context menu when a drag operation is performed using the right mouse button.</remarks>
1228 protected virtual bool HasContextMenu => Element . ContextMenu != null ;
29+
30+ /// <summary>
31+ /// Determines if the drag operation can begin (see <see cref="OnBegin(InputEventArgs)"/>).
32+ /// </summary>
1333 protected virtual bool CanBegin { get ; } = true ;
34+
35+ /// <summary>
36+ /// Determines if the drag operation can be canceled (see <see cref="OnCancel(InputEventArgs)"/>).
37+ /// </summary>
1438 protected virtual bool CanCancel { get ; } = true ;
39+
40+ /// <summary>
41+ /// Indicates if the drag gesture is a toggle, meaning the same gesture can be used to both start and stop the operation.
42+ /// </summary>
1543 protected virtual bool IsToggle { get ; }
44+
45+ /// <summary>
46+ /// Gets or sets the UI element used to calculate the mouse position during the drag operation.
47+ /// </summary>
1648 protected IInputElement PositionElement { get ; set ; }
1749
1850 private bool _canReceiveInput ;
1951 private Point _initialPosition ;
2052
21- /// <summary>Constructs a new <see cref="EditorState"/>.</summary>
22- /// <param name="element">The owner of the state.</param>
53+ /// <summary>
54+ /// Initializes a new instance of the <see cref="DragState{TElement}"/> class with a begin gesture.
55+ /// </summary>
56+ /// <param name="element">The element associated with this state.</param>
57+ /// <param name="beginGesture">The gesture used to start the drag operation.</param>
2358 public DragState ( TElement element , InputGesture beginGesture ) : base ( element )
2459 {
2560 BeginGesture = beginGesture ;
2661 PositionElement = element ;
2762 }
2863
64+ /// <summary>
65+ /// Initializes a new instance of the <see cref="DragState{TElement}"/> class with begin and cancel gestures.
66+ /// </summary>
67+ /// <param name="element">The element associated with this state.</param>
68+ /// <param name="beginGesture">The gesture used to start the drag operation.</param>
69+ /// <param name="cancelGesture">The gesture used to cancel the drag operation.</param>
2970 public DragState ( TElement element , InputGesture beginGesture , InputGesture cancelGesture )
3071 : this ( element , beginGesture )
3172 {
@@ -116,6 +157,11 @@ private void EndDrag(InputEventArgs e)
116157 }
117158 }
118159
160+ /// <summary>
161+ /// Determines if the given input event represents the release of an input gesture.
162+ /// </summary>
163+ /// <param name="e">The input event to evaluate.</param>
164+ /// <returns>True if the event represents the release of a gesture; otherwise, false.</returns>
119165 protected virtual bool IsInputEventReleased ( InputEventArgs e )
120166 {
121167 if ( e is MouseButtonEventArgs mbe && mbe . ButtonState == MouseButtonState . Released )
@@ -130,6 +176,11 @@ protected virtual bool IsInputEventReleased(InputEventArgs e)
130176 return false ;
131177 }
132178
179+ /// <summary>
180+ /// Determines if the given input event represents the press of an input gesture.
181+ /// </summary>
182+ /// <param name="e">The input event to evaluate.</param>
183+ /// <returns>True if the event represents the press of a gesture; otherwise, false.</returns>
133184 protected virtual bool IsInputEventPressed ( InputEventArgs e )
134185 {
135186 if ( e is MouseButtonEventArgs mbe && mbe . ButtonState == MouseButtonState . Pressed )
@@ -144,14 +195,26 @@ protected virtual bool IsInputEventPressed(InputEventArgs e)
144195 return false ;
145196 }
146197
198+ /// <summary>
199+ /// Called when the drag operation begins. Override to provide custom behavior.
200+ /// </summary>
201+ /// <param name="e">The input event that started the operation.</param>
147202 protected virtual void OnBegin ( InputEventArgs e )
148203 {
149204 }
150205
206+ /// <summary>
207+ /// Called when the drag operation ends. Override to provide custom behavior.
208+ /// </summary>
209+ /// <param name="e">The input event that ended the operation.</param>
151210 protected virtual void OnEnd ( InputEventArgs e )
152211 {
153212 }
154213
214+ /// <summary>
215+ /// Called when the drag operation is canceled. Override to provide custom behavior.
216+ /// </summary>
217+ /// <param name="e">The input event that canceled the operation.</param>
155218 protected virtual void OnCancel ( InputEventArgs e )
156219 {
157220 }
0 commit comments