aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-11-10 15:12:19 +0800
committercrupest <crupest@outlook.com>2020-11-10 15:12:19 +0800
commit02ed6999e9db0c20c3f55ab9c695f939aacb110c (patch)
tree10b4f1cf2d8956ed5dcdd5580eadc64d0d5dbd0d
parent460a45df8be4613053c6a097d9c699c70dbe1a2c (diff)
downloadcru-02ed6999e9db0c20c3f55ab9c695f939aacb110c.tar.gz
cru-02ed6999e9db0c20c3f55ab9c695f939aacb110c.tar.bz2
cru-02ed6999e9db0c20c3f55ab9c695f939aacb110c.zip
...
-rw-r--r--demos/main/main.cpp6
-rw-r--r--include/cru/ui/controls/TextBlock.hpp6
-rw-r--r--src/ui/controls/TextBlock.cpp19
3 files changed, 23 insertions, 8 deletions
diff --git a/demos/main/main.cpp b/demos/main/main.cpp
index 66354289..541a2320 100644
--- a/demos/main/main.cpp
+++ b/demos/main/main.cpp
@@ -32,12 +32,10 @@ int main() {
window->AddChild(flex_layout, 0);
- const auto text_block = TextBlock::Create();
- text_block->SetText(u"Hello World from CruUI!");
+ const auto text_block = TextBlock::Create(u"Hello World from CruUI!", true);
flex_layout->AddChild(text_block, 0);
- const auto button_text_block = TextBlock::Create();
- button_text_block->SetText(u"OK");
+ const auto button_text_block = TextBlock::Create(u"OK");
const auto button = Button::Create();
button->SetChild(button_text_block);
flex_layout->AddChild(button, 1);
diff --git a/include/cru/ui/controls/TextBlock.hpp b/include/cru/ui/controls/TextBlock.hpp
index fdfdb2fa..66ebe476 100644
--- a/include/cru/ui/controls/TextBlock.hpp
+++ b/include/cru/ui/controls/TextBlock.hpp
@@ -9,7 +9,8 @@ class TextBlock : public NoChildControl {
public:
static constexpr std::u16string_view control_type = u"TextBlock";
- static TextBlock* Create() { return new TextBlock(); }
+ static TextBlock* Create();
+ static TextBlock* Create(std::u16string text, bool selectable = false);
protected:
TextBlock();
@@ -28,6 +29,9 @@ class TextBlock : public NoChildControl {
std::u16string GetText() const;
void SetText(std::u16string text);
+ bool IsSelectable() const;
+ void SetSelectable(bool value);
+
gsl::not_null<render::TextRenderObject*> GetTextRenderObject();
render::ScrollRenderObject* GetScrollRenderObject() { return nullptr; }
diff --git a/src/ui/controls/TextBlock.cpp b/src/ui/controls/TextBlock.cpp
index 9ce99ab6..1a432582 100644
--- a/src/ui/controls/TextBlock.cpp
+++ b/src/ui/controls/TextBlock.cpp
@@ -7,10 +7,17 @@
#include "cru/ui/render/TextRenderObject.hpp"
namespace cru::ui::controls {
-using render::CanvasRenderObject;
-using render::StackLayoutRenderObject;
using render::TextRenderObject;
+TextBlock* TextBlock::Create() { return new TextBlock(); }
+
+TextBlock* TextBlock::Create(std::u16string text, bool selectable) {
+ auto c = new TextBlock();
+ c->SetText(text);
+ c->SetSelectable(selectable);
+ return c;
+}
+
TextBlock::TextBlock() {
const auto theme_resources = UiManager::GetInstance()->GetThemeResources();
@@ -21,7 +28,9 @@ TextBlock::TextBlock() {
text_render_object_->SetAttachedControl(this);
service_ = std::make_unique<TextControlService<TextBlock>>(this);
- service_->SetEnabled(true);
+
+ service_->SetEnabled(false);
+ service_->SetEditable(false);
}
TextBlock::~TextBlock() = default;
@@ -36,6 +45,10 @@ void TextBlock::SetText(std::u16string text) {
service_->SetText(std::move(text));
}
+bool TextBlock::IsSelectable() const { return service_->IsEnabled(); }
+
+void TextBlock::SetSelectable(bool value) { service_->SetEnabled(value); }
+
gsl::not_null<render::TextRenderObject*> TextBlock::GetTextRenderObject() {
return text_render_object_.get();
}