HUD & UI scaling improvements

This commit is contained in:
2026-02-27 22:48:51 +01:00
parent 3d582c6a63
commit 0e1bfcb9c8

View File

@@ -61,34 +61,46 @@ void ReactivateDevConsole(std::shared_ptr<spdlog::logger> 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<SDK::UCanvasPanelSlot*>(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<SDK::UCanvasPanelSlot*>(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<SDK::UVerticalBoxSlot*>(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<SDK::UPanelWidget*>(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<SDK::UUserWidget*>(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,