AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
AAssSelector.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 alex2 on 31.12.2020.
14//
15
16#pragma once
17
18#include <AUI/Common/AVector.h>
19#include <AUI/Util/kAUI.h>
20#include <type_traits>
21#include <utility>
22
23class AView;
24class AAssHelper;
25
26namespace ass {
27
28 class API_AUI_VIEWS IAssSubSelector {
29 public:
30 virtual bool isPossiblyApplicable(AView* view) = 0;
31 virtual bool isStateApplicable(AView* view);
32 virtual void setupConnections(AView* view, const _<AAssHelper>& helper);
33 virtual ~IAssSubSelector() = default;
34 };
35
36 class API_AUI_VIEWS AAssSelector final: public IAssSubSelector {
37 private:
38 AVector<_<IAssSubSelector>> mSubSelectors;
39
40 template<typename SubSelector, std::enable_if_t<!std::is_pointer_v<SubSelector>, bool> = true>
41 void processSubSelector(SubSelector&& subSelector) {
42 mSubSelectors << _new<SubSelector>(std::forward<SubSelector>(subSelector));
43 }
44
45 template<typename SubSelector, std::enable_if_t<std::is_pointer_v<SubSelector>, bool> = true>
46 void processSubSelector(SubSelector&& subSelector) {
47 mSubSelectors << _<IAssSubSelector>(subSelector);
48 }
49
50 template<typename SubSelector, typename...SubSelectors>
51 void processSubSelectors(SubSelector&& subSelector, SubSelectors&&... subSelectors) {
52 processSubSelector(std::forward<SubSelector>(subSelector));
53 processSubSelectors(std::forward<SubSelectors>(subSelectors)...);
54 }
55
56 void processSubSelectors() {}
57
58 public:
59 template<typename...SubSelectors>
60 AAssSelector(SubSelectors&&... subSelectors) {
61 processSubSelectors(std::forward<SubSelectors>(subSelectors)...);
62 }
63 AAssSelector(AAssSelector&& move) noexcept: mSubSelectors(std::move(move.mSubSelectors)) {
64
65 }
66 explicit AAssSelector(std::nullptr_t) {}
67 AAssSelector(const AAssSelector&) = default;
68
70 mSubSelectors.clear();
71 }
72
73 AAssSelector& operator=(const AAssSelector& c) = default;
74
75 bool isPossiblyApplicable(AView* view) const {
76 for (const auto& s : mSubSelectors) {
77 if (s->isPossiblyApplicable(view)) {
78 return true;
79 }
80 }
81 return false;
82 }
83
84 bool isPossiblyApplicable(AView* view) override {
85 return constMe()->isPossiblyApplicable(view);
86 }
87
88 bool isStateApplicable(AView* view) const {
89 for (const auto& s : mSubSelectors) {
90 if (s->isStateApplicable(view)) {
91 return true;
92 }
93 }
94 return false;
95 }
96 bool isStateApplicable(AView* view) override {
97 return constMe()->isStateApplicable(view);
98 }
99 void setupConnections(AView* view, const _<AAssHelper>& helper) const;
100 void setupConnections(AView* view, const _<AAssHelper>& helper) override {
101 constMe()->setupConnections(view, helper);
102 }
103 template<typename SubSelector, std::enable_if_t<!std::is_pointer_v<SubSelector>, bool> = true>
104 void addSubSelector(SubSelector&& subSelector) {
105 processSubSelector(std::forward<SubSelector>(subSelector));
106 }
107
108 [[nodiscard]]
109 const AVector<_<IAssSubSelector>>& getSubSelectors() const {
110 return mSubSelectors;
111 }
112
113 static AAssSelector makeCopy(const AAssSelector& from) {
114 AAssSelector result;
115 result.mSubSelectors = from.mSubSelectors;
116 return result;
117 }
118
119 private:
120 const AAssSelector* constMe() {
121 // NOLINTNEXTLINE(*-const-cast)
122 return const_cast<const AAssSelector*>(this);
123 }
124 };
125
126 using sel = AAssSelector;
127}
Remember, ASS is not a butt. ASS is Aui Style Sheets.
Definition: AAssHelper.h:32
A std::vector with AUI extensions.
Definition: AVector.h:38
Base class of all UI objects.
Definition: AView.h:77
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177
Definition: AAssSelector.h:36
Definition: AAssSelector.h:28
Definition: class_of.h:57