aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/render/BorderRenderObject.h
blob: 2fc74f0f3e6d2588c79a4091863f0ae90f5807f4 (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
#pragma once
#include "SingleChildRenderObject.h"

#include "../style/ApplyBorderStyleInfo.h"

namespace cru::ui::render {
class CRU_UI_API BorderRenderObject : public SingleChildRenderObject {
  CRU_DEFINE_CLASS_LOG_TAG(u"cru::ui::render::BorderRenderObject")

 public:
  BorderRenderObject();
  CRU_DELETE_COPY(BorderRenderObject)
  CRU_DELETE_MOVE(BorderRenderObject)
  ~BorderRenderObject() override;

  bool IsBorderEnabled() const { return is_border_enabled_; }
  void SetBorderEnabled(bool enabled);

  std::shared_ptr<platform::graphics::IBrush> GetBorderBrush() {
    return border_brush_;
  }
  void SetBorderBrush(std::shared_ptr<platform::graphics::IBrush> brush);

  Thickness GetBorderThickness() const { return border_thickness_; }
  void SetBorderThickness(const Thickness thickness);

  CornerRadius GetBorderRadius() { return border_radius_; }
  void SetBorderRadius(const CornerRadius radius);

  std::shared_ptr<platform::graphics::IBrush> GetForegroundBrush() {
    return foreground_brush_;
  }

  void SetForegroundBrush(std::shared_ptr<platform::graphics::IBrush> brush);

  std::shared_ptr<platform::graphics::IBrush> GetBackgroundBrush() {
    return background_brush_;
  }

  void SetBackgroundBrush(std::shared_ptr<platform::graphics::IBrush> brush);

  void ApplyBorderStyle(const style::ApplyBorderStyleInfo& style);

  RenderObject* HitTest(const Point& point) override;
  void Draw(platform::graphics::IPainter* painter) override;

  Thickness GetOuterSpaceThickness() const override;
  Rect GetPaddingRect() const override;
  Rect GetContentRect() const override;

  String GetName() const override;

 protected:
  Size OnMeasureContent(const MeasureRequirement& requirement,
                        const MeasureSize& preferred_size) override;
  void OnLayoutContent(const Rect& content_rect) override;

  void OnResize(const Size& new_size) override;

 private:
  void RecreateGeometry();

 private:
  bool is_border_enabled_ = false;

  std::shared_ptr<platform::graphics::IBrush> border_brush_;
  Thickness border_thickness_;
  CornerRadius border_radius_;

  std::shared_ptr<platform::graphics::IBrush> foreground_brush_;
  std::shared_ptr<platform::graphics::IBrush> background_brush_;

  // The ring. Used for painting.
  std::unique_ptr<platform::graphics::IGeometry> geometry_;
  // Area including inner area of the border. Used for painting foreground and
  // background.
  std::unique_ptr<platform::graphics::IGeometry> border_inner_geometry_;
  // Area including border ring and inner area. Used for hit test.
  std::unique_ptr<platform::graphics::IGeometry> border_outer_geometry_;
};
}  // namespace cru::ui::render