makepad_example_simple/
app.rs

1
2use makepad_widgets::*;
3
4live_design!{
5    use link::theme::*;
6    use link::shaders::*;
7    use link::widgets::*;
8        
9    App = {{App}} {
10        ui: <Root>{
11            main_window = <Window>{
12                body = <View>{
13                    flow: Down,
14                    spacing:30,
15                    align: {
16                        x: 0.5,
17                        y: 0.5
18                    },
19                    show_bg: true,
20                    draw_bg:{
21                        fn pixel(self) -> vec4 {
22                                                        
23                            let center = vec2(0.5, 0.5);
24                            let uv = self.pos - center;
25                            let radius = length(uv);
26                            let angle = atan(uv.y, uv.x);
27                            let color1 = mix(#f00, #00f, 0.5 + 10.5 * cos(angle + self.time));
28                            let color2 = mix(#0f0, #ff0, 0.5 + 0.5 * sin(angle + self.time));
29                            let color = mix(color1, color2, radius);
30                            return depth_clip(self.world, color, self.depth_clip);
31                        }
32                    }
33                    <Rotary>{
34                        text:"Slide"
35                    }
36                    button_1 = <Button> {
37                        text: "Click 福 me 😊"
38                        draw_text:{text_style:{font_size:18}}
39                    }
40                    text_input = <TextInput> {
41                        width: 100,
42                        flow: RightWrap,
43                        text: "Lorem ipsum"
44                        draw_text:{text_style:{font_size:18}}
45                    }/*
46                    button_2 = <Button> {
47                        text: "Click me 345 1234"
48                        draw_text:{color:#fff, text_style:{font_size:18}}
49                    }*/
50                /*
51
52                    <SliderRound> {
53                        text: "Short label",
54                        draw_bg: {
55                            val_color_1: #FFCC00
56                            val_color_1_hover: #FF9944
57                            val_color_1_focus: #FFCC44
58                            val_color_1_drag: #FFAA00
59
60                            val_color_2: #F00
61                            val_color_2_hover: #F00
62                            val_color_2_focus: #F00
63                            val_color_2_drag: #F00
64
65                            handle_color: #0000
66                            handle_color_hover: #0008
67                            handle_color_focus: #000C
68                            handle_color_drag: #000F
69                        }
70                    }*/
71                }
72            }
73        }
74    }
75}  
76
77app_main!(App); 
78 
79#[derive(Live, LiveHook)]
80pub struct App {
81    #[live] ui: WidgetRef,
82    #[rust] counter: usize,
83}
84 
85impl LiveRegister for App {
86    fn live_register(cx: &mut Cx) { 
87        crate::makepad_widgets::live_design(cx);
88    }
89}
90
91impl MatchEvent for App{
92    fn handle_startup(&mut self, _cx:&mut Cx){
93    }
94        
95    fn handle_actions(&mut self, cx: &mut Cx, actions:&Actions){
96        if self.ui.button(id!(button_1)).clicked(&actions) {
97            self.ui.button(id!(button_1)).set_text(cx, "Clicked 😀");
98            log!("hi");
99            self.counter += 1;
100        }
101    }
102}
103
104impl AppMain for App {
105    fn handle_event(&mut self, cx: &mut Cx, event: &Event) {
106        if let Event::XrUpdate(_e) = event{
107            //log!("{:?}", e.now.left.trigger.analog);
108        }
109        self.match_event(cx, event);
110        self.ui.handle_event(cx, event, &mut Scope::empty());
111    }
112}