2024-09-04 19:57:53 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2024-10-04 19:12:25 +08:00
|
|
|
using System.Globalization;
|
|
|
|
|
2024-09-04 19:57:53 +08:00
|
|
|
namespace osu.Game.Graphics.UserInterfaceV2
|
|
|
|
{
|
|
|
|
public partial class FormNumberBox : FormTextBox
|
|
|
|
{
|
|
|
|
public bool AllowDecimals { get; init; }
|
|
|
|
|
|
|
|
internal override InnerTextBox CreateTextBox() => new InnerNumberBox
|
|
|
|
{
|
|
|
|
AllowDecimals = AllowDecimals,
|
2024-10-03 17:11:02 +08:00
|
|
|
SelectAllOnFocus = true,
|
2024-09-04 19:57:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
internal partial class InnerNumberBox : InnerTextBox
|
|
|
|
{
|
|
|
|
public bool AllowDecimals { get; init; }
|
|
|
|
|
|
|
|
protected override bool CanAddCharacter(char character)
|
2024-10-04 19:12:25 +08:00
|
|
|
=> char.IsAsciiDigit(character) || (AllowDecimals && CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator.Contains(character));
|
2024-09-04 19:57:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|