aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/IconButton.cpp
blob: e20e422fce81bb569ce22fbaa67f6409be1b5435 (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
49
50
#include "cru/ui/controls/IconButton.h"
#include "cru/platform/graphics/Factory.h"
#include "cru/platform/graphics/Geometry.h"
#include "cru/platform/gui/UiApplication.h"
#include "cru/ui/ThemeManager.h"

namespace cru::ui::controls {
IconButton::IconButton() : Control(kControlName), click_detector_(this) {
  container_render_object_.SetChild(&geometry_render_object_);
  container_render_object_.SetAttachedControl(this);
  geometry_render_object_.SetAttachedControl(this);

  container_render_object_.SetBorderEnabled(true);
  GetStyleRuleSet()->SetParent(
      ThemeManager::GetInstance()->GetResourceStyleRuleSet(
          "icon-button.style"));
}

IconButton::IconButton(std::string_view icon_svg_path_data_string,
                       const Rect& view_port)
    : IconButton() {
  SetIconWithSvgPathDataString(icon_svg_path_data_string, view_port);
}

IconButton::~IconButton() {}

void IconButton::SetIconFillColor(const Color& color) {
  SetIconFillBrush(platform::gui::IUiApplication::GetInstance()
                       ->GetGraphicsFactory()
                       ->CreateSolidColorBrush(color));
}

void IconButton::SetIconWithSvgPathDataString(
    std::string_view icon_svg_path_data_string, const Rect& view_port) {
  SetIconGeometry(
      platform::graphics::CreateGeometryFromSvgPathData(
          platform::gui::IUiApplication::GetInstance()->GetGraphicsFactory(),
          icon_svg_path_data_string),
      view_port);
}

void IconButton::SetIconWithSvgPathDataStringResourceKey(
    std::string_view icon_svg_path_data_string_resource_key,
    const Rect& view_port) {
  SetIconWithSvgPathDataString(ThemeManager::GetInstance()->GetResourceString(
                                   icon_svg_path_data_string_resource_key),
                               view_port);
}

}  // namespace cru::ui::controls