Files
iZo/include/izo/MessageBox.hpp

77 lines
2.3 KiB
C++
Raw Normal View History

#pragma once
#include <cstdint>
#include <string>
#include <string_view>
namespace izo {
enum class MessageIcon { Info, Warning, Error, Question };
enum class MessageButtons { Ok, OkCancel, YesNo, YesNoCancel };
enum class MessageResponse { Ok, Cancel, Yes, No, Error };
struct MessageBoxOptions {
std::string title;
std::string message;
MessageIcon icon = MessageIcon::Info;
MessageButtons buttons = MessageButtons::Ok;
};
MessageResponse ShowMessageBox(const MessageBoxOptions& options,
std::string* errorMessage = nullptr);
MessageResponse ShowMessageBox(std::string_view title, std::string_view message,
MessageIcon icon = MessageIcon::Info,
MessageButtons buttons = MessageButtons::Ok,
std::string* errorMessage = nullptr);
// Convenience wrappers around ShowMessageBox.
MessageResponse ShowErrorBox(std::string_view title, std::string_view message,
std::string* errorMessage = nullptr);
MessageResponse ShowQuestionBox(std::string_view title, std::string_view message,
std::string* errorMessage = nullptr);
struct InputBoxOptions {
std::string title;
std::string message;
std::string initialValue;
bool password = false;
};
struct InputBoxResult {
MessageResponse response = MessageResponse::Cancel;
std::string value;
std::string errorMessage;
explicit operator bool() const noexcept { return response == MessageResponse::Ok; }
};
InputBoxResult ShowInputBox(const InputBoxOptions& options = {});
struct Color {
std::uint8_t red = 0;
std::uint8_t green = 0;
std::uint8_t blue = 0;
friend bool operator==(Color left, Color right) noexcept {
return left.red == right.red && left.green == right.green && left.blue == right.blue;
}
friend bool operator!=(Color left, Color right) noexcept { return !(left == right); }
};
struct ColorPickerOptions {
std::string title;
Color initialColor{};
};
struct ColorPickerResult {
MessageResponse response = MessageResponse::Cancel;
Color color{};
std::string errorMessage;
explicit operator bool() const noexcept { return response == MessageResponse::Ok; }
};
ColorPickerResult PickColor(const ColorPickerOptions& options = {});
} // namespace izo