mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-07-29 05:37:11 +02:00
Check KeyboardMode in GUI (#4343)
* 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>
This commit is contained in:
parent
21c9ac6240
commit
d511c845b7
9 changed files with 109 additions and 22 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue