HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
dialog_intf.hpp
1// Copyright Take Vos 2022.
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 "../macros.hpp"
8#include <string_view>
9#include <iostream>
10#include <format>
11#include <concepts>
12#include <expected>
13#include <system_error>
14
15hi_export_module(hikogui.utility.dialog : intf);
16
17hi_export namespace hi {
18inline namespace v1 {
19
20enum class dialog_button {no, yes, cancel, ok, retry, _continue};
21
22template<std::integral T>
23[[nodiscard]] constexpr unsigned long long operator<<(T const &lhs, dialog_button const &rhs) noexcept
24{
25 return 1ULL << std::to_underlying(rhs);
26}
27
28enum class dialog_button_mask : uint64_t {
29 no = 1 << dialog_button::no,
30 yes = 1 << dialog_button::yes,
31
32 cancel = 1 << dialog_button::cancel,
33
41 ok = 1 << dialog_button::ok,
42 retry = 1 << dialog_button::retry,
43 _continue = 1 << dialog_button::_continue,
44
54 cancel_retry_continue = cancel | retry | _continue,
55
64 yes_no = yes | no,
65
74 ok_cancel = ok | cancel,
75
84 retry_cancel = retry | cancel,
85
95 yes_no_cancel = yes | no | cancel,
96};
97
98[[nodiscard]] constexpr bool to_bool(dialog_button_mask const &rhs) noexcept
99{
100 return std::to_underlying(rhs) != 0;
101}
102
103[[nodiscard]] constexpr dialog_button_mask operator&(dialog_button_mask const &lhs, dialog_button_mask const &rhs) noexcept
104{
105 return static_cast<dialog_button_mask>(std::to_underlying(lhs) & std::to_underlying(rhs));
106}
107
108[[nodiscard]] constexpr dialog_button_mask operator|(dialog_button_mask const &lhs, dialog_button_mask const &rhs) noexcept
109{
110 return static_cast<dialog_button_mask>(std::to_underlying(lhs) | std::to_underlying(rhs));
111}
112
113[[nodiscard]] constexpr dialog_button_mask &operator&=(dialog_button_mask &lhs, dialog_button_mask const &rhs) noexcept
114{
115 return lhs = lhs & rhs;
116}
117
118[[nodiscard]] constexpr dialog_button_mask &operator|=(dialog_button_mask &lhs, dialog_button_mask const &rhs) noexcept
119{
120 return lhs = lhs | rhs;
121}
122
123[[nodiscard]] constexpr dialog_button_mask operator&(dialog_button_mask const &lhs, dialog_button const &rhs) noexcept
124{
125 return lhs & dialog_button_mask{1 << rhs};
126}
127
128[[nodiscard]] constexpr dialog_button_mask operator|(dialog_button_mask const &lhs, dialog_button const &rhs) noexcept
129{
130 return lhs | dialog_button_mask{1 << rhs};
131}
132
133[[nodiscard]] constexpr dialog_button_mask &operator&=(dialog_button_mask &lhs, dialog_button const &rhs) noexcept
134{
135 return lhs = lhs & rhs;
136}
137
138[[nodiscard]] constexpr dialog_button_mask &operator|=(dialog_button_mask &lhs, dialog_button const &rhs) noexcept
139{
140 return lhs = lhs | rhs;
141}
142
152std::expected<dialog_button, std::error_code> dialog(std::string_view title, std::string_view text, dialog_button_mask button_mask = dialog_button_mask::ok) noexcept;
153
154} // namespace v1
155} // namespace hi::inline v1
The HikoGUI namespace.
Definition array_generic.hpp:20
std::expected< dialog_button, std::error_code > dialog(std::string_view title, std::string_view text, dialog_button_mask button_mask=dialog_button_mask::ok) noexcept
Display a modal dialog.
Definition dialog_win32_impl.hpp:20
dialog_button_mask
Definition dialog_intf.hpp:28
@ yes_no
A dialog box with "yes" and "no" buttons.
@ ok
A dialog box with just a "ok" button.
@ yes_no_cancel
A dialog box with "yes", "no" and "cancel" buttons.
@ retry_cancel
A dialog box with "retry" and "cancel" buttons.
@ ok_cancel
A dialog box with "ok" and "cancel" buttons.
@ cancel_retry_continue
A dialog box with "cancel", "retry" and "continue" buttons.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20