AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
ALinearLayout.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/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
   31        AVector<_<AView>> getAllViews() override {
   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>>
   59class ALinearLayout: public aui::detail::LinearLayoutImpl<Storage> {};
   60
   61template<>
   62class ALinearLayout<_<AView>>: public aui::detail::LinearLayoutImpl<_<AView>> {
   63public:
   64    void addView(const _<AView>& view, AOptional<size_t> index) override {
   65        addViewBasicImpl(view, index);
   66    }
   67};
Implements addView/removeView/getAllViews and protected mViews field for Vertical,...
Definition ALinearLayout.h:59
void addView(const _< AView > &view, AOptional< size_t > index) override
Attaches view to the layout.
Definition ALinearLayout.h:64
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition AOptional.h:33
Base class of all UI objects.
Definition AView.h:78
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
#define AUI_ASSERT(condition)
Asserts that the passed condition evaluates to true.
Definition Assert.h:55