AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AGridLayout.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#include "ALayout.h"
   14
   20class API_AUI_VIEWS AGridLayout: public ALayout
   21{
   22private:
   23    int mCurrentIndex = 0;
   24    int mCellsX, mCellsY;
   25
   26    struct GridCell
   27    {
   28        _<AView> view;
   29        int x, y;
   30
   31        operator _<AView>() const {
   32            return view;
   33        }
   34    };
   35    AVector<GridCell> mCells;
   36    AVector<int> mIndices;
   37
   38
   39    int& indexAt(int x, int y);
   40
   41    AVector<_<AView>> getRow(int row);
   42    AVector<_<AView>> getColumn(int column);
   43public:
   44    AGridLayout(int cellsX, int cellsY);
   45    virtual ~AGridLayout() = default;
   46
   47    _<AView> getViewAt(size_t index) {
   48        return mCells.at(index).view;
   49    }
   50
   51    void setViewAt(size_t index, _<AView> view) {
   52        mCells.at(index).view = view;
   53    }
   54
   55    void onResize(int x, int y, int width, int height) override;
   56    void addView(const _<AView>& view, int x, int y);
   57    void addView(const _<AView>& view, AOptional<size_t> index) override;
   58    void removeView(aui::no_escape<AView> view, size_t index) override;
   59    int getMinimumWidth() override;
   60    int getMinimumHeight() override;
   62
   63    int indexOf(_<AView> view);
   64};
   65
void addView(const _< AView > &view, AOptional< size_t > index) override
Attaches view to the layout.
void removeView(aui::no_escape< AView > view, size_t index) override
Detaches view from the layout.
AVector< _< AView > > getAllViews() override
Visits all views in 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
Does not allow escaping, allowing to accept lvalue ref, rvalue ref, shared_ptr and etc without overhe...
Definition values.h:128