template "widget[@type='DropDown']", mode="widget_defs" {
dispatch: function(value) {
let span = this.text_elt.firstElementChild;
span.textContent = (value >= 0 && value < this.content.length) ?
this.content[value] : String(value);
this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click()");
this.text_bbox = this.text_elt.getBBox()
this.box_bbox = this.box_elt.getBBox()
lmargin = this.text_bbox.x - this.box_bbox.x;
tmargin = this.text_bbox.y - this.box_bbox.y;
rmargin = this.box_bbox.width - this.text_bbox.width - lmargin;
bmargin = this.box_bbox.height - this.text_bbox.height - tmargin;
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"];
try_grow_one: function() {
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 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];
if(this.offset + slots - elipses.length < l)
elipses.push(spans.length-1);
if(elipses.indexOf(c) != -1)
spans[c].textContent = "...";
spans[c].textContent = this.content[this.offset + i];
for(let span of Array.from(txt.children).slice(1)){
adjust_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;
// | let p = new DOMPoint(this.box_elt.x.baseVal.value, this.box_elt.y.baseVal.value);
// | let k = DOMMatrix.fromMatrix(this.box_elt.getCTM());
// | let new_corner = k.transformPoint(p);
// | let nc = k.inverse().transformPoint(new_corner);
// | this.box_elt.x.baseVal.value = nc.x;
// | this.box_elt.y.baseVal.value = nc.y;