slighly better font

This commit is contained in:
2025-05-07 10:07:57 -05:00
parent 1c80803994
commit 3a54739410
6 changed files with 21 additions and 17 deletions
@@ -86,9 +86,9 @@ public class RenderScope {
matrices.push();
matrices.translate(x, y, 0);
matrices.scale(2.0f, 2.0f, 1.0f);
matrices.scale(1.0f, 1.0f, 1.0f);
TextRenderer textRenderer = SaturnClient.client.textRenderer;
textRenderer.draw(Fonts.setFont(text, font), 0, 0, color, false, this.matrices.peek().getPositionMatrix(),
textRenderer.draw(Fonts.setFont(text, font), 0, 7, color, false, this.matrices.peek().getPositionMatrix(),
this.vertexConsumers, TextLayerType.NORMAL, 0, 15728880);
matrices.pop();
}
@@ -98,13 +98,13 @@ public class SaturnModule extends Element {
}
private static String formatText(String text, int width) {
width -= Fonts.getWidth("..", Fonts.INTER);
width -= Fonts.getWidth("..", false);
StringBuilder trimmedText = new StringBuilder();
for (int i = 0; i < text.length(); i++) {
String current = trimmedText.toString() + text.charAt(i);
double currentWidth = Fonts.getWidth(current, Fonts.INTER) * 0.7;
double currentWidth = Fonts.getWidth(current, false) * 0.7;
if (currentWidth > width) {
trimmedText.append("..");
@@ -7,8 +7,6 @@ import org.saturnclient.ui2.RenderContext;
import org.saturnclient.ui2.RenderScope;
import org.saturnclient.ui2.resources.Fonts;
import net.minecraft.util.Identifier;
public class Button extends Element {
private static ThemeManager theme = new ThemeManager("Button", "hovering");
private static Property<Integer> bgColor = theme.property("bg-color", new Property<Integer>(0xFF000000));
@@ -21,14 +19,12 @@ public class Button extends Element {
}
private String text;
private Identifier font;
private Runnable onClick;
public Button(String text, Runnable onClick) {
this.text = text;
this.font = Fonts.getFont(bold.value);
this.onClick = onClick;
this.dimensions(Fonts.getWidth(text, font) + 50, Fonts.getHeight() + 20);
this.dimensions(Fonts.getWidth(text, bold.value) + 50, 38);
}
@Override
@@ -40,7 +36,8 @@ 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, (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);
}
@Override
@@ -31,12 +31,19 @@ public class Fonts {
// return SaturnClient.client.textRenderer.fontHeight;
// }
public static int getWidth(String text, Identifier font) {
return SaturnClient.client.textRenderer.getWidth(Text.literal(text).setStyle(
Style.EMPTY.withFont(font))) * 2;
public static int getWidth(String text, boolean bold) {
return SaturnClient.client.textRenderer.getWidth(setFont(text, getFont(bold)));
}
public static int getHeight() {
return SaturnClient.client.textRenderer.fontHeight * 2;
return 18;
}
public static int centerX(int w, String text, boolean bold) {
return (w - Fonts.getWidth(text, bold)) / 2;
}
public static int centerY(int h) {
return (h - 18) / 2;
}
}
@@ -4,8 +4,8 @@
"type": "ttf",
"file": "saturnclient:inter.ttf",
"shift": [0, 0],
"size": 9,
"oversample": 8.0,
"size": 18,
"oversample": 12.0,
"skip_missing": true
}
]
@@ -4,7 +4,7 @@
"type": "ttf",
"file": "saturnclient:inter_bold.ttf",
"shift": [0, 0],
"size": 9,
"size": 18,
"oversample": 8.0,
"skip_missing": true
}