edouard@2883: // widget_input.ysl2 Edouard@2779: edouard@3233: widget_desc("Input") { edouard@3233: longdesc edouard@3233: || edouard@3233: Input widget takes one variable path, and displays current value in edouard@3241: optional "value" labeled sub-element. edouard@3241: edouard@3241: Click on optional "edit" labeled element opens keypad to edit value. edouard@3241: edouard@3241: Operation on current value is performed when click on sub-elements with edouard@3241: label starting with '=', '+' or '-' sign. Value after sign is used as edouard@3241: operand. edouard@3233: || edouard@3100: edouard@3233: shortdesc > Input field with predefined operation buttons edouard@3100: edouard@3241: arg name="format" accepts="string" > optional printf-like format edouard@3232: edouard@3241: path name="edit" accepts="HMI_INT, HMI_REAL, HMI_STRING" > single variable to edit edouard@3233: edouard@3094: } edouard@3094: edouard@3232: widget_class("Input") edouard@3232: || edouard@3232: on_op_click(opstr) { edouard@3232: this.change_hmi_value(0, opstr); edouard@3232: } edouard@3232: edit_callback(new_val) { edouard@3232: this.apply_hmi_value(0, new_val); edouard@3232: } edouard@3232: edouard@3232: is_inhibited = false; edouard@3232: alert(msg){ edouard@3232: this.is_inhibited = true; edouard@3232: this.display = msg; edouard@3232: setTimeout(() => this.stopalert(), 1000); edouard@3232: this.request_animate(); edouard@3232: } edouard@3232: edouard@3232: stopalert(){ edouard@3232: this.is_inhibited = false; edouard@3232: this.display = this.last_value; edouard@3232: this.request_animate(); edouard@3232: } edouard@3232: edouard@3232: overshot(new_val, max) { edouard@3232: this.alert("max"); edouard@3232: } edouard@3232: edouard@3232: undershot(new_val, min) { edouard@3232: this.alert("min"); edouard@3232: } edouard@3232: || edouard@3232: edouard@3232: widget_defs("Input") { edouard@3094: edouard@3094: const "value_elt" optional_labels("value"); edouard@2883: const "have_value","string-length($value_elt)>0"; edouard@2883: value "$value_elt"; edouard@3094: edouard@3094: const "edit_elt" optional_labels("edit"); edouard@3094: const "have_edit","string-length($edit_elt)>0"; edouard@3094: value "$edit_elt"; edouard@3094: edouard@2883: if "$have_value" edouard@2883: | frequency: 5, edouard@3094: edouard@2883: | dispatch: function(value) { edouard@3094: edouard@3094: edouard@3155: if "$have_value or $have_edit" { edouard@3153: choose{ edouard@3153: when "count(arg) = 1" { Edouard@3188: | this.last_value = vsprintf("«arg[1]/@value»", [value]); edouard@3153: } edouard@3153: otherwise { Edouard@3188: | this.last_value = value; edouard@3153: } edouard@3153: } Edouard@3188: | if(!this.is_inhibited){ Edouard@3188: | this.display = this.last_value; Edouard@3188: if "$have_value" { Edouard@3188: | this.request_animate(); edouard@3155: } Edouard@3188: | } edouard@3100: } edouard@3100: | }, Edouard@2836: edouard@3100: if "$have_value" { edouard@3100: | animate: function(){ Edouard@3188: | this.value_elt.textContent = String(this.display); edouard@2883: | }, edouard@3100: } edouard@3094: edouard@2883: | init: function() { edouard@3094: edouard@3094: if "$have_edit" { Edouard@3188: | this.edit_elt.onclick = () => edit_value("«path/@value»", "«path/@type»", this, this.last_value); edouard@3153: if "$have_value" { edouard@3153: | this.value_elt.style.pointerEvents = "none"; edouard@3153: } edouard@2883: } edouard@3094: edouard@2883: foreach "$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]" { edouard@3094: | id("«@id»").onclick = () => this.on_op_click("«func:escape_quotes(@inkscape:label)»"); Edouard@2792: } Edouard@2911: Edouard@2911: | }, Edouard@2753: }