]> O.S.I.I.S - jp/crow.git/commitdiff
numeric control: min/max change => actual value check
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 13 Sep 2021 13:39:28 +0000 (13:39 +0000)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 13 Sep 2021 13:39:28 +0000 (13:39 +0000)
Crow/src/Widgets/NumericControl.cs
Crow/src/Widgets/Slider.cs

index df8fa17d016de544adb0e60a72979f59cac6bd45..5c7c50c2d347cc502fadc6e1e9a5aadea4f18a51 100644 (file)
@@ -55,6 +55,10 @@ namespace Crow {
 
                                maxValue = value;
                                NotifyValueChangedAuto (maxValue);
+
+                               if (Value > maxValue)
+                                       Value = maxValue;
+
                                registerUpdate ();
                        }
                }
@@ -68,6 +72,10 @@ namespace Crow {
 
                                smallStep = value;
                                NotifyValueChangedAuto (smallStep);
+
+                               if (Value < minValue)
+                                       Value = minValue;
+
                                registerUpdate ();
                        }
                }
@@ -97,7 +105,7 @@ namespace Crow {
                                        actualValue = minValue;
                                else if (value > maxValue)
                                        actualValue = maxValue;
-                               else                    
+                               else
                                        actualValue = value;
 
                                actualValue = Math.Round (actualValue, decimals);
@@ -110,7 +118,7 @@ namespace Crow {
 
                protected virtual void registerUpdate ()
                        => RegisterForRedraw ();
-               
+
                protected virtual void onUp (object sender, MouseButtonEventArgs e)
                {
                        if (IFace.Ctrl)
index 8e197fda72d7072eff58c24bcebe60cbdf38f863..e1e8d90ed4a6227f8d62cd20b3a2b22f03d37151 100644 (file)
@@ -56,10 +56,10 @@ namespace Crow
                public virtual Orientation Orientation
                {
                        get { return _orientation; }
-                       set { 
+                       set {
                                if (_orientation == value)
                                        return;
-                               _orientation = value; 
+                               _orientation = value;
 
                                RegisterForLayouting (LayoutingType.All);
                                NotifyValueChangedAuto (_orientation);
@@ -110,9 +110,9 @@ namespace Crow
                public override bool ArrangeChildren => true;
                public override bool UpdateLayout (LayoutingType layoutType)
                {
-                       if (layoutType == LayoutingType.ArrangeChildren) 
+                       if (layoutType == LayoutingType.ArrangeChildren)
                                computeCursorPosition ();
-                       
+
                        return base.UpdateLayout (layoutType);
                }
 
@@ -192,13 +192,13 @@ namespace Crow
                }
                public override void onMouseMove (object sender, MouseMoveEventArgs e)
                {
-                       if (holdCursor) {                               
+                       if (holdCursor) {
                                Point m = ScreenPointToLocal (e.Position) - mouseDownInit;
                                Rectangle r = cursor.Parent.ClientRectangle;
 
                                if (_orientation == Orientation.Horizontal) {
                                        if (r.Width - cursorSize == 0)
-                                               return;                                 
+                                               return;
                                        double unit = (Maximum - Minimum) / (double)(r.Width - cursorSize);
                                        if (inverted)
                                                unit = -unit;
@@ -207,17 +207,17 @@ namespace Crow
                                        Value = tmp;
                                } else {
                                        if (r.Height - cursorSize == 0)
-                                               return;                                 
+                                               return;
                                        double unit = (Maximum - Minimum) / (double)(r.Height - cursorSize);
                                        if (inverted)
                                                unit = -unit;
                                        double tmp = mouseDownInitValue + (double)m.Y * unit;
                                        tmp -= tmp % SmallIncrement;
                                        Value = tmp;
-                               }                               
+                               }
                        }
                        e.Handled = true;
-                       
+
                        base.onMouseMove (sender, e);
                }
                #endregion