commons 0.1.5
Header-only C++23 library of common/shared types for the C++ libraries
Loading...
Searching...
No Matches
display_info.hpp
Go to the documentation of this file.
1#pragma once
2
31
32#include <commons/color.hpp>
33#include <commons/icon.hpp>
34
35#include <concepts>
36#include <optional>
37#include <string>
38
39namespace comms {
40
44 std::optional<std::string> name = std::nullopt;
45 std::optional<std::string> description = std::nullopt;
46 std::optional<Icon> icon = std::nullopt;
47 std::optional<Color> color = std::nullopt;
48 bool operator==(const DisplayInfo&) const = default;
49};
50
51namespace detail {
52template <typename T>
53concept HasMemberDisplayInfo = requires {
54 { T::display_info() } -> std::same_as<const DisplayInfo&>;
55};
56} // namespace detail
57
61template <typename T>
63 [[nodiscard]] static const DisplayInfo& display_info()
64 requires detail::HasMemberDisplayInfo<T>
65 {
66 return T::display_info();
67 }
68};
69
72template <typename T>
73[[nodiscard]] const DisplayInfo& display_info() {
75}
76
81template <typename T>
82concept Displayable = requires {
83 { HasDisplayInfo<T>::display_info() } -> std::same_as<const DisplayInfo&>;
84};
85
86} // namespace comms
A tiny RGBA color container with rich, mostly-constexpr color manipulation, plus the Hsl/Hsv model st...
True when T has display metadata — via a member display_info() or a HasDisplayInfo<T> specialization.
Definition display_info.hpp:82
const DisplayInfo & display_info()
Retrieve the DisplayInfo for T via whichever mechanism is present.
Definition display_info.hpp:73
A tiny value type carrying an Iconify icon identifier such as mdi:abacus (a set:name pair).
Presentation metadata for a type/value.
Definition display_info.hpp:43
std::optional< Color > color
Associated display color.
Definition display_info.hpp:47
std::optional< std::string > name
Human-readable label.
Definition display_info.hpp:44
std::optional< std::string > description
Longer explanatory text.
Definition display_info.hpp:45
std::optional< Icon > icon
Associated Iconify icon.
Definition display_info.hpp:46
bool operator==(const DisplayInfo &) const =default
Field-wise equality.
Customization point: the primary template forwards to a member T::display_info() when present; specia...
Definition display_info.hpp:62