fix(gui): align panel ClickGui widget glyphs by capHeight (#37)
Reworks vertical placement in PanelClickGui / CategoryBar / ProfileWidget / SettingsPopup / NumberSettingRenderer so search-bar icon + placeholder, category bar Y, role badge, dropdown header/value/arrow/items, and the number widget label/sign/value/caret all derive their Y from CapHeight instead of ascent+descent or hard-coded pixel offsets — fixes drift at non-100% GUI scale. Co-Authored-By: Koe <KoeNotPrism@proton.me>
This commit is contained in:
@@ -372,7 +372,8 @@ extends Screen {
|
||||
FontRenderer iconFont = FontPresets.materialIcons(20.0f * this.currentScale);
|
||||
String iconText = "\uE8B6";
|
||||
float iconX = searchX + 12.0f * this.currentScale;
|
||||
float iconY = searchY + searchHeight / 2.0f + iconFont.getMetrics().capHeight() / 2.0f - 12.0f * this.currentScale + 10F;
|
||||
// 已修复:添加 this.currentScale 乘数
|
||||
float iconY = searchY + searchHeight / 2.0f + iconFont.getMetrics().capHeight() / 2.0f - 12.0f * this.currentScale + (10.0f * this.currentScale);
|
||||
int iconColor = new Color(255, 255, 255, (int)(180.0f * alpha)).getRGB();
|
||||
TextGlow.drawGlowText(iconText, iconX, iconY, iconFont, 0xffdddddd, iconColor, 12.0f * this.currentScale);
|
||||
FontRenderer queryFont = FontPresets.axiformaRegular(16.0f * this.currentScale);
|
||||
@@ -381,12 +382,14 @@ extends Screen {
|
||||
String placeholder = "search";
|
||||
float placeholderWidth = GlHelper.getStringWidth(placeholder, placeholderFont);
|
||||
float placeholderX = searchX + (searchWidth - placeholderWidth) / 2.0f;
|
||||
float placeholderY = searchY + searchHeight / 2.0f + placeholderFont.getMetrics().capHeight() / 2.0f - 8.0f * this.currentScale + 5F;
|
||||
// 已修复:添加 this.currentScale 乘数
|
||||
float placeholderY = searchY + searchHeight / 2.0f + placeholderFont.getMetrics().capHeight() / 2.0f - 8.0f * this.currentScale + (5.0f * this.currentScale);
|
||||
TextGlow.drawGlowText(placeholder, placeholderX, placeholderY, placeholderFont, 0xffcccccc,
|
||||
new Color(255, 255, 255, (int)(130.0f * alpha)).getRGB(), 10.0f * this.currentScale);
|
||||
} else {
|
||||
float queryX = searchX + 35.0f * this.currentScale;
|
||||
float queryY = searchY + searchHeight / 2.0f + queryFont.getMetrics().capHeight() / 2.0f - 9.0f * this.currentScale + 6F;
|
||||
// 已修复:添加 this.currentScale 乘数
|
||||
float queryY = searchY + searchHeight / 2.0f + queryFont.getMetrics().capHeight() / 2.0f - 9.0f * this.currentScale + (6.0f * this.currentScale);
|
||||
int queryColor = new Color(255, 255, 255, (int)(120.0f * alpha)).getRGB();
|
||||
TextGlow.drawGlowText(this.searchQuery, queryX, queryY, queryFont, -1, queryColor, 8.0f * this.currentScale);
|
||||
if (this.searchFocused) {
|
||||
@@ -449,6 +452,7 @@ extends Screen {
|
||||
int textColor = textAlpha << 24 | 0xFFFFFF;
|
||||
int glowAlpha = (int)(120.0f * toast.alpha * alpha);
|
||||
int glowColor = glowAlpha << 24 | 0xFFFFFF;
|
||||
// 已修复:将 8.0f * scale 改为 8.0f * this.currentScale
|
||||
TextGlow.drawGlowText(toast.message, toastX, toastY + 6.0f * this.currentScale, toastFont, textColor, glowColor, 8.0f * this.currentScale);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -29,7 +29,7 @@ extends ClientBase {
|
||||
float iconFontSize = 24.0f * scale;
|
||||
int horizontalOffset = (int)(420.0f * scale);
|
||||
int baseX = originX + horizontalOffset;
|
||||
int baseY = originY + verticalOffset - (int)(65.0f * scale);
|
||||
int baseY = originY + verticalOffset - (int)(60.0f * scale);
|
||||
Category[] categories = Category.values();
|
||||
Renderer.renderConsumer(drawContext -> {
|
||||
FontRenderer iconFont = FontPresets.materialIcons(iconFontSize);
|
||||
@@ -102,7 +102,7 @@ extends ClientBase {
|
||||
int verticalOffset = (int)(80.0f * scale);
|
||||
int horizontalOffset = (int)(420.0f * scale);
|
||||
int baseX = originX + horizontalOffset;
|
||||
int baseY = originY + verticalOffset - (int)(65.0f * scale);
|
||||
int baseY = originY + verticalOffset - (int)(60.0f * scale);
|
||||
Category[] categories = Category.values();
|
||||
for (int i = 0; i < categories.length; ++i) {
|
||||
Category category = categories[i];
|
||||
@@ -129,7 +129,7 @@ extends ClientBase {
|
||||
int verticalOffset = (int)(80.0f * scale);
|
||||
int horizontalOffset = (int)(420.0f * scale);
|
||||
int baseX = originX + horizontalOffset;
|
||||
int baseY = originY + verticalOffset - (int)(65.0f * scale);
|
||||
int baseY = originY + verticalOffset - (int)(60.0f * scale);
|
||||
Category[] categories = Category.values();
|
||||
for (int i = 0; i < categories.length; ++i) {
|
||||
int iconX = baseX + i * iconSpacing;
|
||||
|
||||
@@ -9,7 +9,6 @@ import net.minecraft.client.player.AbstractClientPlayer;
|
||||
import shit.zen.ClientBase;
|
||||
import shit.zen.ZenClient;
|
||||
import shit.zen.gui.panel.SettingsPopup;
|
||||
import shit.zen.render.DrawContext;
|
||||
import shit.zen.render.FontPresets;
|
||||
import shit.zen.render.FontRenderer;
|
||||
import shit.zen.render.GlHelper;
|
||||
@@ -59,19 +58,27 @@ extends ClientBase {
|
||||
FontRenderer nameFont = FontPresets.axiformaRegular(14.0f * scale);
|
||||
int glowColor = new Color(255, 255, 255, (int)(100.0f * alpha)).getRGB();
|
||||
TextGlow.drawGlowText(userId, textX, textY, nameFont, this.applyAlpha(-1, alpha), glowColor, 8.0f * scale);
|
||||
|
||||
float nameWidth = GlHelper.getStringWidth(userId, nameFont);
|
||||
int roleBoxX = (int)((float)textX + nameWidth + 8.0f * scale);
|
||||
int roleBoxY = textY - (int)(6.0f * scale);
|
||||
Color roleColor = this.getRoleColor(userRole);
|
||||
FontRenderer roleFont = FontPresets.axiformaBold(11.0f * scale);
|
||||
float roleStrWidth = GlHelper.getStringWidth(userRole, roleFont);
|
||||
int roleBoxW = (int)(roleStrWidth + 8.0f * scale);
|
||||
int roleBoxH = (int)(10.0f * scale);
|
||||
|
||||
float roleBoxW = roleStrWidth + 8.0f * scale;
|
||||
float roleBoxH = 12.0f * scale;
|
||||
float roleBoxX = textX + nameWidth + 8.0f * scale;
|
||||
|
||||
float roleBoxY = textY + (nameFont.getMetrics().capHeight() - roleBoxH) / 2.0f;
|
||||
|
||||
Color roleColor = this.getRoleColor(userRole);
|
||||
int roleShadowColor = new Color(roleColor.getRed(), roleColor.getGreen(), roleColor.getBlue(), (int)(180.0f * alpha)).getRGB();
|
||||
RenderUtil.drawRoundedRect(guiGraphics.pose(), roleBoxX - 3, (float)roleBoxY + 2.5f * scale - 2.0f, roleBoxW + 2, roleBoxH + 2, 5.0f * scale, this.applyAlpha(roleShadowColor, alpha * 0.35f));
|
||||
RenderUtil.drawRoundedRect(guiGraphics.pose(), roleBoxX - 2, (float)roleBoxY + 3.5f * scale - 2.0f, roleBoxW, roleBoxH, 4.0f * scale, this.applyAlpha(roleColor.getRGB(), alpha));
|
||||
|
||||
RenderUtil.drawRoundedRect(guiGraphics.pose(), roleBoxX - 1.0f * scale, roleBoxY - 1.0f * scale, roleBoxW + 2.0f * scale, roleBoxH + 2.0f * scale, 5.0f * scale, this.applyAlpha(roleShadowColor, alpha * 0.35f));
|
||||
RenderUtil.drawRoundedRect(guiGraphics.pose(), roleBoxX, roleBoxY, roleBoxW, roleBoxH, 4.0f * scale, this.applyAlpha(roleColor.getRGB(), alpha));
|
||||
|
||||
int roleTextGlow = new Color(255, 255, 255, (int)(120.0f * alpha)).getRGB();
|
||||
TextGlow.drawGlowText(userRole, (float)roleBoxX + 1.5f * scale, (float)roleBoxY + 6.5f * scale, roleFont, this.applyAlpha(-1, alpha), roleTextGlow, 5.0f * scale);
|
||||
float roleTextX = roleBoxX + (roleBoxW - roleStrWidth) / 2.0f;
|
||||
float roleTextY = roleBoxY + (roleBoxH - roleFont.getMetrics().capHeight()) / 2.0f + 0.5f * scale;
|
||||
TextGlow.drawGlowText(userRole, roleTextX, roleTextY, roleFont, this.applyAlpha(-1, alpha), roleTextGlow, 5.0f * scale);
|
||||
});
|
||||
this.settingsPopup.render(guiGraphics, mouseX, mouseY, scale, alpha);
|
||||
} catch (Exception exception) {
|
||||
|
||||
@@ -108,7 +108,7 @@ extends ClientBase {
|
||||
rowY = (int)((float)rowY + 8.0f * scale);
|
||||
this.drawDropdown(drawContext, guiGraphics, "Menu Scale", this.selectedScale, SCALES, "scale", popupX, rowY, mouseX, mouseY, this.openAlpha, scale, popupWidth);
|
||||
FontRenderer footerFont = FontPresets.axiformaRegular(12.0f * scale);
|
||||
String footer = "7unknown © 2024-2025";
|
||||
String footer = "7unknown \u00a9 2024-2025";
|
||||
float footerWidth = GlHelper.getStringWidth(footer, footerFont);
|
||||
GlHelper.drawText(footer, (float)popupX + ((float)popupWidth - footerWidth) / 2.0f, (float)(popupY + popupHeight) - 15.0f * scale, footerFont, labelColor);
|
||||
}
|
||||
@@ -132,23 +132,33 @@ extends ClientBase {
|
||||
FontRenderer valueFont = FontPresets.axiformaRegular(13.0f * scale);
|
||||
int labelColor = this.applyAlpha(new Color(0xAAAAAA).getRGB(), openAlpha);
|
||||
int valueColor = this.applyAlpha(new Color(0xFFFFFF).getRGB(), openAlpha);
|
||||
GlHelper.drawText(label, (float)popupX + 15.0f * scale, (float)rowY + 6.0f * scale, labelFont, labelColor);
|
||||
|
||||
int dropdownWidth = (int)(90.0f * scale);
|
||||
int dropdownX = (int)((float)(popupX + popupWidth - dropdownWidth) - 15.0f * scale);
|
||||
int dropdownHeaderHeight = (int)(20.0f * scale);
|
||||
int itemHeight = (int)(18.0f * scale);
|
||||
|
||||
// --- 核心修复:标签左侧文字基于 CapHeight 垂直居中 ---
|
||||
float labelY = rowY + (dropdownHeaderHeight - labelFont.getMetrics().capHeight()) / 2.0f;
|
||||
GlHelper.drawText(label, (float)popupX + 15.0f * scale, labelY, labelFont, labelColor);
|
||||
|
||||
float openFactor = this.dropdownAlpha.getOrDefault(key, 0.0f).floatValue();
|
||||
String[] filteredItems = this.filterDropdownItems(items, selectedValue);
|
||||
int expandedHeight = (int)((float)(filteredItems.length * itemHeight) * openFactor);
|
||||
RenderUtil.drawRoundedRect(guiGraphics.pose(), dropdownX, rowY, dropdownWidth, dropdownHeaderHeight + expandedHeight, 4.0f * scale, this.applyAlpha(POPUP_BG_COLOR.getRGB(), openAlpha));
|
||||
|
||||
// --- 核心修复:选择框内部文字基于 CapHeight 垂直居中(抛弃无脑的常量加减偏移) ---
|
||||
float valueX = (float)dropdownX + 8.0f * scale;
|
||||
float valueY = (float)rowY + (float)dropdownHeaderHeight / 2.0f - valueFont.getMetrics().capHeight() / 2.0f + 3.0f * scale;
|
||||
GlHelper.drawText(selectedValue, valueX, valueY - 2.0f, valueFont, valueColor);
|
||||
float valueY = rowY + (dropdownHeaderHeight - valueFont.getMetrics().capHeight()) / 2.0f;
|
||||
GlHelper.drawText(selectedValue, valueX, valueY, valueFont, valueColor);
|
||||
|
||||
// --- 核心修复:展开的小箭头基于 CapHeight 垂直居中(抛弃 +7.0f 的不缩放硬编码偏移) ---
|
||||
FontRenderer arrowFont = FontPresets.materialIcons(18.0f * scale);
|
||||
String arrowIcon = "";
|
||||
float arrowX = (float)(dropdownX + dropdownWidth) - 18.0f * scale;
|
||||
float arrowY = (float)rowY + (float)dropdownHeaderHeight / 2.0f + arrowFont.getMetrics().capHeight() / 2.0f - 10.5f * scale + 7.0f;
|
||||
float arrowY = rowY + (dropdownHeaderHeight - arrowFont.getMetrics().capHeight()) / 2.0f;
|
||||
GlHelper.drawText(arrowIcon, arrowX, arrowY, arrowFont, valueColor);
|
||||
|
||||
if (openFactor > 0.01f) {
|
||||
drawContext.save();
|
||||
drawContext.clip(Rectangle.ofXYWH(dropdownX, rowY + dropdownHeaderHeight, dropdownWidth, expandedHeight));
|
||||
@@ -159,7 +169,8 @@ extends ClientBase {
|
||||
this.updateItemHover(itemHovers, item, hovered);
|
||||
float hoverAmount = itemHovers.getOrDefault(item, 0.0f);
|
||||
float itemTextX = (float)dropdownX + 8.0f * scale;
|
||||
float itemTextY = (float)itemY + (float)itemHeight / 2.0f - valueFont.getMetrics().capHeight() / 2.0f + 3.0f * scale;
|
||||
// --- 核心修复:展开列表里的每一项文字也基于 CapHeight 完美居中 ---
|
||||
float itemTextY = itemY + (itemHeight - valueFont.getMetrics().capHeight()) / 2.0f;
|
||||
int itemColor = this.applyAlpha(valueColor, openFactor);
|
||||
float glowAmount = hoverAmount * openFactor;
|
||||
if (glowAmount > 0.01f) {
|
||||
|
||||
@@ -10,7 +10,6 @@ import shit.zen.gui.PanelClickGui;
|
||||
import shit.zen.render.FontPresets;
|
||||
import shit.zen.render.FontRenderer;
|
||||
import shit.zen.render.GlHelper;
|
||||
import shit.zen.render.GlyphMetrics;
|
||||
import shit.zen.render.TextGlow;
|
||||
import shit.zen.settings.Setting;
|
||||
import shit.zen.settings.impl.NumberSetting;
|
||||
@@ -47,7 +46,7 @@ implements SettingRenderer {
|
||||
int iconSize = Math.round(16.0f * scale);
|
||||
int iconGap = Math.round(4.0f * scale);
|
||||
int iconX = widgetX - iconSize - iconGap;
|
||||
int iconY = Math.round(centerY - (float)iconSize / 2.0f) + Math.round(3.0f * scale);
|
||||
int iconY = Math.round(centerY - (float)iconSize / 2.0f);
|
||||
this.updateHoverStates(numberSetting, mouseX, mouseY, widgetX, widgetY, widgetWidth, sidePadding, widgetHeight, iconX, iconY, iconSize);
|
||||
this.drawNumberWidget(guiGraphics, numberSetting, x, y, width, widgetX, widgetY, widgetWidth, widgetHeight, iconX, iconY, editing, alpha, scale);
|
||||
return rowHeight;
|
||||
@@ -177,30 +176,35 @@ implements SettingRenderer {
|
||||
FontRenderer nameFont = FontPresets.axiformaRegular(14.0f * scale);
|
||||
FontRenderer valueFont = FontPresets.axiformaBold(14.0f * scale);
|
||||
FontRenderer signFont = FontPresets.axiformaBold(12.0f * scale);
|
||||
GlyphMetrics nameMetrics = nameFont.getMetrics();
|
||||
float nameY = centerY - (nameMetrics.ascent() + nameMetrics.descent()) / 2.0f + nameMetrics.ascent() + 6.0f * scale;
|
||||
|
||||
float nameY = centerY - nameFont.getMetrics().capHeight() / 2.0f;
|
||||
TextGlow.drawGlowText(numberSetting.getName(), x, nameY, nameFont, this.applyAlpha(-1, alpha), this.applyAlpha(new Color(255, 255, 255, 120).getRGB(), alpha), 8.0f * scale);
|
||||
this.drawEditIcon(guiGraphics, iconX, iconY, numberSetting, alpha, scale);
|
||||
|
||||
int sidePadding = Math.round(12.0f * scale);
|
||||
RenderUtil.drawRoundedRect(guiGraphics.pose(), widgetX, widgetY, widgetWidth, widgetHeight, 5.0f * scale, this.applyAlpha(0x50F5F5F5, alpha));
|
||||
int middleX = widgetX + sidePadding;
|
||||
int middleWidth = widgetWidth - sidePadding * 2;
|
||||
RenderUtil.drawRoundedRect(guiGraphics.pose(), middleX, widgetY, middleWidth, widgetHeight, 0.0f, this.applyAlpha(1086900424, alpha));
|
||||
GlyphMetrics signMetrics = signFont.getMetrics();
|
||||
float widgetCenterY = (float)widgetY + (float)widgetHeight / 2.0f;
|
||||
float signY = widgetCenterY - (signMetrics.ascent() + signMetrics.descent()) / 2.0f + signMetrics.ascent() + 5.0f * scale - 2.5f;
|
||||
int minusColor = this.minusButtonHover.getOrDefault(numberSetting, false) != false ? new Color(255, 255, 255).getRGB() : -1;
|
||||
GlHelper.drawText("-", (float)widgetX + (float)sidePadding / 2.0f - GlHelper.getStringWidth("-", signFont) / 2.0f, signY, signFont, this.applyAlpha(minusColor, alpha));
|
||||
int plusColor = this.plusButtonHover.getOrDefault(numberSetting, false) != false ? new Color(255, 255, 255).getRGB() : -1;
|
||||
GlHelper.drawText("+", (float)(widgetX + widgetWidth - sidePadding) + ((float)sidePadding / 2.0f - GlHelper.getStringWidth("+", signFont) / 2.0f), signY, signFont, this.applyAlpha(plusColor, alpha));
|
||||
String dup = displayText = editing ? editingText : this.formatValue(numberSetting.getValue().doubleValue());
|
||||
|
||||
float widgetCenterY = widgetY + widgetHeight / 2.0f;
|
||||
float signY = widgetCenterY - signFont.getMetrics().capHeight() / 2.0f;
|
||||
|
||||
int minusColor = this.minusButtonHover.getOrDefault(numberSetting, false) ? new Color(255, 255, 255).getRGB() : -1;
|
||||
GlHelper.drawText("-", widgetX + sidePadding / 2.0f - GlHelper.getStringWidth("-", signFont) / 2.0f, signY, signFont, this.applyAlpha(minusColor, alpha));
|
||||
|
||||
int plusColor = this.plusButtonHover.getOrDefault(numberSetting, false) ? new Color(255, 255, 255).getRGB() : -1;
|
||||
GlHelper.drawText("+", widgetX + widgetWidth - sidePadding + sidePadding / 2.0f - GlHelper.getStringWidth("+", signFont) / 2.0f, signY, signFont, this.applyAlpha(plusColor, alpha));
|
||||
|
||||
displayText = editing ? editingText : this.formatValue(numberSetting.getValue().doubleValue());
|
||||
if (editing && displayText.isEmpty()) {
|
||||
displayText = "0";
|
||||
}
|
||||
|
||||
float displayWidth = GlHelper.getStringWidth(displayText, valueFont);
|
||||
float displayX = (float)widgetX + (float)widgetWidth / 2.0f - displayWidth / 2.0f;
|
||||
GlyphMetrics valueMetrics = valueFont.getMetrics();
|
||||
float displayY = signY + scale - 1.5f;
|
||||
float displayX = widgetX + widgetWidth / 2.0f - displayWidth / 2.0f;
|
||||
float displayY = widgetCenterY - valueFont.getMetrics().capHeight() / 2.0f;
|
||||
|
||||
if (editing) {
|
||||
long now = System.currentTimeMillis();
|
||||
float cyclePos = (float)(now % 1000L) / 1000.0f;
|
||||
@@ -208,12 +212,12 @@ implements SettingRenderer {
|
||||
int textAlpha = (int)(255.0f * (0.6f + sineWave * 0.4f) * alpha);
|
||||
int textColor = textAlpha << 24 | 0xFFFFFF;
|
||||
GlHelper.drawText(displayText, displayX, displayY, valueFont, textColor);
|
||||
|
||||
float caretX = displayX + displayWidth + 2.0f * scale;
|
||||
int caretAlpha = (int)(255.0f * sineWave * alpha);
|
||||
int caretColor = caretAlpha << 24 | 0xFFFFFF;
|
||||
float caretHeight = valueMetrics.capHeight();
|
||||
float caretY = displayY - valueMetrics.ascent() + (valueMetrics.ascent() - caretHeight) / 2.0f;
|
||||
RenderUtil.drawFilledRect(guiGraphics.pose(), caretX, caretY, Math.round(scale), Math.round(caretHeight), caretColor);
|
||||
float caretHeight = valueFont.getMetrics().capHeight();
|
||||
RenderUtil.drawFilledRect(guiGraphics.pose(), caretX, displayY, Math.max(1.0f, Math.round(scale)), caretHeight, caretColor);
|
||||
} else {
|
||||
int glowColor = new Color(255, 255, 255, 120).getRGB();
|
||||
TextGlow.drawGlowText(displayText, displayX, displayY, valueFont, this.applyAlpha(-1, alpha), this.applyAlpha(glowColor, alpha), 6.0f * scale);
|
||||
@@ -235,9 +239,10 @@ implements SettingRenderer {
|
||||
FontRenderer iconFont = FontPresets.materialIcons(iconSize);
|
||||
String iconText = "\uE3C9";
|
||||
float iconTextWidth = GlHelper.getStringWidth(iconText, iconFont);
|
||||
GlyphMetrics iconMetrics = iconFont.getMetrics();
|
||||
float drawX = (float)iconX + ((float)iconSize - iconTextWidth) / 2.0f;
|
||||
float drawY = (float)iconY + (float)iconSize / 2.0f - (iconMetrics.ascent() + iconMetrics.descent()) / 2.0f + iconMetrics.ascent() + 1.0f;
|
||||
|
||||
float drawX = iconX + (iconSize - iconTextWidth) / 2.0f;
|
||||
float drawY = iconY + iconSize / 2.0f - iconFont.getMetrics().capHeight() / 2.0f;
|
||||
|
||||
GlHelper.drawText(iconText, drawX, drawY, iconFont, this.applyAlpha(iconColor, alpha));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user