aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx/Ui
diff options
context:
space:
mode:
authorWilliamWsyHK <WilliamWsyHK@users.noreply.github.com>2023-06-04 11:30:24 +0800
committerGitHub <noreply@github.com>2023-06-04 05:30:24 +0200
commitd511c845b70a8771de7d64369e24ab3f1ed1c325 (patch)
treecb57689ed2f6080b8e3e8bbc465db6358a7e9012 /src/Ryujinx/Ui
parent21c9ac6240a3db3300143d1d0dd4a1070d4f576f (diff)
Check KeyboardMode in GUI (#4343)1.1.862
* Update SoftwareKeyboard to send KeyboardMode to UI * Update GTK UI to check text against KeyboardMode * Update Ava UI to check text against KeyboardMode * Restructure input validation * true when text is not empty * Add English validation text for SoftwareKeyboardMode * Add Chinese validation text for SoftwareKeyboardMode * Update base on feedback --------- Co-authored-by: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
Diffstat (limited to 'src/Ryujinx/Ui')
-rw-r--r--src/Ryujinx/Ui/Applet/GtkHostUiHandler.cs1
-rw-r--r--src/Ryujinx/Ui/Applet/SwkbdAppletDialog.cs56
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