AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AFontFamily.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
   15#include <AUI/Common/AMap.h>
   16
   17class AFont;
   18
   20public:
   21    enum Weight {
   22        W100,
   23        W200,
   24        W300,
   25        W400,
   26        W500,
   27        W600,
   28        W700,
   29        W800,
   30        W900,
   31        NORMAL = W400,
   32        BOLD   = W700,
   33    };
   34
   35
   36private:
   37    struct {
   38        _<AFont> nonItalic;
   39        _<AFont> italic;
   40    } mFonts[9]; // weights 100-900;
   41
   42
   43    template<bool italic>
   44    _<AFont> getEitherWeight() {
   45        for (auto& e : {
   46            W400,
   47            W500,
   48            W300,
   49            W600,
   50            W200,
   51            W700,
   52            W100,
   53            W800,
   54            W900
   55        }) {
   56            if (auto& f = get(NORMAL, italic)) {
   57                return f;
   58            }
   59        }
   60        return nullptr;
   61    }
   62    template<bool italicPrefer>
   63    _<AFont> getEitherWeightItalicPreferred() {
   64        if (auto f = getEitherWeight<italicPrefer>()) {
   65            return f;
   66        }
   67        return getEitherWeight<!italicPrefer>();
   68    }
   69
   70public:
   71    _<AFont>& get(Weight weight, bool isItalic) {
   72        auto& r = mFonts[weight];
   73        return isItalic ? r.italic : r.nonItalic;
   74    }
   75
   81    _<AFont> getEither(bool italicPreferred = false) {
   82        if (italicPreferred) {
   83            return getEitherWeightItalicPreferred<true>();
   84        }
   85        return getEitherWeightItalicPreferred<false>();
   86    }
   87};
   88
   89
Definition AFontFamily.h:19
_< AFont > getEither(bool italicPreferred=false)
Definition AFontFamily.h:81
Definition AFont.h:36
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179