Add support for center label to ProgressBarComponent
Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
package net.runelite.client.ui.overlay.components;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FontMetrics;
|
||||
@@ -41,6 +42,7 @@ public class ProgressBarComponent implements LayoutableRenderableEntity
|
||||
{
|
||||
PERCENTAGE,
|
||||
FULL,
|
||||
TEXT_ONLY,
|
||||
BOTH
|
||||
}
|
||||
|
||||
@@ -53,6 +55,7 @@ public class ProgressBarComponent implements LayoutableRenderableEntity
|
||||
private long maximum = 100;
|
||||
private double value;
|
||||
private LabelDisplayMode labelDisplayMode = LabelDisplayMode.PERCENTAGE;
|
||||
private String centerLabel;
|
||||
private String leftLabel;
|
||||
private String rightLabel;
|
||||
private Color foregroundColor = new Color(82, 161, 82);
|
||||
@@ -75,20 +78,34 @@ public class ProgressBarComponent implements LayoutableRenderableEntity
|
||||
final long span = maximum - minimum;
|
||||
final double currentValue = value - minimum;
|
||||
final double pc = currentValue / span;
|
||||
final String textToWrite;
|
||||
String textToWrite;
|
||||
|
||||
switch (labelDisplayMode)
|
||||
{
|
||||
case TEXT_ONLY:
|
||||
textToWrite = "";
|
||||
break;
|
||||
case PERCENTAGE:
|
||||
textToWrite = formatPercentageProgress(pc);
|
||||
break;
|
||||
case BOTH:
|
||||
textToWrite = formatFullProgress(currentValue, maximum) + " (" + formatPercentageProgress(pc) + ")";
|
||||
break;
|
||||
case FULL:
|
||||
default:
|
||||
textToWrite = formatFullProgress(currentValue, maximum);
|
||||
}
|
||||
|
||||
if (!Strings.isNullOrEmpty(centerLabel))
|
||||
{
|
||||
if (!textToWrite.isEmpty())
|
||||
{
|
||||
textToWrite += " ";
|
||||
}
|
||||
|
||||
textToWrite += centerLabel;
|
||||
}
|
||||
|
||||
final int width = preferredSize.width;
|
||||
final int height = Math.max(preferredSize.height, 16);
|
||||
final int progressTextX = barX + (width - metrics.stringWidth(textToWrite)) / 2;
|
||||
|
||||
Reference in New Issue
Block a user