| 2413 | //----------------------------------------------------------------------------- |
| 2414 | |
| 2415 | U32 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 |
nothing calls this directly
no test coverage detected