|
|
|
@ -3,8 +3,6 @@ using Connected.Utilities;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
|
|
|
using System.Numerics;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using static Connected.Colors;
|
|
|
|
|
|
|
|
|
|
namespace Connected.Components;
|
|
|
|
|
public partial class InputNumber<NumberType>:InputBase where NumberType : INumber<NumberType>
|
|
|
|
@ -18,7 +16,7 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_step = CalculateStep(value);
|
|
|
|
|
_step=value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -29,7 +27,7 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
|
|
|
|
|
{
|
|
|
|
|
double num = (double)Convert.ChangeType(Value, typeof(double));
|
|
|
|
|
num += _step;
|
|
|
|
|
Value = (NumberType)Convert.ChangeType(num, typeof(NumberType));
|
|
|
|
|
Value = AdjustDecimalPlaces((NumberType)Convert.ChangeType(num, typeof(NumberType)));
|
|
|
|
|
await ValueChanged.InvokeAsync(Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -37,12 +35,12 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
|
|
|
|
|
{
|
|
|
|
|
double num = (double)Convert.ChangeType(Value, typeof(double));
|
|
|
|
|
num -= _step;
|
|
|
|
|
Value = (NumberType)Convert.ChangeType(num, typeof(NumberType));
|
|
|
|
|
Value = AdjustDecimalPlaces((NumberType)Convert.ChangeType(num, typeof(NumberType)));
|
|
|
|
|
await ValueChanged.InvokeAsync(Value);
|
|
|
|
|
}
|
|
|
|
|
protected async Task OnMouseWheel(WheelEventArgs obj)
|
|
|
|
|
{
|
|
|
|
|
if (DisableMouseWheel==false)
|
|
|
|
|
if (!DisableMouseWheel)
|
|
|
|
|
{
|
|
|
|
|
if (!obj.ShiftKey || Disabled || Readonly)
|
|
|
|
|
return;
|
|
|
|
@ -57,8 +55,20 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private NumberType _value;
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public NumberType Value { get; set; }
|
|
|
|
|
public NumberType Value
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _value;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_value = AdjustDecimalPlaces(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public int DecimalPlaces { get; set; } =0;
|
|
|
|
@ -72,38 +82,13 @@ public partial class InputNumber<NumberType>:InputBase where NumberType : INumbe
|
|
|
|
|
if (args.Value is not null)
|
|
|
|
|
{
|
|
|
|
|
NumberType value = (NumberType)Convert.ChangeType(args.Value, typeof(NumberType));
|
|
|
|
|
if (value.ToString().Length > 0)
|
|
|
|
|
if (value.ToString().Length <= 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
value = AdjustDecimalPlaces(value);
|
|
|
|
|
//await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(value, typeof(NumberType)));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
value = (NumberType)Convert.ChangeType(0, typeof(NumberType));
|
|
|
|
|
//await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(0, typeof(NumberType)));
|
|
|
|
|
}
|
|
|
|
|
Value = value;
|
|
|
|
|
await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(Value, typeof(NumberType)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private double CalculateStep(double step)
|
|
|
|
|
{
|
|
|
|
|
double CalculatedStep = 1;
|
|
|
|
|
if (DecimalPlaces > 0)
|
|
|
|
|
{
|
|
|
|
|
var CurrentStepDecmalPlaces = Helper.GetDecimalPlaces(step);
|
|
|
|
|
|
|
|
|
|
if (CurrentStepDecmalPlaces > DecimalPlaces)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < DecimalPlaces; i++)
|
|
|
|
|
{
|
|
|
|
|
CalculatedStep = CalculatedStep / 10;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
await ValueChanged.InvokeAsync((NumberType)Convert.ChangeType(AdjustDecimalPlaces(value), typeof(NumberType)));
|
|
|
|
|
}
|
|
|
|
|
return CalculatedStep;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private NumberType AdjustDecimalPlaces(NumberType value)
|
|
|
|
|