diff options
author | crupest <crupest@outlook.com> | 2021-11-15 16:26:25 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-11-15 16:26:25 +0800 |
commit | 4ac58d91bac0cebe2bdf5e11b9d63b9c41e6b39e (patch) | |
tree | 7a4a8f587ffadb9f722b33badf2568e1d325b818 /include | |
parent | 63b4956c3a802ee1c0fd92d1ce56e9330b6de4d2 (diff) | |
download | cru-4ac58d91bac0cebe2bdf5e11b9d63b9c41e6b39e.tar.gz cru-4ac58d91bac0cebe2bdf5e11b9d63b9c41e6b39e.tar.bz2 cru-4ac58d91bac0cebe2bdf5e11b9d63b9c41e6b39e.zip |
...
Diffstat (limited to 'include')
-rw-r--r-- | include/cru/common/String.hpp | 15 | ||||
-rw-r--r-- | include/cru/ui/controls/TextHostControlService.hpp | 13 | ||||
-rw-r--r-- | include/cru/ui/helper/ShortcutHub.hpp | 4 |
3 files changed, 28 insertions, 4 deletions
diff --git a/include/cru/common/String.hpp b/include/cru/common/String.hpp index 9996f617..264a44ff 100644 --- a/include/cru/common/String.hpp +++ b/include/cru/common/String.hpp @@ -395,6 +395,21 @@ inline bool Utf16IsValidInsertPosition(StringView str, Index position) { return Utf16IsValidInsertPosition(str.data(), str.size(), position); } +// Return position after the character making predicate returns true or 0 if no +// character doing so. +inline Index CRU_BASE_API +Utf16BackwardUntil(StringView str, Index position, + const std::function<bool(CodePoint)>& predicate) { + return Utf16BackwardUntil(str.data(), str.size(), position, predicate); +} +// Return position before the character making predicate returns true or +// str.size() if no character doing so. +inline Index CRU_BASE_API +Utf16ForwardUntil(StringView str, Index position, + const std::function<bool(CodePoint)>& predicate) { + return Utf16ForwardUntil(str.data(), str.size(), position, predicate); +} + inline Index Utf16PreviousWord(StringView str, Index position, bool* is_space = nullptr) { return Utf16PreviousWord(str.data(), str.size(), position, is_space); diff --git a/include/cru/ui/controls/TextHostControlService.hpp b/include/cru/ui/controls/TextHostControlService.hpp index adf72d69..da9547ac 100644 --- a/include/cru/ui/controls/TextHostControlService.hpp +++ b/include/cru/ui/controls/TextHostControlService.hpp @@ -8,6 +8,7 @@ #include "cru/ui/helper/ShortcutHub.hpp" #include <functional> +#include <vector> namespace cru::ui::render { class TextRenderObject; @@ -29,6 +30,8 @@ class TextControlMovePattern : public Object { public: static TextControlMovePattern kLeft; static TextControlMovePattern kRight; + static TextControlMovePattern kCtrlLeft; + static TextControlMovePattern kCtrlRight; static TextControlMovePattern kUp; static TextControlMovePattern kDown; static TextControlMovePattern kHome; @@ -36,6 +39,8 @@ class TextControlMovePattern : public Object { static TextControlMovePattern kPageUp; static TextControlMovePattern kPageDown; + static std::vector<TextControlMovePattern> kDefaultPatterns; + using MoveFunction = std::function<gsl::index(TextHostControlService* service, StringView text, gsl::index current_position)>; @@ -44,15 +49,15 @@ class TextControlMovePattern : public Object { MoveFunction move_function) : key_bind_(key_bind), move_function_(move_function) {} - CRU_DELETE_COPY(TextControlMovePattern) - CRU_DELETE_MOVE(TextControlMovePattern) + CRU_DEFAULT_COPY(TextControlMovePattern) + CRU_DEFAULT_MOVE(TextControlMovePattern) ~TextControlMovePattern() override = default; public: helper::ShortcutKeyBind GetKeyBind() const { return key_bind_; } gsl::index Move(TextHostControlService* service, StringView text, - gsl::index current_position) { + gsl::index current_position) const { return move_function_(service, text, current_position); } @@ -118,10 +123,10 @@ class TextHostControlService : public Object { void ScrollToCaret(); - private: gsl::not_null<render::TextRenderObject*> GetTextRenderObject(); render::ScrollRenderObject* GetScrollRenderObject(); + private: // May return nullptr. platform::gui::IInputMethodContext* GetInputMethodContext(); diff --git a/include/cru/ui/helper/ShortcutHub.hpp b/include/cru/ui/helper/ShortcutHub.hpp index 7f098a6d..ed90381d 100644 --- a/include/cru/ui/helper/ShortcutHub.hpp +++ b/include/cru/ui/helper/ShortcutHub.hpp @@ -32,6 +32,10 @@ class ShortcutKeyBind { platform::gui::KeyCode GetKey() const { return key_; } platform::gui::KeyModifier GetModifier() const { return modifier_; } + ShortcutKeyBind AddModifier(platform::gui::KeyModifier modifier) const { + return ShortcutKeyBind(key_, modifier_ | modifier); + } + bool Is(platform::gui::KeyCode key, platform::gui::KeyModifier modifier) const { return key == key_ && modifier == modifier_; |