From 52a0af4dfb55b70e9cc6f6923c5e9c3f460ce72e Mon Sep 17 00:00:00 2001 From: Mikalai Kryvusha Date: Sun, 11 Oct 2026 16:17:09 +0300 Subject: [PATCH 1/2] Fit the slider value box to its text instead of a fixed 50px DrawRangeField drew the number box and the percent label with GUILayout.Width(50), so with a bigger font (4K, custom skin) the value was clipped ("-0.", "0.(") and "100%" wrapped to a second line. The width now fits the longest of the value, the minimum and the maximum in the current style (plus its margin), measured on a sample of zeros so the box does not jump while the slider is dragged, and is never narrower than the old 50. --- .../SettingFieldDrawer.cs | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/ConfigurationManager.Shared/SettingFieldDrawer.cs b/ConfigurationManager.Shared/SettingFieldDrawer.cs index 6697f0c..7524bd7 100644 --- a/ConfigurationManager.Shared/SettingFieldDrawer.cs +++ b/ConfigurationManager.Shared/SettingFieldDrawer.cs @@ -275,6 +275,26 @@ private static GUIContent ObjectToGuiContent(object x) return new GUIContent(x.ToString()); } + /// + /// Width of the value box next to a slider: fits the longest of the given texts in the current style (so a bigger font or a + /// custom skin does not clip the number), never narrower than the old fixed 50. Measured on a sample of zeros of that length, + /// not on the value itself, so the box does not change width while the slider is dragged. + /// + private static float RangeValueWidth(GUIStyle style, params string[] texts) + { + var length = 0; + var negative = false; + foreach (var text in texts) + { + if (text == null) continue; + length = Math.Max(length, text.Length); + negative |= text.StartsWith("-"); + } + var sample = (negative ? "-" : "") + new string('0', Math.Max(1, length - (negative ? 1 : 0))); + // The style's margin is added too: the percent label sits inside a horizontal group, and without it "100%" wrapped. + return Mathf.Max(50, style.CalcSize(ImguiUtils.Content(sample)).x + style.margin.horizontal); + } + private static void DrawRangeField(SettingEntryBase setting) { var value = setting.Get(); @@ -293,12 +313,14 @@ private static void DrawRangeField(SettingEntryBase setting) { DrawCenteredLabel( Mathf.Round(100 * Mathf.Abs(result - leftValue) / Mathf.Abs(rightValue - leftValue)) + "%", - GUILayout.Width(50)); + GUILayout.Width(RangeValueWidth(GUI.skin.label, "100%"))); } else { var strVal = Convert.ToString(value, CultureInfo.InvariantCulture).AppendZeroIfFloat(setting.SettingType); - var strResult = GUILayout.TextField(strVal, GUILayout.Width(50)); + var strMin = Convert.ToString(setting.AcceptableValueRange.Key, CultureInfo.InvariantCulture).AppendZeroIfFloat(setting.SettingType); + var strMax = Convert.ToString(setting.AcceptableValueRange.Value, CultureInfo.InvariantCulture).AppendZeroIfFloat(setting.SettingType); + var strResult = GUILayout.TextField(strVal, GUILayout.Width(RangeValueWidth(GUI.skin.textField, strVal, strMin, strMax))); if (strResult != strVal) { try From 5f1cddfdbc0a4f02bdec146174ea49791c7d3f8b Mon Sep 17 00:00:00 2001 From: Mikalai Kryvusha Date: Sun, 11 Oct 2026 16:48:14 +0300 Subject: [PATCH 2/2] Share one width between all slider value boxes so they line up Per review: every value box and percent label next to a slider now uses one global width, so they stand in one column. It only grows: a value that needs more room bumps it for all of them, up to 10 characters, and it never goes below the old 50. It is reset in ClearCache, when the window opens or closes, so a font or skin change is picked up on the next open. --- .../SettingFieldDrawer.cs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/ConfigurationManager.Shared/SettingFieldDrawer.cs b/ConfigurationManager.Shared/SettingFieldDrawer.cs index 7524bd7..4dd6855 100644 --- a/ConfigurationManager.Shared/SettingFieldDrawer.cs +++ b/ConfigurationManager.Shared/SettingFieldDrawer.cs @@ -84,6 +84,7 @@ public void DrawSettingValue(SettingEntryBase setting) public static void ClearCache() { _comboBoxCache.Clear(); + _rangeValueWidth = 0; foreach (var tex in _colorCache) UnityEngine.Object.Destroy(tex.Value.Tex); @@ -276,9 +277,19 @@ private static GUIContent ObjectToGuiContent(object x) } /// - /// Width of the value box next to a slider: fits the longest of the given texts in the current style (so a bigger font or a - /// custom skin does not clip the number), never narrower than the old fixed 50. Measured on a sample of zeros of that length, - /// not on the value itself, so the box does not change width while the slider is dragged. + /// Width shared by every value box and percent label next to a slider, so they line up in one column. It only grows: a value + /// that needs more room bumps it for all of them, up to characters. Reset when the window + /// opens or closes (), so a font or skin change is picked up on the next open. + /// + private static float _rangeValueWidth; + + private const float RangeValueMinWidth = 50f; + private const int RangeValueMaxChars = 10; + + /// + /// Fits the longest of the given texts in the current style (so a bigger font or a custom skin does not clip the number) and + /// returns the shared width, never narrower than the old fixed 50. Measured on a sample of zeros of that length, not on the + /// value itself, so the box does not change width while the slider is dragged. /// private static float RangeValueWidth(GUIStyle style, params string[] texts) { @@ -290,9 +301,12 @@ private static float RangeValueWidth(GUIStyle style, params string[] texts) length = Math.Max(length, text.Length); negative |= text.StartsWith("-"); } + length = Math.Min(length, RangeValueMaxChars); var sample = (negative ? "-" : "") + new string('0', Math.Max(1, length - (negative ? 1 : 0))); // The style's margin is added too: the percent label sits inside a horizontal group, and without it "100%" wrapped. - return Mathf.Max(50, style.CalcSize(ImguiUtils.Content(sample)).x + style.margin.horizontal); + var fit = style.CalcSize(ImguiUtils.Content(sample)).x + style.margin.horizontal; + _rangeValueWidth = Mathf.Max(_rangeValueWidth, RangeValueMinWidth, fit); + return _rangeValueWidth; } private static void DrawRangeField(SettingEntryBase setting)