SVGHMI: add widget_foreach.ysl2 svghmi
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Fri, 20 Mar 2020 10:46:15 +0100
branchsvghmi
changeset 2891 8927ae8326b2
parent 2890 ae8063127e95
child 2892 27dd409fba1d
SVGHMI: add widget_foreach.ysl2
svghmi/widget_foreach.ysl2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/svghmi/widget_foreach.ysl2	Fri Mar 20 10:46:15 2020 +0100
@@ -0,0 +1,28 @@
+
+template "widget[@type='ForEach']", mode="widget_defs" {
+    param "hmi_element";
+    |     frequency: 2,
+    |     dispatch: function(value) {
+    |                     // do something
+    |     },
+    |     init: function() {
+    foreach "$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]" {
+    |         id("«@id»").addEventListener(
+    |             "click", 
+    |             evt => {let new_val = "«func:escape_quotes(@inkscape:label)»");
+    |                     // do something with new_val
+    |                    });
+    }
+    |     },
+}
+
+template "widget[@type='ForEach']", mode="widget_subscribe"{
+    // param "hmi_element";
+    |     sub: function(off){
+    |         subscribe.call(this,off)
+    |     },
+
+    |     unsub: function(){
+    |         unsubscribe.call(this)
+    |     },
+}