aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/TextBlock.cpp
blob: a36c6b41dd407f392a355b1f718329b9993e6fb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "cru/ui/controls/TextBlock.h"
#include "cru/platform/graphics/Factory.h"
#include "cru/platform/gui/UiApplication.h"
#include "cru/ui/ThemeManager.h"
#include "cru/ui/render/TextRenderObject.h"

#include <memory>

namespace cru::ui::controls {
TextBlock::TextBlock() : Control(kControlName) {
  auto theme_manager = ThemeManager::GetInstance();
  text_render_object_ = std::make_unique<render::TextRenderObject>(
      theme_manager->GetResourceBrush("text.brush"),
      theme_manager->GetResourceFont("text.font"),
      theme_manager->GetResourceBrush("text.selection.brush"),
      theme_manager->GetResourceBrush("text.caret.brush"));

  text_render_object_->SetAttachedControl(this);

  service_ = std::make_unique<TextHostControlService>(this);
  service_->SetEnabled(false);
  service_->SetEditable(false);
}

render::RenderObject* TextBlock::GetRenderObject() {
  return text_render_object_.get();
}

std::string TextBlock::GetText() { return service_->GetText(); }

void TextBlock::SetText(std::string text) {
  service_->SetText(std::move(text));
}

bool TextBlock::IsSelectable() { return service_->IsEnabled(); }

void TextBlock::SetSelectable(bool value) { service_->SetEnabled(value); }

void TextBlock::SetTextColor(const Color& color) {
  text_render_object_->SetBrush(platform::gui::IUiApplication::GetInstance()
                                    ->GetGraphicsFactory()
                                    ->CreateSolidColorBrush(color));
}

render::TextRenderObject* TextBlock::GetTextRenderObject() {
  return text_render_object_.get();
}
}  // namespace cru::ui::controls