HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
icon.hpp
1// Copyright Take Vos 2020-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 "URL.hpp"
8#include "pixel_map.hpp"
9#include "rapid/sfloat_rgba16.hpp"
10#include "text/font_glyph_ids.hpp"
11#include "text/elusive_icon.hpp"
12#include "text/ttauri_icon.hpp"
13#include <variant>
14
15namespace tt {
16
19class icon {
20public:
21 icon(URL const &url);
22 icon(pixel_map<sfloat_rgba16> &&image) noexcept;
23 icon(font_glyph_ids const &glyph) noexcept;
24 icon(elusive_icon const &icon) noexcept;
25 icon(ttauri_icon const &icon) noexcept;
26
27 constexpr icon() noexcept : _image(std::monostate{}) {}
28
29 icon(icon const &) noexcept;
30 icon(icon &&) noexcept = default;
31 icon &operator=(icon const &) noexcept;
32 icon &operator=(icon &&) noexcept = default;
33
34 [[nodiscard]] explicit operator bool () const noexcept
35 {
36 return !std::holds_alternative<std::monostate>(_image);
37 }
38
39 [[nodiscard]] friend bool operator==(icon const &lhs, icon const &rhs) noexcept
40 {
41 return lhs._image == rhs._image;
42 }
43
44 template<typename T>
45 [[nodiscard]] friend bool holds_alternative(tt::icon const &icon) noexcept
46 {
47 return std::holds_alternative<T>(icon._image);
48 }
49
50 template<typename T>
51 [[nodiscard]] friend T const &get(tt::icon const &icon) noexcept
52 {
53 return std::get<T>(icon._image);
54 }
55
56 template<typename T>
57 [[nodiscard]] friend T &get(tt::icon &icon) noexcept
58 {
59 return std::get<T>(_image);
60 }
61
62private:
63 using image_type = std::variant<std::monostate, font_glyph_ids, pixel_map<sfloat_rgba16>>;
64
65 image_type _image;
66
67 friend class stencil;
68};
69
70
71}
A 2D canvas of pixels.
Definition pixel_map.hpp:101
An image, in different formats.
Definition icon.hpp:19
Definition font_glyph_ids.hpp:78
Definition URL.hpp:47