author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Tue, 14 Apr 2020 17:16:25 +0200 | |
branch | svghmi |
changeset 2929 | 9179cbc6fc49 |
parent 2928 | c73d0b042ca8 |
child 2930 | 41edcb8e0a01 |
permissions | -rw-r--r-- |
2922
ddce4ebdf010
SVGHMI: intermediate commit while working on dropdown widget.
Edouard Tisserant
parents:
diff
changeset
|
1 |
// widget_dropdown.ysl2 |
ddce4ebdf010
SVGHMI: intermediate commit while working on dropdown widget.
Edouard Tisserant
parents:
diff
changeset
|
2 |
|
ddce4ebdf010
SVGHMI: intermediate commit while working on dropdown widget.
Edouard Tisserant
parents:
diff
changeset
|
3 |
template "widget[@type='DropDown']", mode="widget_defs" { |
ddce4ebdf010
SVGHMI: intermediate commit while working on dropdown widget.
Edouard Tisserant
parents:
diff
changeset
|
4 |
param "hmi_element"; |
2926
90f9d9782632
SVGHMI: Add button element to HMI:DropDown, also fix problem with computed box margins.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2925
diff
changeset
|
5 |
labels("text box button"); |
2923
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
6 |
|| |
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
7 |
dispatch: function(value) { |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
8 |
if(!this.opened) this.set_selection(value); |
2923
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
9 |
}, |
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
10 |
init: function() { |
2926
90f9d9782632
SVGHMI: Add button element to HMI:DropDown, also fix problem with computed box margins.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2925
diff
changeset
|
11 |
this.button_elt.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_button_click()"); |
2923
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
12 |
this.text_bbox = this.text_elt.getBBox() |
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
13 |
this.box_bbox = this.box_elt.getBBox() |
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
14 |
lmargin = this.text_bbox.x - this.box_bbox.x; |
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
15 |
tmargin = this.text_bbox.y - this.box_bbox.y; |
2926
90f9d9782632
SVGHMI: Add button element to HMI:DropDown, also fix problem with computed box margins.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2925
diff
changeset
|
16 |
this.margins = [lmargin, tmargin].map(x => Math.max(x,0)); |
2925
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
17 |
this.content = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
18 |
"eleven", "twelve", "thirteen", "fourteen", "fifteen"]; |
2923
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
19 |
//this.content = ["one", "two", "three", "four", "5", "6"]; |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
20 |
this.menu_offset = 0; |
2923
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
21 |
this.lift = 0; |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
22 |
this.opened = false; |
2927
23c35f3ba111
SVGHMI: HMI:DropDown now catches all clicks when open
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2926
diff
changeset
|
23 |
this.bound_inhibit_click_elsewhere = this.inhibit_click_elsewhere.bind(this); |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
24 |
}, |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
25 |
on_selection_click: function(selection) { |
2926
90f9d9782632
SVGHMI: Add button element to HMI:DropDown, also fix problem with computed box margins.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2925
diff
changeset
|
26 |
console.log("selected "+selection); |
90f9d9782632
SVGHMI: Add button element to HMI:DropDown, also fix problem with computed box margins.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2925
diff
changeset
|
27 |
this.close(); |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
28 |
this.set_selection(selection); |
2923
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
29 |
}, |
2926
90f9d9782632
SVGHMI: Add button element to HMI:DropDown, also fix problem with computed box margins.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2925
diff
changeset
|
30 |
on_button_click: function() { |
90f9d9782632
SVGHMI: Add button element to HMI:DropDown, also fix problem with computed box margins.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2925
diff
changeset
|
31 |
this.open(); |
2923
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
32 |
}, |
2925
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
33 |
on_backward_click:function(){ |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
34 |
this.move(false); |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
35 |
}, |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
36 |
on_forward_click:function(){ |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
37 |
this.move(true); |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
38 |
}, |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
39 |
set_selection: function(value) { |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
40 |
this.text_elt.firstElementChild.textContent = |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
41 |
(value >= 0 && value < this.content.length) ? |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
42 |
this.content[value] : "?"+String(value)+"?"; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
43 |
}, |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
44 |
grow_text: function(up_to) { |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
45 |
let count = 1; |
2923
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
46 |
let txt = this.text_elt; |
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
47 |
let first = txt.firstElementChild; |
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
48 |
let bounds = svg_root.getBoundingClientRect(); |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
49 |
this.lift = 0; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
50 |
while(count < up_to) { |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
51 |
let next = first.cloneNode(); |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
52 |
next.removeAttribute("y"); |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
53 |
next.setAttribute("dy", "1.1em"); |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
54 |
next.textContent = "..."; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
55 |
txt.appendChild(next); |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
56 |
let rect = txt.getBoundingClientRect(); |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
57 |
if(rect.bottom > bounds.bottom){ |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
58 |
let backup = first.getAttribute("dy"); |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
59 |
first.setAttribute("dy", "-"+String((this.lift+1)*1.1)+"em"); |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
60 |
rect = txt.getBoundingClientRect(); |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
61 |
if(rect.top > bounds.top){ |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
62 |
this.lift += 1; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
63 |
} else { |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
64 |
if(backup) |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
65 |
first.setAttribute("dy", backup); |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
66 |
else |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
67 |
first.removeAttribute("dy"); |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
68 |
txt.removeChild(next); |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
69 |
return count; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
70 |
} |
2923
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
71 |
} |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
72 |
count++; |
2923
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
73 |
} |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
74 |
return count; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
75 |
}, |
2927
23c35f3ba111
SVGHMI: HMI:DropDown now catches all clicks when open
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2926
diff
changeset
|
76 |
inhibit_click_elsewhere: function(e) { |
23c35f3ba111
SVGHMI: HMI:DropDown now catches all clicks when open
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2926
diff
changeset
|
77 |
console.log("inhibit", e); |
23c35f3ba111
SVGHMI: HMI:DropDown now catches all clicks when open
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2926
diff
changeset
|
78 |
console.log(e.target.parentNode, this.text_elt); |
23c35f3ba111
SVGHMI: HMI:DropDown now catches all clicks when open
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2926
diff
changeset
|
79 |
if(e.target.parentNode !== this.text_elt) |
23c35f3ba111
SVGHMI: HMI:DropDown now catches all clicks when open
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2926
diff
changeset
|
80 |
e.stopPropagation(); |
23c35f3ba111
SVGHMI: HMI:DropDown now catches all clicks when open
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2926
diff
changeset
|
81 |
}, |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
82 |
close: function(){ |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
83 |
this.reset_text(); |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
84 |
this.reset_box(); |
2926
90f9d9782632
SVGHMI: Add button element to HMI:DropDown, also fix problem with computed box margins.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2925
diff
changeset
|
85 |
this.element.appendChild(this.button_elt); |
2927
23c35f3ba111
SVGHMI: HMI:DropDown now catches all clicks when open
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2926
diff
changeset
|
86 |
document.removeEventListener("click", this.bound_inhibit_click_elsewhere, true); |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
87 |
this.opened = false; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
88 |
}, |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
89 |
set_complete_text: function(){ |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
90 |
let spans = this.text_elt.children; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
91 |
let c = 0; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
92 |
for(let item of this.content){ |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
93 |
let span=spans[c]; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
94 |
span.textContent = item; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
95 |
span.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_selection_click("+c+")"); |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
96 |
c++; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
97 |
} |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
98 |
}, |
2925
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
99 |
move: function(forward){ |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
100 |
let contentlength = this.content.length; |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
101 |
let spans = this.text_elt.children; |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
102 |
let spanslength = spans.length; |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
103 |
if(this.menu_offset != 0) spanslength--; |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
104 |
if(this.menu_offset < contentlength - 1) spanslength--; |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
105 |
if(forward){ |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
106 |
this.menu_offset = Math.min( |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
107 |
contentlength - spans.length + 1, |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
108 |
this.menu_offset + spanslength); |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
109 |
}else{ |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
110 |
this.menu_offset = Math.max( |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
111 |
0, |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
112 |
this.menu_offset - spanslength); |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
113 |
} |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
114 |
console.log(this.menu_offset); |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
115 |
this.set_partial_text(); |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
116 |
}, |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
117 |
set_partial_text: function(){ |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
118 |
let spans = this.text_elt.children; |
2925
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
119 |
let contentlength = this.content.length; |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
120 |
let spanslength = spans.length; |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
121 |
let i = this.menu_offset, c = 0; |
2925
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
122 |
while(c < spanslength){ |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
123 |
let span=spans[c]; |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
124 |
if(c == 0 && i != 0){ |
2925
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
125 |
span.textContent = "↑ ↑ ↑"; |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
126 |
span.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_backward_click()"); |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
127 |
}else if(c == spanslength-1 && i < contentlength - 1){ |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
128 |
span.textContent = "↓ ↓ ↓"; |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
129 |
span.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_forward_click()"); |
220172cbdcff
SVGHMI: HMI:DropDown now scrolls forward and backward
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2924
diff
changeset
|
130 |
}else{ |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
131 |
span.textContent = this.content[i]; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
132 |
span.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_selection_click("+i+")"); |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
133 |
i++; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
134 |
} |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
135 |
c++; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
136 |
} |
2923
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
137 |
}, |
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
138 |
open: function(){ |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
139 |
let length = this.content.length; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
140 |
this.reset_text(); |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
141 |
let slots = this.grow_text(length); |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
142 |
if(slots == length) { |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
143 |
this.set_complete_text(); |
2923
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
144 |
} else { |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
145 |
this.set_partial_text(); |
2923
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
146 |
} |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
147 |
this.adjust_box_to_text(); |
2926
90f9d9782632
SVGHMI: Add button element to HMI:DropDown, also fix problem with computed box margins.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2925
diff
changeset
|
148 |
this.element.removeChild(this.button_elt); |
2928
c73d0b042ca8
SVGHMI: HMI:DropDown element is brought in front when opened, so that it isn't occulted by other widgets at the same level.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2927
diff
changeset
|
149 |
this.element.parentNode.appendChild(this.element.parentNode.removeChild(this.element)); |
2927
23c35f3ba111
SVGHMI: HMI:DropDown now catches all clicks when open
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2926
diff
changeset
|
150 |
// disable interaction with background |
23c35f3ba111
SVGHMI: HMI:DropDown now catches all clicks when open
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2926
diff
changeset
|
151 |
document.addEventListener("click", this.bound_inhibit_click_elsewhere, true); |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
152 |
this.opened = true; |
2923
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
153 |
}, |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
154 |
reset_text: function(){ |
2923
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
155 |
let txt = this.text_elt; |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
156 |
let first = txt.firstElementChild; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
157 |
first.removeAttribute("onclick"); |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
158 |
first.removeAttribute("dy"); |
2923
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
159 |
for(let span of Array.from(txt.children).slice(1)){ |
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
160 |
txt.removeChild(span) |
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
161 |
} |
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
162 |
}, |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
163 |
reset_box: function(){ |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
164 |
let m = this.box_bbox; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
165 |
let b = this.box_elt; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
166 |
b.x.baseVal.value = m.x; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
167 |
b.y.baseVal.value = m.y; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
168 |
b.width.baseVal.value = m.width; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
169 |
b.height.baseVal.value = m.height; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
170 |
}, |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
171 |
adjust_box_to_text: function(){ |
2926
90f9d9782632
SVGHMI: Add button element to HMI:DropDown, also fix problem with computed box margins.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2925
diff
changeset
|
172 |
let [lmargin, tmargin] = this.margins; |
2923
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
173 |
let m = this.text_elt.getBBox(); |
2924
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
174 |
let b = this.box_elt; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
175 |
b.x.baseVal.value = m.x - lmargin; |
69bb58eb0eac
SVGHMI: progress on HMI:DropDown - now selects some value on click, and close
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2923
diff
changeset
|
176 |
b.y.baseVal.value = m.y - tmargin; |
2926
90f9d9782632
SVGHMI: Add button element to HMI:DropDown, also fix problem with computed box margins.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2925
diff
changeset
|
177 |
b.width.baseVal.value = 2 * lmargin + m.width; |
90f9d9782632
SVGHMI: Add button element to HMI:DropDown, also fix problem with computed box margins.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2925
diff
changeset
|
178 |
b.height.baseVal.value = 2 * tmargin + m.height; |
2923
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
179 |
}, |
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
180 |
|| |
2922
ddce4ebdf010
SVGHMI: intermediate commit while working on dropdown widget.
Edouard Tisserant
parents:
diff
changeset
|
181 |
} |
ddce4ebdf010
SVGHMI: intermediate commit while working on dropdown widget.
Edouard Tisserant
parents:
diff
changeset
|
182 |
|
2923
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
183 |
// | let p = new DOMPoint(this.box_elt.x.baseVal.value, this.box_elt.y.baseVal.value); |
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
184 |
// | let k = DOMMatrix.fromMatrix(this.box_elt.getCTM()); |
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
185 |
// | let new_corner = k.transformPoint(p); |
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
186 |
// | new_corner.y = 0; |
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
187 |
// | let nc = k.inverse().transformPoint(new_corner); |
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
188 |
// | this.box_elt.x.baseVal.value = nc.x; |
5ec1c07ce582
SVGHMI: HMI:DropDown work in progress, intermediate commit. Now menu's rectangle grows up to viewport borders.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2922
diff
changeset
|
189 |
// | this.box_elt.y.baseVal.value = nc.y; |