edouard@2883: // widget_input.ysl2 Edouard@2779: edouard@3094: template "widget[@type='Input']", mode="widget_class"{ edouard@3094: || edouard@3094: class InputWidget extends Widget{ edouard@3094: on_op_click(opstr) { edouard@3101: this.change_hmi_value(0, opstr); edouard@3094: } edouard@3094: edit_callback(new_val) { edouard@3094: this.apply_hmi_value(0, new_val); edouard@3094: } edouard@3100: Edouard@3188: is_inhibited = false; Edouard@3188: alert(msg){ Edouard@3188: this.is_inhibited = true; Edouard@3188: this.display = msg; Edouard@3188: setTimeout(() => this.stopalert(), 1000); edouard@3100: this.request_animate(); edouard@3100: } edouard@3100: Edouard@3188: stopalert(){ Edouard@3188: this.is_inhibited = false; Edouard@3188: this.display = this.last_value; Edouard@3188: this.request_animate(); Edouard@3188: } Edouard@3188: Edouard@3188: overshot(new_val, max) { Edouard@3188: this.alert("max"); Edouard@3188: } Edouard@3188: edouard@3100: undershot(new_val, min) { Edouard@3188: this.alert("min"); edouard@3100: } edouard@3100: edouard@3100: edouard@3094: } edouard@3094: || edouard@3094: } edouard@3094: edouard@2883: template "widget[@type='Input']", mode="widget_defs" { edouard@2883: param "hmi_element"; 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: }