Slate - Visibility delegate


I found this :
SNew(SUniformGridPanel).Visibility(this, &SFriendItemImpl::PendingActionVisibility, EFriendActionType::RemoveFriend)

in the developper folder / FriendsAndChat module on the engine.
While I think I understand that we are settings a delagate to alter the visibility of the SUniformGridPanel, I clearly don’t understand where it’s define.

The only visibility delagate I found is on UMG Widget, nothing in Slate part.
I look are the arguments of SUniformGridPanel, there is no slate marco in the ARGS section defining this, nor in the Construct.

I hope someone will be able to help me to understand where this is declare/done because I can be very interested in having such mechanism, but I need to be sure on how it works before using it.


Visibility comes from a lower level macro that all SWidgets get no matter what they define in their own set of SLATE ARGs.

Ok good to know.

I will keep that in my head, as it is clearly useful :smiley:


More specifically, you can find the macro/template in question within DeclarativeSyntaxSupport.h, look for TSlateBaseNamedArgs. When a widget uses the SLATE_BEGIN_ARGS macro, this template is used to declare the common arguments as well as whichever arguments you want to use yourself.

In the specific example you bring up, it’s worth noting that there is an extra argument specified through a delegate payload. Binding to the Visibility attribute requires a function that returns a EVisibility and takes no argument, but payloads allow adding extra parameters at bind time that are then passed along to the function when called. This allows the PendingActionVisibility function to be reused in two different places with a different payload, ensuring different behaviour at each location.


Thanks for additional information, but I’m clearly not enough familiar to the Macro/Template things to understands everything here.

In fact, What I don’t understand it in the macro, it declare a lof of Template function but in the end how the visibility works?
Does the function is called once when the SNew is processed or anytime that a function called the Visibility Attribute?

I’m confuse on this.


The delegate passed into the visibility attribute is called anytime .Get() is called on the attribute in the widget. Usually once every time slate paints it.

TAttributes are a special wrapper that enables treating direct values and delegate bindings in a transparent fashion. There are lots of ways of initializing delegates, so the slate macros just provide lots of alternate ways of doing this with minimal effort.

What’s happening here is that the Visibility attribute is initialized to use a delegate rather than a value. The delegate is PendingActionVisibility, and is directly called each time Slate needs to know the visibility of the widget.

Using delegates in attributes enables one of the core tenets of Slate, which is to pull values rather than push, so that you don’t have to manually handle state changes and propagate the results of said changes to your widget. In the above example, depending on the value of PendingAction, one of the attributes will return collapsed and the other will return visible, enabling the right section of the UI to be displayed depending on the state of PendingAction.


Yes this was my understanding of the code snippet, but I’m glad this is exactly what’s going on in the engine.

Using delegate binding is clearly awesome! I need to review some part of my UI to use that now ^^

Thanks both of you for the clarification.