Skip to content

ALayout#

Base class for all layout managers.

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

Public Methods#

addView#


virtual void ALayout::addView(const _<AView>& view, AOptional<size_t> index = std::nullopt)

Attaches view to the layout.

Arguments
view
view to attach.
index
index to insert at. If not specified, when the view is inserted at the end.

See ABasicLayout for basic implementation of this method.

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) {

computeMinMaxAxis#


AMinMaxAxis ALayout::computeMinMaxAxis(int height = - 1)

Returns min/max preferred inline (width) size of the layout for a given block (height).

Arguments
height
Content height in px, or -1 for unconstrained.
Returns
`AMinMaxAxis` with `min` and `max` outer widths.

Wraps onComputeIntrinsicMinMaxAxis and applies padding, ass::FixedSize, ass::MinSize, ass::MaxSize. Result is cached; invalidated by requestLayout(). Do not override this method — override onComputeIntrinsicMinMaxAxis instead. See Measurement pipeline in detail for the full pipeline.

getAllViews#


virtual AVector<_<AView>> ALayout::getAllViews()

Visits all views in the layout.

layout#


virtual void ALayout::layout(int x, int y, int width, int height)

Applies geometry to children.

Arguments
x
x coordinate in container's coordinate space, add padding if necessary.
y
y coordinate in container's coordinate space, add padding if necessary.
width
width of the container, add padding if necessary.
height
height of the container, add padding if necessary.

See layout-managers for more info.

measure#


glm::ivec2 ALayout::measure(AConstraints constraints)

Returns the preferred outer size of the layout under given constraints.

Arguments
constraints
Constraints describing the available space (see `AConstraints`).
Returns
Preferred outer `{width, height}` in px.

Wraps onIntrinsicMeasure and applies padding, ass::FixedSize, ass::MinSize, ass::MaxSize. Result is cached per AConstraints key; invalidated by requestLayout(). Do not override this method — override onIntrinsicMeasure instead. See Measurement pipeline in detail for the full pipeline.

onComputeIntrinsicMinMaxAxis#


virtual AMinMaxAxis ALayout::onComputeIntrinsicMinMaxAxis(int height)

Computes the min/max preferred content inline (width) size for a given content height.

Arguments
height
Content height in px, or -1 for unconstrained.
Returns
`AMinMaxAxis` with `min` and `max` content widths.

Override this in a layout manager to report the range of widths the managed children need. The public computeMinMaxAxis wraps this method and handles padding, ass::FixedSize, etc. automatically — never call onComputeIntrinsicMinMaxAxis directly. See Measurement pipeline in detail for the full pipeline.

onIntrinsicMeasure#


virtual glm::ivec2 ALayout::onIntrinsicMeasure(AConstraints constraints)

Computes the preferred content size under given constraints.

Arguments
constraints
Constraints describing the available **content** space (padding already subtracted).
Returns
Preferred content `{width, height}` in px.

Override this in a layout manager to report how much space the managed children need. The public measure wraps this method and handles padding, ass::FixedSize, ass::MinSize, ass::MaxSize automatically — never call onIntrinsicMeasure directly.

The default implementation delegates to onComputeIntrinsicMinMaxAxis and clamps to constraints. See Measurement pipeline in detail for the full pipeline.

Examples:

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.

        (*mCells)[position] = !(*mCells)[position];
        updateTexture();
    }

    glm::ivec2 onIntrinsicMeasure(AConstraints constraints) override {
      return mCells->size() * int(SCALE);
    }

private:
    _<Cells> mCells;

removeView#


virtual void ALayout::removeView(aui::no_escape<AView> view, size_t index)

Detaches view from the layout.

Arguments
view
view to detach.
index
index of the view in the container. This value is indented for optimization purposes in most cases; the value may be ignored safely.

See ABasicLayout for basic implementation of this method.

requestLayout#


virtual void ALayout::requestLayout()

Invalidates cached measurement results, triggering a layout recalculation.

Call this whenever the layout manager's content changes in a way that may affect sizes (e.g. a child was added/removed, spacing changed). Clears mMeasureCache and mMinMaxSizesCache and propagates the invalidation up the view tree so that all ancestor containers re-measure themselves.

This is the direct replacement for the old markMinContentSizeInvalid() from the Qt-style layout system. The two are equivalent — requestLayout() additionally invalidates both measure caches introduced by the new Measurement pipeline in detail.

Note

You rarely need to call this manually. It is called automatically when ASS properties change, when a view is resized, or when addView/removeView is called. Override this in a custom layout manager only if you maintain extra internal caches that also need clearing.

setSpacing#


virtual void ALayout::setSpacing(int spacing)

Layout spacing.

Arguments
spacing
spacing in px.