102 lines
2.8 KiB
C++
102 lines
2.8 KiB
C++
////////////////////////////////////////////////////////////
|
|
//
|
|
// RootCanvas.cpp
|
|
//
|
|
////////////////////////////////////////////////////////////
|
|
|
|
#include "RootCanvas.h"
|
|
#include "Common.h"
|
|
#include "Blueprint/UserWidget.h"
|
|
|
|
UlxRootCanvasSlot::UlxRootCanvasSlot(const FObjectInitializer& ObjectInitializer)
|
|
: Super(ObjectInitializer)
|
|
{
|
|
// Children of the root canvas default to filling the parent,
|
|
// matching the viewport's "stretch" behavior. Individual widgets
|
|
// can still override anchors/offsets after being added.
|
|
SetAnchors(FAnchors(0.0f, 0.0f, 1.0f, 1.0f));
|
|
SetOffsets(FMargin(0.0f, 0.0f, 0.0f, 0.0f));
|
|
}
|
|
|
|
UClass* UlxRootCanvasPanel::GetSlotClass() const
|
|
{
|
|
return UlxRootCanvasSlot::StaticClass();
|
|
}
|
|
|
|
UlxRootCanvasSlot *UlxRootCanvasPanel::GetRootCanvasSlot(UUserWidget *Widget, ElxSuccessOrWrongType &Result)
|
|
{
|
|
if (IsValid(Widget))
|
|
{
|
|
if (UlxRootCanvasSlot *Slot = Cast<UlxRootCanvasSlot>(Widget->Slot))
|
|
{
|
|
Result = ElxSuccessOrWrongType::Success;
|
|
return Slot;
|
|
}
|
|
}
|
|
Result = ElxSuccessOrWrongType::WrongType;
|
|
return nullptr;
|
|
}
|
|
|
|
UlxRootCanvasSlot* UlxRootCanvasPanel::AddChildToRootCanvas(UWidget* Content)
|
|
{
|
|
return Cast<UlxRootCanvasSlot>(Super::AddChild(Content));
|
|
}
|
|
|
|
int32 UlxRootCanvasPanel::GetMaxZOrder() const
|
|
{
|
|
int32 MaxZOrder = 0;
|
|
for (UPanelSlot *PanelSlot : Slots)
|
|
{
|
|
UlxRootCanvasSlot *TypedSlot = Cast<UlxRootCanvasSlot>(PanelSlot);
|
|
check(TypedSlot);
|
|
MaxZOrder = FMath::Max(MaxZOrder, TypedSlot->GetZOrder());
|
|
}
|
|
return MaxZOrder;
|
|
}
|
|
|
|
TArray<UlxRootCanvasSlot*> UlxRootCanvasPanel::GetSortedUserWidgets()
|
|
{
|
|
TArray<UlxRootCanvasSlot*> Result;
|
|
Result.Reserve(Slots.Num());
|
|
for (UPanelSlot *PanelSlot : Slots)
|
|
{
|
|
UlxRootCanvasSlot *TypedSlot = Cast<UlxRootCanvasSlot>(PanelSlot);
|
|
check(TypedSlot);
|
|
if (Cast<UUserWidget>(TypedSlot->Content) == nullptr) continue;
|
|
Result.Add(TypedSlot);
|
|
}
|
|
Result.StableSort([](const UlxRootCanvasSlot &A, const UlxRootCanvasSlot &B)
|
|
{
|
|
return A.GetZOrder() > B.GetZOrder();
|
|
});
|
|
return Result;
|
|
}
|
|
|
|
|
|
void UlxRootCanvasPanel::SetWidgetWindowManagement(class UUserWidget *Widget,
|
|
bool ShowPointer, bool BlockInput, bool EnableEnhancedInput, bool BringToFront, UWidget *DesiredFocusWidget)
|
|
{
|
|
if (!IsValid(Widget))
|
|
{
|
|
UE_LOG(LogLuprexIntegration, Error, TEXT("ManageRootWidget called with an invalid widget."));
|
|
return;
|
|
}
|
|
UlxRootCanvasSlot *Slot = Cast<UlxRootCanvasSlot>(Widget->Slot);
|
|
if (Slot == nullptr)
|
|
{
|
|
UE_LOG(LogLuprexIntegration, Error, TEXT("Widget is not yet a root widget, use 'AddWidgetToRoot' first"));
|
|
return;
|
|
}
|
|
UlxRootCanvasPanel *Panel = Cast<UlxRootCanvasPanel>(Slot->Parent);
|
|
check(Panel);
|
|
Slot->ShowPointer = ShowPointer;
|
|
Slot->BlockInput = BlockInput;
|
|
Slot->EnableEnhancedInput = EnableEnhancedInput;
|
|
Widget->SetDesiredFocusWidget(DesiredFocusWidget);
|
|
if (BringToFront)
|
|
{
|
|
Slot->SetZOrder(Panel->GetMaxZOrder() + 1);
|
|
}
|
|
}
|
|
|