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