mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-01 05:10:50 +01:00
Added TextField.OnEnterPressed event
This commit is contained in:
parent
4c378f7cd9
commit
0eeeed1a27
2 changed files with 17 additions and 4 deletions
|
@ -25,6 +25,7 @@ Fixes
|
||||||
### MLEM.Ui
|
### MLEM.Ui
|
||||||
Additions
|
Additions
|
||||||
- Added Panel.IsVisible method to check if a child element is visible
|
- Added Panel.IsVisible method to check if a child element is visible
|
||||||
|
- Added TextField.OnEnterPressed event
|
||||||
|
|
||||||
## 7.1.1
|
## 7.1.1
|
||||||
|
|
||||||
|
|
|
@ -142,6 +142,13 @@ namespace MLEM.Ui.Elements {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string MobileDescription;
|
public string MobileDescription;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// An event that is invoked if <see cref="Keys.Enter"/> is pressed while this text field is active.
|
||||||
|
/// Note that, for text fields that are <see cref="Multiline"/>, this is ignored.
|
||||||
|
/// This also occurs once the text input window is successfully closed on a mobile device.
|
||||||
|
/// If another <see cref="Element"/>'s press behavior should be invoked when enter is pressed, <see cref="EnterReceiver"/> can be used instead.
|
||||||
|
/// </summary>
|
||||||
|
public GenericCallback OnEnterPressed;
|
||||||
|
/// <summary>
|
||||||
/// An element that should be pressed (using <see cref="UiControls.PressElement"/>) if <see cref="Keys.Enter"/> is pressed while this text field is active.
|
/// An element that should be pressed (using <see cref="UiControls.PressElement"/>) if <see cref="Keys.Enter"/> is pressed while this text field is active.
|
||||||
/// Note that, for text fields that are <see cref="Multiline"/>, this is ignored.
|
/// Note that, for text fields that are <see cref="Multiline"/>, this is ignored.
|
||||||
/// This also occurs once the text input window is successfully closed on a mobile device.
|
/// This also occurs once the text input window is successfully closed on a mobile device.
|
||||||
|
@ -198,12 +205,12 @@ namespace MLEM.Ui.Elements {
|
||||||
var result = await MlemPlatform.Current.OpenOnScreenKeyboard(title, this.MobileDescription, this.Text, false);
|
var result = await MlemPlatform.Current.OpenOnScreenKeyboard(title, this.MobileDescription, this.Text, false);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
this.SetText(this.Multiline ? result : result.Replace('\n', ' '), true);
|
this.SetText(this.Multiline ? result : result.Replace('\n', ' '), true);
|
||||||
this.EnterReceiver?.Controls?.PressElement(this.EnterReceiver);
|
this.InvokeOnEnter();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.OnTextInput += (element, key, character) => {
|
this.OnTextInput += (element, key, character) => {
|
||||||
if (this.IsSelectedActive && !this.IsHidden && !this.textInput.OnTextInput(key, character) && key == Keys.Enter && !this.Multiline)
|
if (this.IsSelectedActive && !this.IsHidden && !this.textInput.OnTextInput(key, character) && key == Keys.Enter && !this.Multiline)
|
||||||
this.EnterReceiver?.Controls?.PressElement(this.EnterReceiver);
|
this.InvokeOnEnter();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,8 +228,8 @@ namespace MLEM.Ui.Elements {
|
||||||
this.textInput.Update(time, this.Input);
|
this.textInput.Update(time, this.Input);
|
||||||
#if FNA
|
#if FNA
|
||||||
// this occurs in OnTextInput outside FNA, where special keys are also counted as text input
|
// this occurs in OnTextInput outside FNA, where special keys are also counted as text input
|
||||||
if (this.EnterReceiver != null && !this.Multiline && this.Input.TryConsumePressed(Keys.Enter))
|
if ((this.OnEnterPressed != null || this.EnterReceiver != null) && !this.Multiline && this.Input.TryConsumePressed(Keys.Enter))
|
||||||
this.EnterReceiver.Controls?.PressElement(this.EnterReceiver);
|
this.InvokeOnEnter();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -276,6 +283,11 @@ namespace MLEM.Ui.Elements {
|
||||||
this.CaretWidth = this.CaretWidth.OrStyle(style.TextFieldCaretWidth);
|
this.CaretWidth = this.CaretWidth.OrStyle(style.TextFieldCaretWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void InvokeOnEnter() {
|
||||||
|
this.OnEnterPressed?.Invoke(this);
|
||||||
|
this.EnterReceiver?.Controls?.PressElement(this.EnterReceiver);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A delegate method used for <see cref="TextField.OnTextChange"/>
|
/// A delegate method used for <see cref="TextField.OnTextChange"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in a new issue