AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
AText.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
15#include "ATextBase.h"
16
31class API_AUI_VIEWS AText : public ATextBase<AWordWrappingEngine<>> {
32public:
34 struct ParsedFlags {
35 WordBreak wordBreak = WordBreak::NORMAL;
36 };
37
38
39public:
40 AText();
41
42 ~AText() override;
43
44 void clearContent() override;
45
46 void setItems(const AVector<std::variant<AString, _<AView>>>& init, const Flags& flags = {});
47
48 void setHtml(const AString& html, const Flags& flags = {});
49
50 void setString(const AString& string, const Flags& flags = {});
51
52 void setString(const AString& string) {
53 setString(string, {});
54 }
55
56 static _<AText> fromItems(std::initializer_list<std::variant<AString, _<AView>>> init, const Flags& flags = {}) {
57 auto v = aui::ptr::manage(new AText());
58 v->setItems(init, flags);
59 return v;
60 }
61
62 static _<AText> fromHtml(const AString& html, const Flags& flags = {}) {
63 auto v = aui::ptr::manage(new AText());
64 v->setHtml(html, flags);
65 return v;
66 }
67
68 static _<AText> fromString(const AString& string, const Flags& flags = {}) {
69 auto v = aui::ptr::manage(new AText());
70 v->setString(string, flags);
71 return v;
72 }
73
74protected:
75 void fillStringCanvas(const _<IRenderer::IMultiStringCanvas>& canvas) override;
76
77private:
78 class WordEntry final : public aui::detail::WordEntry {
79 public:
80 using aui::detail::WordEntry::WordEntry;
81 };
82
83 class CharEntry final : public aui::detail::CharEntry {
84 public:
85 using aui::detail::CharEntry::CharEntry;
86 };
87
88 ADeque<WordEntry> mWordEntries;
89 ADeque<CharEntry> mCharEntries;
90 ParsedFlags mParsedFlags;
91 aui::detail::WhitespaceEntry mWhitespaceEntry = this;
92 aui::detail::NextLineEntry mNextLineEntry = this;
93
94 void pushWord(Entries& entries,
95 AString word,
96 const ParsedFlags& flags);
97
98 static ParsedFlags parseFlags(const Flags& flags);
99
100 void processString(const AString& string, const ParsedFlags& parsedFlags,
101 Entries& entries);
102};
A std::deque with AUI extensions.
Definition: ADeque.h:27
Represents a Unicode character string.
Definition: AString.h:37
Base class for AText without public APIs.
Definition: ATextBase.h:189
HTML-capable text container.
Definition: AText.h:31
A std::vector with AUI extensions.
Definition: AVector.h:38
An std::weak_ptr with AUI extensions.
Definition: SharedPtrTypes.h:177
Definition: ATextBase.h:37
Definition: ATextBase.h:154
Definition: ATextBase.h:124
Definition: ATextBase.h:75
Definition: AText.h:34
Definition: SoftwareRenderer.cpp:369
static _< T > manage(T *raw)
Definition: SharedPtrTypes.h:371