ctrlpad: factor out initUI and call from immediate drag-lift

pull/3383/head
Rob Pilling 2024-04-25 12:48:18 +01:00
parent 375b977967
commit 77e3f9dec7
1 changed files with 15 additions and 10 deletions

View File

@ -163,6 +163,17 @@
let ui: undefined | UI; let ui: undefined | UI;
let touchDown = false; let touchDown = false;
const initUI = () => {
if (ui) return;
const overlay = new Overlay();
ui = {
overlay,
ctrls: new Controls(overlay.g2, controls),
};
ui.ctrls.draw(ui.overlay.g2);
};
const onDrag = (e => { const onDrag = (e => {
const dragDistance = 30; const dragDistance = 30;
@ -195,6 +206,7 @@
//console.log("topdrag stopped, distance: " + (e.y - startY)); //console.log("topdrag stopped, distance: " + (e.y - startY));
if(e.y > startY + dragDistance){ if(e.y > startY + dragDistance){
//console.log("activating"); //console.log("activating");
initUI();
state = State.Active; state = State.Active;
startY = 0; startY = 0;
Bangle.prependListener("touch", onTouch); Bangle.prependListener("touch", onTouch);
@ -210,15 +222,8 @@
// partial drag, show UI feedback: // partial drag, show UI feedback:
const dragOffset = 32; const dragOffset = 32;
if (!ui) { initUI();
const overlay = new Overlay(); ui!.overlay.setBottom(e.y - dragOffset);
ui = {
overlay,
ctrls: new Controls(overlay.g2),
};
ui.ctrls.draw(ui.overlay.g2);
}
ui.overlay.setBottom(e.y - dragOffset);
} }
E.stopEventPropagation?.(); E.stopEventPropagation?.();
break; break;
@ -248,7 +253,7 @@
ui = undefined; ui = undefined;
return; return;
} }
ui!.overlay.setBottom(bottom); ui.overlay.setBottom(bottom);
bottom -= 30; bottom -= 30;
}, 50) }, 50)