Slider: fix logic re roundedness

master
thyttan 2023-10-17 01:15:21 +02:00
parent cd67e0d143
commit c4ba51a498
1 changed files with 8 additions and 6 deletions

View File

@ -50,6 +50,10 @@ try { // For making it possiblie to run the test app in the following catch stat
autoProgress:false, autoProgress:false,
},conf); },conf);
let totalBorderSize = o.c.outerBorderSize + o.c.innerBorderSize;
o.c.rounded = o.c.rounded?o.c.width/2:0;
if (o.c.rounded) o.c._rounded = (o.c.width-2*totalBorderSize)/2;
// If horizontal, flip things around. // If horizontal, flip things around.
if (o.c.horizontal) { if (o.c.horizontal) {
let mediator = o.c.xStart; let mediator = o.c.xStart;
@ -62,14 +66,12 @@ try { // For making it possiblie to run the test app in the following catch stat
} }
// Make room for the border. Underscore indicates the area for the actual indicator bar without borders. // Make room for the border. Underscore indicates the area for the actual indicator bar without borders.
let totalBorderSize = o.c.outerBorderSize + o.c.innerBorderSize;
o.c._xStart = o.c.xStart + totalBorderSize; o.c._xStart = o.c.xStart + totalBorderSize;
o.c._width = o.c.width - 2*totalBorderSize; o.c._width = o.c.width - 2*totalBorderSize;
o.c._yStart = o.c.yStart + totalBorderSize; o.c._yStart = o.c.yStart + totalBorderSize;
o.c._height = o.c.height - 2*totalBorderSize; o.c._height = o.c.height - 2*totalBorderSize;
o.c.rounded = o.c.rounded?o.c._width/2:0;
o.c.STEP_SIZE = ((!o.c.horizontal?o.c._height:o.c._width)-(!o.c.rounded?0:(2*o.c.rounded)))/o.c.steps; o.c.STEP_SIZE = ((!o.c.horizontal?o.c._height:o.c._width)-(!o.c.rounded?0:(2*o.c._rounded)))/o.c.steps;
// Add a rectangle object with x, y, x2, y2, w and h values. // Add a rectangle object with x, y, x2, y2, w and h values.
o.c.r = {x:o.c.xStart, y:o.c.yStart, x2:o.c.xStart+o.c.width, y2:o.c.yStart+o.c.height, w:o.c.width, h:o.c.height}; o.c.r = {x:o.c.xStart, y:o.c.yStart, x2:o.c.xStart+o.c.width, y2:o.c.yStart+o.c.height, w:o.c.width, h:o.c.height};
@ -181,10 +183,10 @@ try { // For making it possiblie to run the test app in the following catch stat
g.setColor(o.c.colorFG).fillRect(o.c.borderRect). // To get outer border... g.setColor(o.c.colorFG).fillRect(o.c.borderRect). // To get outer border...
setColor(o.c.colorBG).fillRect(o.c.hollowRect). // ... and here it's made hollow. setColor(o.c.colorBG).fillRect(o.c.hollowRect). // ... and here it's made hollow.
setColor(0==level?o.c.colorBG:o.c.colorFG).fillRect(o.f.updateBar((!o.c.rounded?0:(2*o.c.rounded))+level*o.c.STEP_SIZE)); // Here the bar is drawn. setColor(0==level?o.c.colorBG:o.c.colorFG).fillRect(o.f.updateBar((!o.c.rounded?0:(2*o.c._rounded))+level*o.c.STEP_SIZE)); // Here the bar is drawn.
if (o.c.rounded && level===0) { // Hollow circle indicates level zero when slider is rounded. if (o.c.rounded && level===0) { // Hollow circle indicates level zero when slider is rounded.
g.setColor(o.c.colorFG).fillCircle(o.c._xStart+(!o.c.horizontal?o.c._width/2:o.c.rounded-2), o.c._yStart+o.c._height-o.c.rounded, o.c.rounded). g.setColor(o.c.colorFG).fillCircle(o.c._xStart+(!o.c.horizontal?o.c._rounded:o.c._rounded), o.c._yStart+o.c._height-o.c._rounded, o.c._rounded).
setColor(o.c.colorBG).fillCircle(o.c._xStart+(!o.c.horizontal?o.c._width/2:o.c.rounded-2), o.c._yStart+o.c._height-o.c.rounded, o.c.rounded-o.c.outerBorderSize); setColor(o.c.colorBG).fillCircle(o.c._xStart+(!o.c.horizontal?o.c._rounded:o.c._rounded), o.c._yStart+o.c._height-o.c._rounded, o.c._rounded-o.c.outerBorderSize);
} }
}; };
} }