Skip to content

CoreLess

Helper class allowing you to easily create your own platform-independent composite views without having to create a specialized ViewCore.

Declaration

namespace bdn::ui {
    template<class BASE>
    class CoreLess : public BASE
}

Example

#include <bdn/ui/CoreLess.h>
#include <bdn/ui/ContainerView.h>
#include <bdn/ui/Label.h>

using namespace bdn::ui;

class MyCustomView : public CoreLess<ContainerView>
{
public:
    using CoreLess<ContainerView>::CoreLess;

    void init() override {
        _firstLabel = std::make_shared<Label>();
        _firstLabel->text = "Hello";

        _secondLabel = std::make_shared<Label>();
        _secondLabel->text = "World";

        addChildView(_firstLabel);
        addChildView(_secondLabel);
    }

private:
    std::shared_ptr<Label> _firstLabel;
    std::shared_ptr<Label> _secondLabel;
};

void test() {
    auto myCustomView = std::make_shared<MyCustomView>(needsInit);
    // ...
}

Constuctor

  • explicit CoreLess(bdn::NeedsInit, std::shared_ptr viewCoreFactory = nullptr)

    Expects a bdn::NeedsInit so that make_shared is used which will automatically call the init() function.

Virtual methods

  • virtual void init() = 0

    Override the init function to create children. This is needed because ContainerView::addChildView() uses shared_from_this() which is not available during construction.

Source

CoreLess.h