I’m building UI wokflow which greatly reduces time needed to build UI.
Most of it blueprint based but there are few small functions I had to add in C++. And I think it would be useful for many devs just to have these functions available in engine because functions are universal, nothing custom.
And with these functions integrated + PreConstruct event (already implemented in 4.16) I could remove code plugin and my UI worflow would be available to people as 100% blueprint solution
Normally I would prepare pull request but I honestly I’m not sure what is the best place for them in engine code. Although implementing it in engine should be really quick job
I’m just pasting my code here, it should be self-explanatory
-
Is Game World
.h
/** Returns true if we're playing on cook or standalone game in editor. */
UFUNCTION(BlueprintPure, Category = "Composite UI", Meta = (DisplayName = "Is Game World"))
static bool IsGameWorld();
.cpp
bool UCompositeUIFunctions::IsGameWorld()
{
UWorld* World = GEngine->GetWorld();
if (World != nullptr)
return (World->WorldType == EWorldType::Game);
return false;
}
-
Get Root Widget
.h
/** Returns the root widget of User Widget. */
UFUNCTION(BlueprintPure, Category = "Composite UI", Meta = (DisplayName = "Get Root Widget"))
static UWidget* GetRootWidget(const class UUserWidget* UserWidget);
.cpp
UWidget* UCompositeUIFunctions::GetRootWidget(const class UUserWidget* UserWidget)
{
if (UserWidget != nullptr)
return UserWidget->GetRootWidget();
return nullptr;
}
-
Get Text Size - how much space is occupied by given text?
.h
/** Returns size of rendered text. */
UFUNCTION(BlueprintPure, Category = "Composite UI| Text", Meta = (DisplayName = "Get Text Size"))
static FVector2D GetTextSize(const FString& Text, const FSlateFontInfo& FontInfo);
.cpp
FVector2D UCompositeUIFunctions::GetTextSize(const FString& Text, const FSlateFontInfo& FontInfo)
{
FVector2D Size;
if (!Text.IsEmpty() && FontInfo.HasValidFont())
{
TSharedRef<FSlateFontMeasure> FontMeasure = FSlateApplication::Get().GetRenderer()->GetFontMeasureService();
Size = FontMeasure->Measure(Text, FontInfo, 1.0);
}
return Size;
}
PS
The really old version of this UI workflow was available for some time on GitHub (but I wasn’t satisfied with its quality, wasn’t that easy to use as I wanted it to be). [FREE] Lucy: lightweight UI & Input framework - Community Content, Tools and Tutorials - Unreal Engine Forums