svghmi/widget_animate.ysl2
author usveticic
Thu, 24 Sep 2020 11:52:40 +0200
branchsvghmi
changeset 3059 e0db3f6a5f39
parent 3058 svghmi/widget_button.ysl2@6ea4b7e1a9ed
child 3062 9ec338a99a18
permissions -rw-r--r--
Button and toggle reworked to use animate and dispatch
Slider added buttons to incremente/decrement by 1
Init for animate widget
Changed test svg and plc
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
     1
// widget_animate.ysl2
2944
2a20038fbea9 Added button and circular bar widgets.
dgaberscek
parents:
diff changeset
     2
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
     3
template "widget[@type='Animate']", mode="widget_class"{
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
     4
    ||
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
     5
    class AnimateWidget extends Widget{
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
     6
        frequency = 5;
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
     7
        speed = 0;
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
     8
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3024
diff changeset
     9
        dispatch(value) {
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    10
            this.speed = value;
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    11
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    12
            //reconfigure animation
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    13
            this.request_animate();
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3024
diff changeset
    14
        }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3024
diff changeset
    15
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    16
        animate(){
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    17
           // change animation properties
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    18
           this.element.children[0].setAttribute("dur", String(this.speed)+"s")
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    19
        }
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    20
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    21
        init() {
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    22
             let width = this.element.getAttribute("width");
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    23
             let height = this.element.getAttribute("height");
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    24
             this.element.setAttribute("x",width/-2);
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    25
             this.element.setAttribute("y",height/-2);
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    26
        }
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    27
    }
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    28
    ||
3024
Edouard Tisserant
parents: 3018
diff changeset
    29
}
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    30
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    31
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    32
template "widget[@type='Animate']", mode="widget_defs" {
2976
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    33
    param "hmi_element";
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    34
    |,
3000
a9a45977bac0 SVGHMI: prefer apply_hmi_value() to change_hmi_value() when possible
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2976
diff changeset
    35
}