HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
text_theme.hpp
1// Copyright Take Vos 2021-2022.
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 "text_style.hpp"
8#include "../concurrency/module.hpp"
9#include <vector>
10#include <array>
11#include <algorithm>
12#include <cstdint>
13
14namespace hi { inline namespace v1 {
15
16class text_theme : public std::vector<text_style> {
17public:
19
20 [[nodiscard]] text_style const& find(text_phrasing phrasing, language_tag language) const noexcept
21 {
22 for (hilet& style : *this) {
23 if (matches(style, phrasing, language)) {
24 return style;
25 }
26 }
27 hi_axiom(not empty());
28 return back();
29 }
30
40 [[nodiscard]] text_style& find_or_add(text_phrasing_mask phrasing_mask, language_tag language_mask) noexcept
41 {
42 for (auto& style : *this) {
43 if (style.phrasing_mask == phrasing_mask and style.language_mask == language_mask) {
44 return style;
45 }
46 }
47
48 // Styles with filters are added before, so that the last style in the
49 // CSS file is found first. And the style without filters is the last one.
50 auto it = [&]{
51 if (empty()) {
52 return insert(cbegin(), text_style{});
53 } else {
54 auto non_filter_style = back();
55 return insert(cbegin(), std::move(non_filter_style));
56 }
57 }();
58
59 it->phrasing_mask = phrasing_mask;
60 it->language_mask = language_mask;
61 return *it;
62 }
63};
64
65}} // namespace hi::v1
66
67template<typename CharT>
68struct std::formatter<hi::text_theme, CharT> : std::formatter<std::string_view, CharT> {
69 auto format(hi::text_theme const& t, auto& fc)
70 {
71 return std::formatter<std::string_view, CharT>::format(std::format("#{}", t.size()), fc);
72 }
73};
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
Definition text_style.hpp:15
Definition text_theme.hpp:16
text_style & find_or_add(text_phrasing_mask phrasing_mask, language_tag language_mask) noexcept
Find or add an text_style to the text-theme.
Definition text_theme.hpp:40
text_style back(text_style ... args)
text_style cbegin(text_style ... args)
text_style empty(text_style ... args)
text_style insert(text_style ... args)
T move(T... args)
T size(T... args)