diff --git a/src/main/java/cc/fros/features/modules/hud/ArrayListHudModule.java b/src/main/java/cc/fros/features/modules/hud/ArrayListHudModule.java index 702329e..e6ca73e 100644 --- a/src/main/java/cc/fros/features/modules/hud/ArrayListHudModule.java +++ b/src/main/java/cc/fros/features/modules/hud/ArrayListHudModule.java @@ -42,10 +42,19 @@ public class ArrayListHudModule extends HudModule { int lineHeight = mc.font.lineHeight; int color = Fros.colorManager.getColorAsInt(); boolean right = alignment.getValue() == Align.RIGHT; - int widest = 0; + int nameBlock = 0; + int content = 0; for (Module module : shown) { - widest = Math.max(widest, width(module)); + int nameWidth = mc.font.width(module.getDisplayName()); + nameBlock = Math.max(nameBlock, nameWidth); + + int rowWidth = nameWidth; + String info = module.getDisplayInfo(); + if (info != null) { + rowWidth += GAP + infoWidth(info); + } + content = Math.max(content, rowWidth); } for (int i = 0; i < shown.size(); i++) { @@ -56,15 +65,17 @@ public class ArrayListHudModule extends HudModule { int rowY = (int) (y + i * lineHeight); int baseColor = on ? color : DISABLED_COLOR; + int nameWidth = mc.font.width(name); - // name sits on the alignment side - int nameX = (int) (right ? x + widest - mc.font.width(name) : x); + // name is anchored to the alignment side using names only, so it + // never moves when dynamic module info appears or changes + int nameX = (int) (right ? x + nameBlock - nameWidth : x); e.getContext().drawString(mc.font, name, nameX, rowY, baseColor); if (info != null) { - // info sits on the opposite side of the row + // info sits on the opposite side of the name int blockWidth = infoWidth(info); - int infoX = (int) (right ? x : x + widest - blockWidth); + int infoX = right ? nameX - GAP - blockWidth : nameX + nameWidth + GAP; int bracketColor = on ? BRACKET_COLOR : DISABLED_COLOR; e.getContext().drawString(mc.font, " [", infoX, rowY, bracketColor); @@ -75,19 +86,10 @@ public class ArrayListHudModule extends HudModule { } } - setWidth(widest); + setWidth(Math.max(content, nameBlock)); setHeight(lineHeight * shown.size()); } - private int width(Module module) { - int width = mc.font.width(module.getDisplayName()); - String info = module.getDisplayInfo(); - if (info != null) { - width += GAP + infoWidth(info); - } - return width; - } - private int infoWidth(String info) { return mc.font.width(" [") + mc.font.width(info) + mc.font.width("]"); }