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 "i18n/translate.hpp"
11#include <string>
12#include <type_traits>
13#include <memory>
14
15namespace hi::inline v1 {
16
27class label {
28public:
31 hi::icon icon;
32
37
42 label(hi::icon icon, tr text) noexcept : icon(std::move(icon)), text(std::move(text)) {}
43
47 label(tr text) noexcept : icon(), text(std::move(text)) {}
48
52 constexpr label(hi::icon icon) noexcept : icon(std::move(icon)), text() {}
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
63 [[nodiscard]] constexpr bool empty() const noexcept
64 {
65 return icon.empty() and text.empty();
66 }
67
68 constexpr explicit operator bool() const noexcept
69 {
70 return not empty();
71 }
72
78 [[nodiscard]] friend bool operator==(label const &lhs, label const &rhs) noexcept
79 {
80 return lhs.icon == rhs.icon and lhs.text == rhs.text;
81 }
82
83 [[nodiscard]] friend std::string to_string(label const &rhs) noexcept
84 {
85 return rhs.text();
86 }
87
88 friend std::ostream &operator<<(std::ostream &lhs, label const &rhs)
89 {
90 return lhs << to_string(rhs);
91 }
92
93private:
94};
95
96} // namespace hi::inline v1
97
98template<typename CharT>
99struct std::formatter<hi::label, CharT> : std::formatter<std::string_view, CharT> {
100 auto format(hi::label const &t, auto &fc)
101 {
102 return std::formatter<std::string_view, CharT>::format(to_string(t), fc);
103 }
104};
This file includes required definitions.
A localizable message.
Definition translate.hpp:155
An image, in different formats.
Definition icon.hpp:19
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:78
tr text
Localizable text.
Definition label.hpp:36
label(tr text) noexcept
Construct a new label from text.
Definition label.hpp:47
hi::icon icon
The icon.
Definition label.hpp:31
label(hi::icon icon, tr text) noexcept
Construct a new label from an icon and text.
Definition label.hpp:42
constexpr label(hi::icon icon) noexcept
Construct a new label from an icon.
Definition label.hpp:52
constexpr label() noexcept
Construct a empty label.
Definition label.hpp:56
T move(T... args)
T to_string(T... args)