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