MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / clipText

Method clipText

Engine/source/gui/core/guiControl.cpp:2415–2454  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2413//-----------------------------------------------------------------------------
2414
2415U32 GuiControl::clipText( String &text, U32 clipWidth ) const
2416{
2417 PROFILE_SCOPE( GuiControl_clipText );
2418
2419 U32 textWidth = mProfile->mFont->getStrWidthPrecise( text );
2420
2421 if ( textWidth <= clipWidth )
2422 return textWidth;
2423
2424 // Start removing characters from the end of the string
2425 // until the string width plus the elipsesWidth is less
2426 // than clipWidth...
2427
2428 // Note this would be more efficient without calling
2429 // getStrWidthPrecise each loop iteration. eg. get the
2430 // length of each char, store in a temporary U32 array,
2431 // and then remove the number we need from the end all at once.
2432
2433 String temp;
2434
2435 while ( text.isNotEmpty() )
2436 {
2437 text.erase( text.length() - 1, 1 );
2438 temp = text;
2439 temp += "...";
2440 textWidth = mProfile->mFont->getStrWidthPrecise( temp );
2441
2442 if ( textWidth <= clipWidth )
2443 {
2444 text = temp;
2445 return textWidth;
2446 }
2447 }
2448
2449 // Uh, not even the ellipses will fit in the passed width.
2450 // Text should be an ellipses string now,
2451 // which is the right thing to do in this case.
2452
2453 return 0;
2454}
2455
2456//-----------------------------------------------------------------------------
2457

Callers

nothing calls this directly

Calls 4

getStrWidthPreciseMethod · 0.80
isNotEmptyMethod · 0.45
eraseMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected