Browse Source

Improved scroll buildup

flabbet 6 months ago
parent
commit
13946a3a35
1 changed files with 12 additions and 10 deletions
  1. 12 10
      src/PixiEditor/Views/Input/NumberInput.cs

+ 12 - 10
src/PixiEditor/Views/Input/NumberInput.cs

@@ -242,7 +242,7 @@ internal partial class NumberInput : TextBox
 
 
         behavior.Bind(TextBoxFocusBehavior.ConfirmOnEnterProperty, confirmOnEnterBinding);
         behavior.Bind(TextBoxFocusBehavior.ConfirmOnEnterProperty, confirmOnEnterBinding);
     }
     }
-    
+
     private static double CoerceValue(AvaloniaObject o, double value)
     private static double CoerceValue(AvaloniaObject o, double value)
     {
     {
         double min = (double)o.GetValue(MinProperty);
         double min = (double)o.GetValue(MinProperty);
@@ -251,14 +251,14 @@ internal partial class NumberInput : TextBox
 
 
         return Math.Round(Math.Clamp(value, min, max), decimals);
         return Math.Round(Math.Clamp(value, min, max), decimals);
     }
     }
-    
+
     private static int CoerceDecimals(AvaloniaObject o, int value)
     private static int CoerceDecimals(AvaloniaObject o, int value)
     {
     {
         if (value < 0)
         if (value < 0)
         {
         {
             value = 0;
             value = 0;
         }
         }
-        
+
         return value;
         return value;
     }
     }
 
 
@@ -350,23 +350,25 @@ internal partial class NumberInput : TextBox
         }
         }
 
 
         e.Handled = true;
         e.Handled = true;
-        double requiredBuildup = 1;
-        
-        if(Decimals == 0 && e.KeyModifiers.HasFlag(KeyModifiers.Control))
+        double requiredBuildup = 1f;
+
+        if (Decimals == 0 && e.KeyModifiers.HasFlag(KeyModifiers.Control))
         {
         {
             requiredBuildup = 2;
             requiredBuildup = 2;
         }
         }
-        
+
+        scrollBuildup += e.Delta.Y;
+
         if (Math.Abs(scrollBuildup) < requiredBuildup)
         if (Math.Abs(scrollBuildup) < requiredBuildup)
         {
         {
-            scrollBuildup += e.Delta.Y;
             return;
             return;
         }
         }
 
 
         double step = Math.Sign(e.Delta.Y);
         double step = Math.Sign(e.Delta.Y);
 
 
         double newValue = Value;
         double newValue = Value;
-        if (e.KeyModifiers.HasFlag(KeyModifiers.Shift) && Min - double.NegativeInfinity > 0.1f && Max - double.PositiveInfinity > 0.1f)
+        if (e.KeyModifiers.HasFlag(KeyModifiers.Shift) && Min - double.NegativeInfinity > 0.1f &&
+            Max - double.PositiveInfinity > 0.1f)
         {
         {
             double multiplier = (Max - Min) * 0.1f;
             double multiplier = (Max - Min) * 0.1f;
             newValue += step * multiplier;
             newValue += step * multiplier;
@@ -381,7 +383,7 @@ internal partial class NumberInput : TextBox
         }
         }
 
 
         Value = (float)Math.Round(Math.Clamp(newValue, Min, Max), Decimals);
         Value = (float)Math.Round(Math.Clamp(newValue, Min, Max), Decimals);
-        
+
         scrollBuildup = 0;
         scrollBuildup = 0;
         OnScrollAction?.Invoke();
         OnScrollAction?.Invoke();
     }
     }