From 184c3b2b39d3fa34f9349a7d7fbebe49bc62f7fc Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 24 Sep 2018 14:03:20 +0800 Subject: Basically add text control. --- CruUI/ui/controls/text_block.h | 90 +++--------------------------------------- 1 file changed, 6 insertions(+), 84 deletions(-) (limited to 'CruUI/ui/controls/text_block.h') diff --git a/CruUI/ui/controls/text_block.h b/CruUI/ui/controls/text_block.h index c87ffc51..c307fd2f 100644 --- a/CruUI/ui/controls/text_block.h +++ b/CruUI/ui/controls/text_block.h @@ -1,9 +1,6 @@ #pragma once -#include -#include - -#include "ui/control.h" +#include "text_control.h" namespace cru { @@ -11,11 +8,9 @@ namespace cru { namespace controls { - class TextBlock : public Control + class TextBlock : public TextControl { public: - using TextLayoutHandlerPtr = FunctionPtr)>; - static TextBlock* Create( const String& text = L"", const Microsoft::WRL::ComPtr& init_text_format = nullptr, @@ -27,89 +22,16 @@ namespace cru } protected: - explicit TextBlock( - const Microsoft::WRL::ComPtr& init_text_format = nullptr, - const Microsoft::WRL::ComPtr& init_brush = nullptr + TextBlock( + const Microsoft::WRL::ComPtr& init_text_format, + const Microsoft::WRL::ComPtr& init_brush ); public: TextBlock(const TextBlock& other) = delete; TextBlock(TextBlock&& other) = delete; TextBlock& operator=(const TextBlock& other) = delete; TextBlock& operator=(TextBlock&& other) = delete; - ~TextBlock() override; - - String GetText() const - { - return text_; - } - - void SetText(const String& text); - - Microsoft::WRL::ComPtr GetBrush() const - { - return brush_; - } - - void SetBrush(const Microsoft::WRL::ComPtr& brush); - - Microsoft::WRL::ComPtr GetTextFormat() const - { - return text_format_; - } - - void SetTextFormat(const Microsoft::WRL::ComPtr& text_format); - - - void AddTextLayoutHandler(TextLayoutHandlerPtr handler); - - void RemoveTextLayoutHandler(const TextLayoutHandlerPtr& handler); - - bool IsSelectable() const - { - return is_selectable_; - } - - void SetSelectable(bool is_selectable); - - std::optional GetSelectedRange() const - { - return selected_range_; - } - - void SetSelectedRange(std::optional text_range); - - protected: - void OnSizeChangedCore(events::SizeChangedEventArgs& args) override final; - void OnDraw(ID2D1DeviceContext* device_context) override; - - void OnMouseDownCore(events::MouseButtonEventArgs& args) override final; - void OnMouseMoveCore(events::MouseEventArgs& args) override final; - void OnMouseUpCore(events::MouseButtonEventArgs& args) override final; - - void OnLoseFocusCore(events::FocusChangeEventArgs& args) override final; - - Size OnMeasure(const Size& available_size) override final; - - private: - void OnTextChangedCore(const String& old_text, const String& new_text); - - void RecreateTextLayout(); - - private: - String text_; - - Microsoft::WRL::ComPtr brush_; - Microsoft::WRL::ComPtr selection_brush_; - Microsoft::WRL::ComPtr text_format_; - Microsoft::WRL::ComPtr text_layout_; - - Vector text_layout_handlers_; - - bool is_selectable_ = false; - - bool is_selecting_ = false; - unsigned mouse_down_position_ = 0; - std::optional selected_range_ = std::nullopt; + ~TextBlock() override = default; }; } } -- cgit v1.2.3