Fix GuiGetTextWidth() to measure multi-line text correctly#540
Open
shyraptor wants to merge 1 commit intoraysan5:masterfrom
Open
Fix GuiGetTextWidth() to measure multi-line text correctly#540shyraptor wants to merge 1 commit intoraysan5:masterfrom
shyraptor wants to merge 1 commit intoraysan5:masterfrom
Conversation
Resolves raysan5#415. GuiGetTextWidth() stopped at the first '\n', so auto-sized widgets (GuiLabel, GuiMessageBox, ...) clipped multi-line text. Factor the existing single-line measurement into a new static GetLineWidth() helper and turn GuiGetTextWidth() into a wrapper that iterates '\n'-separated lines and returns the maximum line width. GuiDrawText() now calls GetLineWidth() directly for per-line text positioning, so its existing per-line alignment behavior is preserved byte-for-byte (the icon is already stripped by GetTextIcon() before measurement, so GetLineWidth() takes no icon path there). Incidental corrections in GetLineWidth() vs. the old GuiGetTextWidth() body, to bring it into agreement with GetTextIcon(): - The icon-marker skip now uses text += (pos + 1) to land past the closing '#', matching GetTextIcon(). Previously it was text += textIconOffset where textIconOffset was the index OF the closing '#', leaving that '#' in the measured string and over-measuring icon-prefixed labels by ~1 glyph. - The icon marker is recognised only as '#' + 1..3 digits + '#', matching GetTextIcon(). The old detector accepted any character between the hashes, so e.g. "#abc#Text" was misclassified as an icon and the label width was computed incorrectly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #415.
GuiGetTextWidth()was stopping at the first'\n', so auto-sized widgets (GuiLabel,GuiMessageBox, ...) clipped multi-line text.Fix
GetLineWidth()helper — single-line measurement, identical to the oldGuiGetTextWidth()body except for the icon corrections below.GuiGetTextWidth()becomes a wrapper that iterates'\n'-separated lines and returnsmax(GetLineWidth(line)).GuiDrawText()now callsGetLineWidth()directly for per-line text positioning, preserving its existing alignment behavior byte-for-byte (the icon is already stripped byGetTextIcon()before measurement, soGetLineWidth()takes no icon path there).Incidental corrections in
GetLineWidth()Both corrections bring the icon-marker handling in line with the authoritative
GetTextIcon():text += (pos + 1)instead oftext += textIconOffset. The old code settextIconOffsetto the index of the closing#and then advanced by that, leaving the closing#in the measured string. This over-measured every icon-prefixed label by ~1 glyph.#+ 1..3 digits +#. The old detector accepted any character between the hashes, so e.g."#abc#Text"was misclassified as an icon and the label width was computed incorrectly.MRE (from #415)
Both examples in the issue body now render with the border/message box fully enclosing the multi-line text.