// Copyright Epic Games, Inc. All Rights Reserved. #include "Components/NativeWidgetHost.h" #include "Widgets/SNullWidget.h" #include "Widgets/DeclarativeSyntaxSupport.h" #include "Widgets/Layout/SBorder.h" #include "Widgets/Text/STextBlock.h" #include "Widgets/Layout/SBox.h" #include "UMGStyle.h" #include UE_INLINE_GENERATED_CPP_BY_NAME(NativeWidgetHost) #define LOCTEXT_NAMESPACE "UMG" ///////////////////////////////////////////////////// // UNativeWidgetHost UNativeWidgetHost::UNativeWidgetHost(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { bIsVariable = false; } void UNativeWidgetHost::SetContent(TSharedRef InContent) { if (NativeWidget != InContent) { NativeWidget = InContent; TSharedPtr StableMyWidget = MyWidget.Pin(); if (StableMyWidget.IsValid()) { TSharedPtr MyBox = StaticCastSharedPtr(StableMyWidget); MyBox->SetContent(InContent); } } } void UNativeWidgetHost::ReleaseSlateResources(bool bReleaseChildren) { Super::ReleaseSlateResources(bReleaseChildren); NativeWidget.Reset(); } TSharedRef UNativeWidgetHost::RebuildWidget() { return SNew(SBox) [ ( NativeWidget.IsValid() ) ? NativeWidget.ToSharedRef() : GetDefaultContent() ]; } TSharedRef UNativeWidgetHost::GetDefaultContent() { if ( IsDesignTime() ) { return SNew(SBorder) .Visibility(EVisibility::HitTestInvisible) .BorderImage(FUMGStyle::Get().GetBrush("MarchingAnts")) .HAlign(HAlign_Center) .VAlign(VAlign_Center) [ SNew(STextBlock) .Text(LOCTEXT("NativeWidgetHostText", "Slate Widget Host")) ]; } else { return SNullWidget::NullWidget; } } #if WITH_EDITOR const FText UNativeWidgetHost::GetPaletteCategory() { return LOCTEXT("Primitive", "Primitive"); } #endif ///////////////////////////////////////////////////// #undef LOCTEXT_NAMESPACE