Add Start/EndTextInput for control to toggle character input events

This commit is contained in:
Ari Vuollet
2026-08-18 21:56:35 +03:00
parent 0461389017
commit 0f47b6d9a2
12 changed files with 166 additions and 5 deletions
+14
View File
@@ -673,6 +673,20 @@ namespace FlaxEditor.Content.GUI
}
}
/// <inheritdoc />
public override void OnGotFocus()
{
StartTextInput();
base.OnGotFocus();
}
/// <inheritdoc />
public override void OnLostFocus()
{
EndTextInput();
base.OnLostFocus();
}
/// <inheritdoc />
public override bool OnMouseDown(Float2 location, MouseButton button)
{
@@ -441,6 +441,20 @@ namespace FlaxEditor.GUI.ContextMenu
}
}
/// <inheritdoc />
protected override void OnShow()
{
StartTextInput();
base.OnShow();
}
/// <inheritdoc />
protected override void OnHide()
{
EndTextInput();
base.OnHide();
}
/// <inheritdoc />
public override bool OnCharInput(char c)
{
@@ -401,6 +401,13 @@ namespace FlaxEditor.Surface
base.OnMouseMove(location);
CustomMouseMove?.Invoke(ref location);
}
/// <inheritdoc />
public override void OnGotFocus()
{
StartTextInput();
base.OnGotFocus();
}
/// <inheritdoc />
public override void OnLostFocus()
@@ -423,6 +430,7 @@ namespace FlaxEditor.Surface
}
_isMovingSelection = false;
ConnectingEnd(null);
EndTextInput();
base.OnLostFocus();
}
@@ -834,7 +842,7 @@ namespace FlaxEditor.Surface
return true;
}
/// <inheritdoc />
public override bool OnCharInput(char c)
{
+12
View File
@@ -144,7 +144,19 @@ namespace FlaxEditor.Windows
{
rect = new Rectangle(2, 0, Width - 4, Height);
}
public override void OnGotFocus()
{
StartTextInput();
base.OnGotFocus();
}
public override void OnLostFocus()
{
EndTextInput();
base.OnLostFocus();
}
public override bool OnCharInput(char c)
{
if (Owner != null && (!Owner._searchPopup?.Visible ?? true))
+15
View File
@@ -43,6 +43,7 @@ protected:
Rectangle _mouseOffsetScreenSize;
bool _isUsingMouseOffset = false;
bool _isTrackingMouse = false;
bool _isTextInputEnabled = false;
bool _isHorizontalFlippingMouse = false;
bool _isVerticalFlippingMouse = false;
bool _isClippingCursor = false;
@@ -495,6 +496,20 @@ public:
API_FUNCTION() virtual void EndTrackingMouse()
{
}
/// <summary>
/// Enables character input events.
/// </summary>
API_FUNCTION() virtual void StartTextInput()
{
}
/// <summary>
/// Disables character input events.
/// </summary>
API_FUNCTION() virtual void EndTextInput()
{
}
/// <summary>
/// Starts the cursor clipping.
@@ -157,8 +157,6 @@ bool SDLPlatform::Init()
SDLImpl::SystemDpi = (int)(SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay()) * DefaultDPI);
//SDL_StartTextInput(); // TODO: Call this only when text input is expected (shows virtual keyboard in some cases)
return SDLPlatformBase::Init();
}
+31 -1
View File
@@ -298,7 +298,7 @@ SDLWindow::~SDLWindow()
// The text input events seems to be controlled globally on macOS,
// calling this for closing window seems to remove keyboard focus from other windows...
#if !PLATFORM_MAC
#if !PLATFORM_MAC // TODO: Verify if this is still needed
if (_settings.AllowInput && SDL_TextInputActive(_window))
SDL_StopTextInput(_window);
#endif
@@ -514,8 +514,12 @@ void SDLWindow::HandleEvent(SDL_Event& event)
case SDL_EVENT_WINDOW_FOCUS_GAINED:
{
OnGotFocus();
#if PLATFORM_MAC // TODO: Verify if this is still needed
if (_settings.AllowInput && !SDLPlatform::UsesX11())
SDL_StartTextInput(_window);
#endif
if (_isTextInputEnabled)
SDL_StartTextInput(_window);
if (_isClippingCursor)
{
// The relative mode needs to be disabled for clipping to take effect
@@ -537,8 +541,12 @@ void SDLWindow::HandleEvent(SDL_Event& event)
}
case SDL_EVENT_WINDOW_FOCUS_LOST:
{
#if PLATFORM_MAC // TODO: Verify if this is still needed
if (_settings.AllowInput && !SDLPlatform::UsesX11())
SDL_StopTextInput(_window);
#endif
if (_isTextInputEnabled)
SDL_StopTextInput(_window);
if (_isClippingCursor)
SDL_SetWindowMouseRect(_window, nullptr);
@@ -910,6 +918,28 @@ void SDLWindow::EndTrackingMouse()
_restoreRelativeMode = false;
}
void SDLWindow::StartTextInput()
{
#if !PLATFORM_MAC // TODO: Verify if this is still needed
if (_isTextInputEnabled || !_settings.AllowInput || SDLPlatform::UsesX11())
return;
_isTextInputEnabled = true;
SDL_StartTextInput(_window);
#endif
}
void SDLWindow::EndTextInput()
{
#if !PLATFORM_MAC // TODO: Verify if this is still needed
if (!_isTextInputEnabled || !_settings.AllowInput || SDLPlatform::UsesX11())
return;
_isTextInputEnabled = false;
SDL_StopTextInput(_window);
#endif
}
void SDLWindow::StartClippingCursor(const Rectangle& bounds)
{
if (!IsFocused())
+2
View File
@@ -103,6 +103,8 @@ public:
DragDropEffect DoDragDrop(const StringView& data, const Float2& offset, Window* dragSourceWindow) override;
void StartTrackingMouse(bool useMouseScreenOffset) override;
void EndTrackingMouse() override;
void StartTextInput() override;
void EndTextInput() override;
void StartClippingCursor(const Rectangle& bounds) override;
void EndClippingCursor() override;
void SetMousePosition(const Float2& position) const override;
+28
View File
@@ -120,6 +120,20 @@ namespace FlaxEngine.GUI
parent?.EndTrackingMouse();
}
/// <inheritdoc />
public override void StartTextInput()
{
var parent = Parent?.Root;
parent?.StartTextInput();
}
/// <inheritdoc />
public override void EndTextInput()
{
var parent = Parent?.Root;
parent?.EndTextInput();
}
/// <inheritdoc />
public override bool GetKey(KeyboardKeys key)
{
@@ -293,6 +307,20 @@ namespace FlaxEngine.GUI
heldTime = rateTime = 0;
}
}
/// <inheritdoc />
public override void OnGotFocus()
{
StartTextInput();
base.OnGotFocus();
}
/// <inheritdoc />
public override void OnLostFocus()
{
EndTextInput();
base.OnLostFocus();
}
/// <inheritdoc />
public override bool OnCharInput(char c)
@@ -1223,6 +1223,8 @@ namespace FlaxEngine.GUI
if (IsReadOnly)
return;
StartTextInput();
OnEditBegin();
}
@@ -1233,6 +1235,8 @@ namespace FlaxEngine.GUI
if (IsReadOnly)
return;
EndTextInput();
OnEditEnd();
}
+25 -1
View File
@@ -598,6 +598,26 @@ namespace FlaxEngine.GUI
public virtual void OnEndMouseCapture()
{
}
/// <summary>
/// Enables <see cref="OnCharInput"/> events.
/// </summary>
[NoAnimate]
public virtual void StartTextInput()
{
var parent = Root;
parent?.StartTextInput();
}
/// <summary>
/// Disables <see cref="OnCharInput"/> events.
/// </summary>
[NoAnimate]
public virtual void EndTextInput()
{
var parent = Root;
parent?.EndTextInput();
}
#endregion
@@ -853,8 +873,12 @@ namespace FlaxEngine.GUI
#region Keyboard
/// <summary>
/// On input character
/// On character input
/// </summary>
/// <remarks>
/// Requires text input enabled in order to receive character input events.
/// See <see cref="StartTextInput"/>.
/// </remarks>
/// <param name="c">Input character</param>
/// <returns>True if event has been handled, otherwise false</returns>
[NoAnimate]
+12
View File
@@ -195,6 +195,18 @@ namespace FlaxEngine.GUI
_window.EndTrackingMouse();
}
}
/// <inheritdoc />
public override void StartTextInput()
{
_window.StartTextInput();
}
/// <inheritdoc />
public override void EndTextInput()
{
_window.EndTextInput();
}
/// <inheritdoc />
public override bool GetKey(KeyboardKeys key)