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#include <utility>
15
16hi_export_module(hikogui.utility.dialog : intf);
17
18hi_export namespace hi {
19inline namespace v1 {
20
21enum class dialog_button {no, yes, cancel, ok, retry, _continue};
22
23template<std::integral T>
24[[nodiscard]] constexpr unsigned long long operator<<(T const &lhs, dialog_button const &rhs) noexcept
25{
26 return 1ULL << std::to_underlying(rhs);
27}
28
29enum class dialog_button_mask : uint64_t {
30 no = 1 << dialog_button::no,
31 yes = 1 << dialog_button::yes,
32
33 cancel = 1 << dialog_button::cancel,
34
42 ok = 1 << dialog_button::ok,
43 retry = 1 << dialog_button::retry,
44 _continue = 1 << dialog_button::_continue,
45
55 cancel_retry_continue = cancel | retry | _continue,
56
65 yes_no = yes | no,
66
75 ok_cancel = ok | cancel,
76
85 retry_cancel = retry | cancel,
86
96 yes_no_cancel = yes | no | cancel,
97};
98
99[[nodiscard]] constexpr bool to_bool(dialog_button_mask const &rhs) noexcept
100{
101 return std::to_underlying(rhs) != 0;
102}
103
104[[nodiscard]] constexpr dialog_button_mask operator&(dialog_button_mask const &lhs, dialog_button_mask const &rhs) noexcept
105{
106 return static_cast<dialog_button_mask>(std::to_underlying(lhs) & std::to_underlying(rhs));
107}
108
109[[nodiscard]] constexpr dialog_button_mask operator|(dialog_button_mask const &lhs, dialog_button_mask const &rhs) noexcept
110{
111 return static_cast<dialog_button_mask>(std::to_underlying(lhs) | std::to_underlying(rhs));
112}
113
114[[nodiscard]] constexpr dialog_button_mask &operator&=(dialog_button_mask &lhs, dialog_button_mask const &rhs) noexcept
115{
116 return lhs = lhs & rhs;
117}
118
119[[nodiscard]] constexpr dialog_button_mask &operator|=(dialog_button_mask &lhs, dialog_button_mask const &rhs) noexcept
120{
121 return lhs = lhs | rhs;
122}
123
124[[nodiscard]] constexpr dialog_button_mask operator&(dialog_button_mask const &lhs, dialog_button const &rhs) noexcept
125{
126 return lhs & dialog_button_mask{1 << rhs};
127}
128
129[[nodiscard]] constexpr dialog_button_mask operator|(dialog_button_mask const &lhs, dialog_button const &rhs) noexcept
130{
131 return lhs | dialog_button_mask{1 << rhs};
132}
133
134[[nodiscard]] constexpr dialog_button_mask &operator&=(dialog_button_mask &lhs, dialog_button const &rhs) noexcept
135{
136 return lhs = lhs & rhs;
137}
138
139[[nodiscard]] constexpr dialog_button_mask &operator|=(dialog_button_mask &lhs, dialog_button const &rhs) noexcept
140{
141 return lhs = lhs | rhs;
142}
143
153std::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;
154
155} // namespace v1
156} // namespace hi::inline v1
The HikoGUI namespace.
Definition array_generic.hpp:21
The HikoGUI API version 1.
Definition array_generic.hpp:22
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:29
@ yes_no
A dialog box with "yes" and "no" buttons.
Definition dialog_intf.hpp:65
@ ok
A dialog box with just a "ok" button.
Definition dialog_intf.hpp:42
@ yes_no_cancel
A dialog box with "yes", "no" and "cancel" buttons.
Definition dialog_intf.hpp:96
@ retry_cancel
A dialog box with "retry" and "cancel" buttons.
Definition dialog_intf.hpp:85
@ ok_cancel
A dialog box with "ok" and "cancel" buttons.
Definition dialog_intf.hpp:75
@ cancel_retry_continue
A dialog box with "cancel", "retry" and "continue" buttons.
Definition dialog_intf.hpp:55