AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
UIBuildingHelpers.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#include "AUI/Common/AVector.h"
14#include "AUI/View/AView.h"
15#include "AUI/Layout/AGridLayout.h"
16#include <variant>
17#include "AUI/View/AViewContainer.h"
18#include "AUI/View/ALabel.h"
19#include <AUI/Common/SharedPtr.h>
20#include <AUI/Util/kAUI.h>
21#include <AUI/Util/AMetric.h>
22#include <AUI/View/ASpacerExpanding.h>
23#include <AUI/View/AForEachUI.h>
24#include <AUI/Layout/AWordWrappingLayout.h>
25#include <AUI/Layout/AHorizontalLayout.h>
26#include <AUI/Layout/AVerticalLayout.h>
27#include <AUI/Layout/AStackedLayout.h>
28#include <AUI/Layout/AGridLayout.h>
29#include <AUI/Layout/AAdvancedGridLayout.h>
30#include <AUI/Layout/AAbsoluteLayout.h>
31#include <AUI/Image/AImageLoaderRegistry.h>
32#include <AUI/i18n/AI18n.h>
33#include <AUI/ASS/ASS.h>
34#include <AUI/Traits/strings.h>
35#include "Declarative.h"
36
37
38template<typename Layout, typename... Args>
39inline auto _container(AVector<_<AView>> views, Args&&... args)
40{
41 auto c = _new<AViewContainer>();
42 c->setLayout(std::make_unique<Layout>(std::forward<Args>(args)...));
43
44 c->setViews(std::move(views));
45
46 return c;
47}
48
49inline auto _form(const AVector<std::pair<std::variant<AString, _<AView>>, _<AView>>>& views)
50{
51 auto c = _new<AViewContainer>();
52 c->setLayout(std::make_unique<AAdvancedGridLayout>(2, views.size()));
53 c->setExpanding({2, 0});
54 for (const auto& v : views) {
55 try {
56 c->addView(_new<ALabel>(std::get<AString>(v.first)));
57 }
58 catch (const std::bad_variant_access&) {
59 c->addView(std::get<_<AView>>(v.first));
60 }
61 v.second->setExpanding({2, 0});
62 c->addView(v.second);
63 }
64
65 return c;
66}
67
68
81
94
107
118
130
131
132
139using Centered = Stacked;
Represents a Unicode character string.
Definition: AString.h:37
A std::vector with AUI extensions.
Definition: AVector.h:38
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177
API_AUI_CORE const ACommandLineArgs & args() noexcept
Definition: OSAndroid.cpp:29