bWidgets
Core widget toolkit designed for Blender
bWidgets::bwScreenGraph::Builder Class Reference

Helper class to construct screen-graphs. More...

#include <Builder.h>

Public Types

template<typename _BuilderType = Builder>
using BuildFunc = std::function< void(_BuilderType &)>
 A callable type to build a layout. More...
 

Public Member Functions

 Builder (LayoutNode &active_layout_node)
 
 Builder (ScreenGraph &screen_graph)
 
virtual ~Builder ()=default
 
void setActiveLayout (bwScreenGraph::LayoutNode &)
 Activate a layout node. More...
 
template<typename _LayoutType , typename... _Args>
auto addLayout (_Args &&... __args) -> LayoutNode &
 Add and activate a child node for a layout created in-place. More...
 
template<typename _LayoutType , typename... _Args>
auto buildLayout (BuildFunc<> build_func, _Args &&... __args) -> LayoutNode &
 Build a sub-layout node in-place using build_func. More...
 
template<typename _LayoutType , typename _BuilderType , typename... _Args>
auto buildLayout (BuildFunc< _BuilderType > build_func, _Args &&... __args) -> LayoutNode &
 Build a sub-layout node in-place using build_func. More...
 
template<typename _WidgetType , typename... _Args>
auto addWidget (_Args &&... __args) -> _WidgetType &
 
template<typename _WidgetType , typename... _Args>
auto addContainer (std::unique_ptr< bwLayoutInterface > layout, _Args &&... __args) -> ContainerNode &
 
template<typename _WidgetType , typename... _Args>
auto buildContainer (BuildFunc<> build_func, std::unique_ptr< bwLayoutInterface > layout, _Args &&... __args) -> ContainerNode &
 Build a container node in-place using build_func. More...
 
template<typename _WidgetType , typename _BuilderType , typename... _Args>
auto buildContainer (BuildFunc< _BuilderType > build_func, std::unique_ptr< bwLayoutInterface > layout, _Args &&... __args) -> ContainerNode &
 Build a container node in-place using build_func. More...
 

Static Public Member Functions

static void setLayout (LayoutNode &node, std::unique_ptr< bwLayoutInterface > layout)
 
static void setWidget (WidgetNode &node, std::unique_ptr< bwWidget > widget)
 
static auto addWidget (LayoutNode &node, std::unique_ptr< bwWidget > widget) -> bwWidget &
 
template<typename _WidgetType , typename... _Args>
static auto emplaceWidget (LayoutNode &node, _Args &&... __args) -> _WidgetType &
 Add child node for a widget created in-place. More...
 

Detailed Description

Helper class to construct screen-graphs.

Use this to create all screen-graphs or sub-trees.

  • addFoo functions add a node and constructs its item (widget or layout) in-place. That means arguments are passed to the function are forwarded to the widget or layout constructor.
  • buildFoo functions do the same but allow specifying a build-function for sub-layouts. This is the prefered way to construct sub-layouts, because the builder manages all state. For the caller it's a stateless way to build.

Member Typedef Documentation

◆ BuildFunc

template<typename _BuilderType = Builder>
using bWidgets::bwScreenGraph::Builder::BuildFunc = std::function<void(_BuilderType&)>

A callable type to build a layout.

buildFoo functions use this to receive a callback for building their sub-layout. Can bind to a plain old function pointer, a function object (functor) or a lambda.

Constructor & Destructor Documentation

◆ Builder() [1/2]

bWidgets::bwScreenGraph::Builder::Builder ( LayoutNode active_layout_node)

◆ Builder() [2/2]

bWidgets::bwScreenGraph::Builder::Builder ( ScreenGraph screen_graph)

◆ ~Builder()

virtual bWidgets::bwScreenGraph::Builder::~Builder ( )
virtualdefault

Member Function Documentation

◆ addContainer()

template<typename _WidgetType , typename... _Args>
auto bWidgets::bwScreenGraph::Builder::addContainer ( std::unique_ptr< bwLayoutInterface layout,
_Args &&...  __args 
) -> ContainerNode&
inline

