diff --git a/libs/UEngine/UETools.cpp b/libs/UEngine/UETools.cpp index 4759611..1888b09 100644 --- a/libs/UEngine/UETools.cpp +++ b/libs/UEngine/UETools.cpp @@ -61,34 +61,46 @@ void ReactivateDevConsole(std::shared_ptr logger) { } }).detach(); } - -static void ApplyCanvasOffsetsRecursive_Internal(SDK::UWidget* Widget, float Left, float Right, int CurrentDepth, int MaxDepth) { +// --- HUD & UI methods --- +static void ApplyOffsetsRecursive_Internal(SDK::UWidget* Widget, float Left, float Right, int CurrentDepth, int MaxDepth) { if (!Widget || CurrentDepth > MaxDepth) return; - // Apply offsets if CanvasPanelSlot - if (Widget->Slot && Widget->Slot->IsA(SDK::UCanvasPanelSlot::StaticClass())) { - auto* Slot = static_cast(Widget->Slot); - if (!Slot) return; - SDK::FMargin Offsets = Slot->GetOffsets(); - - if (Offsets.Left != Left || Offsets.Right != Right) { + // Apply offsets according to Slot type + if (Widget->Slot) { + if (Widget->Slot->IsA(SDK::UCanvasPanelSlot::StaticClass())) { + auto* Slot = static_cast(Widget->Slot); + SDK::FMargin Offsets = Slot->GetOffsets(); Offsets.Left = Left; Offsets.Right = Right; Slot->SetOffsets(Offsets); } + else if (Widget->Slot->IsA(SDK::UVerticalBoxSlot::StaticClass())) { + auto* Slot = static_cast(Widget->Slot); + SDK::FMargin Margin = Slot->Padding; + Margin.Left = Left; + Margin.Right = Right; + Slot->SetPadding(Margin); + } } - // Go deeper if PanelWidget + // Go deeper in children if we got a Panel if (Widget->IsA(SDK::UPanelWidget::StaticClass()) && CurrentDepth < MaxDepth) { auto* Panel = static_cast(Widget); int childrenCount = Panel->GetChildrenCount(); for (int i = 0; i < childrenCount; ++i) { - ApplyCanvasOffsetsRecursive_Internal( Panel->GetChildAt(i), Left, Right, CurrentDepth + 1, MaxDepth); + ApplyOffsetsRecursive_Internal(Panel->GetChildAt(i), Left, Right, CurrentDepth + 1, MaxDepth); + } + } + // Go deeper if the widget is an UserWidget + if (Widget->IsA(SDK::UUserWidget::StaticClass())) { + auto* ChildWidget = static_cast(Widget); + if (ChildWidget->WidgetTree && ChildWidget->WidgetTree->RootWidget) { + ApplyOffsetsRecursive_Internal(ChildWidget->WidgetTree->RootWidget, Left, Right, CurrentDepth + 1, MaxDepth); } } } void ApplyOffsetsRecursive(SDK::UWidget* Widget, float Left, float Right, int MaxDepth) { - ApplyCanvasOffsetsRecursive_Internal( Widget, Left, Right, 0, MaxDepth); + ApplyOffsetsRecursive_Internal(Widget, Left, Right, 0, MaxDepth); } static void ApplyOverlayOffsetRecursive_Internal(SDK::UWidget* Widget, float Offset, SDK::EHorizontalAlignment alignment,