AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AAdvancedGridLayout.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 Alex2772 and Contributors
    4 *
    5 * SPDX-License-Identifier: MPL-2.0
    6 *
    7 * This Source Code Form is subject to the terms of the Mozilla Public
    8 * License, v. 2.0. If a copy of the MPL was not distributed with this
    9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
   10 */
   11
   12#pragma once
   13
   14#include "ALayout.h"
   15
   20class API_AUI_VIEWS AAdvancedGridLayout : public ALayout {
   21public:
   22    AAdvancedGridLayout(int cellsX, int cellsY);
   23
   24    virtual ~AAdvancedGridLayout() = default;
   25
   26    _<AView> getViewAt(size_t index) { return mCells.at(index).view; }
   27
   28    void setViewAt(size_t index, _<AView> view) { mCells.at(index).view = view; }
   29
   30    void onResize(int x, int y, int width, int height) override;
   31    void addView(const _<AView>& view, int x, int y);
   32
   33    void addView(const _<AView>& view, AOptional<size_t> index) override;
   34
   35    void removeView(aui::no_escape<AView> view, size_t index) override;
   36
   37    int getMinimumWidth() override;
   38
   39    int getMinimumHeight() override;
   40
   41    int indexOf(_<AView> view);
   42
   44
   45    void setSpacing(int spacing) override;
   46
   47protected:
   48    struct CompositionCache {
   49        unsigned expandingSum = 0;
   50        int minSize = 0;
   51
   52        int finalPos = 0;
   53        int finalSize = 0;
   54    };
   55
   56    struct GridCell {
   57        _<AView> view;
   58        int x, y;
   59
   60        operator _<AView>() const { return view; }
   61    };
   62
   63    int mCurrentIndex = 0;
   64    int cellsX, cellsY;
   65    unsigned mSpacing = 0;
   66
   67    AVector<GridCell> mCells;
   68    AVector<int> mIndices;
   69
   70protected:
   71    int& indexAt(int x, int y);
   72
   73    AVector<_<AView>> getRow(int row);
   74    AVector<_<AView>> getColumn(int column);
   75
   76    virtual void prepareCache(AVector<CompositionCache>& columns, AVector<CompositionCache>& rows);
   77};
void setSpacing(int spacing) override
Layout spacing.
AVector< _< AView > > getAllViews() override
Visits all views in the layout.
void removeView(aui::no_escape< AView > view, size_t index) override
Detaches view from the layout.
void addView(const _< AView > &view, AOptional< size_t > index) override
Attaches view to the layout.
virtual void addView(const _< AView > &view, AOptional< size_t > index=std::nullopt)=0
Attaches view to the layout.
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition AOptional.h:33
A std::vector with AUI extensions.
Definition AVector.h:39
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
Definition AAdvancedGridLayout.h:48
Definition AAdvancedGridLayout.h:56
Does not allow escaping, allowing to accept lvalue ref, rvalue ref, shared_ptr and etc without overhe...
Definition values.h:128