svghmi/widget_back.ysl2
author etisserant <edouard@beremiz.fr>
Sat, 14 Dec 2024 15:39:42 +0100 (3 months ago)
changeset 4074 a6e72555d562
parent 4070 fabc5d6c5a8c
child 4091 b9fea435d886
permissions -rw-r--r--
Tests: matiec version bump
// widget_back.ysl2

widget_desc("Back") {
    longdesc
    ||
    Back widget brings focus back to previous page in history when clicked.

    "active" + "inactive" labeled elements can be provided and reflect whether
    widget is pressed or not.
    ||

    shortdesc > Jump to previous page
}

widget_class("Back") {
||
    onmouseup(evt) {
        svg_root.removeEventListener("pointerup", this.bound_onmouseup, true);
        this.activity_state = false;
        this.request_animate();
        let page_name, index;
        if (jump_history.length > 1) {
           do {
               jump_history.pop(); // forget current page
               if (jump_history.length == 0) return;
               [page_name, index] = jump_history[jump_history.length-1];
           } while (page_name == "ScreenSaver") // never go back to ScreenSaver
           fading_page_switch(page_name, index);
        }
    }

    onmousedown(){
        svg_root.addEventListener("pointerup", this.bound_onmouseup, true);
        this.activity_state = true;
        this.request_animate();
    }

    init() {
        this.bound_onmouseup = this.onmouseup.bind(this);
        this.activity_state = false;
        this.element.addEventListener("pointerdown", this.onmousedown.bind(this));
    }
||
}

widget_defs("Back") {
    activable();
}