clock_info: factor out focus/defocus
parent
4b38e2af42
commit
a667fc8061
|
|
@ -284,38 +284,39 @@ exports.addInteractive = function(menu, options) {
|
||||||
E.stopEventPropagation&&E.stopEventPropagation();
|
E.stopEventPropagation&&E.stopEventPropagation();
|
||||||
}
|
}
|
||||||
Bangle.on("swipe",swipeHandler);
|
Bangle.on("swipe",swipeHandler);
|
||||||
|
const unfocus = () => {
|
||||||
|
options.focus=false;
|
||||||
|
delete Bangle.CLKINFO_FOCUS;
|
||||||
|
options.redraw();
|
||||||
|
};
|
||||||
|
const focus = (redraw) => {
|
||||||
|
options.focus=true;
|
||||||
|
Bangle.CLKINFO_FOCUS=true;
|
||||||
|
if (redraw) options.redraw();
|
||||||
|
};
|
||||||
let touchHandler, lockHandler;
|
let touchHandler, lockHandler;
|
||||||
if (options.x!==undefined && options.y!==undefined && options.w && options.h) {
|
if (options.x!==undefined && options.y!==undefined && options.w && options.h) {
|
||||||
touchHandler = function(_,e) {
|
touchHandler = function(_,e) {
|
||||||
if (e.x<options.x || e.y<options.y ||
|
if (e.x<options.x || e.y<options.y ||
|
||||||
e.x>(options.x+options.w) || e.y>(options.y+options.h)) {
|
e.x>(options.x+options.w) || e.y>(options.y+options.h)) {
|
||||||
if (options.focus) {
|
if (options.focus)
|
||||||
options.focus=false;
|
unfocus();
|
||||||
delete Bangle.CLKINFO_FOCUS;
|
|
||||||
options.redraw();
|
|
||||||
}
|
|
||||||
return; // outside area
|
return; // outside area
|
||||||
}
|
}
|
||||||
if (!options.focus) {
|
if (!options.focus) {
|
||||||
options.focus=true; // if not focussed, set focus
|
focus(true);
|
||||||
Bangle.CLKINFO_FOCUS=true;
|
|
||||||
options.redraw();
|
|
||||||
} else if (menu[options.menuA].items[options.menuB].run) {
|
} else if (menu[options.menuA].items[options.menuB].run) {
|
||||||
Bangle.buzz(100, 0.7);
|
Bangle.buzz(100, 0.7);
|
||||||
menu[options.menuA].items[options.menuB].run(); // allow tap on an item to run it (eg home assistant)
|
menu[options.menuA].items[options.menuB].run(); // allow tap on an item to run it (eg home assistant)
|
||||||
} else {
|
} else {
|
||||||
options.focus=true;
|
focus();
|
||||||
Bangle.CLKINFO_FOCUS=true;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Bangle.on("touch",touchHandler);
|
Bangle.on("touch",touchHandler);
|
||||||
if (settings.defocusOnLock) {
|
if (settings.defocusOnLock) {
|
||||||
lockHandler = function() {
|
lockHandler = function() {
|
||||||
if(options.focus) {
|
if(options.focus)
|
||||||
options.focus=false;
|
unfocus();
|
||||||
delete Bangle.CLKINFO_FOCUS;
|
|
||||||
options.redraw();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
Bangle.on("lock", lockHandler);
|
Bangle.on("lock", lockHandler);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue