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>
|
/// <summary>
|
||||||
/// A text field element for use inside of a <see cref="UiSystem"/>.
|
/// 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.
|
/// 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>
|
/// </summary>
|
||||||
public class TextField : Element {
|
public class TextField : Element {
|
||||||
|
|
||||||
|
@ -142,14 +142,12 @@ namespace MLEM.Ui.Elements {
|
||||||
this.Font.Set(font);
|
this.Font.Set(font);
|
||||||
|
|
||||||
TextInputWrapper.EnsureExists();
|
TextInputWrapper.EnsureExists();
|
||||||
if (TextInputWrapper.Current.RequiresOnScreenKeyboard) {
|
this.OnPressed += async e => {
|
||||||
this.OnPressed += async e => {
|
var title = this.MobileTitle ?? this.PlaceholderText;
|
||||||
var title = this.MobileTitle ?? this.PlaceholderText;
|
var result = await TextInputWrapper.Current.OpenOnScreenKeyboard(title, this.MobileDescription, this.Text, false);
|
||||||
var result = await TextInputWrapper.Current.OpenOnScreenKeyboard(title, this.MobileDescription, this.Text, false);
|
if (result != null)
|
||||||
if (result != null)
|
this.SetText(result.Replace('\n', ' '), true);
|
||||||
this.SetText(result.Replace('\n', ' '), true);
|
};
|
||||||
};
|
|
||||||
}
|
|
||||||
this.OnTextInput += (element, key, character) => {
|
this.OnTextInput += (element, key, character) => {
|
||||||
if (!this.IsSelected || this.IsHidden)
|
if (!this.IsSelected || this.IsHidden)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -21,24 +21,16 @@ namespace MLEM.Misc {
|
||||||
/// <exception cref="InvalidOperationException"></exception>
|
/// <exception cref="InvalidOperationException"></exception>
|
||||||
public static TextInputWrapper Current;
|
public static TextInputWrapper Current;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Determines if this text input wrapper requires an on-screen keyboard.
|
|
||||||
/// </summary>
|
|
||||||
public abstract bool RequiresOnScreenKeyboard { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Opens the on-screen keyboard for this text input wrapper.
|
/// 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>
|
/// </summary>
|
||||||
/// <param name="title">Title of the dialog box.</param>
|
/// <param name="title">Title of the dialog box.</param>
|
||||||
/// <param name="description">Description 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="defaultText">Default text displayed in the input area.</param>
|
||||||
/// <param name="usePasswordMode">If password mode is enabled, the characters entered are not displayed.</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>
|
/// <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 abstract Task<string> OpenOnScreenKeyboard(string title, string description, string defaultText, bool usePasswordMode);
|
||||||
public virtual Task<string> OpenOnScreenKeyboard(string title, string description, string defaultText, bool usePasswordMode) {
|
|
||||||
throw new InvalidOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a text input listener to this text input wrapper.
|
/// Adds a text input listener to this text input wrapper.
|
||||||
|
@ -78,9 +70,6 @@ namespace MLEM.Misc {
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
public class DesktopGl<T> : TextInputWrapper {
|
public class DesktopGl<T> : TextInputWrapper {
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override bool RequiresOnScreenKeyboard => false;
|
|
||||||
|
|
||||||
private FieldInfo key;
|
private FieldInfo key;
|
||||||
private FieldInfo character;
|
private FieldInfo character;
|
||||||
private readonly Action<GameWindow, EventHandler<T>> addListener;
|
private readonly Action<GameWindow, EventHandler<T>> addListener;
|
||||||
|
@ -93,6 +82,11 @@ namespace MLEM.Misc {
|
||||||
this.addListener = addListener;
|
this.addListener = addListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Task<string> OpenOnScreenKeyboard(string title, string description, string defaultText, bool usePasswordMode) {
|
||||||
|
return Task.FromResult<string>(null);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void AddListener(GameWindow window, TextInputCallback callback) {
|
public override void AddListener(GameWindow window, TextInputCallback callback) {
|
||||||
this.addListener(window, (sender, args) => {
|
this.addListener(window, (sender, args) => {
|
||||||
|
@ -118,9 +112,6 @@ namespace MLEM.Misc {
|
||||||
/// </example>
|
/// </example>
|
||||||
public class Mobile : TextInputWrapper {
|
public class Mobile : TextInputWrapper {
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override bool RequiresOnScreenKeyboard => true;
|
|
||||||
|
|
||||||
private readonly OpenOnScreenKeyboardDelegate openOnScreenKeyboard;
|
private readonly OpenOnScreenKeyboardDelegate openOnScreenKeyboard;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -159,7 +150,9 @@ namespace MLEM.Misc {
|
||||||
public class None : TextInputWrapper {
|
public class None : TextInputWrapper {
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <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 />
|
/// <inheritdoc />
|
||||||
public override void AddListener(GameWindow window, TextInputCallback callback) {
|
public override void AddListener(GameWindow window, TextInputCallback callback) {
|
||||||
|
@ -175,9 +168,6 @@ namespace MLEM.Misc {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Primitive : TextInputWrapper {
|
public class Primitive : TextInputWrapper {
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override bool RequiresOnScreenKeyboard => false;
|
|
||||||
|
|
||||||
private TextInputCallback callback;
|
private TextInputCallback callback;
|
||||||
|
|
||||||
/// <summary>
|
/// <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 />
|
/// <inheritdoc />
|
||||||
public override void AddListener(GameWindow window, TextInputCallback callback) {
|
public override void AddListener(GameWindow window, TextInputCallback callback) {
|
||||||
this.callback += callback;
|
this.callback += callback;
|
||||||
|
|
Loading…
Reference in a new issue