Bläddra i källkod

DoubleBox and IntegerBox can now do negatives.

Kenric Nugteren 1 månad sedan
förälder
incheckning
784f9e62c8

+ 4 - 1
InABox.Avalonia/Components/DoubleBox/DoubleBox.cs

@@ -1,6 +1,7 @@
 using Avalonia.Controls;
 using Avalonia.Input;
 using Avalonia.Interactivity;
+using InABox.Core;
 using System;
 using System.Collections.Generic;
 using System.Globalization;
@@ -23,7 +24,9 @@ public class DoubleBox : NumericUpDown
 
     private void TunnelTextEvent(object? sender, TextInputEventArgs e)
     {
-        e.Text = new string(e.Text?.Where(c => Char.IsDigit(c) || c == '.').ToArray());
+        e.Text = new string(e.Text?.WithIndex()
+            .Where(x => (x.Key == 0 && x.Value == '-') || Char.IsDigit(x.Value) || x.Value == '.')
+            .Select(x => x.Value).ToArray());
         if(e.Text == "")
         {
             e.Handled = true;

+ 4 - 1
InABox.Avalonia/Components/IntegerBox/IntegerBox.cs

@@ -1,6 +1,7 @@
 using Avalonia.Controls;
 using Avalonia.Input;
 using Avalonia.Interactivity;
+using InABox.Core;
 using System;
 using System.Collections.Generic;
 using System.Globalization;
@@ -24,7 +25,9 @@ public class IntegerBox : NumericUpDown
 
     private void TunnelTextEvent(object? sender, TextInputEventArgs e)
     {
-        e.Text = new string(e.Text?.Where(c => Char.IsDigit(c)).ToArray());
+        e.Text = new string(e.Text?.WithIndex()
+            .Where(x => (x.Key == 0 && x.Value == '-') || Char.IsDigit(x.Value))
+            .Select(x => x.Value).ToArray());
         if(e.Text == "")
         {
             e.Handled = true;