--- a/svghmi/gen_index_xhtml.xslt Sun Apr 12 21:43:42 2020 +0200
+++ b/svghmi/gen_index_xhtml.xslt Mon Apr 13 18:28:22 2020 +0200
@@ -827,11 +827,7 @@
<xsl:text> dispatch: function(value) {
- <xsl:text> let span = this.text_elt.firstElementChild;
- <xsl:text> span.textContent = (value >= 0 && value < this.content.length) ?
- <xsl:text> this.content[value] : String(value);
+ <xsl:text> if(!this.opened) this.set_selection(value); @@ -859,19 +855,47 @@
<xsl:text> //this.content = ["one", "two", "three", "four", "5", "6"];
- <xsl:text> this.offset = 0;
+ <xsl:text> this.menu_offset = 0; <xsl:text> this.lift = 0;
+ <xsl:text> this.opened = false; + <xsl:text> on_selection_click: function(selection) { + <xsl:text> this.set_selection(selection); <xsl:text> on_click: function() {
- <xsl:text> this.open();
+ <xsl:text> if(this.opened){ + <xsl:text> this.close(); + <xsl:text> this.open(); - <xsl:text> try_grow_one: function() {
+ <xsl:text> set_selection: function(value) { + <xsl:text> this.text_elt.firstElementChild.textContent = + <xsl:text> (value >= 0 && value < this.content.length) ? + <xsl:text> this.content[value] : "?"+String(value)+"?"; + <xsl:text> grow_text: function(up_to) { + <xsl:text> let count = 1; <xsl:text> let txt = this.text_elt;
@@ -879,134 +903,172 @@
<xsl:text> let bounds = svg_root.getBoundingClientRect();
- <xsl:text> let next = first.cloneNode();
- <xsl:text> //next.removeAttribute("x");
- <xsl:text> next.removeAttribute("y");
- <xsl:text> next.setAttribute("dy", "1.1em");
- <xsl:text> next.textContent = "...";
- <xsl:text> txt.appendChild(next);
- <xsl:text> let rect = txt.getBoundingClientRect();
- <xsl:text> console.log("bounds", bounds);
- <xsl:text> console.log("rect", rect);
- <xsl:text> if(rect.bottom > bounds.bottom){
- <xsl:text> let backup = first.getAttribute("dy");
- <xsl:text> first.setAttribute("dy", "-"+String((this.lift+1)*1.1)+"em");
- <xsl:text> rect = txt.getBoundingClientRect();
- <xsl:text> if(rect.top > bounds.top){
- <xsl:text> console.log("rect2ok", rect);
- <xsl:text> this.lift += 1;
- <xsl:text> console.log("rect2Nok", rect);
- <xsl:text> first.setAttribute("dy", backup);
- <xsl:text> first.removeAttribute("dy");
- <xsl:text> txt.removeChild(next);
- <xsl:text> return false;
+ <xsl:text> this.lift = 0; + <xsl:text> while(count < up_to) { + <xsl:text> let next = first.cloneNode(); + <xsl:text> next.removeAttribute("y"); + <xsl:text> next.setAttribute("dy", "1.1em"); + <xsl:text> next.textContent = "..."; + <xsl:text> txt.appendChild(next); + <xsl:text> let rect = txt.getBoundingClientRect(); + <xsl:text> if(rect.bottom > bounds.bottom){ + <xsl:text> let backup = first.getAttribute("dy"); + <xsl:text> first.setAttribute("dy", "-"+String((this.lift+1)*1.1)+"em"); + <xsl:text> rect = txt.getBoundingClientRect(); + <xsl:text> if(rect.top > bounds.top){ + <xsl:text> this.lift += 1; + <xsl:text> first.setAttribute("dy", backup); + <xsl:text> first.removeAttribute("dy"); + <xsl:text> txt.removeChild(next); + <xsl:text> return count; - <xsl:text> return true;
+ <xsl:text> return count; + <xsl:text> close: function(){ + <xsl:text> this.reset_text(); + <xsl:text> this.reset_box(); + <xsl:text> this.opened = false; + <xsl:text> set_complete_text: function(){ + <xsl:text> let spans = this.text_elt.children; + <xsl:text> for(let item of this.content){ + <xsl:text> let span=spans[c]; + <xsl:text> span.textContent = item; + <xsl:text> span.setAttribute("onclick", "hmi_widgets['</xsl:text> + <xsl:value-of select="$hmi_element/@id"/> + <xsl:text>'].on_selection_click("+c+")"); + <xsl:text> set_partial_text: function(){ + <xsl:text> let spans = this.text_elt.children; + <xsl:text> let length = this.content.length; + <xsl:text> let i = this.menu_offset, c = 0; + <xsl:text> while(c < spans.length){ + <xsl:text> if(c == 0 && i != 0){ + <xsl:text> spans[c].textContent = "..."; + <xsl:text> /* TODO: set onclick */ + <xsl:text> }else if(c == spans.length-1 && i < length - 1) + <xsl:text> spans[c].textContent = "..."; + <xsl:text> /* TODO: set onclick */ + <xsl:text> let span=spans[c]; + <xsl:text> span.textContent = this.content[i]; + <xsl:text> /* TODO: set onclick */ + <xsl:text> span.setAttribute("onclick", "hmi_widgets['</xsl:text> + <xsl:value-of select="$hmi_element/@id"/> + <xsl:text>'].on_selection_click("+i+")"); <xsl:text> open: function(){
- <xsl:text> let l = this.content.length;
- <xsl:text> this.lift = 0;
- <xsl:text> this.purge();
- <xsl:text> while(c < l && this.try_grow_one()) c++;
- <xsl:text> let spans = Array.from(this.text_elt.children);
- <xsl:text> if(c == l) {
- <xsl:text> while(c < l){
- <xsl:text> spans[c].textContent = this.content[c];
+ <xsl:text> let length = this.content.length; + <xsl:text> this.reset_text(); + <xsl:text> let slots = this.grow_text(length); + <xsl:text> if(slots == length) { + <xsl:text> this.set_complete_text(); - <xsl:text> let slots = c;
- <xsl:text> let elipses = [];
- <xsl:text> if(this.offset != 0)
- <xsl:text> elipses.push(0);
- <xsl:text> if(this.offset + slots - elipses.length < l)
- <xsl:text> elipses.push(spans.length-1);
- <xsl:text> while(c < spans.length){
- <xsl:text> if(elipses.indexOf(c) != -1)
- <xsl:text> spans[c].textContent = "...";
- <xsl:text> spans[c].textContent = this.content[this.offset + i];
+ <xsl:text> this.set_partial_text(); - <xsl:text> this.adjust_to_text();
+ <xsl:text> this.adjust_box_to_text(); + <xsl:text> /* TODO disable interaction with background */ + <xsl:text> this.opened = true; - <xsl:text> purge: function(){
+ <xsl:text> reset_text: function(){ <xsl:text> let txt = this.text_elt;
+ <xsl:text> let first = txt.firstElementChild; + <xsl:text> first.removeAttribute("onclick"); + <xsl:text> first.removeAttribute("dy"); <xsl:text> for(let span of Array.from(txt.children).slice(1)){
<xsl:text> txt.removeChild(span)
@@ -1015,19 +1077,37 @@
- <xsl:text> adjust_to_text: function(){
+ <xsl:text> reset_box: function(){ + <xsl:text> let m = this.box_bbox; + <xsl:text> let b = this.box_elt; + <xsl:text> b.x.baseVal.value = m.x; + <xsl:text> b.y.baseVal.value = m.y; + <xsl:text> b.width.baseVal.value = m.width; + <xsl:text> b.height.baseVal.value = m.height; + <xsl:text> adjust_box_to_text: function(){ <xsl:text> let [lmargin, tmargin, rmargin, bmargin] = this.margins;
<xsl:text> let m = this.text_elt.getBBox();
- <xsl:text> this.box_elt.x.baseVal.value = m.x - lmargin;
- <xsl:text> this.box_elt.y.baseVal.value = m.y - tmargin;
- <xsl:text> this.box_elt.width.baseVal.value = lmargin + m.width + rmargin;
- <xsl:text> this.box_elt.height.baseVal.value = tmargin + m.height + bmargin;
+ <xsl:text> let b = this.box_elt; + <xsl:text> b.x.baseVal.value = m.x - lmargin; + <xsl:text> b.y.baseVal.value = m.y - tmargin; + <xsl:text> b.width.baseVal.value = lmargin + m.width + rmargin; + <xsl:text> b.height.baseVal.value = tmargin + m.height + bmargin; --- a/svghmi/widget_dropdown.ysl2 Sun Apr 12 21:43:42 2020 +0200
+++ b/svghmi/widget_dropdown.ysl2 Mon Apr 13 18:28:22 2020 +0200
@@ -5,9 +5,7 @@
dispatch: function(value) {
- let span = this.text_elt.firstElementChild;
- span.textContent = (value >= 0 && value < this.content.length) ?
- this.content[value] : String(value);
+ if(!this.opened) this.set_selection(value); this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click()");
@@ -20,91 +18,131 @@
this.margins = [lmargin, tmargin, rmargin, bmargin].map(x => Math.max(x,0));
this.content = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"];
//this.content = ["one", "two", "three", "four", "5", "6"];
+ on_selection_click: function(selection) { + this.set_selection(selection);
- try_grow_one: function() {
+ set_selection: function(value) { + this.text_elt.firstElementChild.textContent = + (value >= 0 && value < this.content.length) ? + this.content[value] : "?"+String(value)+"?"; + grow_text: function(up_to) { let first = txt.firstElementChild;
let bounds = svg_root.getBoundingClientRect();
- let next = first.cloneNode();
- //next.removeAttribute("x");
- next.removeAttribute("y");
- next.setAttribute("dy", "1.1em");
- next.textContent = "...";
- let rect = txt.getBoundingClientRect();
- console.log("bounds", bounds);
- console.log("rect", rect);
- if(rect.bottom > bounds.bottom){
- let backup = first.getAttribute("dy");
- first.setAttribute("dy", "-"+String((this.lift+1)*1.1)+"em");
- rect = txt.getBoundingClientRect();
- if(rect.top > bounds.top){
- console.log("rect2ok", rect);
- console.log("rect2Nok", rect);
- first.setAttribute("dy", backup);
- first.removeAttribute("dy");
+ let next = first.cloneNode(); + next.removeAttribute("y"); + next.setAttribute("dy", "1.1em"); + next.textContent = "..."; + let rect = txt.getBoundingClientRect(); + if(rect.bottom > bounds.bottom){ + let backup = first.getAttribute("dy"); + first.setAttribute("dy", "-"+String((this.lift+1)*1.1)+"em"); + rect = txt.getBoundingClientRect(); + if(rect.top > bounds.top){ + first.setAttribute("dy", backup); + first.removeAttribute("dy");
+ set_complete_text: function(){ + let spans = this.text_elt.children; + for(let item of this.content){ + span.textContent = item; + span.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_selection_click("+c+")"); + set_partial_text: function(){ + let spans = this.text_elt.children; + let length = this.content.length; + let i = this.menu_offset, c = 0; + while(c < spans.length){ + spans[c].textContent = "..."; + /* TODO: set onclick */ + }else if(c == spans.length-1 && i < length - 1) + spans[c].textContent = "..."; + /* TODO: set onclick */ + span.textContent = this.content[i]; + /* TODO: set onclick */ + span.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_selection_click("+i+")"); - let l = this.content.length;
- while(c < l && this.try_grow_one()) c++;
- let spans = Array.from(this.text_elt.children);
- spans[c].textContent = this.content[c];
+ let length = this.content.length; + let slots = this.grow_text(length); + this.set_complete_text();
- if(this.offset + slots - elipses.length < l)
- elipses.push(spans.length-1);
- while(c < spans.length){
- if(elipses.indexOf(c) != -1)
- spans[c].textContent = "...";
- spans[c].textContent = this.content[this.offset + i];
+ this.set_partial_text();
+ this.adjust_box_to_text(); + /* TODO disable interaction with background */
+ reset_text: function(){ + let first = txt.firstElementChild; + first.removeAttribute("onclick"); + first.removeAttribute("dy"); for(let span of Array.from(txt.children).slice(1)){
- adjust_to_text: function(){
+ b.x.baseVal.value = m.x; + b.y.baseVal.value = m.y; + b.width.baseVal.value = m.width; + b.height.baseVal.value = m.height; + adjust_box_to_text: function(){ let [lmargin, tmargin, rmargin, bmargin] = this.margins;
let m = this.text_elt.getBBox();
- this.box_elt.x.baseVal.value = m.x - lmargin;
- this.box_elt.y.baseVal.value = m.y - tmargin;
- this.box_elt.width.baseVal.value = lmargin + m.width + rmargin;
- this.box_elt.height.baseVal.value = tmargin + m.height + bmargin;
+ b.x.baseVal.value = m.x - lmargin; + b.y.baseVal.value = m.y - tmargin; + b.width.baseVal.value = lmargin + m.width + rmargin; + b.height.baseVal.value = tmargin + m.height + bmargin;