SVGHMI: Parameters common to all widget constructors now passed as ordered parameters. svghmi
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Sun, 10 May 2020 16:32:19 +0200
branchsvghmi
changeset 2950 1e53d8b60ee9
parent 2949 e50908ddec60
child 2951 506fe9272660
SVGHMI: Parameters common to all widget constructors now passed as ordered parameters.
svghmi/widgets_common.ysl2
--- a/svghmi/widgets_common.ysl2	Fri May 08 16:51:43 2020 +0200
+++ b/svghmi/widgets_common.ysl2	Sun May 10 16:32:19 2020 +0200
@@ -24,25 +24,19 @@
 template "svg:*", mode="hmi_elements" {
     const "widget", "func:widget(@id)";
     const "eltid","@id";
-    |   "«@id»": new «$widget/@type»Widget ({
-    |     args: [
-    foreach "$widget/arg"
-    |         "«@value»"`if "position()!=last()" > ,`
-    |     ],
-    |     offset: 0,
-    |     indexes: [
-    foreach "$widget/path" {
+    const "args" foreach "$widget/arg" > "«@value»"`if "position()!=last()" > ,`
+    const "indexes" foreach "$widget/path" {
         choose {
             when "not(@index)" {
                 warning > Widget «$widget/@type» id="«$eltid»" : No match for path "«@value»" in HMI tree
             }
             otherwise {
-    |         «@index» /* «@value» */ `if "position()!=last()" > ,`
+                > «@index»`if "position()!=last()" > ,`
             }
         }
     }
-    |     ],
-    |     element: id("«@id»"),
+
+    |   "«@id»": new «$widget/@type»Widget ("«@id»",[«$args»],[«$indexes»],{
     apply "$widget", mode="widget_defs" with "hmi_element",".";
     apply "$widget", mode="widget_subscribe" with "hmi_element",".";
     |   })`if "position()!=last()" > ,`
@@ -72,7 +66,11 @@
 emit "preamble:widget-base-class" {
     ||    
     class Widget {
-        constructor(members){
+        constructor(elt_id,args,indexes,members){
+            this.element = id(elt_id);
+            this.args = args;
+            this.indexes = indexes;
+            this.offset = 0;
             Object.keys(members).forEach(prop => this[prop]=members[prop]);
         }
     }