diff --git a/libs/UEngine/UEWidgets.cpp b/libs/UEngine/UEWidgets.cpp index bba186e..80df104 100644 --- a/libs/UEngine/UEWidgets.cpp +++ b/libs/UEngine/UEWidgets.cpp @@ -1,3 +1,4 @@ +#pragma once #include "UEWidgets.hpp" #include "Engine_classes.hpp" @@ -15,6 +16,7 @@ void ApplyPositionOffset(SDK::UUserWidget* Widget, float offset, SDK::FVector2D void ApplyTransformOffset(SDK::UWidget* Widget, float OffsetX, float OffsetY) { if (!Widget) return; + SDK::FWidgetTransform Transform = Widget->RenderTransform; Transform.Translation.X = OffsetX; // Horizontal shifting Transform.Translation.Y = OffsetY; // Vertical shifting (optional) @@ -23,17 +25,18 @@ void ApplyTransformOffset(SDK::UWidget* Widget, float OffsetX, float OffsetY) { void CenterWidget(SDK::UUserWidget* Widget, float offset, float screenWidth, float screenHeight, float targetWidth, float targetHeight, float compensation) { if (!Widget) return; - float aspectRatio = screenWidth / screenHeight; - float targetAspect = targetWidth / targetHeight; + float aspectRatio = screenWidth / screenHeight; + float targetAspect = targetWidth / targetHeight; + + float scale = 1.f; if (aspectRatio > targetAspect) { - float scale = targetHeight / screenHeight; // horizontal scale to apply to get the same vertical size as 1080p + scale = targetHeight / screenHeight; // horizontal scale to apply to get the same vertical size as 1080p targetWidth = (float)screenWidth * scale; } targetWidth -= offset * 2; - Widget->SetDesiredSizeInViewport(SDK::FVector2D(targetWidth, targetHeight)); - Widget->SetPositionInViewport(SDK::FVector2D(offset, 0.f), true); + Widget->SetPositionInViewport(SDK::FVector2D(offset / scale, 0.f), true); ApplyTransformOffset(Widget, compensation, 0); } @@ -180,7 +183,7 @@ static void ApplyOverlayOffsetRecursive_Internal(SDK::UWidget* Widget, float lef return true; } return false; - }; + }; auto AdjustOverlaySlot = [&](SDK::UOverlaySlot* Slot) { if (!Slot || IsExcluded(Widget)) return; @@ -192,7 +195,7 @@ static void ApplyOverlayOffsetRecursive_Internal(SDK::UWidget* Widget, float lef Padding.Right = right; } Slot->SetPadding(Padding); - }; + }; if (Widget->Slot && Widget->Slot->IsA(SDK::UOverlaySlot::StaticClass())) AdjustOverlaySlot((SDK::UOverlaySlot*)Widget->Slot);