Download

Centering a text in a scrollbox?

I’ve done a bit of searching and can find no way to center text horizontally and vertically within a scrollbox. I would like the scroll box to consume a specific region of space and then center the text within it.

Can you be a little bit more specific about what you’re trying to achieve?

If I understand what you’re asking, you could center the text using Appearance -> Justification -> Align Text Center.

And you could keep the text centered vertically by having a Spacer both above and below it inside the scroll box, with Slot -> Size set to Fill.

Is that what you’re after?

There will probably better show what I’m aiming for:

I haven’t seen any space component in UMG but I can take another look when I have the time.

Actually, spacers don’t work quite the way I described when they’re inside a scroll box.

You’ll want to have just one spacer above the text, and you’ll need to do some calculations – subtract the height of the current text box from the height of the scrollbox itself and make the spacer half the remainder.

Let me know if you have trouble getting it to work.

The ‘text’ is set to Size To Content and you can control its width by *Wrap Text At *parameter.
The ‘canvas’ has *top padding *added.
The ‘border’ is optional, ofc.

Let us know if the solution is satisfactory.

Hello, I have been away past few days. I’ll explore these options first chance I get.

Everynone: I think using your suggested method will cause text to align to the top vertically if it’s not a full page of text. I’ll check, but I think that’s the issue I was running into.

Everynone’s idea mixed with your own should work. I could add padding based on calculations of text screen real-estate. However, I am unable to find where to obtain the Y size for a textblock. Documentation is empty and all similar questions I’ve founded through searching have gone unanswered.

c3091780e3ce5260cf4d845a53feddda.jpg

Vertical is fine I think, as I said the canvas has top padding. The horizontal is meh because of the scrollbar visibility, this can be fixed easily, though.

Everynone: the issue though is not whether there is padding, but how to set the padding such that the text is centred vertically. Doing this outside of a scroll box can be done by placing an auto-filling spacer above and below the content inside something like a vertical box. That way the spacers size to occupy the remaining space such that the text box floats perfectly in the middle. But… in a scrollbox that method doesn’t work.

Remove the padding, center the scrollbox vertically. Now the text always sits in the middle until it’s larger than the container, like so:

Is this the desired behaviour?

That’s what I was aiming for. I didn’t realize the scrollbox would resize as the text did if I set it to align center vertically.

Here is how I set it up, and it’s working. Thank you both.