svghmi/widget_tooglebutton.ysl2
author etisserant <edouard.tisserant@gmail.com>
Tue, 25 Jan 2022 16:37:16 +0100
changeset 3415 c270b6c8162b
parent 3241 fe945f1f48b7
child 3478 c04c6db09eff
permissions -rw-r--r--
Create README.md in tests
2977
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
     1
// widget_tooglebutton.ysl2
82f062408e70 SVGHMI: Added widget toggleButton.
dgaberscek
parents:
diff changeset
     2
3011
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
     3
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     4
widget_desc("ToggleButton") {
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     5
    longdesc
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     6
    ||
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     7
    Button widget takes one boolean variable path, and reflect current true
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     8
    or false value by showing "active" or "inactive" labeled element
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     9
    respectively. Clicking or touching button toggles variable.
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    10
    ||
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    11
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    12
    shortdesc > Toggle button reflecting given boolean variable
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    13
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    14
    path name="value" accepts="HMI_BOOL" > Boolean variable
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    15
    
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    16
}
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    17
3232
7bdb766c2a4d SVGHMI: In order to allow widget signature and description to coexist in same ysl2 file, introduced widget_class, widget_defs to declare widget codegen templates and gen_index_xhtml to mark templates that are only usefull in gen_index_xhtml.xslt.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3219
diff changeset
    18
widget_class("ToggleButton") {
3011
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    19
    ||
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    20
        frequency = 5;
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    21
        state = 0;
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    22
        active_style = undefined;
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    23
        inactive_style = undefined;
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    24
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    25
        dispatch(value) {
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    26
            this.state = value;
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    27
            //redraw toggle button
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    28
            this.request_animate();
3011
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    29
        }
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    30
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    31
        on_click(evt) {
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    32
            //toggle state and apply
3219
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    33
            this.state = this.state ? false : true;
3018
Edouard Tisserant
parents: 3011
diff changeset
    34
            this.apply_hmi_value(0, this.state);
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    35
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    36
            //redraw toggle button
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    37
            this.request_animate();
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    38
        }
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    39
3219
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    40
        activate(val) {
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    41
            let [active, inactive] = val ? ["none",""] : ["", "none"];
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    42
            if (this.active_elt)
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    43
                this.active_elt.style.display = active;
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    44
            if (this.inactive_elt)
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    45
                this.inactive_elt.style.display = inactive;
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    46
        }
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    47
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    48
        animate(){
3219
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    49
            // redraw toggle button on screen refresh
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    50
            this.activate(this.state);
3011
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    51
        }
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    52
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    53
        init() {
3219
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    54
            this.activate(false);
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    55
            this.element.onclick = (evt) => this.on_click(evt);
3011
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    56
        }
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    57
    ||
3024
Edouard Tisserant
parents: 3018
diff changeset
    58
}
3011
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    59
3232
7bdb766c2a4d SVGHMI: In order to allow widget signature and description to coexist in same ysl2 file, introduced widget_class, widget_defs to declare widget codegen templates and gen_index_xhtml to mark templates that are only usefull in gen_index_xhtml.xslt.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3219
diff changeset
    60
widget_defs("ToggleButton") {
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    61
    optional_labels("active inactive");
3004
705e34c6fe93 SVGHMI: More JS code refactoring : change_hmi_value and apply_hmi_value now methods of widget class.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2977
diff changeset
    62
}