Integrating these 3 little universal UI functions

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 :slight_smile:

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 :slight_smile:
I’m just pasting my code here, it should be self-explanatory :slight_smile:

  1. 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;
}


  1. 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;
}


  1. 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

#1 & #2 would be very useful in BP, I can remember times when I’ve wanted that functionality.

Knowing the difference between gameworld/editor is so useful for distinct editor functionality in BP constructors.
and I just ran into the problem of GetParent not being able to return the root userwidget

btw, you’ve accidentally included #3’s code for #2

You pasted the CPP file for #3 twice and missed #2 :slight_smile:

Oopsie… It’s fixed now :slight_smile: