aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/CheckBox.cpp
blob: a28c46333583e1e5d8913c7ef3cd9cb5cc0366f1 (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
#include "cru/ui/controls/CheckBox.h"
#include "cru/ui/ThemeManager.h"
#include "cru/ui/helper/ClickDetector.h"
#include "cru/ui/render/BorderRenderObject.h"

namespace cru::ui::controls {
CheckBox::CheckBox()
    : container_render_object_(new render::BorderRenderObject()),
      click_detector_(this) {
  container_render_object_->SetAttachedControl(this);

  container_render_object_->SetBorderEnabled(true);
  auto default_checkbox_style =
      ThemeManager::GetInstance()->GetResourceStyleRuleSet(u"checkbox.style");
  GetStyleRuleSet()->SetParent(std::move(default_checkbox_style));

  click_detector_.ClickEvent()->AddHandler(
      [this](const helper::ClickEventArgs&) { Toggle(); });
}

CheckBox::~CheckBox() {}

void CheckBox::SetChecked(bool checked) {
  checked_ = checked;
  checked_change_event_.Raise(checked);
}

void CheckBox::ApplyBorderStyle(const style::ApplyBorderStyleInfo& style) {
  container_render_object_->ApplyBorderStyle(style);
}
}  // namespace cru::ui::controls