use winio_handle::MaybeBorrowedWindow;
use winio_primitive::{MessageBoxButton, MessageBoxResponse, MessageBoxStyle};
use crate::{sys, sys::Result};
#[derive(Debug, Default, Clone)]
pub struct MessageBox(sys::MessageBox);
impl MessageBox {
pub fn new() -> Self {
Self(sys::MessageBox::new())
}
pub async fn show(
self,
parent: impl Into<MaybeBorrowedWindow<'_>>,
) -> Result<MessageBoxResponse> {
self.0.show(parent.into().0).await
}
pub fn message(mut self, msg: impl AsRef<str>) -> Self {
self.0.message(msg.as_ref());
self
}
pub fn title(mut self, title: impl AsRef<str>) -> Self {
self.0.title(title.as_ref());
self
}
pub fn instruction(mut self, instr: impl AsRef<str>) -> Self {
self.0.instruction(instr.as_ref());
self
}
pub fn style(mut self, style: MessageBoxStyle) -> Self {
self.0.style(style);
self
}
pub fn buttons(mut self, btns: MessageBoxButton) -> Self {
self.0.buttons(btns);
self
}
pub fn custom_button(mut self, btn: impl Into<CustomButton>) -> Self {
self.0.custom_button(btn.into().0);
self
}
pub fn custom_buttons(mut self, btn: impl IntoIterator<Item = CustomButton>) -> Self {
self.0.custom_buttons(btn.into_iter().map(|b| b.0));
self
}
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct CustomButton(sys::CustomButton);
impl CustomButton {
pub fn new(result: u16, text: impl AsRef<str>) -> Self {
Self(sys::CustomButton::new(result, text.as_ref()))
}
}
impl<S: AsRef<str>> From<(u16, S)> for CustomButton {
fn from((result, text): (u16, S)) -> Self {
Self::new(result, text)
}
}