AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
AAdvancedGridLayout.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 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
23 AAdvancedGridLayout(int cellsX, int cellsY);
24
25 virtual ~AAdvancedGridLayout() = default;
26
27 _<AView> getViewAt(size_t index) {
28 return mCells.at(index).view;
29 }
30
31 void setViewAt(size_t index, _<AView> view) {
32 mCells.at(index).view = view;
33 }
34
35 void onResize(int x, int y, int width, int height) override;
36 void addView(const _<AView>& view, int x, int y);
37
38 void addView(const _<AView>& view, AOptional<size_t> index) override;
39
40 void removeView(aui::no_escape<AView> view, size_t index) override;
41
42 int getMinimumWidth() override;
43
44 int getMinimumHeight() override;
45
46 int indexOf(_<AView> view);
47
48 AVector<_<AView>> getAllViews() override;
49
50protected:
52 unsigned expandingSum = 0;
53 int minSize = 0;
54
55 int finalPos = 0;
56 int finalSize = 0;
57 };
58
59 struct GridCell {
60 _<AView> view;
61 int x, y;
62
63 operator _<AView>() const {
64 return view;
65 }
66 };
67
68 int mCurrentIndex = 0;
69 int cellsX, cellsY;
70 unsigned mSpacing = 0;
71
72 AVector<GridCell> mCells;
73 AVector<int> mIndices;
74
75protected:
76 int& indexAt(int x, int y);
77
78 AVector<_<AView>> getRow(int row);
79 AVector<_<AView>> getColumn(int column);
80
81 virtual void prepareCache(AVector<CompositionCache>& columns, AVector<CompositionCache>& rows);
82
83};
84
Grid layout. Unlike AGridLayout, cells may have different sizes.
Definition: AAdvancedGridLayout.h:20
Base class for all layout managers.
Definition: ALayout.h:207
virtual void addView(const _< AView > &view, AOptional< size_t > index=std::nullopt)=0
Attaches view to the layout.
virtual void removeView(aui::no_escape< AView > view, size_t index)=0
Detaches view from the layout.
virtual AVector< _< AView > > getAllViews()=0
Visits all views in the layout.
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition: AOptional.h:32
A std::vector with AUI extensions.
Definition: AVector.h:38
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177
Definition: AAdvancedGridLayout.h:51
Definition: AAdvancedGridLayout.h:59
Definition: Size.h:22
Does not allow escaping, allowing to accept lvalue ref, rvalue ref, shared_ptr and etc without overhe...
Definition: values.h:127