AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
ParentSelector.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//
   13// Created by alex2772 on 1/3/21.
   14//
   15
   16#pragma once
   17
   18#include "AAssSelector.h"
   19#include <AUI/View/AViewContainer.h>
   20
   21namespace ass {
   22    template <typename L, typename R>
   23    struct ParentSubSelector: public IAssSubSelector {
   24    private:
   25        L l;
   26        R r;
   27
   28    public:
   29        ParentSubSelector(L l, R r) : l(std::move(l)), r(std::move(r)) {}
   30
   31        bool isPossiblyApplicable(AView* view) override {
   32            if (r.isPossiblyApplicable(view)) {
   33                for (AView* v = view->getParent(); v; v = v->getParent()) {
   34                    if (l.isPossiblyApplicable(v)) {
   35                        return true;
   36                    }
   37                }
   38            }
   39            return false;
   40        }
   41
   42        bool isStateApplicable(AView* view) override {
   43            if (r.isStateApplicable(view)) {
   44                for (AView* v = view->getParent(); v; v = v->getParent()) {
   45                    if (l.isStateApplicable(v) && l.isPossiblyApplicable(v)) {
   46                        return true;
   47                    }
   48                }
   49            }
   50            return false;
   51        }
   52
   53        void setupConnections(AView* view, const _<AAssHelper>& helper) override {
   54            if (r.isPossiblyApplicable(view)) {
   55                for (AView* v = view->getParent(); v; v = v->getParent()) {
   56                    if (l.isPossiblyApplicable(v)) {
   57                        l.setupConnections(v, helper);
   58                        r.setupConnections(view, helper);
   59                        return;
   60                    }
   61                }
   62            }
   67            AUI_ASSERT(0);
   68        }
   69    };
   70
   88    template <typename L, typename R, std::enable_if_t<std::is_base_of_v<IAssSubSelector, L> && std::is_base_of_v<IAssSubSelector, R>, bool> = true>
   90        return ParentSubSelector<L, R>(std::move(l), std::move(r));
   91    }
   92}
Base class of all UI objects.
Definition AView.h:78
AViewContainerBase * getParent() const
Parent AView.
Definition AView.h:412
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
Definition AAssSelector.h:28
ParentSubSelector< L, R > operator>>(L l, R r)
Makes indirect parent subselector.
Definition ParentSelector.h:89
#define AUI_ASSERT(condition)
Asserts that the passed condition evaluates to true.
Definition Assert.h:55
Definition ParentSelector.h:23
void setupConnections(AView *view, const _< AAssHelper > &helper) override
Definition ParentSelector.h:53