13 |
13 |
14 In case Display widget is a svg::text element, it is also possible to give |
14 In case Display widget is a svg::text element, it is also possible to give |
15 format string as first argument. |
15 format string as first argument. |
16 || |
16 || |
17 |
17 |
18 shortdesc > Printf-like formated text display |
18 shortdesc > Printf-like formated text display |
19 |
19 |
20 arg name="format" count="optional" accepts="string" > printf-like format string when not given as svg:text |
20 arg name="format" count="optional" accepts="string" > printf-like format string when not given as svg:text |
21 |
21 |
22 path name="fields" count="many" accepts="HMI_INT,HMI_REAL,HMI_STRING,HMI_BOOL" > variables to be displayed |
22 path name="fields" count="many" accepts="HMI_INT,HMI_REAL,HMI_STRING,HMI_BOOL" > variables to be displayed |
23 |
23 |
24 } |
24 } |
25 |
25 |
26 |
26 |
27 widget_class("Display") |
27 widget_class("Display") |
28 || |
28 || |
29 frequency = 5; |
29 frequency = 5; |
30 dispatch(value, oldval, index) { |
30 dispatch(value, oldval, index) { |
31 this.fields[index] = value; |
31 this.fields[index] = value; |
|
32 if(!this.ready){ |
|
33 this.readyfields[index] = true; |
|
34 this.ready = this.readyfields.every(x=>x); |
|
35 } |
32 this.request_animate(); |
36 this.request_animate(); |
33 } |
37 } |
34 || |
38 || |
35 |
39 |
36 widget_defs("Display") { |
40 widget_defs("Display") { |
47 otherwise > 0 |
51 otherwise > 0 |
48 } |
52 } |
49 if "position()!=last()" > , |
53 if "position()!=last()" > , |
50 } |
54 } |
51 | fields: [«$field_initializer»], |
55 | fields: [«$field_initializer»], |
|
56 const "readyfield_initializer" foreach "path" { |
|
57 > false |
|
58 if "position()!=last()" > , |
|
59 } |
|
60 | readyfields: [«$readyfield_initializer»], |
|
61 | ready: false, |
52 | animate: function(){ |
62 | animate: function(){ |
53 choose { |
63 choose { |
54 when "$has_format" { |
64 when "$has_format" { |
55 | if(this.format_elt.getAttribute("lang")) { |
65 | if(this.format_elt.getAttribute("lang")) { |
56 | this.format = svg_text_to_multiline(this.format_elt); |
66 | this.format = svg_text_to_multiline(this.format_elt); |
57 | this.format_elt.removeAttribute("lang"); |
67 | this.format_elt.removeAttribute("lang"); |
58 | } |
68 | } |
59 | let str = vsprintf(this.format,this.fields); |
69 | let str = vsprintf(this.format,this.fields); |
60 | multiline_to_svg_text(this.format_elt, str); |
70 | multiline_to_svg_text(this.format_elt, str, !this.ready); |
61 } |
71 } |
62 otherwise { |
72 otherwise { |
63 | let str = this.args.length == 1 ? vsprintf(this.args[0],this.fields) : this.fields.join(' '); |
73 | let str = this.args.length == 1 ? vsprintf(this.args[0],this.fields) : this.fields.join(' '); |
64 | multiline_to_svg_text(this.element, str); |
74 | multiline_to_svg_text(this.element, str, !this.ready); |
65 } |
75 } |
66 } |
76 } |
67 | }, |
77 | }, |
68 | |
78 | |
|
79 | init: function() { |
69 if "$has_format" { |
80 if "$has_format" { |
70 | init: function() { |
|
71 | this.format = svg_text_to_multiline(this.format_elt); |
81 | this.format = svg_text_to_multiline(this.format_elt); |
|
82 } |
|
83 | this.animate(); |
72 | }, |
84 | }, |
73 } |
|
74 } |
85 } |