From bcf4e71558bc67b29143e35d4beef6429b9cd1db Mon Sep 17 00:00:00 2001 From: LeonardoVAC Date: Fri, 16 Oct 2026 00:29:39 -0300 Subject: [PATCH] fix: Browser tabs cut off text labels --- src/TerraSharp/UI/GridBrowser.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/TerraSharp/UI/GridBrowser.cs b/src/TerraSharp/UI/GridBrowser.cs index 450f7be..3d0cd1b 100644 --- a/src/TerraSharp/UI/GridBrowser.cs +++ b/src/TerraSharp/UI/GridBrowser.cs @@ -71,7 +71,11 @@ public abstract class GridBrowser(string id, string title, Vector2 position, int const int TabGap = 4; int iconTabs = tabs.Count(tab => tab.Icon >= 0); 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; bool changed = false; int x = body.X; @@ -79,7 +83,7 @@ public abstract class GridBrowser(string id, string title, Vector2 position, int { BrowserCategory tab = tabs[i]; 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; if (Widgets.Button(bounds, iconTab ? "" : tab.Name, i == selected, scale) && i != selected) {