Created
September 2, 2016 23:54
-
-
Save LordNed/38502635113f8b606115f0570648773a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Sandbox.h" | |
#include "SandboxStatics.h" | |
USandboxStatics::USandboxStatics(const FObjectInitializer& ObjectInitializer) | |
: Super(ObjectInitializer) | |
{ | |
} | |
void USandboxStatics::GetStringHeightAndWidth(const UFont *Font, const FString & InString, int32& Height, int32& Width) | |
{ | |
Font->GetStringHeightAndWidth(InString, Height, Width); | |
} | |
FString USandboxStatics::CalculateMaxCharacterLength(FString InString, const UFont* Font, const float MaximumDrawLength) | |
{ | |
FString RemainingString = FString(InString); | |
do | |
{ | |
int32 Height, Width; | |
Font->GetStringHeightAndWidth(RemainingString, Height, Width); | |
if (Width < MaximumDrawLength) | |
return RemainingString; | |
// The string is still too wide for where we're trying to place it, remove another character. | |
RemainingString.RemoveAt(RemainingString.Len() - 1, 1, false); | |
} while (InString.Len() > 0); | |
return FString(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UCLASS() | |
class SANDBOX_API USandboxStatics : public UBlueprintFunctionLibrary | |
{ | |
GENERATED_UCLASS_BODY() | |
public: | |
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Game|UI|Font", DisplayName = "Get String Height and Width", meta = (WorldContext = "WorldContextObject")) | |
static void GetStringHeightAndWidth(const UFont *Font, const FString & InString, int32& Height, int32& Width); | |
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Game|UI|Font", DisplayName = "Calculate Max Character Length", meta = (WorldContext = "WorldContextObject")) | |
static FString CalculateMaxCharacterLength(FString InString, const UFont* Font, const float MaximumDrawLength); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment