Skip to content

Commit

Permalink
Implementing #7
Browse files Browse the repository at this point in the history
Incrementing/Decrementing via mouse can be configured to:
- Vertical only
- Horizontal only
- Vertical and Horizontal

mouse drags.
  • Loading branch information
Dirkster99 committed May 3, 2020
1 parent 869afbe commit 8a556b6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
24 changes: 22 additions & 2 deletions source/NumericUpDownLib/Base/AbstractBaseUpDown.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace NumericUpDownLib.Base
{
using NumericUpDownLib.Enums;
using NumericUpDownLib.Models;
using System;
using System.Windows;
Expand Down Expand Up @@ -165,6 +166,13 @@ public abstract partial class AbstractBaseUpDown<T> : InputBaseUpDown
DependencyProperty.Register("IsMouseDragEnabled", typeof(bool),
typeof(AbstractBaseUpDown<T>), new PropertyMetadata(true, OnIsMouseDragEnabledChanged));

/// <summary>
/// Backing store of <see cref="CanIncDecMouseDrag"/> dependency property.
/// </summary>
public static readonly DependencyProperty CanMouseDragProperty =
DependencyProperty.Register("CanMouseDrag", typeof(CanIncDecMouseDrag),
typeof(AbstractBaseUpDown<T>), new PropertyMetadata(CanIncDecMouseDrag.VerticalHorizontal));

/// <summary>
/// Holds the REQUIRED textbox instance part for this control.
/// </summary>
Expand Down Expand Up @@ -353,6 +361,18 @@ public bool IsMouseDragEnabled
set { SetValue(IsMouseDragEnabledProperty, value); }
}

/// <summary>
/// Gets/sets wether small/large step sizes can be incremented/decremented
/// both with vertical/horizontal mouse drag moves or,
/// whether only horizontal or only vertical mouse drag moves can
/// incremented/decremented only in small or only in large values.
/// </summary>
public CanIncDecMouseDrag CanMouseDrag
{
get { return (CanIncDecMouseDrag)GetValue(CanMouseDragProperty); }
set { SetValue(CanMouseDragProperty, value); }
}

/// <summary>
/// Determines whether last text input was from a user (key was down) or not.
/// </summary>
Expand Down Expand Up @@ -594,8 +614,8 @@ private void _PART_TextBox_MouseMove(object sender, MouseEventArgs e)
}

var pos = GetPositionFromThis(e);
double deltaX = _objMouseIncr.Point.X - pos.X;
double deltaY = _objMouseIncr.Point.Y - pos.Y;
double deltaX = (CanMouseDrag == CanIncDecMouseDrag.VerticalOnly ? 0 : _objMouseIncr.Point.X - pos.X);
double deltaY = (CanMouseDrag == CanIncDecMouseDrag.HorizontalOnly ? 0 : _objMouseIncr.Point.Y - pos.Y);

if (_objMouseIncr.MouseDirection == MouseDirections.None)
{
Expand Down
26 changes: 26 additions & 0 deletions source/NumericUpDownLib/Enums/CanIncDecMouseDrag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace NumericUpDownLib.Enums
{
/// <summary>
/// Defines the mouse drag modes that are supported to increment/decrement
/// small/large values allowing horizontal/vertical mouse drag moves at the same
/// time or each direction only by itself.
/// </summary>
public enum CanIncDecMouseDrag
{
/// <summary>
/// A value can be incremented/decremented in small steps using vertical mouse drag moves only.
/// </summary>
VerticalOnly,

/// <summary>
/// A value can be incremented/decremented in large steps using horizontal mouse drag moves only.
/// </summary>
HorizontalOnly,

/// <summary>
/// A value can be incremented/decremented in small steps or large steps
/// using vertical or horizontal mouse drag moves at the same time.
/// </summary>
VerticalHorizontal
}
}
2 changes: 1 addition & 1 deletion source/NumericUpDownLib/NumericUpDownLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</PropertyGroup>

<ItemGroup>
<None Include="images/SyncArrow_64x.png" Pack="true" PackagePath=""/>
<None Include="images/SyncArrow_64x.png" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 8a556b6

Please sign in to comment.