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"

I don't understand ChildSlot[...]

So, I am using Slate a bit and it works, but I really don't understand it. Here is working code:

     ChildSlot
         [
             SNew(SOverlay)
             + SOverlay::Slot()
         .HAlign(HAlign_Center)
         .VAlign(VAlign_Top)
         [
             SNew(STextBlock)
         .Text(FText::FromString("Main Menu"))
         ]


     + SOverlay::Slot()
         .HAlign(HAlign_Center)
         .VAlign(VAlign_Center)
         [
             createMenu()
         ]
         ];

It does what I want. But, what is happening here, C++ wise? Childslot is a member of type FSimpleSlot.

I use that member, behind I do what? I start an array with '['? Or is that some kind of initialization? What is the +Overlay doing?

I understand what is happending, I think.

I do not understand why it is happening. I have problems with the C++ here. I think the answer could be something very basic, which i just don't get yet.

Product Version: UE 4.17
Tags:
more ▼

asked Oct 23 '17 at 07:34 PM in C++ Programming

avatar image

BugSwat
210 9 14 20

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

1 answer: sort voted first

This is "hack" in C++ using operator overloads which allows to modify behavior of operators, also add support of operators to structs and classes (that why you can use them with FVector or FRotator for example even thru they are custom structs inside UE4).

http://en.cppreference.com/w/cpp/language/operators

Slate using it to create this nice looking layout definition syntax that looks nice in C++, because using function or setting varbales would be annoying to write entire layout in, the final result of it is constructed widget class based on that layout data. so + SOverlay::Slot() is just + operator overload of slot builder which adds slots together (SOverlay::Slot() + SOverlay::Slot() that what really happening here). the array brackets "[]" are operator too, this allows to make custom array system (in fact UE4 got it's own array implementations TArray, TMap, TSet etc.), slate use this to contain layout definition of widgets inside the slot Slot

It's kind of more fancy looking chained builder pattern if you ever seen those in C++

http://www.spuriousthoughts.com/2012/11/06/chaining-setters-in-c-builder-pattern/

So yes, even thru Slate do those twists here it is still 100% valid C++ syntax and any today compiler by standard should deal with it without any issue.

The tabulation might be what confusing you, remember that in most languages "new lines", tabs and spaces (outside quotes) are ignored, you can hit enter after every space all the time, compiler will still compiler it normally as it process everything as single stream of characters. it actually prime reason why you need to place ";" after everything and yes you can place everything in single line (except preprocessor instruction like #include), compiler have 0 issue with that. This is something you wont see in UE4, but for example some C/C++ projects place enter and tabs on each argument of a function definition so it is not cut by text editor and all of them are visible all at once, compiler will process that normally without any issue. It is recmanded to do new lines and tabs like that so Slate layout information is more readable to programmers

more ▼

answered Oct 23 '17 at 08:29 PM

avatar image

Shadowriver
36.7k 932 169 1111

avatar image BugSwat Oct 23 '17 at 09:30 PM

Oh my god. Operators. I never thought about these here. Thanks a lot man!

(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