AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
ATextLayoutHelper.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//
13// Created by Alex2772 on 11/28/2021.
14//
15
16#pragma once
17
18#include <AUI/Common/AVector.h>
19#include <AUI/Font/AFontStyle.h>
20#include <glm/glm.hpp>
21
26public:
27 struct Boundary {
28 glm::ivec2 position;
29 };
30
37 using Symbols = AVector<Line>;
38
39private:
40 Symbols mSymbols;
41
42 static size_t xToIndex(const AVector<Boundary>& line, int pos);
43
44public:
45 ATextLayoutHelper() = default;
46 explicit ATextLayoutHelper(Symbols symbols) : mSymbols(std::move(symbols)) {}
47
48 void setSymbols(Symbols symbols) {
49 mSymbols = std::move(symbols);
50 }
51
52 [[nodiscard]]
53 AOptional<glm::ivec2> indexToPos(size_t line, size_t column);
54
55 [[nodiscard]]
56 size_t posToIndexFixedLineHeight(const glm::ivec2& position, const AFontStyle& font) const;
57};
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition: AOptional.h:32
Helps mapping prerendered string with positions.
Definition: ATextLayoutHelper.h:25
A std::vector with AUI extensions.
Definition: AVector.h:38
Definition: AFontStyle.h:24
Definition: ATextLayoutHelper.h:27