slighly better font
This commit is contained in:
@@ -86,9 +86,9 @@ public class RenderScope {
|
|||||||
|
|
||||||
matrices.push();
|
matrices.push();
|
||||||
matrices.translate(x, y, 0);
|
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 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);
|
this.vertexConsumers, TextLayerType.NORMAL, 0, 15728880);
|
||||||
matrices.pop();
|
matrices.pop();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,13 +98,13 @@ public class SaturnModule extends Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String formatText(String text, int width) {
|
private static String formatText(String text, int width) {
|
||||||
width -= Fonts.getWidth("..", Fonts.INTER);
|
width -= Fonts.getWidth("..", false);
|
||||||
|
|
||||||
StringBuilder trimmedText = new StringBuilder();
|
StringBuilder trimmedText = new StringBuilder();
|
||||||
|
|
||||||
for (int i = 0; i < text.length(); i++) {
|
for (int i = 0; i < text.length(); i++) {
|
||||||
String current = trimmedText.toString() + text.charAt(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) {
|
if (currentWidth > width) {
|
||||||
trimmedText.append("..");
|
trimmedText.append("..");
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import org.saturnclient.ui2.RenderContext;
|
|||||||
import org.saturnclient.ui2.RenderScope;
|
import org.saturnclient.ui2.RenderScope;
|
||||||
import org.saturnclient.ui2.resources.Fonts;
|
import org.saturnclient.ui2.resources.Fonts;
|
||||||
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
public class Button extends Element {
|
public class Button extends Element {
|
||||||
private static ThemeManager theme = new ThemeManager("Button", "hovering");
|
private static ThemeManager theme = new ThemeManager("Button", "hovering");
|
||||||
private static Property<Integer> bgColor = theme.property("bg-color", new Property<Integer>(0xFF000000));
|
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 String text;
|
||||||
private Identifier font;
|
|
||||||
private Runnable onClick;
|
private Runnable onClick;
|
||||||
|
|
||||||
public Button(String text, Runnable onClick) {
|
public Button(String text, Runnable onClick) {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.font = Fonts.getFont(bold.value);
|
|
||||||
this.onClick = onClick;
|
this.onClick = onClick;
|
||||||
this.dimensions(Fonts.getWidth(text, font) + 50, Fonts.getHeight() + 20);
|
this.dimensions(Fonts.getWidth(text, bold.value) + 50, 38);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -40,7 +36,8 @@ public class Button extends Element {
|
|||||||
}
|
}
|
||||||
renderScope.drawRoundedRectangle(0, 0, width, height, cornerRadius.value, bgColor.value);
|
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
|
@Override
|
||||||
|
|||||||
@@ -31,12 +31,19 @@ public class Fonts {
|
|||||||
// return SaturnClient.client.textRenderer.fontHeight;
|
// return SaturnClient.client.textRenderer.fontHeight;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public static int getWidth(String text, Identifier font) {
|
public static int getWidth(String text, boolean bold) {
|
||||||
return SaturnClient.client.textRenderer.getWidth(Text.literal(text).setStyle(
|
return SaturnClient.client.textRenderer.getWidth(setFont(text, getFont(bold)));
|
||||||
Style.EMPTY.withFont(font))) * 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getHeight() {
|
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",
|
"type": "ttf",
|
||||||
"file": "saturnclient:inter.ttf",
|
"file": "saturnclient:inter.ttf",
|
||||||
"shift": [0, 0],
|
"shift": [0, 0],
|
||||||
"size": 9,
|
"size": 18,
|
||||||
"oversample": 8.0,
|
"oversample": 12.0,
|
||||||
"skip_missing": true
|
"skip_missing": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"type": "ttf",
|
"type": "ttf",
|
||||||
"file": "saturnclient:inter_bold.ttf",
|
"file": "saturnclient:inter_bold.ttf",
|
||||||
"shift": [0, 0],
|
"shift": [0, 0],
|
||||||
"size": 9,
|
"size": 18,
|
||||||
"oversample": 8.0,
|
"oversample": 8.0,
|
||||||
"skip_missing": true
|
"skip_missing": true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user