svghmi/widget_tooglebutton.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Sun, 08 Dec 2024 11:41:31 +0100
changeset 4063 6668dcbca915
parent 3599 0d7c41546854
permissions -rw-r--r--
IDE: Fix wrong red wire coloring in FBD, this time for good.
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
        active_style = undefined;
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    22
        inactive_style = undefined;
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    23
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    24
        dispatch(value) {
3599
0d7c41546854 SVGHMI: fix ToggleButton not always reflecting current state
Edouard Tisserant
parents: 3596
diff changeset
    25
            this.activity_state = Boolean(value);
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    26
            //redraw toggle button
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    27
            this.request_animate();
3011
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    28
        }
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
        on_click(evt) {
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    31
            //toggle state and apply
3596
9c725829d8f0 SVGHMI: continue rework of Jump widget to cope with Enable Expressions.
Edouard Tisserant
parents: 3520
diff changeset
    32
            this.activity_state = this.activity_state ? false : true;
9c725829d8f0 SVGHMI: continue rework of Jump widget to cope with Enable Expressions.
Edouard Tisserant
parents: 3520
diff changeset
    33
            this.apply_hmi_value(0, this.activity_state);
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    34
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    35
            //redraw toggle button
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    36
            this.request_animate();
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    37
        }
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
    38
3011
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    39
        init() {
3219
cc0ecc5e918f SVGHMI: Code cleanup for ToggleButton.
Edouard Tisserant
parents: 3059
diff changeset
    40
            this.element.onclick = (evt) => this.on_click(evt);
3596
9c725829d8f0 SVGHMI: continue rework of Jump widget to cope with Enable Expressions.
Edouard Tisserant
parents: 3520
diff changeset
    41
            this.activity_state = undefined;
3011
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    42
        }
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    43
    ||
3024
Edouard Tisserant
parents: 3018
diff changeset
    44
}
3011
601c6dbc1da7 Reworked togglebutton widget to extand class widget
usveticic
parents: 3004
diff changeset
    45
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
    46
widget_defs("ToggleButton") {
3520
b27e50143083 SVGHMI: generalize detach/re-attach of binary choices for ToggleButton, PushButton, Button and Keypad's Shit and CapsLock.
Edouard Tisserant
parents: 3519
diff changeset
    47
    activable();
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
    48
}
3519
43b2bff95289 SVGHMI: also use order-preserving detach re-attach for hiding and showing active and inactive state.
Edouard Tisserant
parents: 3495
diff changeset
    49