AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
DirectParentSelector.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
   20namespace ass {
   21    template <typename L, typename R>
   22    struct DirectParentSubSelector: public IAssSubSelector {
   23    private:
   24        L l;
   25        R r;
   26
   27    public:
   28        DirectParentSubSelector(L l, R r) : l(std::move(l)), r(std::move(r)) {}
   29
   30        bool isPossiblyApplicable(AView* view) override {
   31            if (r.isPossiblyApplicable(view)) {
   32                if (auto parent = view->getParent()) {
   33                    return l.isPossiblyApplicable(parent);
   34                }
   35            }
   36            return false;
   37        }
   38
   39        bool isStateApplicable(AView* view) override {
   40            if (r.isStateApplicable(view)) {
   41                if (auto parent = view->getParent()) {
   42                    return l.isStateApplicable(parent);
   43                }
   44            }
   45            return false;
   46        }
   47
   48        void setupConnections(AView* view, const _<AAssHelper>& helper) override {
   49            auto parent = view->getParent();
   50            AUI_ASSERT(parent);
   51
   52            r.setupConnections(view, helper);
   53            l.setupConnections(parent, helper);
   54        }
   55    };
   56
   71    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>
   73        return DirectParentSubSelector<L, R>(std::move(l), std::move(r));
   74    }
   75}
   76
   77#include <AUI/View/AViewContainer.h>
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
DirectParentSubSelector< L, R > operator>(L l, R r)
Makes direct parent subselector.
Definition DirectParentSelector.h:72
#define AUI_ASSERT(condition)
Asserts that the passed condition evaluates to true.
Definition Assert.h:55
Definition DirectParentSelector.h:22