diff options
Diffstat (limited to 'src/Ryujinx/Ui')
-rw-r--r-- | src/Ryujinx/Ui/Applet/GtkHostUiHandler.cs | 1 | ||||
-rw-r--r-- | src/Ryujinx/Ui/Applet/SwkbdAppletDialog.cs | 56 |
2 files changed, 47 insertions, 10 deletions
diff --git a/src/Ryujinx/Ui/Applet/GtkHostUiHandler.cs b/src/Ryujinx/Ui/Applet/GtkHostUiHandler.cs index d81cbe3c..b7577b85 100644 --- a/src/Ryujinx/Ui/Applet/GtkHostUiHandler.cs +++ b/src/Ryujinx/Ui/Applet/GtkHostUiHandler.cs @@ -106,6 +106,7 @@ namespace Ryujinx.Ui.Applet swkbdDialog.OkButton.Label = args.SubmitText; swkbdDialog.SetInputLengthValidation(args.StringLengthMin, args.StringLengthMax); + swkbdDialog.SetInputValidation(args.KeyboardMode); if (swkbdDialog.Run() == (int)ResponseType.Ok) { diff --git a/src/Ryujinx/Ui/Applet/SwkbdAppletDialog.cs b/src/Ryujinx/Ui/Applet/SwkbdAppletDialog.cs index 7c14f0e8..28067b75 100644 --- a/src/Ryujinx/Ui/Applet/SwkbdAppletDialog.cs +++ b/src/Ryujinx/Ui/Applet/SwkbdAppletDialog.cs @@ -1,5 +1,7 @@ using Gtk; +using Ryujinx.HLE.HOS.Applets.SoftwareKeyboard; using System; +using System.Linq; namespace Ryujinx.Ui.Applet { @@ -7,8 +9,12 @@ namespace Ryujinx.Ui.Applet { private int _inputMin; private int _inputMax; + private KeyboardMode _mode; - private Predicate<int> _checkLength; + private string _validationInfoText = ""; + + private Predicate<int> _checkLength = _ => true; + private Predicate<string> _checkInput = _ => true; private readonly Label _validationInfo; @@ -38,8 +44,12 @@ namespace Ryujinx.Ui.Applet ((Box)MessageArea).PackEnd(_validationInfo, true, true, 0); ((Box)MessageArea).PackEnd(InputEntry, true, true, 4); + } - SetInputLengthValidation(0, int.MaxValue); // Disable by default. + private void ApplyValidationInfo() + { + _validationInfo.Visible = !string.IsNullOrEmpty(_validationInfoText); + _validationInfo.Markup = _validationInfoText; } public void SetInputLengthValidation(int min, int max) @@ -53,23 +63,49 @@ namespace Ryujinx.Ui.Applet { _validationInfo.Visible = false; - _checkLength = (length) => true; + _checkLength = _ => true; } else if (_inputMin > 0 && _inputMax == int.MaxValue) { - _validationInfo.Visible = true; - _validationInfo.Markup = $"<i>Must be at least {_inputMin} characters long</i>"; + _validationInfoText = $"<i>Must be at least {_inputMin} characters long.</i> "; - _checkLength = (length) => _inputMin <= length; + _checkLength = length => _inputMin <= length; } else { - _validationInfo.Visible = true; - _validationInfo.Markup = $"<i>Must be {_inputMin}-{_inputMax} characters long</i>"; + _validationInfoText = $"<i>Must be {_inputMin}-{_inputMax} characters long.</i> "; - _checkLength = (length) => _inputMin <= length && length <= _inputMax; + _checkLength = length => _inputMin <= length && length <= _inputMax; + } + + ApplyValidationInfo(); + OnInputChanged(this, EventArgs.Empty); + } + + public void SetInputValidation(KeyboardMode mode) + { + _mode = mode; + + switch (mode) + { + case KeyboardMode.NumbersOnly: + _validationInfoText += "<i>Must be numbers only.</i>"; + _checkInput = text => text.All(char.IsDigit); + break; + case KeyboardMode.Alphabet: + _validationInfoText += "<i>Must be alphabets only.</i>"; + _checkInput = text => text.All(char.IsAsciiLetter); + break; + case KeyboardMode.ASCII: + _validationInfoText += "<i>Must be ASCII text only.</i>"; + _checkInput = text => text.All(char.IsAscii); + break; + default: + _checkInput = _ => true; + break; } + ApplyValidationInfo(); OnInputChanged(this, EventArgs.Empty); } @@ -83,7 +119,7 @@ namespace Ryujinx.Ui.Applet private void OnInputChanged(object sender, EventArgs e) { - OkButton.Sensitive = _checkLength(InputEntry.Text.Length); + OkButton.Sensitive = _checkLength(InputEntry.Text.Length) && _checkInput(InputEntry.Text); } } }
\ No newline at end of file |