16 } |
16 } |
17 |
17 |
18 widget_class("ToggleButton") { |
18 widget_class("ToggleButton") { |
19 || |
19 || |
20 frequency = 5; |
20 frequency = 5; |
21 state = 0; |
|
22 active_style = undefined; |
21 active_style = undefined; |
23 inactive_style = undefined; |
22 inactive_style = undefined; |
24 |
23 |
25 dispatch(value) { |
24 dispatch(value) { |
26 this.state = value; |
25 this.activity_state = Boolean(value); |
27 //redraw toggle button |
26 //redraw toggle button |
28 this.request_animate(); |
27 this.request_animate(); |
29 } |
28 } |
30 |
29 |
31 on_click(evt) { |
30 on_click(evt) { |
32 //toggle state and apply |
31 //toggle state and apply |
33 this.state = this.state ? false : true; |
32 this.activity_state = this.activity_state ? false : true; |
34 this.apply_hmi_value(0, this.state); |
33 this.apply_hmi_value(0, this.activity_state); |
35 |
34 |
36 //redraw toggle button |
35 //redraw toggle button |
37 this.request_animate(); |
36 this.request_animate(); |
38 } |
37 } |
39 |
38 |
40 animate(){ |
|
41 // redraw toggle button on screen refresh |
|
42 this.set_activation_state(this.state); |
|
43 } |
|
44 |
|
45 init() { |
39 init() { |
46 this.element.onclick = (evt) => this.on_click(evt); |
40 this.element.onclick = (evt) => this.on_click(evt); |
47 this.set_activation_state(undefined); |
41 this.activity_state = undefined; |
48 } |
42 } |
49 || |
43 || |
50 } |
44 } |
51 |
45 |
52 widget_defs("ToggleButton") { |
46 widget_defs("ToggleButton") { |