Skip to content

AViewContainerBase#

A view that represents a set of views.

Header:#include <AUI/View/AViewContainerBase.h>
CMake:aui_link(my_target PUBLIC aui::views)

Detailed Description#

AViewContainerBase can store, render, resize, provide events to and handle the child views.

AViewContainerBase does not control the position and size of the child views by itself; instead, it delegates that responsibility to it's layout manager.

Since AViewContainerBase is an instance of AView, AViewContainerBase can handle AViewContainerBases recursively, thus, making possible complex UI by nested AViewContainerBases with different layout managers.

This class is abstract. The methods for modifying it's views are protected. You can use AViewContainer which exposes these methods to public or extend AViewContainerBase to make your own container-like view.

Public Types#


PointerEventsMapping#

struct AViewContainerBase::PointerEventsMapping

Empty structure.

Public fields and Signals#


childrenChanged#

emits<> childrenChanged

Emitted when addView(s)/removeView/setLayout was called.

Public Methods#

addView#


void AViewContainerBase::addView(const _<AView>& view)

Add view to the container.

Examples:

examples/app/minesweeper/src/MinesweeperWindow.cpp

Minesweeper Game — Minesweeper game implementation driven by ass.

        int y = i / columns;
        auto cell = _new<CellView>(fieldAt(x, y));

        setupEventHandlers(x, y, cell);
        mGrid->addView(cell);
    }

    pack();
}
/// [beginGame]
examples/ui/views/src/ExampleWindow.cpp

Views Example — All-in-one views building example.

using namespace declarative;

void fillWindow(_<AViewContainer> t) {
    t->setLayout(std::make_unique<AStackedLayout>());
    t->addView(_new<ALabel>("Window contents"));
}

