# Lambda as slate delegate

**URL:** <https://forums.unrealengine.com/t/lambda-as-slate-delegate/286547>\
**Category:** UI\
**Tags:** unreal-engine, delegate, slate, question\
**Created:** [June 23, 2014, 12:42am UTC](https://forums.unrealengine.com/t/lambda-as-slate-delegate/286547 "2014-06-23T00:42:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![twiddle](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@twiddle](https://forums.unrealengine.com/u/twiddle)\
**Post date:** [June 23, 2014, 12:42am UTC](https://forums.unrealengine.com/t/lambda-as-slate-delegate/286547/1 "2014-06-23T00:42:24Z")

</div>

Is it possible to use a lambda as a slate delegate for generating items in a SListView?

eg

```
SNew(SListView<TSharedRef<FString> >)
    .ListItemsSource(&SessionNames)
    .OnGenerateRow([](TSharedRef<FString> string)->TSharedRef < ITableRow > {return SNew(STextBlock).Text((*string)); })

```

I’m guessing that if it is possible I’d have to wrap this somehow as an actual delegate, as I get an error about being unable to convert from the lambda to a RetVal\_TwoParams delegate. Is this the case, and if so how would I go about doing so?

---

<div class="post-metadata">

**Author:** ![MorskoyZmey](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MorskoyZmey](https://forums.unrealengine.com/u/MorskoyZmey)\
**Post date:** [June 23, 2014, 5:37am UTC](https://forums.unrealengine.com/t/lambda-as-slate-delegate/286547/2 "2014-06-23T05:37:40Z")

</div>

Does RetVal\_TwoParams mean that your lambda should accept two arguments?

---

<div class="post-metadata">

**Author:** ![twiddle](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@twiddle](https://forums.unrealengine.com/u/twiddle)\
**Post date:** [June 23, 2014, 5:47am UTC](https://forums.unrealengine.com/t/lambda-as-slate-delegate/286547/3 "2014-06-23T05:47:19Z")

</div>

According to the comments in SListView.h:

```
* A sample implementation of OnGenerateWidgetForList would simply return a TextBlock with the corresponding text:
 *
 * TSharedRef<ITableRow> OnGenerateWidgetForList( FString* InItem )
 * {
 * return SNew(STextBlock).Text( (*InItem) )
 * }

```

Bearing this in mind, I shouldn’t need two parameters in the lambda, because the sample delegate function provided there doesn’t take two.

---

<div class="post-metadata">

**Author:** ![Jamie\_Dale](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jamie_dale/32/1165413_2.png) [@Jamie\_Dale](https://forums.unrealengine.com/u/Jamie_Dale)\
**Post date:** [June 23, 2014, 9:35am UTC](https://forums.unrealengine.com/t/lambda-as-slate-delegate/286547/4 "2014-06-23T09:35:52Z")

</div>

That comment is wrong (perhaps old), I’ve updated it.

FOnGenerateRow needs two parameters, your item, and the owner table. To update the example you used above, this would be:

```
 TSharedRef<ITableRow> OnGenerateWidgetForList( FString* InItem, const TSharedRef<STableViewBase>& OwnerTable )
 {
     return SNew(STextBlock).Text( (*InItem) )
 }

```

---

<div class="post-metadata">

**Author:** ![Jamie\_Dale](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jamie_dale/32/1165413_2.png) [@Jamie\_Dale](https://forums.unrealengine.com/u/Jamie_Dale)\
**Post date:** [June 23, 2014, 9:38am UTC](https://forums.unrealengine.com/t/lambda-as-slate-delegate/286547/5 "2014-06-23T09:38:30Z")

</div>

You should be able to use a lambda providing they don’t capture anything. Our delegates don’t really support lambdas, but they do support static function pointers, and a stateless lambda will convert to a function pointer.

---

<div class="post-metadata">

**Author:** ![twiddle](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@twiddle](https://forums.unrealengine.com/u/twiddle)\
**Post date:** [June 23, 2014, 9:40am UTC](https://forums.unrealengine.com/t/lambda-as-slate-delegate/286547/6 "2014-06-23T09:40:10Z")

</div>

Thanks for the clarification, Jamie. Will give it a shot and see how things go 🙂

---

<div class="post-metadata">

**Author:** ![vmc\_petter](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@vmc\_petter](https://forums.unrealengine.com/u/vmc_petter)\
**Post date:** [October 31, 2019, 1:31pm UTC](https://forums.unrealengine.com/t/lambda-as-slate-delegate/286547/7 "2019-10-31T13:31:40Z")

</div>

A little bit late, but you can now wrap a lambda in a TAttribute similar to this (just change types to whatever you need):

```
SNew(STextBlock)
.Text(TAttribute<FText>::Create(TAttribute<FText>::FGetter::CreateLambda([&](){ return Something.GetText(); })))
```

---

<div class="post-metadata">

**Author:** ![vmc\_petter](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@vmc\_petter](https://forums.unrealengine.com/u/vmc_petter)\
**Post date:** [October 31, 2019, 1:31pm UTC](https://forums.unrealengine.com/t/lambda-as-slate-delegate/286547/8 "2019-10-31T13:31:42Z")

</div>

Or even better:

```
SNew(STextBlock)
 .Text_Lambda([&](){ return Something.GetText(); })
```

---

<div class="post-metadata">

**Author:** ![Kulmanseidl](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kulmanseidl](https://forums.unrealengine.com/u/Kulmanseidl)\
**Post date:** [October 13, 2020, 6:19am UTC](https://forums.unrealengine.com/t/lambda-as-slate-delegate/286547/9 "2020-10-13T06:19:09Z")

</div>

Tried it, that works. Looked for this for a really long time, wish I had found this answer earlier 😉
