edouard@2883: // widget_display.ysl2 Edouard@2792: edouard@3241: widget_desc("Display") { edouard@3241: longdesc edouard@3241: || edouard@3241: If Display widget is a svg:text element, then text content is replaced by edouard@3241: value of given variables, space separated. edouard@3241: edouard@3241: Otherwise, if Display widget is a group containing a svg:text element edouard@3241: labelled "format", then text content is replaced by printf-like formated edouard@3241: string. In other words, if "format" labeled text is "%d %s %f", then 3 edouard@3241: variables paths are expected : HMI_IN, HMI_STRING and HMI_REAL. edouard@3241: edouard@3241: In case Display widget is a svg::text element, it is also possible to give edouard@3241: format string as first argument. edouard@3241: || edouard@3241: edouard@3241: shortdesc > Printf-like formated text display edouard@3241: edouard@3241: arg name="format" count="optional" accepts="string" > printf-like format string when not given as svg:text edouard@3241: edouard@3241: path name="fields" count="many" accepts="HMI_INT,HMI_REAL,HMI_STRING,HMI_BOOL" > variables to be displayed edouard@3241: edouard@3241: } edouard@3241: Edouard@2790: edouard@3232: widget_class("Display") edouard@2998: || edouard@2998: frequency = 5; edouard@3008: dispatch(value, oldval, index) { edouard@3008: this.fields[index] = value; edouard@3142: this.request_animate(); edouard@2998: } edouard@2998: || edouard@2998: edouard@3232: widget_defs("Display") { edouard@3142: const "format" optional_labels("format"); edouard@3142: const "has_format","string-length($format)>0"; edouard@3142: value "$format"; edouard@3142: edouard@3142: if "$hmi_element[not(self::svg:text)] and not($has_format)" edouard@3142: error > Display Widget id="«$hmi_element/@id»" must be a svg::text element itself or a group containing a svg:text element labelled "format" edouard@3008: Edouard@3022: const "field_initializer" foreach "path" { Edouard@3022: choose{ Edouard@3022: when "@type='HMI_STRING'" > "" Edouard@3065: otherwise > 0 Edouard@3022: } Edouard@3022: if "position()!=last()" > , Edouard@3022: } Edouard@3022: | fields: [«$field_initializer»], edouard@3142: | animate: function(){ edouard@3142: choose { edouard@3142: when "$has_format" { edouard@3142: | if(this.format_elt.getAttribute("lang")) { edouard@3142: | this.format = svg_text_to_multiline(this.format_elt); edouard@3142: | this.format_elt.removeAttribute("lang"); edouard@3142: | } edouard@3142: | let str = vsprintf(this.format,this.fields); edouard@3142: | multiline_to_svg_text(this.format_elt, str); edouard@3142: } edouard@3142: otherwise { edouard@3142: | let str = this.args.length == 1 ? vsprintf(this.args[0],this.fields) : this.fields.join(' '); edouard@3142: | multiline_to_svg_text(this.element, str); edouard@3142: } edouard@3142: } edouard@3142: | }, edouard@3142: | edouard@3142: if "$has_format" { edouard@3142: | init: function() { edouard@3142: | this.format = svg_text_to_multiline(this.format_elt); edouard@3142: | }, edouard@3142: } Edouard@2753: }