class AllViewsWindow : public AWindow {
public:
    AllViewsWindow() : AWindow("All views", 300_dp, 500_dp, nullptr, WindowStyle::MODAL) {

void AViewContainerBase::addView(size_t index, const _<AView>& view)

Add view at specific index to the container.

Examples:

addViewCustomLayout#


void AViewContainerBase::addViewCustomLayout(const _<AView>& view)

Adds view to container without exposing it to the layout manager.

User is obligated to manage view's layout by themselves.

View is not visible until it's layout is determined. @see AView::mSkipUntilLayoutUpdate

addViews#


void AViewContainerBase::addViews(AVector<_<AView> > views)

Add all views from vector.

focusChainTarget#


_<AView> AViewContainerBase::focusChainTarget()
Returns
Focus chain target.

See mFocusChainTarget for further info.

getLayout#


const _unique<ALayout>& AViewContainerBase::getLayout()

Get layout manager of the container.

getViewAt#


virtual _<AView> AViewContainerBase::getViewAt(glm::ivec2 pos, ABitField<AViewLookupFlags> flags = AViewLookupFlags::NONE)

Finds first direct child view under position.

Arguments
pos
position relative to this container
flags
see AViewLookupFlags
Returns
found view or nullptr

Some containers may implement getViewAt by it's own (i.e. AListView for performance reasons).

getViewAtRecursive#


_<AView> AViewContainerBase::getViewAtRecursive(glm::ivec2 pos, ABitField<AViewLookupFlags> flags = AViewLookupFlags::NONE)

Acts as AViewContainerBase::getViewAt but recursively (may include non-direct child).

Arguments
pos
position relative to this container
flags
see AViewLookupFlags
Returns
found view or nullptr

template<aui::predicate<_<AView> > Callback >
bool AViewContainerBase::getViewAtRecursive(glm::ivec2 pos, const Callback& callback, ABitField<AViewLookupFlags> flags = AViewLookupFlags::NONE)

Acts as AViewContainerBase::getViewAtRecursive but calls a callback instead of returning value.

Arguments
pos
position relative to this container
callback
callback to call
flags
see AViewLookupFlags
Returns
true if callback returned true; false otherwise

The passed callback is a predicate. If predicate returns true, the execution of lookup is stopped and getViewAt returns true. If predicate returns false, the lookup continues.

getViewAtRecursiveOfType#


template<typename T >
_<T> AViewContainerBase::getViewAtRecursiveOfType(glm::ivec2 pos, ABitField<AViewLookupFlags> flags = AViewLookupFlags::NONE)

Acts as AViewContainerBase::getViewAtRecursive but finds a view castable to specified template type.

Arguments
pos
position relative to this container
flags
see AViewLookupFlags
Returns
found view or nullptr

getViews#


const AVector<_<AView>>& AViewContainerBase::getViews()

Get all views of the container.

Examples:

examples/7guis/cells/src/main.cpp

7GUIs Cells — Spreadsheet processor (Excel).

                      [](const AString& v) -> _<AView> { return Label { "{}"_format(v) }; },
                      [](const formula::Range& v) -> _<AView> { return Label { "#RANGE?" }; },
                    },
                    v));
            connect(getViews().first()->clicked, me::inflateEditor);
        });
    }

    void inflateEditor() {
        mState->currentExpression = mCell.expression;

pointerEventsMapping#


const ASmallVector<PointerEventsMapping,1>& AViewContainerBase::pointerEventsMapping()

removeAllViews#


void AViewContainerBase::removeAllViews()

Remove all views from container.

removeView#


void AViewContainerBase::removeView(const _<AView>& view)

Remove view from the container.


void AViewContainerBase::removeView(size_t index)

Remove view from the container at specified index.

removeViews#


void AViewContainerBase::removeViews(aui::range<AVector<_<AView> >::const_iterator> views)

Remove views from the container.

setContents#


void AViewContainerBase::setContents(const _<AViewContainer>& container)

Moves (like via std::move) all children and layout of the specified container to this container.

Arguments
container
container. Must be pure AViewContainer (cannot be a derivative from AViewContainer).

Examples:

examples/7guis/flight_booker/src/main.cpp

7GUIs Flight Booker — Flight Booker.

    // Create window
    auto window = _new<AWindow>("AUI - 7GUIs - Book Flight", 150_dp, 50_dp);

    // Set contents
    window->setContents(Centered {
      Vertical {
        _new<ADropdownList>(AListModel<AString>::make({ "one-way flight", "return flight" })) AUI_LET {
                AObject::connect(AUI_REACT(state->isReturnFlight ? 1 : 0), it->selectionId());
                AObject::connect(it->selectionId().changed, AObject::GENERIC_OBSERVER, [=](int newSelection) {
                    state->isReturnFlight = newSelection == 1;
examples/7guis/circle_drawer/src/main.cpp

7GUIs Circle Drawer — Undo, redo, dialog control.

              .onAction =
                  [this, circle] {
                      auto radiusPopup = _new<AWindow>(
                          "", 200_dp, 50_dp, dynamic_cast<AWindow*>(ASurface::current()), WindowStyle::MODAL);
                      radiusPopup->setContents(Vertical {
                        Label { "Adjust diameter of circle at {}."_format(circle->position) },
                        Slider {
                          .value = AUI_REACT(circle->radius / MAX_RADIUS),
                          .onValueChanged =
                              [this, circle](aui::float_within_0_1 s) {
examples/7guis/timer/src/main.cpp

7GUIs Timer — Timer example.

/// [example]
class TimerWindow : public AWindow {
public:
    TimerWindow() : AWindow("AUI - 7GUIs - Timer", 300_dp, 50_dp) {
        setContents(Centered {
          Vertical::Expanding {
            Horizontal {
              Label { "Elapsed Time:" },
              Centered::Expanding {
                _new<AProgressBar>() AUI_LET {
examples/7guis/crud/src/main.cpp

7GUIs CRUD — Create/Read/Update/Delete example.

        auto FILTER_VIEW = ranges::views::filter([this](const _<User>& user) {
            return user->displayName->startsWith(*mFilterPrefix);
        });

        setContents(Vertical {
          Horizontal::Expanding {
            Vertical::Expanding {
              Horizontal {
                Label { "Filter prefix:" },
                _new<ATextField>() AUI_OVERRIDE_STYLE { Expanding(1, 0) } && mFilterPrefix,
examples/7guis/counter/src/main.cpp

7GUIs Counter — Simple counter.

/// [counter]
class CounterWindow : public AWindow {
public:
    CounterWindow() : AWindow("AUI - 7GUIs - Counter", 200_dp, 100_dp) {
        setContents(Centered {
          Horizontal {
            Label { AUI_REACT("Count: {}"_format(mCounter)) },
            Button { Label { "Count" }, [this] { mCounter += 1; } },
          } AUI_OVERRIDE_STYLE { LayoutSpacing { 4_dp } },
        });
examples/7guis/temperature_converter/src/main.cpp

7GUIs Temperature Converter — Fahrenheit to Celsius and vice versa.

/// [window]
class TemperatureConverterWindow : public AWindow {
public:
    TemperatureConverterWindow() : AWindow("AUI - 7GUIs - TempConv", 300_dp, 50_dp) {
        setContents(Centered {
          Horizontal {
            myPicker() AUI_LET {
                biConnect(it->value(), mCelsius);
                it->focus();
            },
examples/app/minesweeper/src/NewGameWindow.cpp

Minesweeper Game — Minesweeper game implementation driven by ass.

  : AWindow("New game", 100, 100, minesweeper), mMinesweeper(minesweeper) {
    setWindowStyle(WindowStyle::MODAL);

    setLayout(std::make_unique<AVerticalLayout>());
    setContents(Vertical {
      _form({
        {
          "Cells by width:"_as,
          mWidth = _new<ANumberPicker>() AUI_LET {
                       it->setMin(8);
examples/app/fractal/src/FractalWindow.cpp

Fractal Example — Fractal viewer application demonstrating usage of custom shaders.

    connect(fractal->centerPosChanged, this, [centerPosDisplay](const glm::dvec2& newPos, double scale) {
        centerPosDisplay->setText("Center position: {} {}, scale: {}"_format(newPos.x, -newPos.y, scale));
    });

    setContents(Horizontal {
      Stacked::Expanding {
        fractal,
        Vertical::Expanding {
          SpacerExpanding {},
          Horizontal {
examples/app/fractal/src/JumpToCoordsWindow.cpp

Fractal Example — Fractal viewer application demonstrating usage of custom shaders.

    re->setText(AString::number(pos.x));
    im->setText(AString::number(pos.y));
    scale->setText(AString::number(fractalView->getPlotScale()));

    setContents(Vertical {
      _form({
        { "Re="_as, re },
        { "Im="_as, im },
        { "Scale="_as, scale },
      }) AUI_OVERRIDE_STYLE { LayoutSpacing { 4_dp } },
examples/app/game_of_life/src/main.cpp

Game of Life — Game of Life implementation that uses advanced large dynamic data rendering techniques such as ITexture, AImage to be GPU friendly. The computation is performed in AThreadPool.

class GameOfLifeWindow : public AWindow {
public:
    GameOfLifeWindow() : AWindow("Game of Life") {
        setContents(Vertical {
          Centered {
            Horizontal {
              _new<AButton>("Randomize") AUI_LET {
                      connect(it->clicked, AUI_SLOT(mCells)::randomize);
                  },
examples/app/notes/src/main.cpp

Notes App — Note taking app that demonstrates usage of AListModel, AProperty, user data saving and loading.

        load();

        connect(mNotes.changed, me::markDirty);

        setContents(Vertical {
          ASplitter::Horizontal()
                  .withItems({
                    Vertical {
                      Centered {
                        Horizontal {
examples/ui/minimal_ui_assets_xmake/src/MainWindow.cpp

Minimal UI Template XMake with Assets — Minimal UI boilerplate template XMake with AUI Assets.

using namespace declarative;

MainWindow::MainWindow(): AWindow("Project template app", 300_dp, 200_dp) {
    setContents(
        Centered{
            Vertical{
                Centered { Icon { ":img/logo.svg" } AUI_OVERRIDE_STYLE { FixedSize(64_dp) } },
                Centered { Label { "Hello world from AUI!" } },
                _new<AButton>("Visit GitHub repo").connect(&AView::clicked, this, [] {
examples/ui/minimal_ui_xmake/src/MainWindow.cpp

Minimal UI Template XMake — Minimal UI boilerplate template XMake.

using namespace declarative;

MainWindow::MainWindow(): AWindow("Project template app", 300_dp, 200_dp) {
    setContents(
        Centered{
            Vertical{
                Centered { Label { "Hello world from AUI!" } },
                _new<AButton>("Visit GitHub repo").connect(&AView::clicked, this, [] {
                    APlatform::openUrl("https://github.com/aui-framework/aui");
examples/ui/contacts/src/main.cpp

AUI Contacts — Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.

class ContactsWindow : public AWindow {
public:
    ContactsWindow() : AWindow("AUI Contacts", 600_dp, 300_dp) {
        setContents(
            Horizontal {
              AScrollArea::Builder()
                      .withContents(
                          Vertical {
                            SpacerFixed(8_dp),
examples/ui/contacts/src/view/ContactDetailsView.cpp

AUI Contacts — Usage of AUI_DECLARATIVE_FOR to make a contacts-like application.

        Expanding(1, 0),
      },
    });
    connect(mEditorMode, [this] {
        setContents(Vertical::Expanding {
          AScrollArea::Builder().withContents(Centered {
            Vertical::Expanding {
              Horizontal {
                profilePhoto(mContact),
                Centered::Expanding {
examples/ui/backdrop/src/main.cpp

Backdrop — Backdrop effects demo.

AUI_ENTRY {
    auto window = _new<AWindow>("Backdrop test", 600_dp, 300_dp);

    window->setContents(headerWithContents(
        Centered {
          Vertical::Expanding {
            Centered {
              Icon { ":logo.svg" } AUI_OVERRIDE_STYLE { FixedSize { 128_dp } },
            } AUI_OVERRIDE_STYLE { FixedSize { 500_dp, {} } },
examples/ui/opengl_simple/src/main.cpp

OpenGL Example — Demonstrates how to integrate custom OpenGL rendering with AUI Framework.

    });

    auto window = _new<AWindow>("OpenGL Demo", 600_dp, 300_dp);
    auto state = _new<State>();
    window->setContents(
        Stacked {
          _new<MyRenderer>(state) AUI_OVERRIDE_STYLE { Expanding() },
          Horizontal::Expanding {
            Vertical {
              Vertical {
examples/ui/infinite_lazy_list/src/main.cpp

Infinite Lazy List — Usage of AUI_DECLARATIVE_FOR to make an infinite lazy list.

}

AUI_ENTRY {
    auto window = _new<AWindow>("Infinite Lazy List", 200_dp, 300_dp);
    window->setContents(Stacked { AScrollArea::Builder().withContents(myLazyList(_new<State>())) });
    window->show();

    return 0;
}

setFocusChainTarget#


void AViewContainerBase::setFocusChainTarget(_weak<AView> target)

Set focus chain target.

Arguments
target
a new focus chain view belonging to this container

See mFocusChainTarget for further info.

setLayout#


void AViewContainerBase::setLayout(_unique<ALayout> layout)

Set new layout manager for this AViewContainerBase. DESTROYS OLD LAYOUT MANAGER WITH ITS VIEWS!!!

Examples:

setViews#


void AViewContainerBase::setViews(AVector<_<AView> > views)

Replace views.

visitsViewRecursive#


template<aui::predicate<_<AView> > Callback >
bool AViewContainerBase::visitsViewRecursive(Callback&& callback, ABitField<AViewLookupFlags> flags = AViewLookupFlags::NONE)

Performs recursive view traversal.

Arguments
callback
callback to call. Returns true to finish traversal.
flags
see AViewLookupFlags
Returns
true if there's at least one view for which callback returned true, false otherwise.