I’m building a slate widget and I need to position the residing elements precisely. Using .Padding has an effect, but padding does not use the same units as screen size or screen resolution, or FGeometry, or anything!
.Padding units are the product of screen size and DPI scaling. you can use GetDPIScaleBasedOnSize to get the current DPI scaling and then use that to calculate the current screen size in slate units. (this is for slate, its even easier for UMG, just GetViewportScale())
#include "Runtime/Engine/Classes/Engine/UserInterfaceSettings.h"/*this is for accessing GetDPIScaleBasedOnSize()*/
GEngine->GameViewport->GetViewportSize(viewportSize);
int32 X = FGenericPlatformMath::FloorToInt(viewportSize.X);/*notice here there is some rounding but the effect on location accuracy should be negligible*/
int32 Y = FGenericPlatformMath::FloorToInt(viewportSize.Y);
float DPI_Scale = GetDefault<UUserInterfaceSettings>(UUserInterfaceSettings::StaticClass())->GetDPIScaleBasedOnSize(FIntPoint(X, Y));
/*from here the DPI_Scale alters screen size as follows: if
viewportSize = (1920, 1080)
DPI_Scale = 0.54
adjustedViewportSize = (1/DPI_Scale) * viewportSize (got this first guess)*/
this all worked for me all directly within my slateWidget.cpp file
P.S. other software or hardware may contain other DPI effects which could interfere on a case by case basis.
2 Likes
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.