svghmi/widget_switch.ysl2
branchsvghmi
changeset 3241 fe945f1f48b7
parent 3232 7bdb766c2a4d
child 3386 608f48ad3dfc
equal deleted inserted replaced
3238:8a9d4c794cba 3241:fe945f1f48b7
     1 // widget_switch.ysl2
     1 // widget_switch.ysl2
       
     2 
       
     3 widget_desc("Switch") {
       
     4     longdesc
       
     5     ||
       
     6     Switch widget hides all subelements whose label do not match given
       
     7     variable current value representation. For exemple if given variable type
       
     8     is HMI_INT and value is 1, then elements with label '1' will be displayed.
       
     9     Label can have comments, so '1#some comment' would also match. If matching
       
    10     variable of type HMI_STRING, then double quotes must be used. For exemple,
       
    11     '"hello"' or '"hello"#another comment' match HMI_STRING 'hello'.
       
    12     ||
       
    13 
       
    14     shortdesc > Show elements whose label match value.
       
    15 
       
    16     // TODO: add optional format/precision argument to support floating points
       
    17     // TODO: support (in)equations and ranges
       
    18 
       
    19     path name="value" accepts="HMI_INT,HMI_STRING" > value to compare to labels
       
    20     
       
    21 }
     2 
    22 
     3 widget_class("Switch")
    23 widget_class("Switch")
     4     ||
    24     ||
     5         frequency = 5;
    25         frequency = 5;
     6         dispatch(value) {
    26         dispatch(value) {
    13             }
    33             }
    14         }
    34         }
    15     ||
    35     ||
    16 
    36 
    17 widget_defs("Switch") {
    37 widget_defs("Switch") {
    18     param "hmi_element";
       
    19     |     choices: [
    38     |     choices: [
    20     const "regex",!"'^(\"[^\"].*\"|\-?[0-9]+|false|true)(#.*)?$'"!;
    39     const "regex",!"'^(\"[^\"].*\"|\-?[0-9]+|false|true)(#.*)?$'"!;
    21 
    40 
    22     const "subelts", "$result_widgets[@id = $hmi_element/@id]//*";
    41     const "subelts", "$result_widgets[@id = $hmi_element/@id]//*";
    23     const "subwidgets", "$subelts//*[@id = $hmi_widgets/@id]";
    42     const "subwidgets", "$subelts//*[@id = $hmi_widgets/@id]";
    25 
    44 
    26     foreach "$accepted[regexp:test(@inkscape:label,$regex)]" {
    45     foreach "$accepted[regexp:test(@inkscape:label,$regex)]" {
    27         const "literal", "regexp:match(@inkscape:label,$regex)[2]";
    46         const "literal", "regexp:match(@inkscape:label,$regex)[2]";
    28     |         {
    47     |         {
    29     |             elt:id("«@id»"),
    48     |             elt:id("«@id»"),
       
    49                   // TODO : use style.display = "none" to hide element
    30     |             style:"«@style»",
    50     |             style:"«@style»",
    31     |             value:«$literal»
    51     |             value:«$literal»
    32     |         }`if "position()!=last()" > ,`
    52     |         }`if "position()!=last()" > ,`
    33     }
    53     }
    34     |     ],
    54     |     ],