fix: Browser tabs cut off text labels

This commit is contained in:
VAC committed 2026-10-16 00:29:39 -03:00
1 parent be429a9448
commit bcf4e71558
1 file changed
+6 -2
+6 -2
View File
@@ -71,7 +71,11 @@ public abstract class GridBrowser(string id, string title, Vector2 position, int
const int TabGap = 4; const int TabGap = 4;
int iconTabs = tabs.Count(tab => tab.Icon >= 0); int iconTabs = tabs.Count(tab => tab.Icon >= 0);
int textTabs = tabs.Length - iconTabs; int textTabs = tabs.Length - iconTabs;
int textWidth = textTabs == 0 ? 0 : (body.Width - TabGap * (tabs.Length - 1) - iconTabs * IconTabWidth) / textTabs; int available = body.Width - TabGap * (tabs.Length - 1);
int LabelWidth(BrowserCategory tab) => (int)Math.Ceiling(Render.Measure(tab.Name, scale).X) + 16;
int labels = tabs.Where(tab => tab.Icon < 0).Sum(LabelWidth);
int iconWidth = iconTabs == 0 ? 0 : Math.Max(24, Math.Min(IconTabWidth, (available - labels) / iconTabs));
int spare = textTabs == 0 ? 0 : (available - labels - iconTabs * iconWidth) / textTabs;
Texture2D? icons = iconTabs > 0 ? GameTextures.Request("Images/UI/Creative/Infinite_Icons") : null; Texture2D? icons = iconTabs > 0 ? GameTextures.Request("Images/UI/Creative/Infinite_Icons") : null;
bool changed = false; bool changed = false;
int x = body.X; int x = body.X;
@@ -79,7 +83,7 @@ public abstract class GridBrowser(string id, string title, Vector2 position, int
{ {
BrowserCategory tab = tabs[i]; BrowserCategory tab = tabs[i];
bool iconTab = tab.Icon >= 0; bool iconTab = tab.Icon >= 0;
var bounds = new Rectangle(x, y, iconTab ? IconTabWidth : textWidth, height); var bounds = new Rectangle(x, y, iconTab ? iconWidth : LabelWidth(tab) + spare, height);
x += bounds.Width + TabGap; x += bounds.Width + TabGap;
if (Widgets.Button(bounds, iconTab ? "" : tab.Name, i == selected, scale) && i != selected) if (Widgets.Button(bounds, iconTab ? "" : tab.Name, i == selected, scale) && i != selected)
{ {