[UMG] Text box text justification

Heyo!

I’m trying to get the text inside my text box justified to center, but I can’t seem to find the way to do it.

I can find this in a multi-line text box:


but I can’t find anything similar in a single-line text box.


Any advice on how to do it? :slight_smile:

Thanks!

Unfortunately the single-line editable text is currently the only Slate text widget that doesn’t use a text layout internally, and so doesn’t currently support text justification.

I have a task on my list to unify the internals of the two widgets as much as possible, however I couldn’t say when I might get to it. Sorry :frowning:

If you’re up for editing the code you could maybe hack in a quick version. I can provide more details if you’re interested in trying that out?

Okay, I’ve just taken a quick look at the code and I may have overstated the simplicity slightly :slight_smile:

How familiar are you with Slate?

Essentially what needs to happen is that the draw location of everything needs to be offset in SEditableText::OnPaint based on the justification used, FTextLayout::JustifyLayout shows what the text layout does to achieve this (except it’s offsetting the text blocks rather than hacking it into paint) - you could probably use GetDesiredSize() to get the size of the text currently in the editable text.

The part I’d initially forgotten you’d have to do, and this is where a text layout shines as it does this for you, is that your mouse input also has to be adjusted to compensate for the fact that the text is being drawn at an offset (see SEditableText::OnMouseButtonDown, SEditableText::OnMouseButtonUp, SEditableText::OnMouseMove, and SEditableText::OnMouseButtonDoubleClick). You can use FPointerEvent::MakeTranslatedEvent to adjust the hit position by the inverse of the transform applied in OnPaint before letting the function handle the mouse event.

I see, no wonder I couldn’t find it then, haha!

Sure, I’m interested! Thanks for taking the time to help me out. :slight_smile:

I’ll see what I can do! Thanks a bunch. :slight_smile:

Any news on this ?
You doing something for it rokesy ?