aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/render
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-04-24 00:03:16 +0800
committercrupest <crupest@outlook.com>2020-04-24 00:03:16 +0800
commit75ff8a6a05afd02aaadf7e3049b0a0e305241182 (patch)
tree5444bbb3ef80036cc38a827b8ccf03f48b310728 /include/cru/ui/render
parent922d7f6c96f81a33538900f8a8992a5b6f640874 (diff)
downloadcru-75ff8a6a05afd02aaadf7e3049b0a0e305241182.tar.gz
cru-75ff8a6a05afd02aaadf7e3049b0a0e305241182.tar.bz2
cru-75ff8a6a05afd02aaadf7e3049b0a0e305241182.zip
...
Diffstat (limited to 'include/cru/ui/render')
-rw-r--r--include/cru/ui/render/text_render_object.hpp40
1 files changed, 30 insertions, 10 deletions
diff --git a/include/cru/ui/render/text_render_object.hpp b/include/cru/ui/render/text_render_object.hpp
index c062c9f0..4b1e91e0 100644
--- a/include/cru/ui/render/text_render_object.hpp
+++ b/include/cru/ui/render/text_render_object.hpp
@@ -6,9 +6,13 @@
namespace cru::ui::render {
class TextRenderObject : public RenderObject {
public:
+ constexpr static float default_caret_width = 2;
+
+ public:
TextRenderObject(std::shared_ptr<platform::graph::IBrush> brush,
std::shared_ptr<platform::graph::IFont> font,
- std::shared_ptr<platform::graph::IBrush> selection_brush);
+ std::shared_ptr<platform::graph::IBrush> selection_brush,
+ std::shared_ptr<platform::graph::IBrush> caret_brush);
TextRenderObject(const TextRenderObject& other) = delete;
TextRenderObject(TextRenderObject&& other) = delete;
TextRenderObject& operator=(const TextRenderObject& other) = delete;
@@ -19,30 +23,41 @@ class TextRenderObject : public RenderObject {
void SetText(std::string new_text);
std::shared_ptr<platform::graph::IBrush> GetBrush() const { return brush_; }
- void SetBrush(std::shared_ptr<platform::graph::IBrush> new_brush) {
- new_brush.swap(brush_);
- }
+ void SetBrush(std::shared_ptr<platform::graph::IBrush> new_brush);
std::shared_ptr<platform::graph::IFont> GetFont() const;
void SetFont(std::shared_ptr<platform::graph::IFont> font);
std::vector<Rect> TextRangeRect(const TextRange& text_range);
- Point TextSingleRect(gsl::index position, bool trailing);
+ Point TextSinglePoint(gsl::index position, bool trailing);
platform::graph::TextHitTestResult TextHitTest(const Point& point);
std::optional<TextRange> GetSelectionRange() const {
return selection_range_;
}
- void SetSelectionRange(std::optional<TextRange> new_range) {
- selection_range_ = std::move(new_range);
- }
+ void SetSelectionRange(std::optional<TextRange> new_range);
std::shared_ptr<platform::graph::IBrush> GetSelectionBrush() const {
return selection_brush_;
}
- void SetSelectionBrush(std::shared_ptr<platform::graph::IBrush> new_brush) {
- new_brush.swap(selection_brush_);
+ void SetSelectionBrush(std::shared_ptr<platform::graph::IBrush> new_brush);
+
+ bool IsDrawCaret() const { return draw_caret_; }
+ void SetDrawCaret(bool draw_caret);
+ void ToggleDrawCaret() { SetDrawCaret(!IsDrawCaret()); }
+
+ // Caret position can be any value. When it is negative, 0 is used. When it
+ // exceeds the size of the string, the size of the string is used.
+ gsl::index GetCaretPosition() const { return caret_position_; }
+ void SetCaretPosition(gsl::index position);
+
+ std::shared_ptr<platform::graph::IBrush> GetCaretBrush() const {
+ return caret_brush_;
}
+ void GetCaretBrush(std::shared_ptr<platform::graph::IBrush> brush);
+
+ float GetCaretWidth() const { return caret_width_; }
+ void SetCaretWidth(float width);
void Draw(platform::graph::IPainter* painter) override;
@@ -61,5 +76,10 @@ class TextRenderObject : public RenderObject {
std::optional<TextRange> selection_range_ = std::nullopt;
std::shared_ptr<platform::graph::IBrush> selection_brush_;
+
+ bool draw_caret_ = false;
+ gsl::index caret_position_ = 0;
+ std::shared_ptr<platform::graph::IBrush> caret_brush_;
+ float caret_width_ = default_caret_width;
};
} // namespace cru::ui::render