HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
label.hpp
1// Copyright Take Vos 2020.
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 "required.hpp"
8#include "strings.hpp"
9#include "icon.hpp"
10#include "l10n.hpp"
11#include <string>
12#include <type_traits>
13#include <memory>
14
15namespace tt {
16
27class label {
28public:
32
37
43
47 label(l10n text) noexcept : icon(), text(std::move(text)) {}
48
53
56 constexpr label() noexcept : icon(), text() {}
57
58 label(label const &other) noexcept = default;
59 label &operator=(label const &other) noexcept = default;
60 label(label &&other) noexcept = default;
61 label &operator=(label &&other) noexcept = default;
62
68 [[nodiscard]] friend bool operator==(label const &lhs, label const &rhs) noexcept
69 {
70 return lhs.icon == rhs.icon and lhs.text == rhs.text;
71 }
72
73 [[nodiscard]] friend std::string to_string(label const &rhs) noexcept
74 {
75 return rhs.text();
76 }
77
78 friend std::ostream &operator<<(std::ostream &lhs, label const &rhs)
79 {
80 return lhs << to_string(rhs);
81 }
82
83private:
84};
85
86} // namespace tt
87
88namespace std {
89
90template<typename CharT>
91struct std::formatter<tt::label, CharT> : std::formatter<std::string_view, CharT> {
92 auto format(tt::label const &t, auto &fc)
93 {
94 return std::formatter<std::string_view, CharT>::format(to_string(t), fc);
95 }
96};
97
98} // namespace std
STL namespace.
An image, in different formats.
Definition icon.hpp:19
A localizable message.
Definition l10n.hpp:149
A label consisting of localizable text and an icon.
Definition label.hpp:27
friend bool operator==(label const &lhs, label const &rhs) noexcept
Compare if both labels are equal.
Definition label.hpp:68
tt::icon icon
The icon.
Definition label.hpp:31
constexpr label() noexcept
Construct a empty label.
Definition label.hpp:56
l10n text
Localizable text.
Definition label.hpp:36
label(tt::icon icon, l10n text) noexcept
Construct a new label from an icon and text.
Definition label.hpp:42
label(l10n text) noexcept
Construct a new label from text.
Definition label.hpp:47
label(tt::icon icon) noexcept
Construct a new label from an icon.
Definition label.hpp:52
T move(T... args)
T to_string(T... args)