From 05f277deeb8ef72d919a8053cbce3bfa2f484e23 Mon Sep 17 00:00:00 2001 From: S6066 Date: Fri, 3 Aug 2018 08:43:48 +0200 Subject: [PATCH] Ndk/TextAreaWidget: Add possibility to write only one specific character category (#174) * Ndk/TextAreaWidget: Add possibility to write only one specific character category * Add support for multiple categories * Use a predicate instead of an enum * Log change * String::FindLast/FindWord: Fix bug where index wouldn't be used (#177) * String::FindLast/FindWord: Fix bug where index wouldn't be used * Log change * Update Physics2D Component and Body (#178) * Update * Add: [Get/Set]AngularDaming for standardization * Fix: Name error * Add: [Get/Set][AngularDamping/MomentOfInertia] in PhysicsComponent2D * Forgot in last commit * Add: param coordSys in [PhysicsComponent2D/RigidBody2D]::SetMassCenter * Add: Some forgotten inline * Fix little error * Fix: Indentation before case * Move and Change GetCenterOfGravity * Physics2D: Add Arbiter2D * Fix deprecation warning * Fix units tests :derp: * Fixies --- ChangeLog.md | 5 +++-- SDK/include/NDK/Widgets/TextAreaWidget.hpp | 6 ++++++ SDK/include/NDK/Widgets/TextAreaWidget.inl | 10 ++++++++++ SDK/src/NDK/Widgets/TextAreaWidget.cpp | 3 ++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 4cd68d12a..f50db11c2 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -177,11 +177,12 @@ Nazara Development Kit: - ⚠️ TextAreaWidget::GetHoveredGlyph now returns a two-dimensional position instead of a single glyph position - Fixed Entity::OnEntityDestruction signal not being properly moved and thus not being called. - Fixed EntityOwner move assignment which was losing entity ownership -- Add GraphicsComponent:ForEachRenderable method +- Added GraphicsComponent:ForEachRenderable method - Fixed GraphicsComponent reflective material count which was not initialized - Added PhysicsComponent2D::ClosestPointQuery -- Fix GraphicsComponent copy constructor not copying scissor rect +- Fixed GraphicsComponent copy constructor not copying scissor rect - Force parent parameter to be present in widgets constructor +- Added the possibility to write only specific characters with a predicate in TextAreaWidget # 0.4: diff --git a/SDK/include/NDK/Widgets/TextAreaWidget.hpp b/SDK/include/NDK/Widgets/TextAreaWidget.hpp index af5377e6f..4c3168c4e 100644 --- a/SDK/include/NDK/Widgets/TextAreaWidget.hpp +++ b/SDK/include/NDK/Widgets/TextAreaWidget.hpp @@ -12,12 +12,15 @@ #include #include #include +#include namespace Ndk { class NDK_API TextAreaWidget : public BaseWidget { public: + using CharacterFilter = std::function; + TextAreaWidget(BaseWidget* parent); TextAreaWidget(const TextAreaWidget&) = delete; TextAreaWidget(TextAreaWidget&&) = default; @@ -33,6 +36,7 @@ namespace Ndk void EraseSelection(); + inline CharacterFilter GetCharacterFilter() const; inline unsigned int GetCharacterSize() const; inline const Nz::Vector2ui& GetCursorPosition() const; inline Nz::Vector2ui GetCursorPosition(std::size_t glyphIndex) const; @@ -54,6 +58,7 @@ namespace Ndk void ResizeToContent() override; + inline void SetCharacterFilter(CharacterFilter filter); inline void SetCharacterSize(unsigned int characterSize); inline void SetCursorPosition(std::size_t glyphIndex); inline void SetCursorPosition(Nz::Vector2ui cursorPosition); @@ -96,6 +101,7 @@ namespace Ndk void RefreshCursor(); void UpdateDisplayText(); + std::function m_characterFilter; EchoMode m_echoMode; EntityHandle m_cursorEntity; EntityHandle m_textEntity; diff --git a/SDK/include/NDK/Widgets/TextAreaWidget.inl b/SDK/include/NDK/Widgets/TextAreaWidget.inl index 274d46a02..7b49ddb26 100644 --- a/SDK/include/NDK/Widgets/TextAreaWidget.inl +++ b/SDK/include/NDK/Widgets/TextAreaWidget.inl @@ -23,6 +23,11 @@ namespace Ndk m_multiLineEnabled = enable; } + inline TextAreaWidget::CharacterFilter TextAreaWidget::GetCharacterFilter() const + { + return m_characterFilter; + } + inline unsigned int TextAreaWidget::GetCharacterSize() const { return m_drawer.GetCharacterSize(); @@ -140,6 +145,11 @@ namespace Ndk SetCursorPosition(cursorPosition); } + inline void TextAreaWidget::SetCharacterFilter(CharacterFilter filter) + { + m_characterFilter = filter; + } + inline void TextAreaWidget::SetCharacterSize(unsigned int characterSize) { m_drawer.SetCharacterSize(characterSize); diff --git a/SDK/src/NDK/Widgets/TextAreaWidget.cpp b/SDK/src/NDK/Widgets/TextAreaWidget.cpp index f10f57953..bf35c726e 100644 --- a/SDK/src/NDK/Widgets/TextAreaWidget.cpp +++ b/SDK/src/NDK/Widgets/TextAreaWidget.cpp @@ -11,6 +11,7 @@ namespace Ndk { TextAreaWidget::TextAreaWidget(BaseWidget* parent) : BaseWidget(parent), + m_characterFilter(), m_echoMode(EchoMode_Normal), m_cursorPositionBegin(0U, 0U), m_cursorPositionEnd(0U, 0U), @@ -394,7 +395,7 @@ namespace Ndk default: { - if (Nz::Unicode::GetCategory(character) == Nz::Unicode::Category_Other_Control) + if (Nz::Unicode::GetCategory(character) == Nz::Unicode::Category_Other_Control || (m_characterFilter && !m_characterFilter(character))) break; if (HasSelection())