SVGHMI: force initial state of Display widget to empty string.
authorEdouard Tisserant
Fri, 24 Jun 2022 10:46:26 +0200
changeset 3524 27d298c6f961
parent 3523 13282f91e6ff
child 3525 c2f7e9bda366
SVGHMI: force initial state of Display widget to empty string.
svghmi/svghmi.js
svghmi/widget_display.ysl2
--- a/svghmi/svghmi.js	Fri Jun 24 09:24:19 2022 +0200
+++ b/svghmi/svghmi.js	Fri Jun 24 10:46:26 2022 +0200
@@ -229,8 +229,8 @@
     return(Array.prototype.map.call(elt.children, x=>x.textContent).join("\\\\n")); 
 }
 
-function multiline_to_svg_text(elt, str) {
-    str.split('\\\\n').map((line,i) => {elt.children[i].textContent = line;});
+function multiline_to_svg_text(elt, str, blank) {
+    str.split('\\\\n').map((line,i) => {elt.children[i].textContent = blank?"":line;});
 }
 
 function switch_langnum(langnum) {
--- a/svghmi/widget_display.ysl2	Fri Jun 24 09:24:19 2022 +0200
+++ b/svghmi/widget_display.ysl2	Fri Jun 24 10:46:26 2022 +0200
@@ -15,12 +15,12 @@
     format string as first argument.
     ||
 
-    shortdesc > Printf-like formated text display 
+    shortdesc > Printf-like formated text display
 
     arg name="format" count="optional" accepts="string" > printf-like format string when not given as svg:text
 
     path name="fields" count="many" accepts="HMI_INT,HMI_REAL,HMI_STRING,HMI_BOOL" > variables to be displayed
-    
+
 }
 
 
@@ -28,7 +28,11 @@
     ||
         frequency = 5;
         dispatch(value, oldval, index) {
-            this.fields[index] = value;    
+            this.fields[index] = value;
+            if(!this.ready){
+                this.readyfields[index] = true;
+                this.ready = this.readyfields.every(x=>x);
+            }
             this.request_animate();
         }
     ||
@@ -49,6 +53,12 @@
         if "position()!=last()" > ,
     }
     |     fields: [«$field_initializer»],
+    const "readyfield_initializer" foreach "path" {
+        > false
+        if "position()!=last()" > ,
+    }
+    |     readyfields: [«$readyfield_initializer»],
+    |     ready: false,
     |     animate: function(){
     choose {
         when "$has_format" {
@@ -57,18 +67,19 @@
     |           this.format_elt.removeAttribute("lang");
     |       }
     |       let str = vsprintf(this.format,this.fields);
-    |       multiline_to_svg_text(this.format_elt, str);
+    |       multiline_to_svg_text(this.format_elt, str, !this.ready);
         }
         otherwise {
     |       let str = this.args.length == 1 ? vsprintf(this.args[0],this.fields) : this.fields.join(' ');
-    |       multiline_to_svg_text(this.element, str);
+    |       multiline_to_svg_text(this.element, str, !this.ready);
         }
     }
     |     },
-    |     
+    |
+    |     init: function() {
     if "$has_format" {
-    |     init: function() {
     |       this.format = svg_text_to_multiline(this.format_elt);
+    }
+    |       this.animate();
     |     },
-    }
 }