blob: 34f5dcee04af75a0284df617dc8ac165207d6873 (
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
|
#pragma once
#include "pre.hpp"
#include <optional>
#include <vector>
#include "system_headers.hpp"
#include "base.hpp"
#include "ui/ui_base.hpp"
namespace cru::ui {
class Control;
}
namespace cru::ui::render {
class RenderObject : public Object {
protected:
RenderObject() = default;
public:
RenderObject(const RenderObject& other) = delete;
RenderObject(RenderObject&& other) = delete;
RenderObject& operator=(const RenderObject& other) = delete;
RenderObject& operator=(RenderObject&& other) = delete;
~RenderObject() override = default;
Control* GetAttachedControl() const { return control_; }
void SetAttachedControl(Control* new_control) { control_ = new_control; }
RenderObject* GetParent() const { return parent_; }
const std::vector<RenderObject*>& GetChildren() const { return children_; }
void AddChild(RenderObject* render_object, int position);
void RemoveChild(int position);
Point GetOffset() const { return offset_; }
void SetOffset(const Point& offset) { offset_ = offset; }
Size GetSize() const { return size_; }
void SetSize(const Size& size) { size_ = size; }
Thickness GetMargin() const { return margin_; }
void SetMargin(const Thickness& margin) { margin_ = margin; }
Thickness GetPadding() const { return padding_; }
void SetPadding(const Thickness& padding) { padding_ = padding; }
Size GetPreferredSize() const { return preferred_size_; }
void SetPreferredSize(const Size& preferred_size) {
preferred_size_ = preferred_size;
}
void Measure(const Size& available_size);
void Layout(const Rect& rect);
virtual void Draw(ID2D1RenderTarget* render_target) = 0;
virtual RenderObject* HitTest(const Point& point) = 0;
protected:
virtual void OnParentChanged(RenderObject* old_parent,
RenderObject* new_parent);
virtual void OnAddChild(RenderObject* new_child, int position);
virtual void OnRemoveChild(RenderObject* removed_child, int position);
virtual Size OnMeasureContent(const Size& available_size) = 0;
virtual void OnLayoutContent(const Rect& content_rect) = 0;
private:
void SetParent(RenderObject* new_parent);
void OnMeasureCore(const Size& available_size);
void OnLayoutCore(const Rect& rect);
private:
Control* control_ = nullptr;
RenderObject* parent_ = nullptr;
std::vector<RenderObject*> children_{};
Point offset_ = Point::Zero();
Size size_ = Size::Zero();
Thickness margin_ = Thickness::Zero();
Thickness padding_ = Thickness::Zero();
Size preferred_size_ = Size::Zero();
};
} // namespace cru::ui::render
|