TSharedRef<SWidget> UTextBlockComponent::RebuildWidget() { return SNew(STextBlock) .Text( BIND_UOBJECT_ATTRIBUTE(FString, GetDisplayText) ) .Font( FSlateFontInfo(FPaths::EngineContentDir() / TEXT("Slate/Fonts/Roboto-Bold.ttf"), 24) ) .ColorAndOpacity( BIND_UOBJECT_ATTRIBUTE(FSlateColor, GetColorAndOpacity) ) .ShadowOffset(FVector2D(1.0f, 1.0f)) .ShadowColorAndOpacity( BIND_UOBJECT_ATTRIBUTE(FLinearColor, GetShadowColorAndOpacity) ); }
TSharedRef<SWidget> UUserWidget::MakeViewportWidget(TSharedPtr<SWidget>& UserSlateWidget) { UserSlateWidget = TakeWidget(); return SNew(SConstraintCanvas) + SConstraintCanvas::Slot() .Offset(BIND_UOBJECT_ATTRIBUTE(FMargin, GetFullScreenOffset)) .Anchors(BIND_UOBJECT_ATTRIBUTE(FAnchors, GetViewportAnchors)) .Alignment(BIND_UOBJECT_ATTRIBUTE(FVector2D, GetFullScreenAlignment)) [ UserSlateWidget.ToSharedRef() ]; }
void UUserWidget::AddToScreen(ULocalPlayer* Player, int32 ZOrder) { if ( !FullScreenWidget.IsValid() ) { // First create and initialize the variable so that users calling this function twice don't // attempt to add the widget to the viewport again. TSharedRef<SConstraintCanvas> FullScreenCanvas = SNew(SConstraintCanvas); FullScreenWidget = FullScreenCanvas; TSharedRef<SWidget> UserSlateWidget = TakeWidget(); FullScreenCanvas->AddSlot() .Offset(BIND_UOBJECT_ATTRIBUTE(FMargin, GetFullScreenOffset)) .Anchors(BIND_UOBJECT_ATTRIBUTE(FAnchors, GetViewportAnchors)) .Alignment(BIND_UOBJECT_ATTRIBUTE(FVector2D, GetFullScreenAlignment)) [ UserSlateWidget ]; // If this is a game world add the widget to the current worlds viewport. UWorld* World = GetWorld(); if ( World && World->IsGameWorld() ) { if ( UGameViewportClient* ViewportClient = World->GetGameViewport() ) { if ( Player ) { ViewportClient->AddViewportWidgetForPlayer(Player, FullScreenCanvas, ZOrder); } else { // We add 10 to the zorder when adding to the viewport to avoid // displaying below any built-in controls, like the virtual joysticks on mobile builds. ViewportClient->AddViewportWidgetContent(FullScreenCanvas, ZOrder + 10); } // Just in case we already hooked this delegate, remove the handler. FWorldDelegates::LevelRemovedFromWorld.RemoveAll(this); // Widgets added to the viewport are automatically removed if the persistent level is unloaded. FWorldDelegates::LevelRemovedFromWorld.AddUObject(this, &UUserWidget::OnLevelRemovedFromWorld); } } } else { FMessageLog("PIE").Warning(FText::Format(LOCTEXT("WidgetAlreadyOnScreen", "The widget '{0}' was already added to the screen."), FText::FromString(GetClass()->GetName()))); } }
TSharedRef<SWidget> USpinningImageComponent::RebuildWidget() { return SNew(SSpinningImage) .Image( &Image ) .ColorAndOpacity( BIND_UOBJECT_ATTRIBUTE(FSlateColor, GetColorAndOpacity) ) .Period( Period ); }