Loading...
Searching...
No Matches
ml::TextManipulators Class Reference

Static helpers for text layout and string manipulation. More...

#include <TextManipulators.h>

Static Public Member Functions

static std::string wordwrap (const sf::Text &text, float maxwidth)
 Wrap a string to fit within a pixel width, using an existing sf::Text.
static std::string wordwrap (const std::string &input, const sf::Font &font, unsigned int characterSize, float maxWidth)
 Wrap a string to fit within a pixel width, given explicit font settings.

Detailed Description

Static helpers for text layout and string manipulation.

TextManipulators provides the word-wrapping logic used internally by ml::Text when setWordWrap(true) is enabled. Both overloads insert newline characters into the string so that no rendered line exceeds a given pixel width.

Usage

// From an existing sf::Text (uses its current font and character size)
std::string wrapped = ml::TextManipulators::wordwrap(myText, 300.f);
myText.setString(wrapped);
// From raw string + explicit font settings
std::string wrapped = ml::TextManipulators::wordwrap(
"A long string...", font, 18, 300.f);
static std::string wordwrap(const sf::Text &text, float maxwidth)
Wrap a string to fit within a pixel width, using an existing sf::Text.
See also
Text

Definition at line 39 of file TextManipulators.h.

Member Function Documentation

◆ wordwrap() [1/2]

std::string ml::TextManipulators::wordwrap ( const sf::Text & text,
float maxwidth )
static

Wrap a string to fit within a pixel width, using an existing sf::Text.

Reads the font and character size from text, then inserts newlines at word boundaries so that no line exceeds maxwidth pixels when rendered with those settings.

Parameters
textAn sf::Text whose font and character size define the measurement context. The text's current string is used as the input.
maxwidthMaximum line width in pixels.
Returns
A new string with newlines inserted at appropriate word boundaries.

◆ wordwrap() [2/2]

std::string ml::TextManipulators::wordwrap ( const std::string & input,
const sf::Font & font,
unsigned int characterSize,
float maxWidth )
static

Wrap a string to fit within a pixel width, given explicit font settings.

Measures each word using font at characterSize and inserts newlines so that no line exceeds maxWidth pixels.

Parameters
inputThe string to wrap.
fontFont used to measure glyph widths.
characterSizeCharacter size in points used for measurement.
maxWidthMaximum line width in pixels.
Returns
A new string with newlines inserted at appropriate word boundaries.

The documentation for this class was generated from the following file: