FTextBlockStyle does not work at SEditableTextBox

This posting is based on engine version 5.3

Symptom

  1. When we use SEditableTextBox
  2. If we set an FTextBlockStyle inside the FEditableTextBoxStyle
  3. And if you set this style at the construction stage of the Slate statement, like below,
1
2
SNew(SEditableTextBox)
.Style(SomeStyleThatHasAFTextBlockStyle)
  1. FTextBlockStyle above, which is inside the FEditableTextBoxStyle, will not be applied.

Cause

The cause lies in SEditableTextBox::Construct()

  1. SEditableTextBox does not pass styles when creating TSharedPtr< SEditableText > EditableText inside Construct(). GitHub Link
  2. Instead, in earlier timing in the Construct(), SEditableTextBox try to set the style by calling a separate function, SEditableTextBox::SetStyle(). GitHub Link
  3. SEditableTextBox::SetStyle() calls SEditableTextBox::SetTextBlockStyle() at the end, and this function calls SEditableText::SetTextBlockStyle() to set FTextBlockStyle. GitHub Link
  4. Here, before SEditableTextBox::SetTextBlockStyle() calls SEditableText::SetTextBlockStyle(), the part that checks the validity of TSharedPtr< SEditableText > EditableText there is. If it is invalid, ````SEditableText::SetTextBlockStyle()will not be executed. And since this timing is before the creation ofTSharedPtr< SEditableText > EditableText, the setting of FTextBlockStyle``` is skipped. GitHub Link
  5. And without further action, SEditableTextBox::Construct() ends.
  6. As a result, in the construction of the SEditableText, the setting of FTextBlockStyle is always skipped.

Workaround

After the construction, because that validation check will succeed, so after the construction if we call the SEditableTextBox::SetStyle() or SEditableTextBox::SetTextBlockStyle(), we can apply the FTextBlockStyle to SEditableTextBox.

Like this:

1
2
3
4
...
SAssignNew(SomePtr, SEditableTextBox)
...
SomePtr->SetTextBlockStyle(SomeFTextBlockStyle));

I’ve been thinking about sending a pull request, but I’m hesitant because I’ve had several heartbreaking experiences with pull requests recently. The fact that this isn’t that lethal also makes me hesitate.

But for me, it was critical.


                        Before

Before


                        After

After

tags