AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AWordWrappingEngine.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 <AUI/Common/AObject.h>
16#include <AUI/Common/AVector.h>
17#include <glm/glm.hpp>
18#include <AUI/Enum/ATextAlign.h>
19#include <AUI/Enum/AFloat.h>
20
22public:
23 class Entry {
24 public:
25 virtual ~Entry() = default;
26
27 virtual glm::ivec2 getSize() = 0;
28 virtual void setPosition(glm::ivec2 position) {}
29
30 [[nodiscard]]
31 virtual AFloat getFloat() const {
32 return AFloat::NONE;
33 }
34
35 [[nodiscard]]
36 virtual bool forcesNextLine() const {
37 return false;
38 }
39
40 [[nodiscard]]
41 bool isFloating() const {
42 return getFloat() != AFloat::NONE;
43 }
44
45 [[nodiscard]]
46 virtual bool escapesEdges() {
47 return false;
48 }
49 };
50
51protected:
52 float mLineHeight = 1.f;
53 ATextAlign mTextAlign = ATextAlign::LEFT;
54 AOptional<int> mHeight;
55
56public:
57 void setLineHeight(float lineHeight) {
58 mLineHeight = lineHeight;
59 }
60
61 void setTextAlign(ATextAlign textAlign) {
62 mTextAlign = textAlign;
63 }
64
65
66 [[nodiscard]]
67 AOptional<int> height() const {
68 return mHeight;
69 }
70};
71
72template<typename Container = AVector<_<AWordWrappingEngineBase::Entry>>>
74public:
75 using Entries = Container;
76
77 // include AWordWrappingEngineImpl.h for implementation
78 void performLayout(const glm::ivec2& offset, const glm::ivec2& size);
79
80 void setEntries(Container entries) {
81 mEntries = std::move(entries);
82 }
83
84 [[nodiscard]]
85 Container& entries() {
86 return mEntries;
87 }
88
89
90 [[nodiscard]]
91 const Container& entries() const {
92 return mEntries;
93 }
94
95private:
96 Container mEntries;
97};
98
99
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition AOptional.h:32
Definition AWordWrappingEngine.h:23
Definition AWordWrappingEngine.h:21
Definition AWordWrappingEngine.h:73
ATextAlign
Controls the text alignment inside AView.
Definition ATextAlign.h:20
AFloat
Specifies text floating in text wrapping views, i.e, ATextArea, AText.
Definition AFloat.h:19
@ NONE
Definition AFloat.h:23