bWidgets
Core widget toolkit designed for Blender
Node.h
Go to the documentation of this file.
1#pragma once
2
3#include <list>
4
5#include "bwContainerWidget.h"
6#include "bwLayoutInterface.h"
7#include "bwWidget.h"
8
9namespace bWidgets {
10namespace bwScreenGraph {
11
12class EventHandler;
13
36class Node {
37 friend class Builder;
38
39 public:
40 using ChildList = std::list<std::unique_ptr<Node>>;
41 using ChildIterator = ChildList::iterator;
42
43 Node() = default;
44 virtual ~Node() = default;
45
46 virtual auto Children() const -> const ChildList*
47 {
48 return nullptr;
49 }
50 virtual auto Children() -> ChildList*
51 {
52 return nullptr;
53 }
54
55 virtual auto childrenVisible() const -> bool
56 {
57 return true;
58 }
59
60 virtual auto Layout() const -> bwLayoutInterface*
61 {
62 return nullptr;
63 }
64
65 virtual auto Widget() const -> bwWidget*
66 {
67 return nullptr;
68 }
69
70 auto Parent() const -> Node*
71 {
72 return parent;
73 }
74
75 auto eventHandler() const -> EventHandler*
76 {
77 return handler.get();
78 }
79
80 virtual auto Rectangle() const -> bwRectanglePixel = 0;
81 virtual auto MaskRectangle() const -> std::optional<bwRectanglePixel> = 0;
82 virtual auto isVisible() const -> bool = 0;
83
84 private:
85 Node* parent{nullptr};
86 std::unique_ptr<EventHandler> handler{nullptr};
87};
88
92class LayoutNode : virtual public Node {
93 friend class Builder;
94
95 public:
96 auto Children() const -> const ChildList* override
97 {
98 return &children;
99 }
100 auto Children() -> ChildList* override
101 {
102 return &children;
103 }
104
105 auto Layout() const -> bwLayoutInterface* override
106 {
107 return layout.get();
108 }
109
110 auto Rectangle() const -> bwRectanglePixel override
111 {
112 return layout->getRectangle();
113 }
114
115 auto MaskRectangle() const -> std::optional<bwRectanglePixel> override
116 {
117 return std::nullopt;
118 }
119
120 auto isVisible() const -> bool override
121 {
122 return true;
123 }
124
125 private:
126 ChildList children;
127 std::unique_ptr<bwLayoutInterface> layout;
128};
129
133class WidgetNode : virtual public Node {
134 friend class Builder;
135
136 public:
137 auto Widget() const -> bwWidget* override
138 {
139 return &*widget;
140 }
141
142 auto Rectangle() const -> bwRectanglePixel override
143 {
144 return widget->rectangle;
145 }
146
147 auto MaskRectangle() const -> std::optional<bwRectanglePixel> override
148 {
149 return std::nullopt;
150 }
151
152 auto isVisible() const -> bool override
153 {
154 return widget->isHidden() == false;
155 }
156
157 private:
158 std::unique_ptr<bwWidget> widget;
159};
160
167class ContainerNode : public LayoutNode, public WidgetNode {
168 public:
169 auto Children() const -> const ChildList* override
170 {
171 return LayoutNode::Children();
172 }
173 auto Children() -> ChildList* override
174 {
175 return LayoutNode::Children();
176 }
177
178 auto Layout() const -> bwLayoutInterface* override
179 {
180 return LayoutNode::Layout();
181 }
182
183 auto Widget() const -> bwWidget* override
184 {
185 return WidgetNode::Widget();
186 }
187
189 {
190 return static_cast<bwContainerWidget&>(*Widget());
191 }
192
193 auto Rectangle() const -> bwRectanglePixel override
194 {
195 return WidgetNode::Rectangle();
196 }
198 {
199 return LayoutNode::Rectangle();
200 }
201
202 auto MaskRectangle() const -> std::optional<bwRectanglePixel> override
203 {
204 return ContainerWidget().getMaskRectangle();
205 }
206
207 auto isVisible() const -> bool override
208 {
209 return WidgetNode::isVisible();
210 }
211
212 auto childrenVisible() const -> bool override
213 {
214 return ContainerWidget().childrenVisible();
215 }
216};
217
218} // namespace bwScreenGraph
219} // namespace bWidgets
Definition: bwContainerWidget.h:12
Definition: bwLayoutInterface.h:7
Helper class to construct screen-graphs.
Definition: Builder.h:23
Node representing a widget with children.
Definition: Node.h:167
auto Widget() const -> bwWidget *override
Definition: Node.h:183
auto Children() -> ChildList *override
Definition: Node.h:173
auto MaskRectangle() const -> std::optional< bwRectanglePixel > override
Definition: Node.h:202
auto ContainerWidget() const -> bwContainerWidget &
Definition: Node.h:188
auto isVisible() const -> bool override
Definition: Node.h:207
auto Children() const -> const ChildList *override
Definition: Node.h:169
auto Rectangle() const -> bwRectanglePixel override
Definition: Node.h:193
auto Layout() const -> bwLayoutInterface *override
Definition: Node.h:178
auto childrenVisible() const -> bool override
Definition: Node.h:212
auto ContentRectangle() const -> bwRectanglePixel
Definition: Node.h:197
API for registering and calling event-listeners.
Definition: EventHandler.h:31
Node for aligning children to a specific layout.
Definition: Node.h:92
auto isVisible() const -> bool override
Definition: Node.h:120
auto MaskRectangle() const -> std::optional< bwRectanglePixel > override
Definition: Node.h:115
auto Rectangle() const -> bwRectanglePixel override
Definition: Node.h:110
auto Children() const -> const ChildList *override
Definition: Node.h:96
auto Layout() const -> bwLayoutInterface *override
Definition: Node.h:105
auto Children() -> ChildList *override
Definition: Node.h:100
The base data-structure for a screen-graph node.
Definition: Node.h:36
ChildList::iterator ChildIterator
Definition: Node.h:41
virtual auto MaskRectangle() const -> std::optional< bwRectanglePixel >=0
virtual auto childrenVisible() const -> bool
Definition: Node.h:55
virtual auto Children() const -> const ChildList *
Definition: Node.h:46
virtual auto Children() -> ChildList *
Definition: Node.h:50
auto eventHandler() const -> EventHandler *
Definition: Node.h:75
virtual auto Widget() const -> bwWidget *
Definition: Node.h:65
virtual auto isVisible() const -> bool=0
auto Parent() const -> Node *
Definition: Node.h:70
std::list< std::unique_ptr< Node > > ChildList
Definition: Node.h:40
virtual auto Layout() const -> bwLayoutInterface *
Definition: Node.h:60
virtual auto Rectangle() const -> bwRectanglePixel=0
Node representing a single widget with no children.
Definition: Node.h:133
auto Rectangle() const -> bwRectanglePixel override
Definition: Node.h:142
auto Widget() const -> bwWidget *override
Definition: Node.h:137
auto isVisible() const -> bool override
Definition: Node.h:152
auto MaskRectangle() const -> std::optional< bwRectanglePixel > override
Definition: Node.h:147
Abstract base class that all widgets derive from.
Definition: bwWidget.h:22
Definition: bwContext.h:3