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/glyph_ids.hpp"
11#include "text/elusive_icon.hpp"
12#include "text/hikogui_icon.hpp"
13#include <variant>
14
15namespace hi::inline v1 {
16
19class icon {
20public:
21 icon(URL const &url);
22 icon(pixel_map<sfloat_rgba16> &&image) noexcept;
23 icon(glyph_ids const &glyph) noexcept;
24 icon(elusive_icon const &icon) noexcept;
25 icon(hikogui_icon const &icon) noexcept;
26
27 constexpr icon() noexcept : _image(std::monostate{}) {}
28
29 icon(icon const &) noexcept = default;
30 icon(icon &&) noexcept = default;
31 icon &operator=(icon const &) noexcept = default;
32 icon &operator=(icon &&) noexcept = default;
33
34 [[nodiscard]] constexpr bool empty() const noexcept
35 {
36 return std::holds_alternative<std::monostate>(_image);
37 }
38
39 [[nodiscard]] constexpr explicit operator bool() const noexcept
40 {
41 return not empty();
42 }
43
44 [[nodiscard]] friend bool operator==(icon const &lhs, icon const &rhs) noexcept
45 {
46 return lhs._image == rhs._image;
47 }
48
49 template<typename T>
50 [[nodiscard]] friend bool holds_alternative(hi::icon const &icon) noexcept
51 {
52 return std::holds_alternative<T>(icon._image);
53 }
54
55 template<typename T>
56 [[nodiscard]] friend T const &get(hi::icon const &icon) noexcept
57 {
58 return std::get<T>(icon._image);
59 }
60
61 template<typename T>
62 [[nodiscard]] friend T &get(hi::icon &icon) noexcept
63 {
64 return std::get<T>(icon._image);
65 }
66
67 template<typename T>
68 [[nodiscard]] friend std::add_pointer_t<T const> get_if(hi::icon const *icon) noexcept
69 {
70 return std::get_if<T>(&icon->_image);
71 }
72
73 template<typename T>
74 [[nodiscard]] friend std::add_pointer_t<T> get_if(hi::icon *icon) noexcept
75 {
76 return std::get_if<T>(&icon->_image);
77 }
78
79private:
80 using image_type = std::variant<std::monostate, elusive_icon, hikogui_icon, glyph_ids, pixel_map<sfloat_rgba16>>;
81
82 image_type _image;
83
84 friend class stencil;
85};
86
87} // namespace hi::inline v1
A 2D canvas of pixels.
Definition pixel_map.hpp:102
An image, in different formats.
Definition icon.hpp:19
A set of glyph-ids of a font which composites into a single glyph.
Definition glyph_ids.hpp:127
Definition URL.hpp:47