Skip to content

raylib Text: line wrapping ignores inline BBCode [FontSize]/[FontScale] run sizes (wraps at base font) #3532

Description

@vchelaru

Problem

raylib's Text wraps inline BBCode runs at the base font size. A fixed-width raylib Text
containing an enlarged inline run (a [FontSize=N] font swap or a [FontScale=N] multiplier) packs
words onto a base-measured line, so the enlarged run then spills past the wrap width — the same class
of bug fixed for the XNA-family (MonoGame/KNI/FNA) in #3529. raylib's inline-run size reporting was
already made font-aware in #3524; this is the remaining wrapping half.

This is the raylib follow-up split out of #3520 (which is now the XNA-family umbrella: size reporting
via #3523/#3524 and wrapping via #3529).

Root cause

The shared wrap loop IWrappedTextExtensions.UpdateLines (RenderingLibrary/Graphics/IWrappedText.cs)
now threads the current line's absolute stripped-text start index into a font-aware measurement seam,
IWrappedText.MeasureString(string, int absoluteStartIndexInStrippedText) (a default interface method
added in #3529, base-font fallback). RenderingLibrary.Graphics.Text overrides that seam; raylib's
Text does not
, so it uses the base MeasureString and wraps base-only. Separately, raylib's
CustomSetPropertyOnRenderable does not re-wrap after InlineVariables populate (the MonoGame copy
gained that in #3529), so even with the override the first wrap would remain blind to the runs.

Suggested fix (mirror #3529 on the raylib side)

  1. Override MeasureString(string, int absoluteStartIndexInStrippedText) in
    Runtimes/RaylibGum/Renderables/Text.cs to split the range into styled runs (GetStyledSubstrings)
    and sum each run measured at its own size, reusing raylib's ResolveRunFont / ResolveRunFontScale
    helpers (added in RaylibGum Text: inline BBCode [FontSize] font-swap runs not supported (only Color/FontScale) #3524) so drawn / measured / wrapped run sizes stay consistent. Return width in the
    same base units as the base MeasureString(string).
  2. Re-wrap after the runs populate: in Runtimes/RaylibGum/Renderables/CustomSetPropertyOnRenderable.cs
    call asText.UpdateWrappedText() before asText.UpdatePreRenderDimensions() (make raylib
    Text.UpdateWrappedText() public, mirroring the MonoGame change).
  3. Pins in Tests/RaylibGum.Tests: a red-first test where a fixed-width Text with an inline
    [FontSize]/[FontScale] run wraps earlier than the base-font wrap; keep the plain-text wrap
    behavior green.

Source

  • Runtimes/RaylibGum/Renderables/Text.cs — implements IWrappedText (~line 71), shared
    UpdateLines call in UpdateWrappedText (~681, currently private), GetInlineVariableAwareWidthAndHeight
    (~1063), ResolveRunFont (~875). Needs the MeasureString(string, int) override.
  • Runtimes/RaylibGum/Renderables/CustomSetPropertyOnRenderable.csRawText set at ~704,
    InlineVariables populated at ~767, #3481 re-measure at ~777–781. Insert the re-wrap before 781.
  • Reference implementation: PR Make line wrapping honor inline BBCode [FontSize]/[FontScale] runs (part of #3520) #3529 (RenderingLibrary/Graphics/Text.cs override +
    Text.MeasureStyledLineInBaseUnits, IWrappedText.cs seam + index threading,
    Gum/Wireframe/CustomSetPropertyOnRenderable.cs re-wrap).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions