HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
agrapheme.hpp
1// Copyright Take Vos 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
6#pragma once
7
8#include "../unicode/grapheme.hpp"
9#include "../i18n/iso_639.hpp"
10#include "text_phrasing.hpp"
11#include "text_style.hpp"
12#include <bit>
13
14namespace hi::inline v1 {
15
16struct agrapheme {
17 using value_type = uint64_t;
18
26 value_type _value;
27
28 [[nodiscard]] constexpr friend bool operator==(agrapheme const &lhs, agrapheme const &rhs) noexcept = default;
29
30 [[nodiscard]] constexpr friend std::partial_ordering operator<=>(agrapheme const &lhs, agrapheme const &rhs) noexcept
31 {
32 return lhs.grapheme() <=> rhs.grapheme();
33 }
34
35 [[nodiscard]] constexpr bool empty() const noexcept
36 {
37 return grapheme().empty();
38 }
39
40 constexpr explicit operator bool() const noexcept
41 {
42 return not empty();
43 }
44
45 [[nodiscard]] size_t hash() const noexcept
46 {
47 return std::hash<value_type>{}(_value);
48 }
49
50 [[nodiscard]] constexpr hi::grapheme grapheme() const noexcept
51 {
52 return std::bit_cast<hi::grapheme>(truncate<uint32_t>(_value >> 43));
53 }
54
55 [[nodiscard]] constexpr text_phrasing phrasing() const noexcept
56 {
57 return static_cast<text_phrasing>((_value >> 39) & 0xf);
58 }
59
60 [[nodiscard]] constexpr iso_639 language() const noexcept
61 {
62 return std::bit_cast<iso_639>(truncate<uint16_t>(_value >> 16));
63 }
64
65 [[nodiscard]] constexpr text_style style() const noexcept
66 {
67 return std::bit_cast<text_style>(truncate<uint16_t>(_value));
68 }
69
70 [[nodiscard]] text_sub_style sub_style(iso_15924 script = iso_15924{}) const noexcept
71 {
72 return style().sub_style(phrasing(), language(), script);
73 }
74};
75
76}
77
78template<>
79struct std::hash<hi::agrapheme> {
80 [[nodiscard]] size_t operator()(hi::agrapheme const &rhs) const noexcept
81 {
82 return rhs.hash();
83 }
84};
@ grapheme
The gui_event has grapheme data.
DOXYGEN BUG.
Definition algorithm.hpp:15
text_phrasing
Definition text_phrasing.hpp:15
The HikoGUI namespace.
Definition ascii.hpp:19
Definition agrapheme.hpp:16
value_type _value
Internal value.
Definition agrapheme.hpp:26
A grapheme-cluster, what a user thinks a character is.
Definition grapheme.hpp:41
constexpr bool empty() const noexcept
Check if the grapheme is empty.
Definition grapheme.hpp:122
T operator()(T... args)