aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/text_box.h
diff options
context:
space:
mode:
authorYuqian Yang <crupest@outlook.com>2018-09-25 10:13:48 +0000
committerYuqian Yang <crupest@outlook.com>2018-09-25 10:13:48 +0000
commitc8ddc4bc7d96b67aac9526089ade64b31007fa3e (patch)
tree27317ae0d9ac5b1409408ef165595f9c127aa027 /src/ui/controls/text_box.h
parentea4b0966d8eb5a8e76dfbe4d833a07a4797a3284 (diff)
parentda768af31952a28aa7aca8f60acd85bf2832465c (diff)
downloadcru-c8ddc4bc7d96b67aac9526089ade64b31007fa3e.tar.gz
cru-c8ddc4bc7d96b67aac9526089ade64b31007fa3e.tar.bz2
cru-c8ddc4bc7d96b67aac9526089ade64b31007fa3e.zip
Merge branch 'issue4-dev' into 'master'
Resolve "Abstract out the common part of TextBlock and TextBox." Closes #4 See merge request crupest/CruUI!3
Diffstat (limited to 'src/ui/controls/text_box.h')
-rw-r--r--src/ui/controls/text_box.h53
1 files changed, 8 insertions, 45 deletions
diff --git a/src/ui/controls/text_box.h b/src/ui/controls/text_box.h
index b815ed1f..07c4abe4 100644
--- a/src/ui/controls/text_box.h
+++ b/src/ui/controls/text_box.h
@@ -1,11 +1,11 @@
#pragma once
-#include "ui/control.h"
+#include "text_control.h"
#include "timer.h"
namespace cru::ui::controls
{
- class TextBox : public Control
+ class TextBox : public TextControl
{
public:
static TextBox* Create(
@@ -17,8 +17,8 @@ namespace cru::ui::controls
protected:
explicit TextBox(
- const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format = nullptr,
- const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush = nullptr
+ const Microsoft::WRL::ComPtr<IDWriteTextFormat>& init_text_format,
+ const Microsoft::WRL::ComPtr<ID2D1Brush>& init_brush
);
public:
TextBox(const TextBox& other) = delete;
@@ -27,59 +27,22 @@ namespace cru::ui::controls
TextBox& operator=(TextBox&& other) = delete;
~TextBox() override;
- String GetText() const
- {
- return text_;
- }
-
- void SetText(const String& text);
-
- Microsoft::WRL::ComPtr<ID2D1Brush> GetBrush() const
- {
- return brush_;
- }
-
- void SetBrush(const Microsoft::WRL::ComPtr<ID2D1Brush>& brush);
-
- Microsoft::WRL::ComPtr<IDWriteTextFormat> GetTextFormat() const
- {
- return text_format_;
- }
-
- void SetTextFormat(const Microsoft::WRL::ComPtr<IDWriteTextFormat>& text_format);
-
protected:
- void OnSizeChangedCore(events::SizeChangedEventArgs& args) override final;
void OnDraw(ID2D1DeviceContext* device_context) override;
- void OnMouseDownCore(events::MouseButtonEventArgs& args) override final;
-
void OnGetFocusCore(events::FocusChangeEventArgs& args) override final;
void OnLoseFocusCore(events::FocusChangeEventArgs& args) override final;
void OnKeyDownCore(events::KeyEventArgs& args) override final;
void OnCharCore(events::CharEventArgs& args) override final;
- Size OnMeasure(const Size& available_size) override final;
-
- private:
- void OnTextChangedCore(const String& old_text, const String& new_text);
-
- void RecreateTextLayout();
+ void RequestChangeCaretPosition(unsigned position) override;
private:
- String text_;
-
- Microsoft::WRL::ComPtr<ID2D1Brush> brush_;
- Microsoft::WRL::ComPtr<ID2D1Brush> caret_brush_;
- //Microsoft::WRL::ComPtr<ID2D1Brush> selection_brush_;
- Microsoft::WRL::ComPtr<IDWriteTextFormat> text_format_;
- Microsoft::WRL::ComPtr<IDWriteTextLayout> text_layout_;
-
- unsigned position_ = 0;
-
+ unsigned caret_position_ = 0;
TimerTask caret_timer_;
ActionPtr caret_action_;
- bool is_caret_show_;
+ Microsoft::WRL::ComPtr<ID2D1Brush> caret_brush_;
+ bool is_caret_show_ = false;
};
}