AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
ParentSelector.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//
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>
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
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>
72 ParentSubSelector<L, R> operator>>(L l, R r) {
73 return ParentSubSelector<L, R>(std::move(l), std::move(r));
74 }
75}
Base class of all UI objects.
Definition: AView.h:77
AViewContainerBase * getParent() const
Parent AView.
Definition: AView.h:561
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177
Definition: AAssSelector.h:28
#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