1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-09-01 20:33:31 +02:00

Put more focus on normal span and add margin

Instead of having the low, normal and high span be equal, make the
normal span as big as low and high together.

Also add a small margin to avoid having the indicator at the far edge
of the low or high span.
This commit is contained in:
Erik Johansson
2017-12-22 20:42:24 +01:00
committed by OliE
parent 2f53b72a76
commit 658f60f5c9

View File

@@ -123,16 +123,20 @@ public class LinearGaugeView extends View {
final boolean hasFirstLimit = firstLimit >= 0;
// Calculate the size of the "normal" span with a fallback if there is no such span
float span = hasFirstLimit ? secondLimit - firstLimit : 0.3f * secondLimit;
// Calculate how much bar to show to the left and right of the "normal" span
// (or just the second limit if there is no first limit).
float span = hasFirstLimit ? (secondLimit - firstLimit) / 2.0f : 0.3f * secondLimit;
// Add some extra margin to avoid having the indicator too far towards an edge
final float margin = 0.05f * span;
// Adjust the span if needed to make the value fit inside of it
if (hasFirstLimit && value < firstLimit - span) {
span = firstLimit - value;
} else if (!hasFirstLimit && value < secondLimit - span) {
span = secondLimit - value;
} else if (value > secondLimit + span) {
span = value - secondLimit;
if (hasFirstLimit && value - margin < firstLimit - span) {
span = firstLimit - value + margin;
} else if (!hasFirstLimit && value - margin < secondLimit - span) {
span = secondLimit - value + margin;
} else if (value + margin > secondLimit + span) {
span = value - secondLimit + margin;
}
// Round span to some nice value