diff --git a/ChangeLog.md b/ChangeLog.md index 056c4f224..5bbf74f98 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -11,6 +11,7 @@ Nazara Engine: - Fix built-in unserialization of std::string which was corruption memory - Fix Buffer::Destroy() not really destroying buffer + Nazara Development Kit: - Added ImageWidget (#139) - ⚠️ Removed TextAreaWidget::GetLineCount @@ -18,6 +19,10 @@ Nazara Development Kit: - Fix crash occuring sometimes on keyboard event - Add support for EchoMode to TextAreaWidget (which allows to setup password text area) - Add signal OnTextChanged to TextAreaWidget +- ⚠️ Removed TextAreaWidget::GetGlyphUnderCursor +- Fixed minor issues relative to TextAreaWidget cursor handling +- ⚠️ Renamed BaseWidget::GrabKeyboard method to SetFocus +- Added BaseWidget::ClearFocus method and OnFocus[Lost|Received] virtual methods # 0.4: diff --git a/SDK/include/NDK/BaseWidget.hpp b/SDK/include/NDK/BaseWidget.hpp index 9ec7ef7a9..f3c943f70 100644 --- a/SDK/include/NDK/BaseWidget.hpp +++ b/SDK/include/NDK/BaseWidget.hpp @@ -40,6 +40,8 @@ namespace Ndk inline void CenterHorizontal(); inline void CenterVertical(); + void ClearFocus(); + inline void Destroy(); void EnableBackground(bool enable); @@ -56,13 +58,12 @@ namespace Ndk inline bool IsVisible() const; - void GrabKeyboard(); - virtual void ResizeToContent() = 0; void SetBackgroundColor(const Nz::Color& color); void SetCursor(Nz::SystemCursor systemCursor); inline void SetContentSize(const Nz::Vector2f& size); + void SetFocus(); inline void SetPadding(float left, float top, float right, float bottom); void SetSize(const Nz::Vector2f& size); @@ -85,6 +86,8 @@ namespace Ndk virtual void Layout(); void InvalidateNode() override; + virtual void OnFocusLost(); + virtual void OnFocusReceived(); virtual void OnKeyPressed(const Nz::WindowEvent::KeyEvent& key); virtual void OnKeyReleased(const Nz::WindowEvent::KeyEvent& key); virtual void OnMouseEnter(); diff --git a/SDK/include/NDK/Canvas.hpp b/SDK/include/NDK/Canvas.hpp index bcafc1680..44e377aa2 100644 --- a/SDK/include/NDK/Canvas.hpp +++ b/SDK/include/NDK/Canvas.hpp @@ -34,6 +34,8 @@ namespace Ndk Canvas& operator=(Canvas&&) = delete; protected: + inline void ClearKeyboardOwner(std::size_t canvasIndex); + inline void NotifyWidgetBoxUpdate(std::size_t index); inline void NotifyWidgetCursorUpdate(std::size_t index); diff --git a/SDK/include/NDK/Canvas.inl b/SDK/include/NDK/Canvas.inl index 1d64621f2..2e76348af 100644 --- a/SDK/include/NDK/Canvas.inl +++ b/SDK/include/NDK/Canvas.inl @@ -46,6 +46,12 @@ namespace Ndk return m_world; } + inline void Canvas::ClearKeyboardOwner(std::size_t canvasIndex) + { + if (m_keyboardOwner == canvasIndex) + SetKeyboardOwner(InvalidCanvasIndex); + } + inline void Canvas::NotifyWidgetBoxUpdate(std::size_t index) { WidgetBox& entry = m_widgetBoxes[index]; @@ -67,6 +73,12 @@ namespace Ndk inline void Canvas::SetKeyboardOwner(std::size_t canvasIndex) { + if (m_keyboardOwner != InvalidCanvasIndex) + m_widgetBoxes[m_keyboardOwner].widget->OnFocusLost(); + m_keyboardOwner = canvasIndex; + + if (m_keyboardOwner != InvalidCanvasIndex) + m_widgetBoxes[m_keyboardOwner].widget->OnFocusReceived(); } } diff --git a/SDK/src/NDK/BaseWidget.cpp b/SDK/src/NDK/BaseWidget.cpp index aad8c56c6..8af1ef19c 100644 --- a/SDK/src/NDK/BaseWidget.cpp +++ b/SDK/src/NDK/BaseWidget.cpp @@ -46,6 +46,15 @@ namespace Ndk UnregisterFromCanvas(); } + /*! + * \brief Clears keyboard focus if and only if this widget owns it. + */ + void BaseWidget::ClearFocus() + { + if (IsRegisteredToCanvas()) + m_canvas->ClearKeyboardOwner(m_canvasIndex); + } + /*! * \brief Destroy the widget, deleting it in the process. * @@ -85,11 +94,6 @@ namespace Ndk } } - void BaseWidget::GrabKeyboard() - { - m_canvas->SetKeyboardOwner(m_canvasIndex); - } - void BaseWidget::SetBackgroundColor(const Nz::Color& color) { m_backgroundColor = color; @@ -109,6 +113,12 @@ namespace Ndk m_canvas->NotifyWidgetCursorUpdate(m_canvasIndex); } + void BaseWidget::SetFocus() + { + if (IsRegisteredToCanvas()) + m_canvas->SetKeyboardOwner(m_canvasIndex); + } + void BaseWidget::SetSize(const Nz::Vector2f& size) { SetContentSize({std::max(size.x - m_padding.left - m_padding.right, 0.f), std::max(size.y - m_padding.top - m_padding.bottom, 0.f)}); @@ -167,6 +177,14 @@ namespace Ndk m_canvas->NotifyWidgetBoxUpdate(m_canvasIndex); } + void BaseWidget::OnFocusLost() + { + } + + void BaseWidget::OnFocusReceived() + { + } + void BaseWidget::OnKeyPressed(const Nz::WindowEvent::KeyEvent& /*key*/) { }