x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Updating Slate UI Layout On Click (Plugin code)

Hi everyone,

I've been trying to implement the UI for a plugin I'm making using Slate. However, I haven't been able to figure out how I can change the layout itself when a button is clicked. Since the button click should change the layout itself, I imagine there is a way to redraw the UI on demand, but I don't know how to do it.

In OnSpawnPluginTab, I bind a lambda expression to my button click. The expression simply turns a boolean flag to true (initially false). SpawnFLVBox() is the layout segment that I want to change. The code for it follows.

OnSpawnPluginTab:

 TSharedRef<SDockTab> FPickActsModule::OnSpawnPluginTab(const FSpawnTabArgs& SpawnTabArgs)
 {
     return SNew(SDockTab)
         .TabRole(ETabRole::NomadTab)
         [
             SNew(SVerticalBox)
             + SVerticalBox::Slot()
             .HAlign(HAlign_Center)
             .VAlign(VAlign_Center)
             .AutoHeight()
             [
                 SNew(STextBlock)
                 .Text(WidgetText)
             ]
             + SVerticalBox::Slot()
             .HAlign(HAlign_Fill)
             .VAlign(VAlign_Top)
             [
                 SNew(SButton)
                 .OnClicked_Lambda([this]()->FReply { _testFlag = true; return FReply::Handled(); })
             ]
             + SVerticalBox::Slot()
             .HAlign(HAlign_Fill)
             .VAlign(VAlign_Top)
             [
                 SpawnFLVBox()
             ]
         ];
 }

SpawnFLVBox:

 TSharedRef<SHorizontalBox> FPickActsModule::SpawnFLVBox()
 {
     TSharedRef<SHorizontalBox> horizontalBox = _testFlag ?
         // if true
         SNew(SHorizontalBox)
         + SHorizontalBox::Slot()
         [
             SNew(SEditableTextBox)
             .HintText(FText::FromString(TEXT("0")))
         ]
         + SHorizontalBox::Slot()
         [
             SNew(SEditableTextBox)
             .HintText(FText::FromString(TEXT("0")))
         ]:
         // if false
         SNew(SHorizontalBox)
         + SHorizontalBox::Slot()
         [
             SNew(SEditableTextBox)
             .HintText(FText::FromString(TEXT("0")))
         ]
         + SHorizontalBox::Slot()
         [
             SNew(SEditableTextBox)
             .HintText(FText::FromString(TEXT("0")))
         ]
         + SHorizontalBox::Slot()
         [
             SNew(SEditableTextBox)
             .HintText(FText::FromString(TEXT("0")))
         ];
 
     return horizontalBox;
 }

We can see in SpawnFLVBox that I simply check the flag, and draw 2 editable text boxes instead of 3 if the flag is true. However, when I click the button, the layout is not re-drawn, which makes sense because OnSpawnPluginTab is only called at the beginning. So my question is: how do I request a UI re-draw? How do I refresh the view? I seem to understand that Slate doesn't work by updating the UI every frame. But then I don't know what to do to solve my problem. Any help would be greatly appreciated.

Product Version: UE 4.21
Tags:
more ▼

asked Feb 19 '19 at 03:46 PM in C++ Programming

avatar image

Obelisk_Ali
3 1 2 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Two options:

  1. Wrap the contents of your slots in an SBox and bind its visibility to something that returns EVisibility::Collapsed or EVisibility::Visible depending on the state of your bool.

  2. Keep your horizontalBox variable around, and ClearChildren and AddSlot for the children you need when the button is pressed.

more ▼

answered Feb 19 '19 at 11:45 PM

avatar image

Jamie Dale STAFF
7.5k 176 66 304

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question