aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/controls/IconButton.h
blob: 5b0f899d33c52804a852c074dfa5d221dc5df26d (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#pragma once
#include "../helper/ClickDetector.h"
#include "../render/BorderRenderObject.h"
#include "../render/GeometryRenderObject.h"
#include "Control.h"
#include "IBorderControl.h"
#include "IClickableControl.h"
#include "IContentBrushControl.h"

#include <cru/base/Event.h>
#include <cru/platform/graphics/Brush.h>

namespace cru::ui::controls {
class CRU_UI_API IconButton : public Control,
                              public virtual IClickableControl,
                              public virtual IBorderControl,
                              public virtual IContentBrushControl {
 public:
  static constexpr auto kControlName = "IconButton";

 public:
  IconButton();
  IconButton(std::string_view icon_svg_path_data_string, const Rect& view_port);

  render::RenderObject* GetRenderObject() override {
    return &container_render_object_;
  }

 public:
  helper::ClickState GetClickState() override {
    return click_detector_.GetState();
  }

  IEvent<helper::ClickState>* ClickStateChangeEvent() override {
    return click_detector_.StateChangeEvent();
  }

  IEvent<const helper::ClickEventArgs&>* ClickEvent() override {
    return click_detector_.ClickEvent();
  }

  void ApplyBorderStyle(const style::ApplyBorderStyleInfo& style) override {
    container_render_object_.ApplyBorderStyle(style);
  }

  std::shared_ptr<platform::graphics::IGeometry> GetIconGeometry() {
    return geometry_render_object_.GetGeometry();
  }
  void SetIconGeometry(std::shared_ptr<platform::graphics::IGeometry> geometry,
                       std::optional<Rect> view_port = std::nullopt) {
    geometry_render_object_.SetGeometry(std::move(geometry), view_port);
  }

  Rect GetIconViewPort() { return geometry_render_object_.GetViewPort(); }
  void SetIconViewPort(const Rect& view_port) {
    geometry_render_object_.SetViewPort(view_port);
  }

  std::shared_ptr<platform::graphics::IBrush> GetIconFillBrush() {
    return geometry_render_object_.GetFillBrush();
  }
  void SetIconFillBrush(std::shared_ptr<platform::graphics::IBrush> brush) {
    geometry_render_object_.SetFillBrush(std::move(brush));
  }

  std::shared_ptr<platform::graphics::IBrush> GetIconStrokeBrush() {
    return geometry_render_object_.GetStrokeBrush();
  }
  void SetIconStrokeBrush(std::shared_ptr<platform::graphics::IBrush> brush) {
    geometry_render_object_.SetStrokeBrush(std::move(brush));
  }

  float GetIconStrokeWidth() {
    return geometry_render_object_.GetStrokeWidth();
  }
  void SetIconStrokeWidth(float width) {
    geometry_render_object_.SetStrokeWidth(width);
  }

  void SetIconFillColor(const Color& color);
  void SetIconWithSvgPathDataString(std::string_view icon_svg_path_data_string,
                                    const Rect& view_port);
  void SetIconWithSvgPathDataStringResourceKey(
      std::string_view icon_svg_path_data_string_resource_key,
      const Rect& view_port);

  std::shared_ptr<platform::graphics::IBrush> GetContentBrush() override {
    return GetIconFillBrush();
  }

  void SetContentBrush(
      std::shared_ptr<platform::graphics::IBrush> brush) override {
    SetIconFillBrush(std::move(brush));
  }

 private:
  render::BorderRenderObject container_render_object_;
  render::GeometryRenderObject geometry_render_object_;
  helper::ClickDetector click_detector_;
};
}  // namespace cru::ui::controls