From 0487b282d72445adcce127b260b405915fbd2c13 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sat, 11 Nov 2017 18:42:30 +0100 Subject: [PATCH] Sdk/TextAreaWidget: Show cursor as long as focus is active --- ChangeLog.md | 1 + SDK/include/NDK/Widgets/TextAreaWidget.hpp | 4 ++-- SDK/src/NDK/Widgets/TextAreaWidget.cpp | 24 +++++++++++++--------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 5bbf74f98..41d026ffe 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -23,6 +23,7 @@ Nazara Development Kit: - Fixed minor issues relative to TextAreaWidget cursor handling - ⚠️ Renamed BaseWidget::GrabKeyboard method to SetFocus - Added BaseWidget::ClearFocus method and OnFocus[Lost|Received] virtual methods +- TextAreaWidget will now show a cursor as long as it has focus # 0.4: diff --git a/SDK/include/NDK/Widgets/TextAreaWidget.hpp b/SDK/include/NDK/Widgets/TextAreaWidget.hpp index ec0576453..6b60ad873 100644 --- a/SDK/include/NDK/Widgets/TextAreaWidget.hpp +++ b/SDK/include/NDK/Widgets/TextAreaWidget.hpp @@ -73,12 +73,12 @@ namespace Ndk private: void Layout() override; + void OnFocusLost() override; + void OnFocusReceived() override; void OnKeyPressed(const Nz::WindowEvent::KeyEvent& key) override; void OnKeyReleased(const Nz::WindowEvent::KeyEvent& key) override; - void OnMouseEnter() override; void OnMouseButtonPress(int /*x*/, int /*y*/, Nz::Mouse::Button button) override; void OnMouseMoved(int x, int y, int deltaX, int deltaY) override; - void OnMouseExit() override; void OnTextEntered(char32_t character, bool repeated) override; void RefreshCursor(); diff --git a/SDK/src/NDK/Widgets/TextAreaWidget.cpp b/SDK/src/NDK/Widgets/TextAreaWidget.cpp index a963d17e9..671dce2fb 100644 --- a/SDK/src/NDK/Widgets/TextAreaWidget.cpp +++ b/SDK/src/NDK/Widgets/TextAreaWidget.cpp @@ -134,6 +134,16 @@ namespace Ndk RefreshCursor(); } + void TextAreaWidget::OnFocusLost() + { + m_cursorEntity->Enable(false); + } + + void TextAreaWidget::OnFocusReceived() + { + m_cursorEntity->Enable(true); + } + void TextAreaWidget::OnKeyPressed(const Nz::WindowEvent::KeyEvent& key) { switch (key.code) @@ -214,16 +224,11 @@ namespace Ndk { } - void TextAreaWidget::OnMouseEnter() - { - m_cursorEntity->Enable(true); - } - void TextAreaWidget::OnMouseButtonPress(int x, int y, Nz::Mouse::Button button) { if (button == Nz::Mouse::Left) { - GrabKeyboard(); + SetFocus(); SetCursorPosition(GetHoveredGlyph(float(x), float(y))); } @@ -231,11 +236,10 @@ namespace Ndk void TextAreaWidget::OnMouseMoved(int x, int y, int /*deltaX*/, int /*deltaY*/) { - } + if (m_isMouseButtonDown) + { - void TextAreaWidget::OnMouseExit() - { - m_cursorEntity->Enable(false); + } } void TextAreaWidget::OnTextEntered(char32_t character, bool /*repeated*/)