AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
Selected.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/Util/ADataBinding.h>
   15#include "AAssSelector.h"
   16
   17namespace ass {
   21    class ISelectable {
   22    friend struct Selected;
   23    protected:
   24        virtual bool selectableIsSelectedImpl() = 0;
   25    };
   26
   40    struct Selected: IAssSubSelector {
   41    private:
   42        _unique<IAssSubSelector> mWrapped;
   43
   44    public:
   45        template<typename T>
   46        Selected(T value): mWrapped(new T(std::move(value))) {}
   47
   48
   49        bool isPossiblyApplicable(AView* view) override {
   50            return mWrapped->isPossiblyApplicable(view) && dynamic_cast<ISelectable*>(view);
   51        }
   52
   53        bool isStateApplicable(AView* view) override {
   54            if (!mWrapped->isStateApplicable(view))
   55                return false;
   56
   57            if (auto c = dynamic_cast<ISelectable*>(view)) {
   58                return c->selectableIsSelectedImpl();
   59            }
   60            return false;
   61        }
   62
   63        void setupConnections(AView* view, const _<AAssHelper>& helper) override {
   64            IAssSubSelector::setupConnections(view, helper);
   65            mWrapped->setupConnections(view, helper);
   66
   67            view->customCssPropertyChanged.clearAllOutgoingConnectionsWith(helper.get());
   68            AObject::connect(view->customCssPropertyChanged, slot(helper)::onInvalidateStateAss);
   69        }
   70    };
   71}
void clearAllOutgoingConnectionsWith(aui::no_escape< AObjectBase > object) const noexcept override
Destroys all connections with passed receiver, if any.
Definition ASignal.h:211
Base class of all UI objects.
Definition AView.h:78
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
Definition AAssSelector.h:28
Interface to work with ass::Selected selector.
Definition Selected.h:21
class_of c
Selects views that are of the specified classes.
Definition class_of.h:84
static decltype(auto) connect(const Signal &signal, Object *object, Function &&function)
Connects signal to the slot of the specified object.
Definition AObject.h:86
#define slot(v)
Passes some variable and type of the variable separated by comma. It's convenient to use with the con...
Definition kAUI.h:88