diff -r 407a0205405a -r 0a9f6f29b7dd svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Wed Aug 12 13:36:18 2020 +0200 +++ b/svghmi/gen_index_xhtml.xslt Wed Aug 12 15:24:02 2020 +0200 @@ -850,7 +850,7 @@ " - + " , @@ -959,6 +959,34 @@ + const local_defaults = { + + + + + VarInit + + must have only one variable given. + + + + + VarInit + + only applies to HMI variable. + + + + : + + + , + + + + + }; + var cache = hmitree_types.map(_ignored => undefined); @@ -975,20 +1003,12 @@ hmi_locals[pagename] = {[varname]:new_index} - console.log("pagelocalindex insert",varname, pagename, new_index); - } else { - - - console.log("pagevars",pagevars); - let result = pagevars[varname]; if(result != undefined) { - console.log("pagelocalindex reuse",varname, pagename, result); - return result; } @@ -999,12 +1019,8 @@ pagevars[varname] = new_index; - console.log("pagelocalindex addwidget",varname, pagename, new_index); - } - cache[new_index] = ""; - return new_index; } @@ -1030,6 +1046,10 @@ + var pending_widget_animates = []; + + + class Widget { offset = 0; @@ -1038,6 +1058,10 @@ unsubscribable = false; + pending_animate = false; + + + constructor(elt_id,args,indexes,members){ this.element_id = elt_id; @@ -1108,11 +1132,11 @@ apply_cache() { - if(!this.unsubscribable) for(let i = 0; i < this.indexes.length; i++) { + if(!this.unsubscribable) for(let index of this.indexes){ /* dispatch current cache in newly opened page widgets */ - let realindex = this.get_variable_index(i); + let realindex = this.get_variable_index(index); let cached_val = cache[realindex]; @@ -1166,7 +1190,7 @@ new_hmi_value(index, value, oldval) { - /* try {*/ + try { // TODO avoid searching, store index at sub() @@ -1206,11 +1230,39 @@ } - /* } catch(err) { + } catch(err) { console.log(err); - }*/ + } + + } + + + + _animate(){ + + this.animate(); + + this.pending_animate = false; + + } + + + + request_animate(){ + + if(!this.pending_animate){ + + pending_widget_animates.push(this); + + this.pending_animate = true; + + requestHMIAnimation(); + + } + + } @@ -1246,8 +1298,8 @@ } - - + + @@ -1260,7 +1312,7 @@ var hmi_widgets = { - + } @@ -1343,11 +1395,9 @@ - - - - + + @@ -1380,6 +1430,78 @@ } + + class ButtonWidget extends Widget{ + + frequency = 5; + + state = 0; + + active_style = undefined; + + inactive_style = undefined; + + + + on_mouse_down(evt) { + + if (this.active_style && this.inactive_style) { + + this.active_elt.setAttribute("style", this.active_style); + + this.inactive_elt.setAttribute("style", "display:none"); + + } + + this.apply_hmi_value(0, 1); + + } + + + + on_mouse_up(evt) { + + if (this.active_style && this.inactive_style) { + + this.active_elt.setAttribute("style", "display:none"); + + this.inactive_elt.setAttribute("style", this.inactive_style); + + } + + this.apply_hmi_value(0, 0); + + } + + + + init() { + + this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined; + + this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined; + + + + if (this.active_style && this.inactive_style) { + + this.active_elt.setAttribute("style", "display:none"); + + this.inactive_elt.setAttribute("style", this.inactive_style); + + } + + + + this.element.setAttribute("onmousedown", "hmi_widgets["+this.element_id+"].on_mouse_down(evt)"); + + this.element.setAttribute("onmouseup", "hmi_widgets["+this.element_id+"].on_mouse_up(evt)"); + + } + + } + + @@ -1389,63 +1511,7 @@ - frequency: 5, - - on_mouse_down: function(evt) { - - if (this.active_style && this.inactive_style) { - - this.active_elt.setAttribute("style", this.active_style); - - this.inactive_elt.setAttribute("style", "display:none"); - - } - - this.apply_hmi_value(0, 1); - - }, - - on_mouse_up: function(evt) { - - if (this.active_style && this.inactive_style) { - - this.active_elt.setAttribute("style", "display:none"); - - this.inactive_elt.setAttribute("style", this.inactive_style); - - } - - this.apply_hmi_value(0, 0); - - }, - - active_style: undefined, - - inactive_style: undefined, - - init: function() { - - this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined; - - this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined; - - if (this.active_style && this.inactive_style) { - - this.active_elt.setAttribute("style", "display:none"); - - this.inactive_elt.setAttribute("style", this.inactive_style); - - } - - this.element.setAttribute("onmousedown", "hmi_widgets[' - - '].on_mouse_down(evt)"); - - this.element.setAttribute("onmouseup", "hmi_widgets[' - - '].on_mouse_up(evt)"); - - }, + @@ -1544,6 +1610,320 @@ }, + + class CircularSliderWidget extends Widget{ + + frequency = 5; + + range = undefined; + + circle = undefined; + + handle_pos = undefined; + + drag = false; + + enTimer = false; + + + + dispatch(value) { + + if(!this.drag){ + + if(this.value_elt) + + this.value_elt.textContent = String(value); + + + + this.handle_position(value); + + } + + } + + + + handle_position(value){ + + let [min,max,totalDistance] = this.range; + + let length = Math.max(0,Math.min((totalDistance),(Number(value)-min)/(max-min)*(totalDistance))); + + let tip = this.range_elt.getPointAtLength(length); + + this.handle_elt.setAttribute('transform',"translate("+(tip.x-this.handle_pos.x)+","+(tip.y-this.handle_pos.y)+")"); + + } + + + + on_release(evt) { + + if(this.drag){ + + this.drag = false; + + } + + } + + + + update_position(evt){ + + if(this.drag && this.enTimer){ + + var svg_dist = 0; + + + + //calculate center of widget in html + + // --TODO maybe it would be better to bind this part to window change size event ??? + + let [xdest,ydest,svgWidth,svgHeight] = page_desc[current_visible_page].bbox; + + let [cX, cY,fiStart,fiEnd,minMax,x1,y1,width,height] = this.circle; + + let htmlCirc = this.range_elt.getBoundingClientRect(); + + let cxHtml = ((htmlCirc.right-htmlCirc.left)/(width)*(cX-x1))+htmlCirc.left; + + let cyHtml = ((htmlCirc.bottom-htmlCirc.top)/(height)*(cY-y1))+htmlCirc.top; + + + + + + //get mouse coordinates + + let mouseX = undefined; + + let mouseY = undefined; + + if (evt.type.startsWith("touch")){ + + mouseX = Math.ceil(evt.touches[0].clientX); + + mouseY = Math.ceil(evt.touches[0].clientY); + + } + + else{ + + mouseX = evt.pageX; + + mouseY = evt.pageY; + + } + + + + //calculate angle + + let fi = Math.atan2(cyHtml-mouseY, mouseX-cxHtml); + + + + // transform from 0 to 2PI + + if (fi > 0){ + + fi = 2*Math.PI-fi; + + } + + else{ + + fi = -fi; + + } + + + + //offset it to 0 + + fi = fi - fiStart; + + if (fi < 0){ + + fi = fi + 2*Math.PI; + + } + + + + //get handle distance from mouse position + + if(fi<fiEnd){ + + svg_dist=(fi)/(fiEnd)*(this.range[1]-this.range[0]); + + } + + else if(fiEnd<fi && fi<fiEnd+minMax){ + + svg_dist = this.range[1]; + + } + + else{ + + svg_dist = this.range[0]; + + } + + + + //redraw handle --TODO is it fast enough if I just call change_hmi_value??? + + this.handle_position(svg_dist); + + if(this.value_elt) + + this.value_elt.textContent = String(Math.ceil(svg_dist)); + + this.apply_hmi_value(0, Math.ceil(svg_dist)); + + + + //reset timer + + this.enTimer = false; + + setTimeout("{hmi_widgets['"+this.element_id+"'].enTimer = true;}", 100); + + } + + + + } + + + + on_select(evt){ + + this.drag = true; + + this.enTimer = true; + + this.update_position(evt); + + } + + + + init() { + + //get min max + + let min = this.min_elt ? + + Number(this.min_elt.textContent) : + + this.args.length >= 1 ? this.args[0] : 0; + + let max = this.max_elt ? + + Number(this.max_elt.textContent) : + + this.args.length >= 2 ? this.args[1] : 100; + + + + //fiStart ==> offset + + let fiStart = Number(this.range_elt.getAttribute('sodipodi:start')); + + let fiEnd = Number(this.range_elt.getAttribute('sodipodi:end')); + + fiEnd = fiEnd - fiStart; + + + + //fiEnd ==> size of angle + + if (fiEnd < 0){ + + fiEnd = 2*Math.PI + fiEnd; + + } + + + + //min max barrier angle + + let minMax = (2*Math.PI - fiEnd)/2; + + + + //get parameters from svg + + let cX = Number(this.range_elt.getAttribute('sodipodi:cx')); + + let cY = Number(this.range_elt.getAttribute('sodipodi:cy')); + + this.range_elt.style.strokeMiterlimit="0"; //eliminates some weird border around html object + + this.range = [min, max,this.range_elt.getTotalLength()]; + + let cPos = this.range_elt.getBBox(); + + this.handle_pos = this.range_elt.getPointAtLength(0); + + this.circle = [cX, cY,fiStart,fiEnd,minMax,cPos.x,cPos.y,cPos.width,cPos.height]; + + + + //init events + + this.handle_elt.addEventListener("touchstart", hmi_widgets[this.element_id].on_select.bind(this)); + + this.handle_elt.addEventListener("mousedown", hmi_widgets[this.element_id].on_select.bind(this)); + + this.element.addEventListener("mousedown", hmi_widgets[this.element_id].on_select.bind(this)); + + + + window.addEventListener("touchmove", hmi_widgets[this.element_id].update_position.bind(this)); + + window.addEventListener("mousemove", hmi_widgets[this.element_id].update_position.bind(this)); + + + + window.addEventListener("mouseup", hmi_widgets[this.element_id].on_release.bind(this)) + + window.addEventListener("touchend", hmi_widgets[this.element_id].on_release.bind(this)); + + window.addEventListener("touchcancel", hmi_widgets[this.element_id].on_release.bind(this)); + + + + } + + } + + + + + + + + handle range + + + + + + value min max + + + + + + class DisplayWidget extends Widget{ @@ -2833,6 +3213,13 @@ + + + + key_pos + + + @@ -2891,11 +3278,13 @@ on_edit_click: function(opstr) { + var size = (typeof this.key_pos_elt !== 'undefined') ? this.key_pos_elt.getBBox() : undefined + edit_value(" ", " - ", this, this.last_val); + ", this, this.last_val,size); }, @@ -3310,6 +3699,298 @@ + + class KeypadWidget extends Widget{ + + moving = undefined; + + enTimer = undefined; + + offset = undefined; + + + + on_position_click(evt) { + + this.moving = true; + + this.enTimer = true; + + + + // get click position offset from widget x,y and save it to variable + + var keypad_borders = this.position_elt.getBoundingClientRect(); + + var clickX = undefined; + + var clickY = undefined; + + if (evt.type == "touchstart"){ + + clickX = Math.ceil(evt.touches[0].clientX); + + clickY = Math.ceil(evt.touches[0].clientY); + + } + + else{ + + clickX = evt.pageX; + + clickY = evt.pageY; + + } + + this.offset=[clickX-keypad_borders.left,clickY-keypad_borders.top] + + } + + + + off_position_click(evt) { + + if(this.moving) + + this.moving = false; + + } + + + + on_move(evt) { + + if(this.moving && this.enTimer){ + + //get keyboard pos in html + + let [eltid, tmpgrp] = current_modal; + + let [xcoord,ycoord] = this.coordinates; + + let [xdest,ydest,svgWidth,svgHeight] = page_desc[current_visible_page].bbox; + + + + //get mouse coordinates + + var clickX = undefined; + + var clickY = undefined; + + if (evt.type == "touchmove"){ + + clickX = Math.ceil(evt.touches[0].clientX); + + clickY = Math.ceil(evt.touches[0].clientY); + + } + + else{ + + clickX = evt.pageX; + + clickY = evt.pageY; + + } + + + + //translate keyboard position + + let mouseX = ((clickX-this.offset[0])/window.innerWidth)*svgWidth; + + let mouseY = ((clickY-this.offset[1])/window.innerHeight)*svgHeight; + + tmpgrp.setAttribute("transform","translate("+String(xdest-xcoord+mouseX)+","+String(ydest-ycoord+mouseY)+")"); + + + + //reset timer + + this.enTimer = false; + + setTimeout("{hmi_widgets['"+this.element_id+"'].enTimer = true;}", 100); + + } + + + + } + + + + on_key_click(symbols) { + + var syms = symbols.split(" "); + + this.shift |= this.caps; + + this.editstr += syms[this.shift?syms.length-1:0]; + + this.shift = false; + + this.update(); + + } + + + + on_Esc_click() { + + end_modal.call(this); + + } + + + + on_Enter_click() { + + end_modal.call(this); + + let callback_obj = this.result_callback_obj; + + callback_obj.edit_callback(this.editstr); + + } + + + + on_BackSpace_click() { + + this.editstr = this.editstr.slice(0,this.editstr.length-1); + + this.update(); + + } + + + + on_Sign_click() { + + if(this.editstr[0] == "-") + + this.editstr = this.editstr.slice(1,this.editstr.length); + + else + + this.editstr = "-" + this.editstr; + + this.update(); + + } + + + + on_NumDot_click() { + + if(this.editstr.indexOf(".") == "-1"){ + + this.editstr += "."; + + this.update(); + + } + + } + + + + on_Space_click() { + + this.editstr += " "; + + this.update(); + + } + + + + caps = false; + + _caps = undefined; + + on_CapsLock_click() { + + this.caps = !this.caps; + + this.update(); + + } + + + + shift = false; + + _shift = undefined; + + on_Shift_click() { + + this.shift = !this.shift; + + this.caps = false; + + this.update(); + + } + + editstr = ""; + + _editstr = undefined; + + result_callback_obj = undefined; + + start_edit(info, valuetype, callback_obj, initial,size) { + + show_modal.call(this,size); + + this.editstr = initial; + + this.result_callback_obj = callback_obj; + + this.Info_elt.textContent = info; + + this.shift = false; + + this.caps = false; + + this.update(); + + } + + + + update() { + + if(this.editstr != this._editstr){ + + this._editstr = this.editstr; + + this.Value_elt.textContent = this.editstr; + + } + + if(this.shift != this._shift){ + + this._shift = this.shift; + + (this.shift?widget_active_activable:widget_inactive_activable)(this.Shift_sub); + + } + + if(this.caps != this._caps){ + + this._caps = this.caps; + + (this.caps?widget_active_activable:widget_inactive_activable)(this.CapsLock_sub); + + } + + } + + } + + @@ -3321,7 +4002,7 @@ - Sign Space NumDot + Sign Space NumDot position @@ -3359,105 +4040,27 @@ _click()"); + if(this.position_elt){ + + this.position_elt.setAttribute("onmousedown", "hmi_widgets['"+this.element_id+"'].on_position_click(evt)"); + + this.position_elt.setAttribute("ontouchstart", "hmi_widgets['"+this.element_id+"'].on_position_click(evt)"); + + window.addEventListener("mouseup", hmi_widgets[this.element_id].off_position_click.bind(this)); + + window.addEventListener("touchend", hmi_widgets[this.element_id].off_position_click.bind(this)); + + window.addEventListener("touchcancel", hmi_widgets[this.element_id].off_position_click.bind(this)); + + window.addEventListener("mousemove", hmi_widgets[this.element_id].on_move.bind(this)); + + window.addEventListener("touchmove", hmi_widgets[this.element_id].on_move.bind(this)); + + } + }, - on_key_click: function(symbols) { - - var syms = symbols.split(" "); - - this.shift |= this.caps; - - this.editstr += syms[this.shift?syms.length-1:0]; - - this.shift = false; - - this.update(); - - }, - - on_Esc_click: function() { - - end_modal.call(this); - - }, - - on_Enter_click: function() { - - end_modal.call(this); - - callback_obj = this.result_callback_obj; - - callback_obj.edit_callback(this.editstr); - - }, - - on_BackSpace_click: function() { - - this.editstr = this.editstr.slice(0,this.editstr.length-1); - - this.update(); - - }, - - on_Sign_click: function() { - - if(this.editstr[0] == "-") - - this.editstr = this.editstr.slice(1,this.editstr.length); - - else - - this.editstr = "-" + this.editstr; - - this.update(); - - }, - - on_NumDot_click: function() { - - if(this.editstr.indexOf(".") == "-1"){ - - this.editstr += "."; - - this.update(); - - } - - }, - - on_Space_click: function() { - - this.editstr += " "; - - this.update(); - - }, - - caps: false, - - _caps: undefined, - - on_CapsLock_click: function() { - - this.caps = !this.caps; - - this.update(); - - }, - - shift: false, - - _shift: undefined, - - on_Shift_click: function() { - - this.shift = !this.shift; - - this.caps = false; - - this.update(); - - }, + coordinates: [ @@ -3466,58 +4069,6 @@ ], - editstr: "", - - _editstr: undefined, - - result_callback_obj: undefined, - - start_edit: function(info, valuetype, callback_obj, initial) { - - show_modal.call(this); - - this.editstr = initial; - - this.result_callback_obj = callback_obj; - - this.Info_elt.textContent = info; - - this.shift = false; - - this.caps = false; - - this.update(); - - }, - - update: function() { - - if(this.editstr != this._editstr){ - - this._editstr = this.editstr; - - this.Value_elt.textContent = this.editstr; - - } - - if(this.shift != this._shift){ - - this._shift = this.shift; - - (this.shift?widget_active_activable:widget_inactive_activable)(this.Shift_sub); - - } - - if(this.caps != this._caps){ - - this._caps = this.caps; - - (this.caps?widget_active_activable:widget_inactive_activable)(this.CapsLock_sub); - - } - - }, - @@ -3592,16 +4143,20 @@ }, - - class SwitchWidget extends Widget{ + + class MultiStateWidget extends Widget{ frequency = 5; + state = 0; + dispatch(value) { + this.state = value; + for(let choice of this.choices){ - if(value != choice.value){ + if(this.state != choice.value){ choice.elt.setAttribute("style", "display:none"); @@ -3615,10 +4170,62 @@ } + + + on_click(evt) { + + //get current selected value + + let next_ind; + + for(next_ind=0; next_ind<this.choices.length; next_ind++){ + + if(this.state == this.choices[next_ind].value){ + + next_ind = next_ind + 1; + + break; + + } + + } + + + + //get next selected value + + if(this.choices.length > next_ind){ + + this.state = this.choices[next_ind].value; + + } + + else{ + + this.state = this.choices[0].value; + + } + + + + //post value to plc + + this.apply_hmi_value(0, this.state); + + } + + + + init() { + + this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)"); + + } + } - + choices: [ @@ -3649,6 +4256,457 @@ ], + + class SliderWidget extends Widget{ + + frequency = 5; + + range = undefined; + + fi = undefined; + + drag = false; + + enTimer = false; + + + + dispatch(value) { + + if(this.value_elt) + + this.value_elt.textContent = String(value); + + + + this.update_DOM(value, this.handle_elt); + + + + } + + + + last_drag = false; + + + + update_DOM(value, elt){ + + let [min,max,start,totallength] = this.range; + + let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min))); + + let tip = this.range_elt.getPointAtLength(length); + + elt.setAttribute('transform',"translate("+(tip.x-start.x)+","+(tip.y-start.y)+")"); + + + + if(this.setpoint_elt != undefined){ + + if(this.last_drag!= this.drag){ + + if(this.drag){ + + this.setpoint_elt.setAttribute("style", this.setpoint_style); + + }else{ + + this.setpoint_elt.setAttribute("style", "display:none"); + + } + + this.last_drag = this.drag; + + } + + } + + } + + + + on_release(evt) { + + window.removeEventListener("touchmove", this.on_bound_drag, true); + + window.removeEventListener("mousemove", this.on_bound_drag, true); + + + + window.removeEventListener("mouseup", this.bound_on_release, true) + + window.removeEventListener("touchend", this.bound_on_release, true); + + window.removeEventListener("touchcancel", this.bound_on_release, true); + + if(this.drag){ + + this.drag = false; + + } + + this.update_position(evt); + + } + + + + + + on_drag(evt){ + + if(this.enTimer && this.drag){ + + this.update_position(evt); + + //reset timer + + this.enTimer = false; + + setTimeout("{hmi_widgets['"+this.element_id+"'].enTimer = true;}", 100); + + } + + } + + + + update_position(evt){ + + var html_dist = 0; + + + + //calculate size of widget in html + + var range_borders = this.range_elt.getBoundingClientRect(); + + var range_length = Math.sqrt( range_borders.height*range_borders.height + range_borders.width*range_borders.width ); + + var [minX,minY,maxX,maxY] = [range_borders.left,range_borders.bottom,range_borders.right,range_borders.top]; + + + + //get range and mouse coordinates + + var mouseX = undefined; + + var mouseY = undefined; + + if (evt.type.startsWith("touch")){ + + mouseX = Math.ceil(evt.touches[0].clientX); + + mouseY = Math.ceil(evt.touches[0].clientY); + + } + + else{ + + mouseX = evt.pageX; + + mouseY = evt.pageY; + + } + + + + //get handle distance from mouse position + + if (minX > mouseX && minY < mouseY){ + + html_dist = 0; + + } + + else if (maxX < mouseX && maxY > mouseY){ + + html_dist = range_length; + + } + + else{ + + // calculate distace + + if(this.fi > 0.7){ + + html_dist = (minY - mouseY)/Math.sin(this.fi); + + } + + else{ + + html_dist = (mouseX - minX)/Math.cos(this.fi); + + } + + + + //check if in range + + if (html_dist > range_length){ + + html_dist = range_length; + + } + + else if (html_dist < 0){ + + html_dist = 0; + + } + + + + } + + + + this.svg_dist=Math.ceil((html_dist/range_length)*this.range[1]); + + + + this.apply_hmi_value(0, this.svg_dist); + + + + // update ghost cursor + + if(this.setpoint_elt != undefined){ + + this.request_animate(); + + } + + } + + + + animate(){ + + this.update_DOM(this.svg_dist, this.setpoint_elt); + + } + + + + on_select(evt){ + + this.drag = true; + + this.enTimer = true; + + window.addEventListener("touchmove", this.on_bound_drag, true); + + window.addEventListener("mousemove", this.on_bound_drag, true); + + + + window.addEventListener("mouseup", this.bound_on_release, true) + + window.addEventListener("touchend", this.bound_on_release, true); + + window.addEventListener("touchcancel", this.bound_on_release, true); + + this.update_position(evt); + + } + + + + init() { + + let min = this.min_elt ? + + Number(this.min_elt.textContent) : + + this.args.length >= 1 ? this.args[0] : 0; + + let max = this.max_elt ? + + Number(this.max_elt.textContent) : + + this.args.length >= 2 ? this.args[1] : 100; + + + + this.range = [min, max, this.range_elt.getPointAtLength(0),this.range_elt.getTotalLength()]; + + let start = this.range_elt.getPointAtLength(0); + + let end = this.range_elt.getPointAtLength(this.range_elt.getTotalLength()); + + this.fi = Math.atan2(start.y-end.y, end.x-start.x); + + + + this.bound_on_select = this.on_select.bind(this); + + this.bound_on_release = this.on_release.bind(this); + + this.on_bound_drag = this.on_drag.bind(this); + + + + this.element.addEventListener("mousedown", this.bound_on_select); + + this.element.addEventListener("touchstart", this.bound_on_select); + + + + if(this.setpoint_elt != undefined){ + + this.setpoint_style = this.setpoint_elt.getAttribute("style"); + + this.setpoint_elt.setAttribute("style", "display:none"); + + } + + + + } + + } + + + + + + + + handle range + + + + + + value min max setpoint + + + + + + + + class SwitchWidget extends Widget{ + + frequency = 5; + + dispatch(value) { + + for(let choice of this.choices){ + + if(value != choice.value){ + + choice.elt.setAttribute("style", "display:none"); + + } else { + + choice.elt.setAttribute("style", choice.style); + + } + + } + + } + + } + + + + + choices: [ + + + + + { + + elt:id(" + + "), + + style:" + + ", + + value: + + + + } + + , + + + + + ], + + + + class ToggleButtonWidget extends Widget{ + + frequency = 5; + + state = 0; + + active_style = undefined; + + inactive_style = undefined; + + + + dispatch(value) { + + this.state = value; + + if (this.state) { + + this.active_elt.setAttribute("style", this.active_style); + + this.inactive_elt.setAttribute("style", "display:none"); + + this.state = 0; + + } else { + + this.inactive_elt.setAttribute("style", this.inactive_style); + + this.active_elt.setAttribute("style", "display:none"); + + this.state = 1; + + } + + } + + + + on_click(evt) { + + this.apply_hmi_value(0, this.state); + + } + + + + init() { + + this.active_style = this.active_elt.style.cssText; + + this.inactive_style = this.inactive_elt.style.cssText; + + this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)"); + + } + + } + + @@ -3657,55 +4715,7 @@ active inactive - frequency: 5, - - state: 0, - - dispatch: function(value) { - - this.state = value; - - if (this.state) { - - this.active_elt.setAttribute("style", this.active_style); - - this.inactive_elt.setAttribute("style", "display:none"); - - this.state = 0; - - } else { - - this.inactive_elt.setAttribute("style", this.inactive_style); - - this.active_elt.setAttribute("style", "display:none"); - - this.state = 1; - - } - - }, - - on_click: function(evt) { - - this.apply_hmi_value(0, this.state); - - }, - - active_style: undefined, - - inactive_style: undefined, - - init: function() { - - this.active_style = this.active_elt.style.cssText; - - this.inactive_style = this.inactive_elt.style.cssText; - - this.element.setAttribute("onclick", "hmi_widgets[' - - '].on_click(evt)"); - - }, + @@ -3866,8 +4876,6 @@ // -> pass Number(index) instead - console.log("apply updated local variable ",index, updates[index]); - dispatch_value(Number(index), updates[index]); delete updates[index]; @@ -3908,6 +4916,14 @@ apply_updates(); + + + pending_widget_animates.forEach(widget => widget._animate()); + + pending_widget_animates = []; + + + requestAnimationFrameID = null; } @@ -4576,7 +5592,7 @@ var edit_callback; - function edit_value(path, valuetype, callback, initial) { + function edit_value(path, valuetype, callback, initial, size) { @@ -4588,7 +5604,7 @@ let widget = hmi_widgets[keypadid]; - widget.start_edit(path, valuetype, callback, initial); + widget.start_edit(path, valuetype, callback, initial, size); }; @@ -4598,7 +5614,7 @@ - function show_modal() { + function show_modal(size) { let [element, parent] = detachable_elements[this.element.id]; @@ -4608,13 +5624,23 @@ tmpgrpattr = document.createAttribute("transform"); - - let [xcoord,ycoord] = this.coordinates; let [xdest,ydest] = page_desc[current_visible_page].bbox; - tmpgrpattr.value = "translate("+String(xdest-xcoord)+","+String(ydest-ycoord)+")"; + if (typeof size === 'undefined'){ + + tmpgrpattr.value = "translate("+String(xdest-xcoord)+","+String(ydest-ycoord)+")"; + + } + + else{ + + tmpgrpattr.value = "translate("+String(xdest-xcoord+size.x)+","+String(ydest-ycoord+size.y)+")"; + + } + + tmpgrp.setAttributeNode(tmpgrpattr);