Skip to content

Commit afcd0e7

Browse files
author
thyttan
committed
Dial: tweaks
1 parent cb5f492 commit afcd0e7

File tree

1 file changed

+56
-68
lines changed

1 file changed

+56
-68
lines changed

apps/modules/Dial.js

Lines changed: 56 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,77 @@
1-
let Dial = function(cb, options) {
2-
"ram";
3-
const SCREEN_W = g.getWidth();
4-
const SCREEN_H = g.getHeight();
1+
function Dial(cb, options) {
2+
"ram";
3+
const SCREEN_W = g.getWidth();
4+
const SCREEN_H = g.getHeight();
55

6-
options = Object.assign(
7-
{ stepsPerWholeTurn : 8,
8-
dialRect : {
9-
x: 0,
10-
y: 0,
11-
x2: SCREEN_W - 1,
12-
y2: SCREEN_H - 1,
13-
w: SCREEN_W,
14-
h: SCREEN_H,
15-
},
16-
}, options);
6+
options = Object.assign(
7+
{ stepsPerWholeTurn : 8,
8+
dialRect : {
9+
x: 0,
10+
y: 0,
11+
x2: SCREEN_W - 1,
12+
y2: SCREEN_H - 1,
13+
w: SCREEN_W,
14+
h: SCREEN_H,
15+
},
16+
}, options);
1717

18-
const DIAL_RECT = options.dialRect;
18+
const DIAL_RECT = options.dialRect;
1919

20-
const CENTER = {
21-
x: DIAL_RECT.x + DIAL_RECT.w / 2,
22-
y: DIAL_RECT.y + DIAL_RECT.h / 2,
23-
};
20+
const CENTER = {
21+
x: DIAL_RECT.x + DIAL_RECT.w / 2,
22+
y: DIAL_RECT.y + DIAL_RECT.h / 2,
23+
};
2424

25-
const BASE_SCREEN_W = 176;
26-
const STEPS_PER_TURN = options.stepsPerWholeTurn;
27-
const BASE_THRESHOLD = 50;
28-
const THRESHOLD =
29-
BASE_THRESHOLD *
25+
const BASE_SCREEN_W = 176;
26+
const STEPS_PER_TURN = options.stepsPerWholeTurn;
27+
const BASE_THRESHOLD = 50;
28+
const THRESHOLD =
29+
BASE_THRESHOLD *
3030
(10 / STEPS_PER_TURN) *
3131
(DIAL_RECT.w / BASE_SCREEN_W);
3232

33-
let cumulative = 0;
33+
let cumulative = 0;
3434

35-
function onDrag(e) {
36-
"ram";
35+
function onDrag(e) {
36+
"ram";
3737

38-
if (
39-
e.x < DIAL_RECT.x ||
38+
if (
39+
e.x < DIAL_RECT.x ||
4040
e.x > DIAL_RECT.x2 ||
4141
e.y < DIAL_RECT.y ||
4242
e.y > DIAL_RECT.y2
43-
) {
44-
return;
45-
}
46-
47-
if (e.y < CENTER.y) {
48-
cumulative += e.dx;
49-
} else {
50-
cumulative -= e.dx;
51-
}
52-
53-
if (e.x < CENTER.x) {
54-
cumulative -= e.dy;
55-
} else {
56-
cumulative += e.dy;
57-
}
58-
59-
function stepHandler(step) {
60-
cumulative -= THRESHOLD * step;
61-
cb(step);
62-
}
43+
) {
44+
return;
45+
}
6346

64-
while (cumulative > THRESHOLD) {
65-
stepHandler(1);
66-
}
67-
while (cumulative < -THRESHOLD) {
68-
stepHandler(-1);
69-
}
47+
if (e.y < CENTER.y) {
48+
cumulative += e.dx;
49+
} else {
50+
cumulative -= e.dx;
51+
}
7052

71-
E.stopEventPropagation();
53+
if (e.x < CENTER.x) {
54+
cumulative -= e.dy;
55+
} else {
56+
cumulative += e.dy;
7257
}
7358

74-
return onDrag;
75-
/*
76-
if (exports.dial._handler) {
77-
Bangle.removeListener("drag", dial._handler);
59+
function stepHandler(step) {
60+
cumulative -= THRESHOLD * step;
61+
cb(step);
7862
}
7963

80-
exports.dial._handler = onDrag;
81-
Bangle.prependListener("drag", onDrag);
82-
83-
Bangle.prependListener("swipe", ()=>{
84-
E.stopEventPropagation();
64+
while (cumulative > THRESHOLD) {
65+
stepHandler(1);
8566
}
86-
);*/
87-
};
67+
while (cumulative < -THRESHOLD) {
68+
stepHandler(-1);
69+
}
70+
71+
E.stopEventPropagation();
72+
}
73+
74+
return onDrag;
75+
}
8876

8977
exports = Dial;

0 commit comments

Comments
 (0)