Avoid division by zero
This commit is contained in:
@@ -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 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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user