BlueGit

ict rusty-teams

Files

rusty-teams / crates / webview / src / dialog.rs

dialog.rs

dialog.rs 1.2 KiB Download Raw
1use std::sync::{Arc, mpsc};
2
3use crate::transport::UiRequest;
4
5#[derive(Debug, Clone)]
6pub struct DialogSpec {
7 pub title: String,
8 pub width: u32,
9 pub height: u32,
10 pub background: u32,
11 pub owner: Option<isize>,
12 pub page_url: String,
13 pub page_html: String,
14}
15
16#[derive(Debug, Clone, PartialEq, Eq)]
17pub enum DialogEvent {
18 Message(String),
19 Closed,
20}
21
22#[derive(Debug)]
23pub(crate) enum DialogCommand {
24 Post(String),
25 Resize {
26 width: Option<u32>,
27 height: Option<u32>,
28 },
29 Close,
30}
31
32#[derive(Clone)]
33pub struct DialogHandle {
34 pub(crate) id: u64,
35 pub(crate) requests: mpsc::Sender<UiRequest>,
36 pub(crate) waker: Arc<dyn Fn() + Send + Sync>,
37}
38
39impl DialogHandle {
40 pub fn post(&self, json: String) {
41 self.send(DialogCommand::Post(json));
42 }
43
44 pub fn resize(&self, width: Option<u32>, height: Option<u32>) {
45 self.send(DialogCommand::Resize { width, height });
46 }
47
48 pub fn close(&self) {
49 self.send(DialogCommand::Close);
50 }
51
52 fn send(&self, command: DialogCommand) {
53 let request = UiRequest::Dialog {
54 id: self.id,
55 command,
56 };
57 if self.requests.send(request).is_ok() {
58 (self.waker)();
59 }
60 }
61}