aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-03-18 22:57:08 +0800
committercrupest <crupest@outlook.com>2020-03-18 22:57:08 +0800
commitc5a4f8c11d0d84d85359e5ff03477da5e9f12926 (patch)
tree47122aa3c07ecc536ca387f416de1179c8203329 /include/cru/ui
parentbfd277f9f621931a1c6ea05ea2cd6d04455cfe67 (diff)
downloadcru-c5a4f8c11d0d84d85359e5ff03477da5e9f12926.tar.gz
cru-c5a4f8c11d0d84d85359e5ff03477da5e9f12926.tar.bz2
cru-c5a4f8c11d0d84d85359e5ff03477da5e9f12926.zip
...
Diffstat (limited to 'include/cru/ui')
-rw-r--r--include/cru/ui/controls/text_block.hpp15
-rw-r--r--include/cru/ui/controls/text_box.hpp1
-rw-r--r--include/cru/ui/controls/text_common.hpp80
3 files changed, 9 insertions, 87 deletions
diff --git a/include/cru/ui/controls/text_block.hpp b/include/cru/ui/controls/text_block.hpp
index db0fb4e5..701f946f 100644
--- a/include/cru/ui/controls/text_block.hpp
+++ b/include/cru/ui/controls/text_block.hpp
@@ -1,10 +1,11 @@
#pragma once
#include "../no_child_control.hpp"
-#include "text_common.hpp"
-
namespace cru::ui::controls {
-class TextBlock : public NoChildControl, public virtual ITextControl {
+template <typename TControl>
+class TextControlService;
+
+class TextBlock : public NoChildControl {
public:
static constexpr std::string_view control_type = "TextBlock";
@@ -27,9 +28,9 @@ class TextBlock : public NoChildControl, public virtual ITextControl {
std::string GetText() const;
void SetText(std::string text);
- render::TextRenderObject* GetTextRenderObject() override;
- render::CanvasRenderObject* GetCaretRenderObject() override;
- platform::graph::IBrush* GetCaretBrush() override;
+ render::TextRenderObject* GetTextRenderObject();
+ render::CanvasRenderObject* GetCaretRenderObject();
+ platform::graph::IBrush* GetCaretBrush();
private:
std::unique_ptr<render::StackLayoutRenderObject> root_render_object_;
@@ -37,6 +38,6 @@ class TextBlock : public NoChildControl, public virtual ITextControl {
std::unique_ptr<render::CanvasRenderObject> caret_render_object_;
std::shared_ptr<platform::graph::IBrush> caret_brush_;
- std::unique_ptr<TextControlService> service_;
+ std::unique_ptr<TextControlService<TextBlock>> service_;
};
} // namespace cru::ui::controls
diff --git a/include/cru/ui/controls/text_box.hpp b/include/cru/ui/controls/text_box.hpp
index a7e4dfa0..58179a57 100644
--- a/include/cru/ui/controls/text_box.hpp
+++ b/include/cru/ui/controls/text_box.hpp
@@ -22,5 +22,6 @@ class TextBox : public NoChildControl {
std::unique_ptr<render::StackLayoutRenderObject> stack_layout_render_object_;
std::unique_ptr<render::TextRenderObject> text_render_object_;
std::unique_ptr<render::CanvasRenderObject> caret_render_object_;
+
};
} // namespace cru::ui::controls
diff --git a/include/cru/ui/controls/text_common.hpp b/include/cru/ui/controls/text_common.hpp
deleted file mode 100644
index 64a9666c..00000000
--- a/include/cru/ui/controls/text_common.hpp
+++ /dev/null
@@ -1,80 +0,0 @@
-#pragma once
-#include "../base.hpp"
-
-#include "cru/ui/ui_event.hpp"
-
-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:
- bool IsEnabled() { return enable_; }
- void SetEnabled(bool enable);
-
- 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 AbortSelection();
-
- void SetupCaretTimer();
- void TearDownCaretTimer();
-
- void SetupHandlers();
-
- void MouseMoveHandler(event::MouseEventArgs& args);
- void MouseDownHandler(event::MouseButtonEventArgs& args);
- void MouseUpHandler(event::MouseButtonEventArgs& args);
- void LoseFocusHandler(event::FocusChangeEventArgs& args);
-
- private:
- Control* control_;
- ITextControl* text_control_;
- std::vector<EventRevokerGuard> event_revoker_guards_;
-
- bool enable_ = false;
-
- bool caret_visible_ = false;
- int caret_position_ = 0;
-#ifdef CRU_DEBUG
- bool caret_timer_set_ = false;
-#endif
- 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