HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
widget_id.hpp
1// Copyright Take Vos 2023.
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 "../concurrency/concurrency.hpp"
8#include "../macros.hpp"
9#include <cstdint>
10#include <utility>
11#include <concepts>
12#include <compare>
13
14hi_export_module(hikogui.GUI : widget_id);
15
16hi_export namespace hi { inline namespace v1 {
17namespace detail {
18inline id_factory<uint32_t> widget_id_factory;
19}
20
21enum class widget_id : uint32_t {};
22
23[[nodiscard]] inline widget_id make_widget_id() noexcept
24{
25 return static_cast<widget_id>(detail::widget_id_factory.acquire());
26}
27
28inline void release_widget_id(widget_id id) noexcept
29{
30 detail::widget_id_factory.release(std::to_underlying(id));
31}
32
33[[nodiscard]] constexpr bool operator==(widget_id const& lhs, std::integral auto const& rhs) noexcept
34{
35 return std::cmp_equal(std::to_underlying(lhs), rhs);
36}
37
38[[nodiscard]] constexpr std::strong_ordering operator<=>(widget_id const& lhs, std::integral auto const& rhs) noexcept
39{
40 if (std::cmp_equal(std::to_underlying(lhs), rhs)) {
41 return std::strong_ordering::equal;
42 } else if (std::cmp_less(std::to_underlying(lhs), rhs)) {
43 return std::strong_ordering::less;
44 } else {
45 return std::strong_ordering::greater;
46 }
47}
48
49}} // namespace hi::v1
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20