better font management

This commit is contained in:
2025-06-16 07:06:15 -05:00
parent 6c608409e0
commit 67a5b219f5
15 changed files with 226 additions and 146 deletions
@@ -12,6 +12,7 @@ public class ModDimensions {
public Property<Integer> bgColor = new Property<>(0xFF000000, Property.PropertyType.HEX);
public Property<Integer> fgColor = new Property<>(0xFFffffff, Property.PropertyType.HEX);
public Property<Integer> radius = new Property<>(0);
public Property<Integer> font = Property.font(0);
public int width = 0;
public int height = 0;
@@ -23,7 +24,8 @@ public class ModDimensions {
"Scale", scale,
"Background Color", bgColor,
"Foreground Color", fgColor,
"Corner Radius", radius
"Corner Radius", radius,
"Font", font
)).named("In-Game Display");
}
@@ -53,7 +53,7 @@ public class ArmorDisplay extends Module implements HudMod {
}
public void renderHealth(RenderScope scope, int i, int max, int current) {
scope.drawText(0.5f, String.valueOf(((double) current / max) * 100) + "%", 17, (15 * i) + 3, false, dimensions.fgColor.value);
scope.drawText(0.5f, String.valueOf(((double) current / max) * 100) + "%", 17, (15 * i) + 3, dimensions.font.value, dimensions.fgColor.value);
}
@Override
@@ -26,15 +26,15 @@ public class Fps extends Module implements HudMod {
@Override
public void renderHud(RenderScope scope) {
String text = String.valueOf(SaturnClient.client.getCurrentFps()) + " FPS";
scope.drawText(text, 0, 0, false, fgColor.value);
dimensions.width = Fonts.getWidth(text, isEnabled());
scope.drawText(text, 0, 0, dimensions.font.value, fgColor.value);
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
}
@Override
public void renderDummy(RenderScope scope) {
String text = "369 FPS";
scope.drawText(text, 0, 0, false, fgColor.value);
dimensions.width = Fonts.getWidth(text, isEnabled());
scope.drawText(text, 0, 0, dimensions.font.value, fgColor.value);
dimensions.width = Fonts.getWidth(text, dimensions.font.value);
}
@Override
@@ -13,12 +13,14 @@ public class Property<T> {
FLOAT,
STRING,
HEX,
NAMESPACE
NAMESPACE,
SELECT,
}
public T value;
public boolean isReset = false;
private T defaultValue;
private String[] availableValues;
private PropertyType type;
public Property(T value) {
@@ -43,32 +45,45 @@ public class Property<T> {
this.type = type;
}
public boolean getBool() {
if (value instanceof Boolean) {
return (boolean) value;
}
throw new IllegalStateException("Property does not contain a boolean");
public static Property<Integer> select(Integer value, String... availableValues) {
Property<Integer> property = new Property<>(value, PropertyType.SELECT);
property.availableValues = availableValues;
return property;
}
public int getInt() {
if (value instanceof Integer) {
return (int) value;
}
throw new IllegalStateException("Property does not contain an int");
public static Property<Integer> font(int value) {
return select(value, "Default", "Inter", "Inter bold");
}
public float getFloat() {
if (value instanceof Float) {
return (float) value;
}
throw new IllegalStateException("Property does not contain a float");
@SuppressWarnings("unchecked")
public static <T> Property<T> namespace(Map<String, Property<?>> value) {
Property<T> property = new Property<>((T) value, PropertyType.NAMESPACE);
property.type = PropertyType.NAMESPACE;
return property;
}
public String getString() {
if (value instanceof String) {
return (String) value;
public void next() {
if ((Integer) value < availableValues.length-1) setValue((Integer)value+1);
else setValue(0);
}
public void prev() {
if ((Integer) value > 0) setValue((Integer)value-1);
else setValue(availableValues.length - 1);
}
public void setSelection(int selection) {
if (selection >= 0 && selection < availableValues.length && type == PropertyType.SELECT) {
setValue(selection);
}
}
public String getSelection() {
if (type == PropertyType.SELECT) {
return availableValues[(Integer) value];
} else {
return null;
}
throw new IllegalStateException("Property does not contain a string");
}
public void reset() {
@@ -51,7 +51,8 @@ public class ThemeManager {
}
} else {
for (Map.Entry<String, Property<?>> tProp : properties.get(namespace).entrySet()) {
currentStyling.get(tProp.getKey()).setValue(tProp.getValue().value);
Property<?> p = currentStyling.get(tProp.getKey());
if (p != null) p.setValue(tProp.getValue().value);
}
}
}
@@ -61,7 +62,7 @@ public class ThemeManager {
for (Map.Entry<String, Property<?>> tProp : properties.get(namespace+"@"+state).entrySet()) {
Property<?> p = currentStyling.get(tProp.getKey());
Property<?> currProp = properties.get(namespace).get(tProp.getKey());
if (p.value.equals(currProp.value)) {
if (currProp != null && p.value.equals(currProp.value)) {
p.setValue(tProp.getValue().value);
}
}
@@ -92,20 +92,22 @@ public class RenderScope {
vertexConsumer.vertex(matrix4f, (float) x2, (float) y1, 0).color(color);
}
public void drawText(String text, int x, int y, boolean bold, int color) {
drawText(1.0f, text, x, y, bold, color);
}
public void drawText(String text, int x, int y, int font, int color) {
drawText(1.0f, text, x, y, font, color);
}
public void drawText(float scale, String text, int x, int y, boolean bold, int color) {
public void drawText(float scale, String text, int x, int y, int font, int color) {
if (font == 0) {
scale *= 2;
}
int i = 0;
for (String line : text.split("\n")) {
color = getColor(color);
Identifier font = bold ? Fonts.INTER_BOLD : Fonts.INTER;
matrices.push();
matrices.translate(x, y + (i * Fonts.getHeight()), 0);
matrices.scale(scale, scale, 1.0f);
TextRenderer textRenderer = SaturnClient.client.textRenderer;
textRenderer.draw(Fonts.setFont(line, font), 0, 7, color, false, this.matrices.peek().getPositionMatrix(),
textRenderer.draw(Fonts.setFont(line, Fonts.getFont(font)), 0, font == 0 ? 1: 7, color, false, this.matrices.peek().getPositionMatrix(),
this.vertexConsumers, TextLayerType.NORMAL, 0, 15728880);
matrices.pop();
i++;
@@ -179,7 +181,7 @@ public class RenderScope {
public int getScaledWindowWidth() {
return SaturnClient.client.getWindow().getScaledWidth();
}
}
public int getScaledWindowHeight() {
return SaturnClient.client.getWindow().getScaledHeight();
@@ -209,31 +211,31 @@ public class RenderScope {
matrices.push();
matrices.scale(0.25f, 0.25f, 1.0f);
RenderSystem.setShaderTexture(0, sprite);
RenderLayer renderLayer = (RenderLayer)renderLayers.apply(sprite);
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix();
VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(renderLayer);
vertexConsumer.vertex(matrix4f, (float)x1, (float)y1, 0.0F).texture(u1, v1).color(color);
vertexConsumer.vertex(matrix4f, (float)x1, (float)y2, 0.0F).texture(u1, v2).color(color);
vertexConsumer.vertex(matrix4f, (float)x2, (float)y2, 0.0F).texture(u2, v2).color(color);
vertexConsumer.vertex(matrix4f, (float)x2, (float)y1, 0.0F).texture(u2, v1).color(color);
matrices.pop();
RenderSystem.setShaderTexture(0, sprite);
RenderLayer renderLayer = (RenderLayer)renderLayers.apply(sprite);
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix();
VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(renderLayer);
vertexConsumer.vertex(matrix4f, (float)x1, (float)y1, 0.0F).texture(u1, v1).color(color);
vertexConsumer.vertex(matrix4f, (float)x1, (float)y2, 0.0F).texture(u1, v2).color(color);
vertexConsumer.vertex(matrix4f, (float)x2, (float)y2, 0.0F).texture(u2, v2).color(color);
vertexConsumer.vertex(matrix4f, (float)x2, (float)y1, 0.0F).texture(u2, v1).color(color);
matrices.pop();
}
public void enableScissor(int x1, int y1, int x2, int y2) {
ScreenRect screenRect = (new ScreenRect(x1, y1, x2 - x1, y2 - y1)).transform(this.matrices.peek().getPositionMatrix());
this.setScissor(this.scissorStack.push(screenRect));
}
}
public void disableScissor() {
public void disableScissor() {
this.setScissor(this.scissorStack.pop());
}
}
public boolean scissorContains(int x, int y) {
public boolean scissorContains(int x, int y) {
return this.scissorStack.containsPoint(x, y);
}
}
private void setScissor(@Nullable ScreenRect rect) {
private void setScissor(@Nullable ScreenRect rect) {
this.draw();
if (rect != null) {
Window window = SaturnClient.client.getWindow();
@@ -290,68 +292,68 @@ public class RenderScope {
}
public void drawItem(ItemStack item, int x, int y) {
this.drawItem(SaturnClient.client.player, SaturnClient.client.world, item, x, y, 0);
}
this.drawItem(SaturnClient.client.player, SaturnClient.client.world, item, x, y, 0);
}
public void drawItem(ItemStack stack, int x, int y, int seed) {
this.drawItem(SaturnClient.client.player, SaturnClient.client.world, stack, x, y, seed);
}
public void drawItem(ItemStack stack, int x, int y, int seed) {
this.drawItem(SaturnClient.client.player, SaturnClient.client.world, stack, x, y, seed);
}
public void drawItem(ItemStack stack, int x, int y, int seed, int z) {
this.drawItem(SaturnClient.client.player, SaturnClient.client.world, stack, x, y, seed, z);
}
public void drawItem(ItemStack stack, int x, int y, int seed, int z) {
this.drawItem(SaturnClient.client.player, SaturnClient.client.world, stack, x, y, seed, z);
}
public void drawItemWithoutEntity(ItemStack stack, int x, int y) {
this.drawItemWithoutEntity(stack, x, y, 0);
}
public void drawItemWithoutEntity(ItemStack stack, int x, int y) {
this.drawItemWithoutEntity(stack, x, y, 0);
}
public void drawItemWithoutEntity(ItemStack stack, int x, int y, int seed) {
this.drawItem((LivingEntity)null, SaturnClient.client.world, stack, x, y, seed);
}
public void drawItemWithoutEntity(ItemStack stack, int x, int y, int seed) {
this.drawItem((LivingEntity)null, SaturnClient.client.world, stack, x, y, seed);
}
public void drawItem(LivingEntity entity, ItemStack stack, int x, int y, int seed) {
this.drawItem(entity, entity.getWorld(), stack, x, y, seed);
}
public void drawItem(LivingEntity entity, ItemStack stack, int x, int y, int seed) {
this.drawItem(entity, entity.getWorld(), stack, x, y, seed);
}
private void drawItem(@Nullable LivingEntity entity, @Nullable World world, ItemStack stack, int x, int y, int seed) {
this.drawItem(entity, world, stack, x, y, seed, 0);
}
private void drawItem(@Nullable LivingEntity entity, @Nullable World world, ItemStack stack, int x, int y, int seed) {
this.drawItem(entity, world, stack, x, y, seed, 0);
}
private void drawItem(@Nullable LivingEntity entity, @Nullable World world, ItemStack stack, int x, int y, int seed, int z) {
if (!stack.isEmpty()) {
SaturnClient.client.getItemModelManager().update(this.itemRenderState, stack, ModelTransformationMode.GUI, false, world, entity, seed);
this.matrices.push();
this.matrices.translate((float)(x + 8), (float)(y + 8), (float)(150 + (this.itemRenderState.hasDepth() ? z : 0)));
private void drawItem(@Nullable LivingEntity entity, @Nullable World world, ItemStack stack, int x, int y, int seed, int z) {
if (!stack.isEmpty()) {
SaturnClient.client.getItemModelManager().update(this.itemRenderState, stack, ModelTransformationMode.GUI, false, world, entity, seed);
this.matrices.push();
this.matrices.translate((float)(x + 8), (float)(y + 8), (float)(150 + (this.itemRenderState.hasDepth() ? z : 0)));
try {
this.matrices.scale(16.0F, -16.0F, 16.0F);
boolean bl = !this.itemRenderState.isSideLit();
if (bl) {
this.draw();
DiffuseLighting.disableGuiDepthLighting();
try {
this.matrices.scale(16.0F, -16.0F, 16.0F);
boolean bl = !this.itemRenderState.isSideLit();
if (bl) {
this.draw();
DiffuseLighting.disableGuiDepthLighting();
}
this.itemRenderState.render(this.matrices, this.vertexConsumers, 15728880, OverlayTexture.DEFAULT_UV);
this.draw();
if (bl) {
DiffuseLighting.enableGuiDepthLighting();
}
} catch (Throwable var11) {
CrashReport crashReport = CrashReport.create(var11, "Rendering item");
CrashReportSection crashReportSection = crashReport.addElement("Item being rendered");
crashReportSection.add("Item Type", () -> {
return String.valueOf(stack.getItem());
});
crashReportSection.add("Item Components", () -> {
return String.valueOf(stack.getComponents());
});
crashReportSection.add("Item Foil", () -> {
return String.valueOf(stack.hasGlint());
});
throw new CrashException(crashReport);
}
this.itemRenderState.render(this.matrices, this.vertexConsumers, 15728880, OverlayTexture.DEFAULT_UV);
this.draw();
if (bl) {
DiffuseLighting.enableGuiDepthLighting();
}
} catch (Throwable var11) {
CrashReport crashReport = CrashReport.create(var11, "Rendering item");
CrashReportSection crashReportSection = crashReport.addElement("Item being rendered");
crashReportSection.add("Item Type", () -> {
return String.valueOf(stack.getItem());
});
crashReportSection.add("Item Components", () -> {
return String.valueOf(stack.getComponents());
});
crashReportSection.add("Item Foil", () -> {
return String.valueOf(stack.hasGlint());
});
throw new CrashException(crashReport);
}
this.matrices.pop();
}
}
this.matrices.pop();
}
}
}
@@ -3,6 +3,7 @@ package org.saturnclient.ui2;
import java.util.ArrayList;
import java.util.List;
import org.saturnclient.saturnclient.config.ThemeManager;
import org.saturnclient.saturnclient.mixin.DrawContextAccessor;
import org.saturnclient.ui2.anim.Animation;
import org.saturnclient.ui2.components.ElementRenderer;
@@ -62,6 +63,8 @@ public abstract class SaturnScreen extends Screen {
Animation.execute((Float progress) -> {
blurProgress = progress;
}, blurDuration);
ThemeManager.load();
}
public abstract void ui();
@@ -22,6 +22,7 @@ public class SaturnModule extends Element {
private static Property<Integer> iconBg = theme.property("icon-bg", new Property<>(0xFF2e3248));
private static Property<Integer> tagBg = theme.property("tag-bg", new Property<>(0xFF2e3248));
private static Property<Integer> iconRadius = theme.property("icon-radius", new Property<>(10));
private static Property<Integer> font = theme.property("font", Property.font(1));
private static Property<Integer> radius = theme.property("radius", new Property<>(10));
static {
@@ -64,15 +65,15 @@ public class SaturnModule extends Element {
renderScope.drawTexture(mod.getIconTexture(), p + (p / 2), p + (p / 2), 0, 0, h - p, h - p, iconFg.value);
renderScope.drawText(0.6f, mod.getName(), p+h+4, p + 1, true, fgColor.value);
renderScope.drawText(0.6f, mod.getName(), p+h+4, p + 1, font.value, fgColor.value);
renderScope.drawText(0.35f, mod.getVersion(), width - p - (int) (Fonts.getWidth(mod.getVersion(), false) * 0.35f), p + 1, false, fgColor.value);
renderScope.drawText(0.35f, mod.getVersion(), width - p - (int) (Fonts.getWidth(mod.getVersion(), font.value) * 0.35f), p + 1, font.value, fgColor.value);
int xt = p + h + 4;
for (String tag : mod.getTags()) {
int xtb = (int) (Fonts.getWidth(tag, false) * 0.4f);
int xtb = (int) (Fonts.getWidth(tag, font.value) * 0.4f);
renderScope.drawRoundedRectangle(xt, p + (h/2), xtb + 6, 12, 5, tagBg.value);
renderScope.drawText(0.4f, tag, xt+2, p + (h/2) + 3, false, fgColor.value);
renderScope.drawText(0.4f, tag, xt+2, p + (h/2) + 3, font.value, fgColor.value);
xt += xtb + 9;
}
@@ -2,12 +2,17 @@ package org.saturnclient.ui2.components.inputs;
import org.lwjgl.glfw.GLFW;
import org.saturnclient.saturnclient.SaturnClient;
import org.saturnclient.saturnclient.config.Property;
import org.saturnclient.saturnclient.config.ThemeManager;
import org.saturnclient.ui2.Element;
import org.saturnclient.ui2.ElementContext;
import org.saturnclient.ui2.RenderScope;
import org.saturnclient.ui2.resources.Fonts;
public abstract class Input extends Element {
private static ThemeManager theme = new ThemeManager("Input");
private static Property<Integer> font = theme.property("font", Property.font(1));
String text = "";
public int cursorPosition = 0;
public abstract void checkReset();
@@ -66,12 +71,11 @@ public abstract class Input extends Element {
int scrollOffset = getScrollOffset();
String visibleText = getVisibleText(scrollOffset);
int textColor = focused ? 0xFFFFFF : 0xAAAAAA;
renderScope.drawText(0.6f, visibleText, 4, 4, false, textColor);
renderScope.drawText(0.6f, visibleText, 4, 4, font.value, textColor);
if (focused) {
int cursorX = 4 +
(int) (SaturnClient.client.textRenderer.getWidth(
Fonts.setFont(visibleText.substring(0, cursorPosition - scrollOffset))) * 0.6f);
(int) (Fonts.getWidth(visibleText.substring(0, cursorPosition - scrollOffset), font.value) * 0.6f);
renderScope.drawRect(cursorX, 2, 1, height - 4, 0xFFFFFFFF);
}
@@ -86,7 +90,7 @@ public abstract class Input extends Element {
int maxWidth = width - 4; // Available width for text
while (offset < cursorPosition) { // Ensure cursor remains visible
String visibleText = text.substring(offset, cursorPosition);
if (SaturnClient.client.textRenderer.getWidth(Fonts.setFont(visibleText)) > maxWidth) {
if (Fonts.getWidth(visibleText, font.value) > maxWidth) {
offset++;
} else {
break;
@@ -100,8 +104,7 @@ public abstract class Input extends Element {
// Ensure text does not overflow past the available width
for (int i = 1; i <= visibleText.length(); i++) {
if (SaturnClient.client.textRenderer.getWidth(
Fonts.setFont(visibleText.substring(0, i))) > width - 4) {
if (Fonts.getWidth(visibleText.substring(0, i), font.value) > width - 4) {
return visibleText.substring(0, i - 1); // Trim overflow
}
}
@@ -0,0 +1,49 @@
package org.saturnclient.ui2.components.inputs;
import org.saturnclient.saturnclient.config.Property;
import org.saturnclient.saturnclient.config.ThemeManager;
import org.saturnclient.ui2.Element;
import org.saturnclient.ui2.ElementContext;
import org.saturnclient.ui2.RenderScope;
import org.saturnclient.ui2.Utils;
import org.saturnclient.ui2.resources.Fonts;
import net.minecraft.client.render.RenderLayer;
public class Select extends Element {
private static ThemeManager theme = new ThemeManager("Toggle");
private static Property<Integer> fgColor = theme.property("fg-color", new Property<Integer>(0xAAAAAA));
private static Property<Integer> arrowColor = theme.property("arrow-color", new Property<Integer>(0xff8B5CF6));
private static Property<Integer> font = theme.property("font", Property.font(1));
private Property<Integer> prop;
public Select(Property<Integer> prop) {
this.prop = prop;
this.width = 150;
this.height = 15;
}
@Override
public void render(RenderScope renderScope, ElementContext ctx) {
renderScope.setRenderLayer(RenderLayer::getGuiTextured);
renderScope.drawText(0.8f, "<", 0, 0, font.value, arrowColor.value);
String text = prop.getSelection();
renderScope.drawText(0.6f, text, (int) (width - ((float) Fonts.getWidth(text, font.value) * 0.6f)) / 2, 1, font.value, fgColor.value);
renderScope.drawText(0.8f, ">", width - 10, 0, font.value, arrowColor.value);
theme.setState(null);
}
@Override
public void click(int mouseX, int mouseY) {
if (Utils.isHovering(mouseX - (width - 10), mouseY, 10, height, 1.0f)) {
prop.next();
} else if (Utils.isHovering(mouseX, mouseY, 10, height, 1.0f)) {
prop.prev();
}
}
}
@@ -12,7 +12,7 @@ public class Button extends Element {
private static Property<Integer> bgColor = theme.property("bg-color", new Property<Integer>(0xFF000000));
private static Property<Integer> fgColor = theme.property("fg-color", new Property<Integer>(0xFFFFFFFF));
private static Property<Integer> cornerRadius = theme.property("corner-radius", new Property<Integer>(10));
private static Property<Boolean> bold = theme.property("fg-bold", new Property<Boolean>(false));
private static Property<Integer> font = theme.property("font", Property.font(1));
static {
theme.propertyStateDefault("hovering", "fg-color", 0xFF845eee);
@@ -24,7 +24,7 @@ public class Button extends Element {
public Button(String text, Runnable onClick) {
this.text = text;
this.onClick = onClick;
this.dimensions(Fonts.getWidth(text, bold.value) + 50, 38);
this.dimensions(Fonts.getWidth(text, font.value) + 50, 38);
}
@Override
@@ -37,7 +37,7 @@ public class Button extends Element {
renderScope.drawRoundedRectangle(0, 0, width, height, cornerRadius.value, bgColor.value);
// renderScope.drawText(text, (width - Fonts.getWidth(text, font)) / 2, (height - Fonts.getHeight()) / 2, bold.value, fgColor.value);
renderScope.drawText(text, Fonts.centerX(width, text, bold.value), Fonts.centerY(height), bold.value, fgColor.value);
renderScope.drawText(text, Fonts.centerX(width, text, font.value), Fonts.centerY(height), font.value, fgColor.value);
}
@Override
@@ -9,6 +9,7 @@ import org.saturnclient.ui2.RenderScope;
public class Text extends Element {
private static ThemeManager theme = new ThemeManager("Text");
private static Property<Integer> fgColor = theme.property("fg-color", new Property<Integer>(0xFFFFFFFF));
public static Property<Integer> font = theme.property("font", Property.font(1));
private String text;
@@ -18,6 +19,6 @@ public class Text extends Element {
@Override
public void render(RenderScope renderScope, ElementContext ctx) {
renderScope.drawText(this.text, 0, 0, false, fgColor.value);
renderScope.drawText(this.text, 0, 0, font.value, fgColor.value);
}
}
@@ -8,12 +8,16 @@ import net.minecraft.util.Identifier;
public class Fonts {
public static final Identifier INTER = Identifier.of("saturnclient", "inter");
public static final Identifier INTER_BOLD = Identifier.of("saturnclient", "inter_bold");
public static final Identifier DEFAULT = Identifier.ofVanilla("default");
public static Identifier getFont(boolean bold) {
if (bold) {
return INTER_BOLD;
} else {
return INTER;
public static Identifier getFont(int font) {
switch (font) {
case 0:
return DEFAULT;
case 1:
return INTER;
default:
return INTER_BOLD;
}
}
@@ -22,35 +26,24 @@ public class Fonts {
Style.EMPTY.withFont(font));
}
public static Text setFont(String text, boolean bold) {
return Text.literal(text).setStyle(
Style.EMPTY.withFont(bold ? INTER_BOLD : INTER));
public static int getWidth(String text, int font) {
if (font == 0) {
return getWidth(text, getFont(font)) * 2;
} else {
return getWidth(text, getFont(font));
}
}
public static Text setFont(String text) {
return Text.literal(text).setStyle(
Style.EMPTY.withFont(INTER));
}
// public static int getWidth(String text, Identifier font) {
// return SaturnClient.client.textRenderer.getWidth(Text.literal(text).setStyle(
// Style.EMPTY.withFont(font)));
// }
// public static int getHeight() {
// return SaturnClient.client.textRenderer.fontHeight;
// }
public static int getWidth(String text, boolean bold) {
return SaturnClient.client.textRenderer.getWidth(setFont(text, getFont(bold)));
private static int getWidth(String text, Identifier font) {
return SaturnClient.client.textRenderer.getWidth(setFont(text, font));
}
public static int getHeight() {
return 18;
}
public static int centerX(int w, String text, boolean bold) {
return (w - Fonts.getWidth(text, bold)) / 2;
public static int centerX(int w, String text, int font) {
return (w - Fonts.getWidth(text, font)) / 2;
}
public static int centerY(int h) {
@@ -9,6 +9,7 @@ import org.saturnclient.ui2.components.Sidebar;
import org.saturnclient.ui2.components.inputs.FloatInput;
import org.saturnclient.ui2.components.inputs.HexInput;
import org.saturnclient.ui2.components.inputs.IntInput;
import org.saturnclient.ui2.components.inputs.Select;
import org.saturnclient.ui2.components.inputs.Toggle;
import org.saturnclient.ui2.elements.Scroll;
import org.saturnclient.ui2.elements.Text;
@@ -59,7 +60,7 @@ public class ConfigEditor extends SaturnScreen {
configScroll.draw(
new Text(
propName
).position(Fonts.centerX(520, propName, false), modY + 1).scale(0.7f));
).position(Fonts.centerX(520, propName, Text.font.value), modY + 1).scale(0.7f));
} else {
configScroll.draw(
new Text(
@@ -91,6 +92,11 @@ public class ConfigEditor extends SaturnScreen {
Map<String, Property<?>> nestedProperties = (Map<String, Property<?>>) prop.value;
row = drawProperties(configScroll, nestedProperties, row + 1, col, w);
break;
case SELECT:
configScroll.draw(new Select((Property<Integer>) prop).position(w / 2, modY));
break;
case STRING:
}
@@ -9,6 +9,7 @@ import org.saturnclient.ui2.components.Sidebar;
import org.saturnclient.ui2.components.inputs.FloatInput;
import org.saturnclient.ui2.components.inputs.HexInput;
import org.saturnclient.ui2.components.inputs.IntInput;
import org.saturnclient.ui2.components.inputs.Select;
import org.saturnclient.ui2.components.inputs.Toggle;
import org.saturnclient.ui2.elements.Scroll;
import org.saturnclient.ui2.elements.Text;
@@ -55,7 +56,7 @@ public class SaturnConfigEditor extends SaturnScreen {
configScroll.draw(
new Text(
propName
).position(Fonts.centerX(520, propName, false), modY + 1).scale(0.7f));
).position(Fonts.centerX(520, propName, Text.font.value), modY + 1).scale(0.7f));
} else {
configScroll.draw(
new Text(
@@ -88,6 +89,9 @@ public class SaturnConfigEditor extends SaturnScreen {
row = drawProperties(configScroll, nestedProperties, row + 1, col, w);
break;
case SELECT:
configScroll.draw(new Select((Property<Integer>) prop).position(w / 2, modY));
case STRING:
}