1 // widget_dropdown.ysl2 |
1 // widget_dropdown.ysl2 |
2 |
2 |
3 template "widget[@type='DropDown']", mode="widget_defs" { |
3 template "widget[@type='DropDown']", mode="widget_defs" { |
4 param "hmi_element"; |
4 param "hmi_element"; |
5 labels("text box"); |
5 labels("text box button"); |
6 || |
6 || |
7 dispatch: function(value) { |
7 dispatch: function(value) { |
8 if(!this.opened) this.set_selection(value); |
8 if(!this.opened) this.set_selection(value); |
9 }, |
9 }, |
10 init: function() { |
10 init: function() { |
11 this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click()"); |
11 this.button_elt.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_button_click()"); |
12 this.text_bbox = this.text_elt.getBBox() |
12 this.text_bbox = this.text_elt.getBBox() |
13 this.box_bbox = this.box_elt.getBBox() |
13 this.box_bbox = this.box_elt.getBBox() |
14 lmargin = this.text_bbox.x - this.box_bbox.x; |
14 lmargin = this.text_bbox.x - this.box_bbox.x; |
15 tmargin = this.text_bbox.y - this.box_bbox.y; |
15 tmargin = this.text_bbox.y - this.box_bbox.y; |
16 rmargin = this.box_bbox.width - this.text_bbox.width - lmargin; |
16 this.margins = [lmargin, tmargin].map(x => Math.max(x,0)); |
17 bmargin = this.box_bbox.height - this.text_bbox.height - tmargin; |
|
18 this.margins = [lmargin, tmargin, rmargin, bmargin].map(x => Math.max(x,0)); |
|
19 this.content = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", |
17 this.content = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", |
20 "eleven", "twelve", "thirteen", "fourteen", "fifteen"]; |
18 "eleven", "twelve", "thirteen", "fourteen", "fifteen"]; |
21 //this.content = ["one", "two", "three", "four", "5", "6"]; |
19 //this.content = ["one", "two", "three", "four", "5", "6"]; |
22 this.menu_offset = 0; |
20 this.menu_offset = 0; |
23 this.lift = 0; |
21 this.lift = 0; |
24 this.opened = false; |
22 this.opened = false; |
25 }, |
23 }, |
26 on_selection_click: function(selection) { |
24 on_selection_click: function(selection) { |
|
25 console.log("selected "+selection); |
|
26 this.close(); |
27 this.set_selection(selection); |
27 this.set_selection(selection); |
28 }, |
28 }, |
29 on_click: function() { |
29 on_button_click: function() { |
30 if(this.opened){ |
30 this.open(); |
31 //this.close(); |
|
32 }else{ |
|
33 this.open(); |
|
34 } |
|
35 }, |
31 }, |
36 on_backward_click:function(){ |
32 on_backward_click:function(){ |
37 this.move(false); |
33 this.move(false); |
38 }, |
34 }, |
39 on_forward_click:function(){ |
35 on_forward_click:function(){ |
159 b.y.baseVal.value = m.y; |
157 b.y.baseVal.value = m.y; |
160 b.width.baseVal.value = m.width; |
158 b.width.baseVal.value = m.width; |
161 b.height.baseVal.value = m.height; |
159 b.height.baseVal.value = m.height; |
162 }, |
160 }, |
163 adjust_box_to_text: function(){ |
161 adjust_box_to_text: function(){ |
164 let [lmargin, tmargin, rmargin, bmargin] = this.margins; |
162 let [lmargin, tmargin] = this.margins; |
165 let m = this.text_elt.getBBox(); |
163 let m = this.text_elt.getBBox(); |
166 let b = this.box_elt; |
164 let b = this.box_elt; |
167 b.x.baseVal.value = m.x - lmargin; |
165 b.x.baseVal.value = m.x - lmargin; |
168 b.y.baseVal.value = m.y - tmargin; |
166 b.y.baseVal.value = m.y - tmargin; |
169 b.width.baseVal.value = lmargin + m.width + rmargin; |
167 b.width.baseVal.value = 2 * lmargin + m.width; |
170 b.height.baseVal.value = tmargin + m.height + bmargin; |
168 b.height.baseVal.value = 2 * tmargin + m.height; |
171 }, |
169 }, |
172 || |
170 || |
173 } |
171 } |
174 |
172 |
175 // | let p = new DOMPoint(this.box_elt.x.baseVal.value, this.box_elt.y.baseVal.value); |
173 // | let p = new DOMPoint(this.box_elt.x.baseVal.value, this.box_elt.y.baseVal.value); |