◆ addLayout()

template<typename _LayoutType , typename... _Args>
auto bWidgets::bwScreenGraph::Builder::addLayout ( _Args &&...  __args) -> LayoutNode&
inline

Add and activate a child node for a layout created in-place.

◆ addWidget() [1/2]

template<typename _WidgetType , typename... _Args>
auto bWidgets::bwScreenGraph::Builder::addWidget ( _Args &&...  __args) -> _WidgetType&
inline

◆ addWidget() [2/2]

auto bWidgets::bwScreenGraph::Builder::addWidget ( LayoutNode node,
std::unique_ptr< bwWidget widget 
) -> bwWidget&
static

◆ buildContainer() [1/2]

template<typename _WidgetType , typename _BuilderType , typename... _Args>
auto bWidgets::bwScreenGraph::Builder::buildContainer ( BuildFunc< _BuilderType >  build_func,
std::unique_ptr< bwLayoutInterface layout,
_Args &&...  __args 
) -> ContainerNode&
inline

Build a container node in-place using build_func.

This override passes a custom builder type to the build_func (must inherit from Builder).

Only creates widget in-place, layout still needs to be created by the caller. Otherwise, we'd have to do perfect forwarding of parameters to multiple constructors. This can be done (e.g. see https://cpptruths.blogspot.com/2012/06/perfect-forwarding-of-parameter-groups.html) but in the end, just letting the caller create the layout is less verbose and easier to understand.

Parameters
build_funcCallback to create the subtree for this container.

◆ buildContainer() [2/2]

template<typename _WidgetType , typename... _Args>
auto bWidgets::bwScreenGraph::Builder::buildContainer ( BuildFunc<>  build_func,
std::unique_ptr< bwLayoutInterface layout,
_Args &&...  __args 
) -> ContainerNode&
inline

Build a container node in-place using build_func.

This override passes the default builder type (Builder) to the build_func.

◆ buildLayout() [1/2]

template<typename _LayoutType , typename _BuilderType , typename... _Args>
auto bWidgets::bwScreenGraph::Builder::buildLayout ( BuildFunc< _BuilderType >  build_func,
_Args &&...  __args 
) -> LayoutNode&
inline

Build a sub-layout node in-place using build_func.

This override passes a custom builder type to the build_func (must inherit from Builder).

◆ buildLayout() [2/2]

template<typename _LayoutType , typename... _Args>
auto bWidgets::bwScreenGraph::Builder::buildLayout ( BuildFunc<>  build_func,
_Args &&...  __args 
) -> LayoutNode&
inline

Build a sub-layout node in-place using build_func.

This override passes the default builder type (Builder) to the build_func.

◆ emplaceWidget()

template<typename _WidgetType , typename... _Args>
static auto bWidgets::bwScreenGraph::Builder::emplaceWidget ( LayoutNode node,
_Args &&...  __args 
) -> _WidgetType&
inlinestatic

Add child node for a widget created in-place.

Simplifies creating and appending widgets. The arguments __args are forwarded to the widget constructor; a new node for it is added as child to node.

Without emplaceWidget():

auto& widget = static_cast<bwLabel&>(Builder::addWidget<bwLabel>(
screen_graph, std::make_unique<bwLabel>("Foo", 0, 10)));
widget.foo();
// ...
Definition: bwContext.h:6

With emplaceWidget():

auto& widget = Builder::emplaceWidget<bwLabel>(screen_graph, "Foo", 0, 10);
widget.foo();
// ...

◆ setActiveLayout()

void bWidgets::bwScreenGraph::Builder::setActiveLayout ( bwScreenGraph::LayoutNode node)

Activate a layout node.

Adding further items will add them as children to this node, until a different layout node is activated.

◆ setLayout()

void bWidgets::bwScreenGraph::Builder::setLayout ( LayoutNode node,
std::unique_ptr< bwLayoutInterface layout 
)
static

◆ setWidget()

void bWidgets::bwScreenGraph::Builder::setWidget ( WidgetNode node,
std::unique_ptr< bwWidget widget 
)
static

The documentation for this class was generated from the following files: