Slider: change to only add required parts

... depending on how the slider is configured when initializing.
Assumed to reduce ram use, have not tested to see if it actually is an
improvement in rem use or general performance in practice.
master
thyttan 2023-09-19 01:35:45 +02:00
parent 94074304dc
commit 9e978b2c5b
1 changed files with 70 additions and 62 deletions

View File

@ -31,6 +31,8 @@ o.c = Object.assign({ // constants go here.
autoProgress:false,
outerBorderSize:2,
innerBorderSize:2,
drawableSlider:true,
dragableSlider:true,
},conf);
let totalBorderSize = o.c.outerBorderSize + o.c.innerBorderSize;
@ -67,22 +69,14 @@ o.v.level = (o.c.currLevel||o.c.currLevel===0)?o.c.currLevel:o.c.steps/2;
o.v.firstRun = true;
o.v.ebLast = 0;
o.f.wasOnIndicator = (exFirst)=>{
if (o.c.dragableSlider) {
o.f.wasOnIndicator = (exFirst)=>{
"ram";
if (!o.c.horizontal) return exFirst>o.c._xStart-o.c.oversizeL*o.c._width && exFirst<o.c._xStart+o.c._width+o.c.oversizeR*o.c._width;
if (o.c.horizontal) return exFirst>o.c._yStart-o.c.oversizeL*o.c._height && exFirst<o.c._yStart+o.c._height+o.c.oversizeR*o.c._height;
};
};
o.c.borderRect = {x:o.c._xStart-totalBorderSize,y:o.c._yStart-totalBorderSize,w:o.c._width+2*totalBorderSize,h:o.c._height+2*totalBorderSize,r:o.c.rounded};
o.c.hollowRect = {x:o.c._xStart-o.c.innerBorderSize,y:o.c._yStart-o.c.innerBorderSize,w:o.c._width+2*o.c.innerBorderSize,h:o.c._height+2*o.c.innerBorderSize,r:o.c.rounded};
o.f.updateBar = (levelHeight)=>{
"ram";
if (!o.c.horizontal) return {x:o.c._xStart,y:o.c._yStart+o.c._height-levelHeight,w:o.c._width,y2:o.c._yStart+o.c._height,r:o.c.rounded};
if (o.c.horizontal) return {x:o.c._xStart,y:o.c._yStart,w:levelHeight,h:o.c._height,r:o.c.rounded};
};
o.f.dragSlider = e=>{
o.f.dragSlider = e=>{
"ram";
o.v.dragActive = true;
if (!o.c.propagateDrag) E.stopEventPropagation&&E.stopEventPropagation();
@ -100,7 +94,7 @@ o.f.dragSlider = e=>{
o.v.level = Math.min(Math.max(o.c.steps-input,0),o.c.steps);
if (o.v.level != o.v.prevLevel) cb("map",o.v.level);
o.f.draw(o.v.level);
o.f.draw&&o.f.draw(o.v.level);
} else if (o.c.useIncr) { // Heavily inspired by "updown" mode of setUI.
@ -115,13 +109,32 @@ o.f.dragSlider = e=>{
o.v.level = Math.min(Math.max(o.v.level-incr,0),o.c.steps);
cb("incr",incr);
o.f.draw(o.v.level);
o.f.draw&&o.f.draw(o.v.level);
}
}
o.v.ebLast = e.b;
};
};
o.f.draw = (level)=>{
o.f.remove = ()=> {
Bangle.removeListener('drag', o.f.dragSlider);
o.v.dragActive = false;
cb("remove", o.v.prevLevel);
};
}
if (o.c.drawableSlider) {
o.f.updateBar = (levelHeight)=>{
"ram";
if (!o.c.horizontal) return {x:o.c._xStart,y:o.c._yStart+o.c._height-levelHeight,w:o.c._width,y2:o.c._yStart+o.c._height,r:o.c.rounded};
if (o.c.horizontal) return {x:o.c._xStart,y:o.c._yStart,w:levelHeight,h:o.c._height,r:o.c.rounded};
};
o.c.borderRect = {x:o.c._xStart-totalBorderSize,y:o.c._yStart-totalBorderSize,w:o.c._width+2*totalBorderSize,h:o.c._height+2*totalBorderSize,r:o.c.rounded};
o.c.hollowRect = {x:o.c._xStart-o.c.innerBorderSize,y:o.c._yStart-o.c.innerBorderSize,w:o.c._width+2*o.c.innerBorderSize,h:o.c._height+2*o.c.innerBorderSize,r:o.c.rounded};
o.f.draw = (level)=>{
"ram";
if (true || o.v.firstRun || !o.c.lazy) {
@ -138,26 +151,21 @@ o.f.draw = (level)=>{
//print(level);
//print(process.memory().usage);
};
o.f.remove = ()=> {
Bangle.removeListener('drag', o.f.dragSlider);
o.v.dragActive = false;
cb("remove", o.v.prevLevel);
};
};
}
if (o.c.autoProgress) {
o.v.shouldAutoDraw = true;
o.f.autoUpdate = ()=>{
//if (o.v.level===undefined) o.v.level = -1;
o.v.level = o.v.level+1;
if (o.v.shouldAutoDraw) o.f.draw(o.v.level);
if (o.v.shouldAutoDraw) o.f.draw&&o.f.draw(o.v.level);
cb("auto");
if (o.v.level==o.c.steps) {o.f.stopAutoUpdate();}
};
o.f.startAutoUpdate = ()=>{
o.f.stopAutoUpdate();
if (o.v.shouldAutoDraw) o.f.draw(o.v.level);
if (o.v.shouldAutoDraw) o.f.draw&&o.f.draw(o.v.level);
o.v.autoIntervalID = setInterval(o.f.autoUpdate,1000);
};
o.f.stopAutoUpdate = ()=>{if (o.v.autoIntervalID) {clearInterval(o.v.autoIntervalID); o.v.autoIntervalID = undefined;}};