HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
font_grapheme_id.hpp
1// Copyright Take Vos 2021.
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 "../unicode/grapheme.hpp"
8#include "../hash.hpp"
9
10namespace hi::inline v1 {
11
15 hi::font const *font;
16 grapheme g;
17
18 font_grapheme_id(hi::font const &font, grapheme g) noexcept : font(&font), g(std::move(g)) {}
19
20 [[nodiscard]] std::size_t hash() const noexcept
21 {
23 return hash_mix(reinterpret_cast<ptrdiff_t>(font), g);
24 }
25
26 [[nodiscard]] friend bool operator==(font_grapheme_id const &lhs, font_grapheme_id const &rhs) noexcept
27 {
28 hi_assert_not_null(lhs.font);
29 hi_assert_not_null(rhs.font);
30 return (lhs.font == rhs.font) and (lhs.g == rhs.g);
31 }
32};
33
34} // namespace hi::inline v1
35
36template<>
37struct std::hash<hi::font_grapheme_id> {
38 [[nodiscard]] std::size_t operator()(hi::font_grapheme_id const &rhs) const noexcept
39 {
40 return rhs.hash();
41 }
42};
#define hi_assert_not_null(x)
Assert if an expression is not nullptr.
Definition assert.hpp:118
DOXYGEN BUG.
Definition algorithm.hpp:15
The HikoGUI namespace.
Definition ascii.hpp:19
Definition font.hpp:32
Combined font_id + grapheme for use as a key in a std::unordered_map.
Definition font_grapheme_id.hpp:14
A grapheme-cluster, what a user thinks a character is.
Definition grapheme.hpp:41
T move(T... args)
T operator()(T... args)