Skip to content

Fit the slider value box to its text instead of a fixed 50px - #127

Merged
ManlyMarco merged 2 commits into
BepInEx:masterfrom
MikalaiKryvusha:range-field-width
Oct 14, 2026
Merged

ManlyMarco merged 2 commits into
BepInEx:masterfrom
MikalaiKryvusha:range-field-width

Conversation

@MikalaiKryvusha

@MikalaiKryvusha MikalaiKryvusha commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

DrawRangeField draws the number box next to a slider, and the percent label, with a fixed GUILayout.Width(50). With a bigger font (a 4K screen, or a custom skin through WindowSkin) the value gets clipped (-0., 0.() and 100% wraps to a second line.

The width now fits the text in the current style, and one width is shared by all of them so they line up (per review):

  • it is measured on the longest of the current value, the minimum and the maximum of the range, plus the style's margin (the percent label sits inside a horizontal group, and without the margin 100% still wrapped);
  • it is measured on a sample of zeros of that length, not on the value itself, so the box does not jump while the slider is dragged;
  • the width is global and only grows: a value that needs more room bumps it for every slider, up to 10 characters; it is reset when the window opens or closes, so a font or skin change is picked up;
  • it is never narrower than the old 50, so the default look does not change.

Tested in a Unity 2020.3 game: at 3840×2160 with a large font 480.0, 2.0, 0.7 fit whole and 100%, 25% stay on one line; at 1280×720 all value boxes and percent labels stand in one column of the same width.

This is the last one from me, thank you again!

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.
Comment thread ConfigurationManager.Shared/SettingFieldDrawer.cs
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.
@ManlyMarco
ManlyMarco merged commit 7b25a86 into BepInEx:master Oct 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants