svghmi/widget_back.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Sun, 26 Jan 2025 14:58:13 +0100 (2 months ago)
changeset 4103 63c002e87c57
parent 4091 b9fea435d886
permissions -rw-r--r--
Merge remote-tracking branch 'hggit/python3' into python3
// 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") {
    optional_activable();
}