When I make a new User Widget, and add a Canvas and a Text widget, and check “Size To Content”, there’s always some extra vertical padding above and below the actual text. Like this:
The left and right sides of the widget wrap pretty close to the text, but the top and bottom always has a substantial padding. There doesn’t seem to be any vertical alignment options, and I don’t have a margin or anything, so…?
Is there at least some way to measure what that distance is?
Well, me, the bottom part of what you’re asking about is referred to as the “baseline” in typography. Not quite sure how to get that in a blueprint, but in C++ you can grab it like this:
int32_t marginSize = 4, fontSize = 128;
TSharedRef<FSlateFontMeasure> fontMeasureService = (FSlateApplication::Get().GetRenderer()->GetFontMeasureService());
FSlateFontInfo fontInfo = FCoreStyle::GetDefaultFontStyle("Regular", fontSize, FFontOutlineSettings(marginSize, FLinearColor::Black));
int16_t baseline = fontMeasureService->GetBaseline(fontInfo);
Obviously that size 128 is a bit ridiculous because you’re rendering some extra-large text, and this doesn’t get you the top… but it gets you what you were actually looking for, so, you’re welcome.