AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
ALinearLayout.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 <AUI/Common/AObject.h>
15#include "ALayout.h"
16#include <AUI/Traits/concepts.h>
17
18class AView;
19
20namespace aui::detail {
21 template<aui::convertible_to<_<AView>> Storage = _<AView>>
22 class LinearLayoutImpl: public ALayout {
23 public:
24 void removeView(aui::no_escape<AView> view, size_t index) override {
25 if constexpr (std::is_same_v<Storage, _<AView>>) {
26 AUI_ASSERT(mViews[index].get() == view.ptr());
27 }
28 mViews.removeAt(index);
29 }
30
32 return { mViews.begin(), mViews.end() };
33 }
34
35 protected:
36 void addViewBasicImpl(Storage view, AOptional<size_t> index) {
37 auto at = mViews.end();
38 if (index) {
39 at = mViews.begin() + *index;
40 }
41 mViews.insert(at, std::move(view));
42 }
43
44 protected:
45 AVector<Storage> mViews;
46 };
47
48}
49
58template<aui::convertible_to<_<AView>> Storage = _<AView>>
60
61template<>
63public:
64 void addView(const _<AView>& view, AOptional<size_t> index) override {
65 addViewBasicImpl(view, index);
66 }
67};
Base class for all layout managers.
Definition: ALayout.h:207
void addView(const _< AView > &view, AOptional< size_t > index) override
Attaches view to the layout.
Definition: ALinearLayout.h:64
Implements addView/removeView/getAllViews and protected mViews field for Vertical,...
Definition: ALinearLayout.h:59
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition: AOptional.h:32
A std::vector with AUI extensions.
Definition: AVector.h:38
Base class of all UI objects.
Definition: AView.h:77
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177
Definition: ALinearLayout.h:22
void removeView(aui::no_escape< AView > view, size_t index) override
Detaches view from the layout.
Definition: ALinearLayout.h:24
AVector< _< AView > > getAllViews() override
Visits all views in the layout.
Definition: ALinearLayout.h:31
#define AUI_ASSERT(condition)
Asserts that the passed condition evaluates to true.
Definition: Assert.h:55
Does not allow escaping, allowing to accept lvalue ref, rvalue ref, shared_ptr and etc without overhe...
Definition: values.h:127