HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
text_style_set.hpp
1// Copyright Take Vos 2024.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "../color/color.hpp"
8#include "../utility/utility.hpp"
9#include "../font/font.hpp"
10#include "../unicode/unicode.hpp"
11#include "../container/container.hpp"
12#include "../macros.hpp"
13#include "text_style.hpp"
14#include <ostream>
15#include <vector>
16#include <algorithm>
17
18hi_export_module(hikogui.text : text_style_set);
19
20hi_export namespace hi { inline namespace v1 {
21
26public:
27 constexpr text_style_set() noexcept = default;
28 text_style_set(text_style_set const&) noexcept = default;
29 text_style_set(text_style_set&&) noexcept = default;
30 text_style_set& operator=(text_style_set const&) noexcept = default;
31 text_style_set& operator=(text_style_set&&) noexcept = default;
32 [[nodiscard]] friend bool operator==(text_style_set const&, text_style_set const&) noexcept = default;
33
34 [[nodiscard]] constexpr bool empty() const noexcept
35 {
36 return _text_styles.empty();
37 }
38
39 [[nodiscard]] text_style get(grapheme_attributes const& attributes) const
40 {
41 auto r = text_style{};
42
43 for (auto const &[mask, style] : _text_styles) {
44 if (matches(mask, attributes)) {
45 r.apply(style);
46 }
47 }
48
49 hi_assert(r.complete());
50 return r;
51 }
52
53 [[nodiscard]] text_style operator[](grapheme_attributes const& attributes) const
54 {
55 return get(attributes);
56 }
57
58 [[nodiscard]] text_style const& front() const
59 {
60 hi_assert(not _text_styles.empty());
61 return _text_styles.front().second;
62 }
63
64 constexpr void clear() noexcept
65 {
66 _text_styles.clear();
67 }
68
69 constexpr void push_back(grapheme_attribute_mask const &mask, text_style const &style)
70 {
71 _text_styles.emplace_back(mask, style);
72 }
73
74private:
76};
77
78}}
Defined the color type.
The HikoGUI namespace.
Definition array_generic.hpp:21
The HikoGUI API version 1.
Definition array_generic.hpp:22
A text-style-set includes styles for displaying text with markup.
Definition text_style_set.hpp:25
Definition style.hpp:22
Definition grapheme_attributes.hpp:16
Definition grapheme_attributes.hpp:32