#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DialogData<D = ()> {
pub title: String,
pub message: String,
pub buttons: Vec<String>,
pub purpose: Option<D>,
pub is_loading: bool,
}
impl<D> DialogData<D> {
pub fn new(
title: impl Into<String>,
message: impl Into<String>,
buttons: impl IntoIterator<Item = impl Into<String>>,
purpose: D,
) -> Self {
Self {
title: title.into(),
message: message.into(),
buttons: buttons.into_iter().map(Into::into).collect(),
purpose: Some(purpose),
is_loading: false,
}
}
pub fn loading(title: impl Into<String>, message: impl Into<String>) -> Self {
Self {
title: title.into(),
message: message.into(),
buttons: Vec::new(),
purpose: None,
is_loading: true,
}
}
pub fn button_count(&self) -> usize {
self.buttons.len()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DialogResult<D> {
Dismissed,
Selected { purpose: Option<D>, index: usize },
}