AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
AFontStyle.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#pragma once
13
14#include "AUI/Enum/ATextAlign.h"
15#include "AFont.h"
16#include "AUI/Platform/AFontManager.h"
17#include "AUI/Render/FontRendering.h"
18#include "AUI/Common/AColor.h"
19
20
21class AString;
22
23
24struct API_AUI_VIEWS AFontStyle {
25 mutable _<AFont> font = AFontManager::inst().getDefaultFont();
26 unsigned size = 12;
27 bool formatting = false;
28 ATextAlign align = ATextAlign::LEFT;
29 bool bold = false;
30 bool italic = false;
31
32 FontRendering fontRendering = FontRendering::SUBPIXEL;
33 float lineSpacing = 0.5f;
34
35
36 size_t getWidth(const AString& text) const;
37
38 template<class Iterator>
39 size_t getWidth(Iterator begin, Iterator end) const {
40 return font->length(*this, std::move(begin), std::move(end));
41 }
42
43 AFont::Character& getCharacter(char32_t c) {
44 return font->getCharacter(getFontEntry(), c);
45 }
46
47 [[nodiscard]]
48 size_t getSpaceWidth() const {
49 return font->getSpaceWidth(size);
50 }
51
52 size_t getLineHeight() const;
53
54 AFont::FontEntry getFontEntry() const {
55 return font->getFontEntry({size, fontRendering});
56 }
57
58 operator AFont::FontEntry() const {
59 return getFontEntry();
60 }
61
62 bool operator==(const AFontStyle&) const noexcept = default;
63 bool operator!=(const AFontStyle&) const noexcept = default;
64};
Represents a Unicode character string.
Definition: AString.h:37
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177
ATextAlign
Controls the text alignment inside AView.
Definition: ATextAlign.h:20
FontRendering
Controls the expanding of AView.
Definition: FontRendering.h:22
Definition: AFontStyle.h:24
Definition: AFont.h:38
Definition: Text.h:21