use crate::core::Bitflagable;
bitflags! {
pub struct WindowType: u32 {
const OK = 0x00000000;
const OK_CANCEL = 0x00000001;
const ABORT_RETRY_IGNORE = 0x00000002;
const CANCEL_TRY_CONTINUE = 0x00000006;
const HELP = 0x00004000;
const RETRY_CANCEL = 0x00000005;
const YES_NO = 0x00000004;
const YES_NO_CANCEL = 0x00000003;
}
}
impl Bitflagable<u32> for WindowType {
fn get_bits(self) -> u32 {
self.bits
}
}
bitflags! {
pub struct IconType: u32 {
const ICON_WARNING = 0x00000030;
const ICON_INFORMATION = 0x00000040;
const ICON_QUESTION = 0x00000020;
const ICON_ERROR = 0x00000010;
}
}
impl Bitflagable<u32> for IconType {
fn get_bits(self) -> u32 {
self.bits
}
}
bitflags! {
pub struct DefaultButton: u32 {
const DEFAULT_BUTTON_ONE = 0x00000000;
const DEFAULT_BUTTON_TWO = 0x00000100;
const DEFAULT_BUTTON_THREE = 0x00000200;
const DEFAULT_BUTTON_FOUR = 0x00000300;
}
}
impl Bitflagable<u32> for DefaultButton {
fn get_bits(self) -> u32 {
self.bits
}
}
bitflags! {
pub struct BoxReturn: i32{
const ABORT = 3;
const CANCEL = 2;
const CONTINUE = 11;
const IGNORE = 5;
const NO = 7;
const OK = 1;
const RETRY = 4;
const TRY_AGAIN = 10;
const YES = 6;
const NONE = 0;
}
}
impl Bitflagable<i32> for BoxReturn {
fn get_bits(self) -> i32 {
self.bits
}
}
#[derive(Clone, Copy, Debug)]
pub struct MessageBox {
pub(crate) title: &'static str,
pub(crate) content: &'static str,
pub(crate) window_type: WindowType,
pub(crate) icon_type: IconType,
pub(crate) default_button: DefaultButton,
}
impl MessageBox {
pub fn new(title: &'static str, content: &'static str) -> MessageBox {
MessageBox {
title,
content,
window_type: WindowType::OK_CANCEL,
icon_type: IconType::ICON_INFORMATION,
default_button: DefaultButton::DEFAULT_BUTTON_ONE,
}
}
pub fn set_title(&mut self, title: &'static str) -> &mut Self {
self.title = title;
self
}
pub fn set_content(&mut self, content: &'static str) -> &mut Self {
self.content = content;
self
}
pub fn set_window_type(&mut self, window_type: WindowType) -> &mut Self {
self.window_type = window_type;
self
}
pub fn set_icon_type(&mut self, icon_type: IconType) -> &mut Self {
self.icon_type = icon_type;
self
}
pub fn set_default_button(&mut self, default_button: DefaultButton) -> &mut Self {
self.default_button = default_button;
self
}
pub fn show(&self) -> Result<BoxReturn, String> {
crate::internal::dialogues::create_message_box(*self)
}
}