commons 0.1.5
Header-only C++23 library of common/shared types for the C++ libraries
Loading...
Searching...
No Matches
display_info.hpp File Reference

Presentation metadata for a type/value — name, description, icon, color, all optional — plus the trait/concept machinery to attach and retrieve it. More...

#include <commons/color.hpp>
#include <commons/icon.hpp>
#include <concepts>
#include <optional>
#include <string>
Include dependency graph for display_info.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  comms::DisplayInfo
 Presentation metadata for a type/value. More...
 
struct  comms::HasDisplayInfo< T >
 Customization point: the primary template forwards to a member T::display_info() when present; specialize it for non-intrusive attachment to types you cannot edit. More...
 

Concepts

concept  comms::Displayable
 True when T has display metadata — via a member display_info() or a HasDisplayInfo<T> specialization.
 

Functions

template<typename T >
const DisplayInfocomms::display_info ()
 Retrieve the DisplayInfo for T via whichever mechanism is present.
 

Detailed Description

Presentation metadata for a type/value — name, description, icon, color, all optional — plus the trait/concept machinery to attach and retrieve it.

comms::DisplayInfo is a tiny container of UI-oriented metadata about a type. The icon and color fields reuse comms::Icon and comms::Color, so they already carry Iconify ids and MUI/CSS palettes and serialize to JSON for a frontend. Every field is optional; populate only what a given type needs.

The intent is static, compile-time-fixed data attached to a type as a trait: define it once (a static const DisplayInfo returned by reference) and never mutate it at runtime.

Two ways to attach it, both supported:

  • Intrusive — give the type a static member static const DisplayInfo& display_info().
  • Non-intrusive — specialize comms::HasDisplayInfo<T> for types you cannot edit (enums, third-party types).

The free comms::display_info<T>() dispatches to whichever is present, and the comms::Displayable<T> concept reports whether either exists. A type with neither is simply not Displayable (no hard error); calling display_info<T>() on such a type is an expected compile error.

Serialization (in commons/json.hpp, gated by COMMONS_WITH_NLOHMANN_JSON): DisplayInfo travels as a JSON object whose absent fields are omitted.

Function Documentation

◆ display_info()

template<typename T >
const DisplayInfo & comms::display_info ( )

Retrieve the DisplayInfo for T via whichever mechanism is present.

Ill-formed for a type that is not Displayable.