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
use pax_lang::*;
use pax_lang::api::{Size2D, Size, Property, Transform2D, EasingCurve, ArgsKeyDown};
use pax_lang::api::numeric::Numeric;
use pax_runtime_api::RuntimeContext;
use crate::primitives::{Frame};
use crate::types::{SidebarDirection};

#[derive(Pax)]
#[inlined(
<Frame transform = {Transform2D::anchor(0%,0%)* Transform2D::align(100%, 0%) * Transform2D::translate(position, 0.0)}
width = 500px
height = 100%
>
slot(1)
</Frame >
<Frame>
slot(0)
</Frame>


@events {
    key_down: handle_key_down,
    did_mount: handle_did_mount,
}

)]
pub struct Sidebar {
    pub enabled: Property<bool>,
    pub position: Property<f64>,
}

impl Sidebar {
    pub fn handle_key_down(&mut self, ctx: RuntimeContext, args: ArgsKeyDown) {
        let enabled = *self.enabled.get();
        if (args.keyboard.key == "c".to_string()) && !enabled {
            self.position.ease_to(-500.0, 80, EasingCurve::InQuad);
            self.enabled.set(true);
        }
        if (args.keyboard.key == "c".to_string()) && enabled {
            self.position.ease_to(0.0, 80, EasingCurve::OutBack);
            self.enabled.set(false);
        }
    }

    pub fn handle_did_mount(&mut self, ctx: RuntimeContext) {
        self.enabled.set(false);
        self.position.set(0.0);
    }
}