1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#![allow(dead_code)]

use crate::*;
use pax_engine::api::*;
use pax_engine::*;
use std::cmp::Ordering;
use std::iter;

#[pax]
#[engine_import_path("pax_engine")]
#[inlined(
    if self.open {
        <Group x=50% y=50% width=300px height=170px>
            <Button width=80px height=30px anchor_y=100% anchor_x=100% y={100%-20px} x={100% -80px -20px -20px} label="Yes" @button_click=handle_yes/>
            <Button width=80px height=30px anchor_y=100% anchor_x=100% y={100% -20px} x={100% -20px} label="No" @button_click=handle_no/>
            <Text x=20px y=20px height=15px width=100px text=text/>
            <Rectangle fill=rgb(20, 20, 20)
            corner_radii={
                RectangleCornerRadii::radii(15.0,15.0,15.0,15.0)
            }/>
        </Group>
        <Rectangle fill=rgba(0, 0, 0, 70)/>
    }
)]
#[custom(Default)]
pub struct ConfirmationDialog {
    pub text: Property<String>,
    pub open: Property<bool>,
    pub signal: Property<bool>,
}

impl Default for ConfirmationDialog {
    fn default() -> Self {
        Self {
            text: Property::new("Are you sure?".to_owned()),
            open: Property::default(),
            signal: Property::default(),
        }
    }
}

impl ConfirmationDialog {
    pub fn handle_yes(&mut self, _ctx: &NodeContext, _event: Event<ButtonClick>) {
        self.open.set(false);
        self.signal.set(true);
    }

    pub fn handle_no(&mut self, _ctx: &NodeContext, _event: Event<ButtonClick>) {
        self.open.set(false);
    }
}