AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AShortcut.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 alex2 on 5/15/2021.
   14//
   15
   16
   17#pragma once
   18
   19
   20#include <AUI/Platform/AInput.h>
   21#include <AUI/Common/AVector.h>
   22
   23class AShortcut {
   24private:
   25    AVector<AInput::Key> mKeys;
   26    friend inline AShortcut operator+(AShortcut k1, const AInput::Key& k2);
   27
   28public:
   29    AShortcut() = default;
   30    AShortcut(const AVector<AInput::Key>& keys) : mKeys(keys) {}
   31    AShortcut(AInput::Key keys) : mKeys({keys}) {}
   32    AShortcut(AVector<AInput::Key>&& keys) noexcept : mKeys(std::move(keys)) {}
   33
   34    const AVector<AInput::Key>& getKeys() const {
   35        return mKeys;
   36    }
   37
   38    operator AString() const {
   39        AString s;
   40        for (auto& k : mKeys) {
   41            if (!s.empty()) {
   42                s += "+";
   43            }
   44            s += AInput::getName(k);
   45        }
   46        return s;
   47    }
   48    bool empty() const {
   49        return mKeys.empty();
   50    }
   51};
   52
   53inline AShortcut operator+(const AInput::Key& k1, const AInput::Key& k2) {
   54    return AShortcut({k1, k2});
   55}
   56
   57inline AShortcut operator+(AShortcut k1, const AInput::Key& k2) {
   58    auto k = std::move(k1.mKeys);
   59    k << k2;
   60    return std::move(k);
   61}
   62
Definition AShortcut.h:23
Represents a Unicode character string.
Definition AString.h:38
A std::vector with AUI extensions.
Definition AVector.h:39