use std::rc::Rc;
use teksilo_canvas::Rect;
use teksilo_core::widget::EventContext;
#[derive(Debug, Clone, PartialEq)]
pub struct WebViewSelectOption {
pub id: usize,
pub label: String,
pub disabled: bool,
pub group: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum WebViewControl {
Alert { message: String },
Confirm { message: String },
Prompt { message: String, default: String },
Select {
options: Vec<WebViewSelectOption>,
selected: Option<usize>,
area: Rect,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum WebViewControlAnswer {
Dismissed,
Confirmed,
Text(String),
Selected(usize),
}
pub type WebViewControlReply = Box<dyn FnOnce(WebViewControlAnswer)>;
pub trait WebViewControlPresenter: 'static {
fn present(&self, control: WebViewControl, ctx: &mut EventContext, reply: WebViewControlReply);
}
#[derive(Clone)]
pub struct SharedWebViewControlPresenter(pub Rc<dyn WebViewControlPresenter>);
impl SharedWebViewControlPresenter {
pub fn new(presenter: impl WebViewControlPresenter) -> Self {
Self(Rc::new(presenter))
}
}
impl std::fmt::Debug for SharedWebViewControlPresenter {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("SharedWebViewControlPresenter")
}
}