# HG changeset patch # User Edouard Tisserant # Date 1589401333 -7200 # Node ID 02ea529fd08c9f7b32e6d3eeaa80b099f07d9ef5 # Parent 00825316ed00f30871166e8fc9516dd1099a91d5 SVGHMI: Switch widget now use class declaration diff -r 00825316ed00 -r 02ea529fd08c svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Wed May 13 18:50:07 2020 +0200 +++ b/svghmi/gen_index_xhtml.xslt Wed May 13 22:22:13 2020 +0200 @@ -866,6 +866,10 @@ class Widget { + offset = 0; + + frequency = 10; /* FIXME arbitrary default max freq. Obtain from config ? */ + constructor(elt_id,args,indexes,members){ this.element_id = elt_id; @@ -876,8 +880,6 @@ this.indexes = indexes; - this.offset = 0; - Object.keys(members).forEach(prop => this[prop]=members[prop]); } @@ -1115,6 +1117,10 @@ init() { + // TODO : use attributes to allow interaction through svg:use + + // TODO : deal with dragging + this.element.addEventListener( "mousedown", @@ -2592,34 +2598,34 @@ }, + + 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); + + } + + } + + } + + } + + - frequency: 5, - - dispatch: function(value) { - - for(let choice of this.choices){ - - if(value != choice.value){ - - choice.elt.setAttribute("style", "display:none"); - - } else { - - choice.elt.setAttribute("style", choice.style); - - } - - } - - }, - - init: function() { - - // Hello Switch - - }, - choices: [ diff -r 00825316ed00 -r 02ea529fd08c svghmi/widget_switch.ysl2 --- a/svghmi/widget_switch.ysl2 Wed May 13 18:50:07 2020 +0200 +++ b/svghmi/widget_switch.ysl2 Wed May 13 22:22:13 2020 +0200 @@ -1,20 +1,23 @@ // widget_switch.ysl2 +template "widget[@type='Switch']", mode="widget_class" + || + 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); + } + } + } + } + || + template "widget[@type='Switch']", mode="widget_defs" { param "hmi_element"; - | frequency: 5, - | dispatch: function(value) { - | for(let choice of this.choices){ - | if(value != choice.value){ - | choice.elt.setAttribute("style", "display:none"); - | } else { - | choice.elt.setAttribute("style", choice.style); - | } - | } - | }, - | init: function() { - | // Hello Switch - | }, | choices: [ const "regex",!"'^(\"[^\"].*\"|\-?[0-9]+|false|true)(#.*)?$'"!; foreach "$hmi_element/*[regexp:test(@inkscape:label,$regex)]" { diff -r 00825316ed00 -r 02ea529fd08c tests/svghmi/svghmi_0@svghmi/svghmi.svg --- a/tests/svghmi/svghmi_0@svghmi/svghmi.svg Wed May 13 18:50:07 2020 +0200 +++ b/tests/svghmi/svghmi_0@svghmi/svghmi.svg Wed May 13 22:22:13 2020 +0200 @@ -31,6 +31,20 @@ + + up + + + + + + + + + + + + + + + + + +