Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add input type for decimal numbers #6498

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

frenzibyte
Copy link
Member

@frenzibyte frenzibyte commented Jan 20, 2025

Required to (fix) ppy/osu#31568.

Specifying a Number input type broke editor textboxes due to the type disallowing decimal characters from being entered. This disability is applied internally within TextBox and is not overridable with CanAddCharacter (rightly so).

As a proper fix for this, a specific input type for decimal numbers is added to support this. It has also came to my attention that displaying the software keyboard on iOS on a textbox that uses TextInputType.Number does not show a decimal button, which suggests that it is a good choice to add a different input type for decimal numbers. Unfortunately there's no corresponding SDL input type for decimal numbers, so this new input type is interpreted as "regular text" in SDL.

In other words, using the new Decimal input type will show the full alphanumeric software keyboard just for the sake of allowing the user to insert decimal points.

Comment on lines +33 to +36
/// <summary>
/// The text input is numerical with decimal point.
/// </summary>
Decimal,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing that worries me with having this separate is the potential of needing to switch between non-decimal and decimal input at some stage. But maybe that's not that frequent of a use case...

Comment on lines 1019 to 1020
// todo: SDL does not have a corresponding type for "number with decimal point", fall back to text for now.
// On iOS, using SDL_TEXTINPUT_TYPE_NUMBER does not offer a key for inserting a decimal.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This 100% needs to be reported to / requested from SDL though because iOS can 100% cope with this. <input type="number"> in browsers pulls up a symbols-only keyboard. This should be one-liner tier effort on their side.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@Susko3 Susko3 Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above issues is fixed, SDL_TEXTINPUT_TYPE_NUMBER will now show "a keyboard with numbers and a decimal point" on iOS, the same as it does on Android.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Susko3 Thanks for the upstream handling. It seems then we can make both Decimal and Number use the SDL_TEXTINPUT_TYPE_NUMBER type.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frenzibyte doesn't this make this PR dependent on an sdl bump then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's sort of a soft dependency so wasn't sure if I should do that, but probably better safe than sorry.

osu.Framework/Graphics/UserInterface/TextBox.cs Outdated Show resolved Hide resolved
if (InputProperties.Type.IsNumerical())
{
// if the input type is decimal and the character is a decimal separator, allow it.
if (InputProperties.Type == TextInputType.Decimal && CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator.Contains(character))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this support the minus sign of the current locale for negative numbers? On android, the number text input type has a - key.

I think this also needs to allow NumberGroupSeparator:

[TestCase("1.400,01", "de-DE", 1400.01)]
[TestCase("1 234,57", "ru-RU", 1234.57)]
[TestCase("1,094", "fr-FR", 1.094)]
[TestCase("1,400.01", "zh-CN", 1400.01)]

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, but if it's allowed here then it should be allowed in Number, and so it starts to become out of scope. Better leave it as-is and/or change separately. Same applies to negative symbol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants