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

Method clipText

Engine/source/gui/core/guiControl.cpp:2400–2439  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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