10namespace bwScreenGraph {
31 template<
typename _BuilderType = Builder>
using BuildFunc = std::function<void(_BuilderType&)>;
46 template<
typename _LayoutType,
typename... _Args>
49 static_assert(std::is_base_of<bwLayoutInterface, _LayoutType>::value,
50 "Should implement bwLayoutInterface");
52 LayoutNode& new_node = addChildNode<LayoutNode>(_active_layout_node);
53 new_node.layout = std::make_unique<_LayoutType>(std::forward<_Args>(__args)...);
64 template<
typename _LayoutType,
typename... _Args>
67 return buildLayout<_LayoutType, Builder>(build_func, std::forward<_Args>(__args)...);
76 template<
typename _LayoutType,
typename _BuilderType,
typename... _Args>
79 static_assert(std::is_base_of_v<bwLayoutInterface, _LayoutType>,
80 "Should implement bwLayoutInterface");
81 static_assert(std::is_base_of_v<Builder, _BuilderType>,
"Should inherit from Builder");
83 LayoutNode& new_node = addChildNode<LayoutNode>(_active_layout_node);
84 new_node.layout = std::make_unique<_LayoutType>(std::forward<_Args>(__args)...);
85 buildChildren(build_func, new_node);
90 template<
typename _WidgetType,
typename... _Args>
93 static_assert(std::is_base_of<bwWidget, _WidgetType>::value,
"Should derrive from bwWidget");
95 WidgetNode& new_node = addChildNode<WidgetNode>(_active_layout_node);
96 new_node.widget = std::make_unique<_WidgetType>(std::forward<_Args>(__args)...);
97 new_node.handler = new_node.widget->createHandler();
98 return static_cast<_WidgetType&
>(*new_node.widget);
101 template<
typename _WidgetType,
typename... _Args>
104 static_assert(std::is_base_of<bwWidget, _WidgetType>::value,
"Should derrive from bwWidget");
105 static_assert(std::is_base_of<bwContainerWidget, _WidgetType>::value,
106 "Should derrive from bwContainerWidget");
108 ContainerNode& new_node = addChildNode<ContainerNode>(_active_layout_node);
112 new_node.widget = std::make_unique<_WidgetType>(new_node, std::forward<_Args>(__args)...);
113 new_node.handler = new_node.widget->createHandler();
124 template<
typename _WidgetType,
typename... _Args>
126 std::unique_ptr<bwLayoutInterface> layout,
129 return buildContainer<_WidgetType, Builder>(
130 build_func, std::move(layout), std::forward<_Args>(__args)...);
148 template<
typename _WidgetType,
typename _BuilderType,
typename... _Args>
150 std::unique_ptr<bwLayoutInterface> layout,
153 static_assert(std::is_base_of<bwWidget, _WidgetType>::value,
"Should derrive from bwWidget");
154 static_assert(std::is_base_of<bwContainerWidget, _WidgetType>::value,
155 "Should derrive from bwContainerWidget");
156 static_assert(std::is_base_of_v<Builder, _BuilderType>,
"Should inherit from Builder");
158 ContainerNode& new_node = addChildNode<ContainerNode>(_active_layout_node);
160 new_node.widget = std::make_unique<_WidgetType>(new_node, std::forward<_Args>(__args)...);
161 new_node.handler = new_node.widget->createHandler();
162 buildChildren(build_func, new_node);
193 template<
typename _WidgetType,
typename... _Args>
196 static_assert(std::is_base_of<bwWidget, _WidgetType>::value,
"Should derrive from bwWidget");
198 WidgetNode& new_node = addChildNode<WidgetNode>(node);
199 new_node.widget = std::make_unique<_WidgetType>(std::forward<_Args>(__args)...);
200 new_node.handler = new_node.widget->createHandler();
201 return static_cast<_WidgetType&
>(*new_node.widget);
205 template<
typename _NodeType>
static auto addChildNode(
LayoutNode& parent_node) -> _NodeType&
207 static_assert(std::is_base_of<Node, _NodeType>::value,
208 "Should derrive from bwScreenGraph::Node");
210 parent_node.children.push_back(std::make_unique<_NodeType>());
211 Node& ref = *parent_node.children.back();
212 ref.parent = &parent_node;
214 return dynamic_cast<_NodeType&
>(ref);
217 template<
typename _BuilderType = Builder>
218 void buildChildren(BuildFunc<_BuilderType> build_func, LayoutNode& new_node)
220 LayoutNode& old_active_layout = _active_layout_node;
222 build_func(
static_cast<_BuilderType&
>(*
this));
227 std::reference_wrapper<bwScreenGraph::LayoutNode> _active_layout_node;