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"

Construct slate from array

As you guys can see, I'm using an array of button templates as Slate arguments, but I have no idea how to iterate within the Slate UI construction structure.

So is there a way to vary the amount of buttons constructed in a Slate construction such as defining a separate function for buttons?

 struct FDHDialogTemplate
 {
 public:
     /** Default constructor */
     FDHDialogTemplate() {}
     FDHDialogTemplate(FText InTitle, FDHTextStyle InTitleStyle, FText InText, FDHTextStyle InTextStyle, TArray<FDHButtonTemplate> InButtons);
 
     /** Text displayed in the title slot of the dialog */
     FText DialogTitle;
 
     /** Style to display the title text */
     FDHTextStyle TitleStyle;
 
     /** Text displayed in the top of the contents in the dialog */
     FText DialogText;
 
     /** Style to display the content text */
     FDHTextStyle TextStyle;
 
     /** Buttons to be displayed in the dialog */
     TArray<FDHButtonTemplate> DialogButtons;
 };


 void SDHDialogWidget::Construct(const FArguments& InArgs)
 {
     Template = InArgs._Template;
 
     SNew(SBorder)
         .HAlign(HAlign_Fill)
         .VAlign(VAlign_Fill)
         .BorderBackgroundColor(FLinearColor(1.0f, 1.0f, 1.0f, 0.1f))
         [
             SNew(SBorder)
             .HAlign(HAlign_Fill)
             .VAlign(VAlign_Top)
             .Padding(FMargin(0.0f, 150.0f))
             .BorderBackgroundColor(FLinearColor::Gray)
             [
                 SNew(SVerticalBox)
                     + SVerticalBox::Slot()
                     .HAlign(HAlign_Left)
                     .VAlign(VAlign_Top)
                     .Padding(FMargin(100.0f, 5.0f))
                     [
                         SNew(STextBlock)
                         .ColorAndOpacity(Template.TitleStyle.TextColor)
                         .ShadowColorAndOpacity(Template.TitleStyle.ShadowColor)
                         .Font(Template.TitleStyle.Font)
                         .Text(Template.DialogTitle)
                     ]
                     + SVerticalBox::Slot()
                     .HAlign(HAlign_Fill)
                     .VAlign(VAlign_Fill)
                     .Padding(FMargin(100.0f, 5.0f))
                     [
                         SNew(STextBlock)
                         .ColorAndOpacity(Template.TextStyle.TextColor)
                         .ShadowColorAndOpacity(Template.TextStyle.ShadowColor)
                         .Font(Template.TextStyle.Font)
                         .Text(Template.DialogText)
                     ]
                     + SVerticalBox::Slot()
                     .HAlign(HAlign_Right)
                     .VAlign(VAlign_Bottom)
                     .Padding(FMargin(5.0f))
                     [
                         // Iteration required here
                     ]
             ]
         ];
 }


Product Version: UE 4.10
Tags:
more ▼

asked Feb 06 '16 at 05:25 AM in C++ Programming

avatar image

Dirt113
95 14 17 21

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

1 answer: sort voted first

Create your SVerticalBox earlier and store reference to it, like this:

 TSharedRef<SVerticalBox> Box = SNew(SVerticalBox)
 + SVerticalBox::Slot()
 .....

Then, all you have to do is iterate your array and add slots to your container:

 for(;;)
 {
 Box->AddSlot()
 .HAlign(HAlign_Right)
 .VAlign(VAlign_Bottom)
 .Padding(FMargin(5.0f))
 [
    // your buttons here
 ]
 }

After that, Box will be filled with buttons and will be ready to be added as child slot:

 SNew(SBorder)
 [
    Box
 ];


Hope this helps.

more ▼

answered Feb 09 '16 at 11:03 AM

avatar image

szyszek
610 16 12 36

(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