AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
UIBuildingHelpers.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 "AUI/Common/AVector.h"
   15#include "AUI/View/AView.h"
   16#include "AUI/Layout/AGridLayout.h"
   17#include <variant>
   18#include "AUI/View/AViewContainer.h"
   19#include "AUI/View/ALabel.h"
   20#include <AUI/Common/SharedPtr.h>
   21#include <AUI/Util/kAUI.h>
   22#include <AUI/Util/AMetric.h>
   23#include <AUI/View/ASpacerExpanding.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
   37template <typename Layout, typename... Args>
   38inline auto _container(AVector<_<AView>> views, Args&&... args) {
   39    auto c = _new<AViewContainer>();
   40    c->setLayout(std::make_unique<Layout>(std::forward<Args>(args)...));
   41
   42    c->setViews(std::move(views));
   43
   44    return c;
   45}
   46
   47inline auto _form(const AVector<std::pair<std::variant<AString, _<AView>>, _<AView>>>& views) {
   48    auto c = _new<AViewContainer>();
   49    c->setLayout(std::make_unique<AAdvancedGridLayout>(2, int(views.size())));
   50    c->setExpanding({ 2, 0 });
   51    for (const auto& v : views) {
   52        try {
   53            c->addView(_new<ALabel>(std::get<AString>(v.first)));
   54        } catch (const std::bad_variant_access&) {
   55            c->addView(std::get<_<AView>>(v.first));
   56        }
   57        v.second->setExpanding({ 2, 0 });
   58        c->addView(v.second);
   59    }
   60
   61    return c;
   62}
   63
   75using Vertical = aui::ui_building::view_container_layout<AVerticalLayout>;
   76
   88using Horizontal = aui::ui_building::view_container_layout<AHorizontalLayout>;
   89
  101using Stacked = aui::ui_building::view_container_layout<AStackedLayout>;
  102
  112using Absolute = aui::ui_building::view_container_layout<AAbsoluteLayout>;
  113
  124using CustomLayout = aui::ui_building::view_container_layout<std::nullopt_t>;
  125
  132using Centered = Stacked;
Represents a Unicode character string.
Definition AString.h:38
A std::vector with AUI extensions.
Definition AVector.h:39
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
class_of c
Selects views that are of the specified classes.
Definition class_of.h:84