diff options
author | crupest <crupest@outlook.com> | 2020-03-03 23:36:45 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-03-03 23:36:45 +0800 |
commit | 0dcf8e686b93cca54a424affe0455d0a97d6c2ef (patch) | |
tree | 744897a3b6a29f6142f1943dab5d9957e670919b /include/cru/ui/controls/text_common.hpp | |
parent | 47053829c322c43032244937cb63f9da178b852d (diff) | |
download | cru-0dcf8e686b93cca54a424affe0455d0a97d6c2ef.tar.gz cru-0dcf8e686b93cca54a424affe0455d0a97d6c2ef.tar.bz2 cru-0dcf8e686b93cca54a424affe0455d0a97d6c2ef.zip |
...
Diffstat (limited to 'include/cru/ui/controls/text_common.hpp')
-rw-r--r-- | include/cru/ui/controls/text_common.hpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/include/cru/ui/controls/text_common.hpp b/include/cru/ui/controls/text_common.hpp new file mode 100644 index 00000000..7398764f --- /dev/null +++ b/include/cru/ui/controls/text_common.hpp @@ -0,0 +1,66 @@ +#pragma once +#include "../base.hpp" + +#include "cru/ui/ui_event.hpp" + +#include <functional> +#include <optional> + +namespace cru::platform::graph { +struct IBrush; +} + +namespace cru::ui::render { +class TextRenderObject; +class CanvasRenderObject; +} // namespace cru::ui::render + +namespace cru::ui::controls { + +struct ITextControl : virtual Interface { + virtual render::TextRenderObject* GetTextRenderObject() = 0; + virtual render::CanvasRenderObject* GetCaretRenderObject() = 0; + virtual platform::graph::IBrush* GetCaretBrush() = 0; +}; + +class TextControlService : public Object { + public: + TextControlService(Control* control, ITextControl* text_control); + + CRU_DELETE_COPY(TextControlService) + CRU_DELETE_MOVE(TextControlService) + + ~TextControlService(); + + public: + int GetCaretPosition() { return caret_position_; } + void SetCaretPosition(int position) { caret_position_ = position; } + + bool IsCaretVisible() { return caret_visible_; } + void SetCaretVisible(bool visible); + + // please set correct offset before calling this + void DrawCaret(platform::graph::IPainter* painter); + + private: + void SetupCaretTimer(); + void TearDownCaretTimer(); + + private: + Control* control_; + ITextControl* text_control_; + std::vector<EventRevokerGuard> event_revoker_guards_; + + bool caret_visible_ = false; + int caret_position_ = 0; + unsigned long caret_timer_tag_; + // this is used for blinking of caret + bool caret_show_ = true; + + // nullopt means not selecting + std::optional<MouseButton> select_down_button_; + + // before the char + int select_start_position_; +}; +} // namespace cru::ui::controls |