mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 22:18:34 +01:00
removed RequiresOnScreenKeyboard
This commit is contained in:
parent
cf9bcc7ae4
commit
338cf383f4
2 changed files with 22 additions and 29 deletions
|
@ -17,7 +17,7 @@ namespace MLEM.Ui.Elements {
|
|||
/// <summary>
|
||||
/// A text field element for use inside of a <see cref="UiSystem"/>.
|
||||
/// A text field is a selectable element that can be typed in, as well as copied and pasted from.
|
||||
/// If <see cref="TextInputWrapper.RequiresOnScreenKeyboard"/> is enabled, then this text field will automatically open an on-screen keyboard when pressed using MonoGame's <c>KeyboardInput</c> class.
|
||||
/// If an on-screen keyboard is required, then this text field will automatically open an on-screen keyboard using <see cref="TextInputWrapper.OpenOnScreenKeyboard"/>
|
||||
/// </summary>
|
||||
public class TextField : Element {
|
||||
|
||||
|
@ -142,14 +142,12 @@ namespace MLEM.Ui.Elements {
|
|||
this.Font.Set(font);
|
||||
|
||||
TextInputWrapper.EnsureExists();
|
||||
if (TextInputWrapper.Current.RequiresOnScreenKeyboard) {
|
||||
this.OnPressed += async e => {
|
||||
var title = this.MobileTitle ?? this.PlaceholderText;
|
||||
var result = await TextInputWrapper.Current.OpenOnScreenKeyboard(title, this.MobileDescription, this.Text, false);
|
||||
if (result != null)
|
||||
this.SetText(result.Replace('\n', ' '), true);
|
||||
};
|
||||
}
|
||||
this.OnPressed += async e => {
|
||||
var title = this.MobileTitle ?? this.PlaceholderText;
|
||||
var result = await TextInputWrapper.Current.OpenOnScreenKeyboard(title, this.MobileDescription, this.Text, false);
|
||||
if (result != null)
|
||||
this.SetText(result.Replace('\n', ' '), true);
|
||||
};
|
||||
this.OnTextInput += (element, key, character) => {
|
||||
if (!this.IsSelected || this.IsHidden)
|
||||
return;
|
||||
|
|
|
@ -21,24 +21,16 @@ namespace MLEM.Misc {
|
|||
/// <exception cref="InvalidOperationException"></exception>
|
||||
public static TextInputWrapper Current;
|
||||
|
||||
/// <summary>
|
||||
/// Determines if this text input wrapper requires an on-screen keyboard.
|
||||
/// </summary>
|
||||
public abstract bool RequiresOnScreenKeyboard { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Opens the on-screen keyboard for this text input wrapper.
|
||||
/// Note that, if <see cref="RequiresOnScreenKeyboard"/> is false, this method should not be called.
|
||||
/// Note that, if no on-screen keyboard is required, a null string should be returned.
|
||||
/// </summary>
|
||||
/// <param name="title">Title of the dialog box.</param>
|
||||
/// <param name="description">Description of the dialog box.</param>
|
||||
/// <param name="defaultText">Default text displayed in the input area.</param>
|
||||
/// <param name="usePasswordMode">If password mode is enabled, the characters entered are not displayed.</param>
|
||||
/// <returns>Text entered by the player. Null if back was used.</returns>
|
||||
/// <exception cref="InvalidOperationException">Thrown if there is no on-screen keyboard to open, or when <see cref="RequiresOnScreenKeyboard"/> is false</exception>
|
||||
public virtual Task<string> OpenOnScreenKeyboard(string title, string description, string defaultText, bool usePasswordMode) {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
public abstract Task<string> OpenOnScreenKeyboard(string title, string description, string defaultText, bool usePasswordMode);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a text input listener to this text input wrapper.
|
||||
|
@ -78,9 +70,6 @@ namespace MLEM.Misc {
|
|||
/// <typeparam name="T"></typeparam>
|
||||
public class DesktopGl<T> : TextInputWrapper {
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool RequiresOnScreenKeyboard => false;
|
||||
|
||||
private FieldInfo key;
|
||||
private FieldInfo character;
|
||||
private readonly Action<GameWindow, EventHandler<T>> addListener;
|
||||
|
@ -93,6 +82,11 @@ namespace MLEM.Misc {
|
|||
this.addListener = addListener;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Task<string> OpenOnScreenKeyboard(string title, string description, string defaultText, bool usePasswordMode) {
|
||||
return Task.FromResult<string>(null);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void AddListener(GameWindow window, TextInputCallback callback) {
|
||||
this.addListener(window, (sender, args) => {
|
||||
|
@ -118,9 +112,6 @@ namespace MLEM.Misc {
|
|||
/// </example>
|
||||
public class Mobile : TextInputWrapper {
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool RequiresOnScreenKeyboard => true;
|
||||
|
||||
private readonly OpenOnScreenKeyboardDelegate openOnScreenKeyboard;
|
||||
|
||||
/// <summary>
|
||||
|
@ -159,7 +150,9 @@ namespace MLEM.Misc {
|
|||
public class None : TextInputWrapper {
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool RequiresOnScreenKeyboard => false;
|
||||
public override Task<string> OpenOnScreenKeyboard(string title, string description, string defaultText, bool usePasswordMode) {
|
||||
return Task.FromResult<string>(null);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void AddListener(GameWindow window, TextInputCallback callback) {
|
||||
|
@ -175,9 +168,6 @@ namespace MLEM.Misc {
|
|||
/// </summary>
|
||||
public class Primitive : TextInputWrapper {
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool RequiresOnScreenKeyboard => false;
|
||||
|
||||
private TextInputCallback callback;
|
||||
|
||||
/// <summary>
|
||||
|
@ -194,6 +184,11 @@ namespace MLEM.Misc {
|
|||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Task<string> OpenOnScreenKeyboard(string title, string description, string defaultText, bool usePasswordMode) {
|
||||
return Task.FromResult<string>(null);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void AddListener(GameWindow window, TextInputCallback callback) {
|
||||
this.callback += callback;
|
||||
|
|
Loading…
Reference in a new issue