forked from FOSS/BangleApps
libslider: Add configurability.
parent
d25f09d7ca
commit
0a81020b37
|
@ -5,4 +5,4 @@ let callback = (mode,fb)=>{
|
||||||
|
|
||||||
g.reset().clear().setColor(1,0,0).fillRect(0,0,176,176);
|
g.reset().clear().setColor(1,0,0).fillRect(0,0,176,176);
|
||||||
|
|
||||||
Bangle.on('drag', ()=>{require("SliderInput").interface(callback,true,true);});
|
Bangle.on('drag', ()=>{require("SliderInput").interface(callback, {useMap:true});});
|
||||||
|
|
|
@ -1,34 +1,39 @@
|
||||||
exports.interface = function(cb, useMap, useIncr) {
|
exports.interface = function(cb, conf) {
|
||||||
// TODO: make configurable
|
// Configuration for the indicator:
|
||||||
// Constants for the indicator:
|
conf = conf?conf:{};
|
||||||
const X_START = 176-55;
|
const USE_MAP = conf.useMap || false;
|
||||||
const WIDTH = 50;
|
const USE_INCR = conf.useIncr || true;
|
||||||
const Y_START = 5;
|
const X_START = conf.xStart || 176-55;
|
||||||
const HEIGHT = 165;
|
const WIDTH = conf.width || 50;
|
||||||
const STEPS = 30; //Currently corresponds to my phones volume range, from 0 to 30. Maybe it should be 31. Math is hard sometimes...
|
const Y_START = conf.yStart || 5;
|
||||||
|
const HEIGHT = conf.height || 165;
|
||||||
|
const STEPS = conf.steps || 30; //Default corresponds to my phones volume range, [0,30]. Maybe it should be 31. Math is hard sometimes...
|
||||||
|
const OVERSIZE_R = conf.oversizeR || 0;
|
||||||
|
const OVERSIZE_L = conf.oversizeL || 0;
|
||||||
|
const TIMEOUT = conf.timeout || 1;
|
||||||
|
|
||||||
const STEP_SIZE = HEIGHT/STEPS;
|
const STEP_SIZE = HEIGHT/STEPS;
|
||||||
const OVERSIZE = 0.65;
|
|
||||||
|
|
||||||
// Initialize the level
|
// Initialize the level
|
||||||
let level; // TODO: Depend on parameter.
|
let level; // TODO: Depend on parameter.
|
||||||
let lastLevel=10;
|
let lastLevel=10;
|
||||||
let levelHeight;
|
let levelHeight;
|
||||||
|
|
||||||
let continDrag = e=>{
|
let dragSlider = e=>{
|
||||||
"ram";
|
"ram";
|
||||||
if (timeout) {clearTimeout(timeout); timeout = setTimeout(remove, 1000*1);}
|
if (timeout) {clearTimeout(timeout); timeout = setTimeout(remove, 1000*TIMEOUT);}
|
||||||
let input = Math.min(e.y,170);
|
let input = Math.min(e.y,170);
|
||||||
input = Math.round(input/STEP_SIZE);
|
input = Math.round(input/STEP_SIZE);
|
||||||
|
|
||||||
// If draging on the indicator, adjust one-to-one.
|
// If draging on the indicator, adjust one-to-one.
|
||||||
if (useMap && e.x>X_START-OVERSIZE*WIDTH && e.x<X_START+OVERSIZE*WIDTH) {
|
if (USE_MAP && e.x>X_START-OVERSIZE_L*WIDTH && e.x<X_START+WIDTH+OVERSIZE_R*WIDTH) {
|
||||||
|
|
||||||
level = Math.min(Math.max(STEPS-input,0),STEPS);
|
level = Math.min(Math.max(STEPS-input,0),STEPS);
|
||||||
|
|
||||||
cb("map",level);
|
cb("map",level);
|
||||||
draw(level);
|
draw(level);
|
||||||
|
|
||||||
} else if (useIncr) { // Heavily inspired by "updown" mode of setUI.
|
} else if (USE_INCR) { // Heavily inspired by "updown" mode of setUI.
|
||||||
|
|
||||||
dy += e.dy;
|
dy += e.dy;
|
||||||
//if (!e.b) dy=0;
|
//if (!e.b) dy=0;
|
||||||
|
@ -82,12 +87,12 @@ let draw = (level)=>{
|
||||||
let remove = ()=> {
|
let remove = ()=> {
|
||||||
ovr.clear().reset();
|
ovr.clear().reset();
|
||||||
Bangle.setLCDOverlay();
|
Bangle.setLCDOverlay();
|
||||||
Bangle.removeListener('drag', continDrag);
|
Bangle.removeListener('drag', dragSlider);
|
||||||
};
|
};
|
||||||
|
|
||||||
let timeout = setTimeout(remove, 1000*1);
|
let timeout = setTimeout(remove, 1000*TIMEOUT);
|
||||||
|
|
||||||
let dy = 0;
|
let dy = 0;
|
||||||
g.reset();
|
g.reset();
|
||||||
Bangle.prependListener('drag', continDrag);
|
Bangle.prependListener('drag', dragSlider);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue