When creating a style, are the font style and font size coupled together?

anonymous_user_253f9674
Thu, 17 May 2018 21:43:22 +0000
Rendering

I’m trying to figure out the TTF_FONT macro when creating my style set. I have a specific color and specific font that I want to make available as a style, but there are multiple font sizes that I want to utilize.

From my style file:

...

#define TTF_FONT(RelativePath, ...) FSlateFontInfo(FPaths::GameContentDir() / "Resources" / RelativePath + TEXT(".ttf"), __VA_ARGS__)

...

Style.Set("MyFontStyle", FTextBlockStyle(FTextBlockStyle::GetDefault())
     .SetColorAndOpacity(FSlateColor(FLinearColor(1.0f, 0.74902f, 0729412f)))
     .SetFont(TTF_FONT("Verdana", 40)));

Note that very last line – if I don’t supply both the font and a size, compiling complains.

When I apply the style to my Slate widget:

...

SNew(STextBlock)
.TextStyle(MyStyleSet::Get(), "MyFontStyle")
.Text(LOCTEXT("Hello World")

...

I thought perhaps I could use this style with a set font, and then when I apply the style to a STextBlock widget, I could then override the style’s font with a .FontSize or something, but nothing like that seems to exist. Does this mean the font and size are coupled together? Do I really need to make a separate style for every size of this text block style that I want to utilize?

Thanks in advance for any insight!

2 posts - 2 participants