10
10
11
11
namespace UnityExplorer . UI . Widgets
12
12
{
13
- public class ButtonListSource < T > : ICellPoolDataSource < ButtonCell >
13
+ public class ButtonListHandler < TData , TCell > : ICellPoolDataSource < TCell > where TCell : ButtonCell
14
14
{
15
- internal ScrollPool < ButtonCell > ScrollPool ;
15
+ internal ScrollPool < TCell > ScrollPool ;
16
16
17
17
public int ItemCount => currentEntries . Count ;
18
- public readonly List < T > currentEntries = new List < T > ( ) ;
18
+ public readonly List < TData > currentEntries = new List < TData > ( ) ;
19
19
20
- public Func < List < T > > GetEntries ;
21
- public Action < ButtonCell , int > SetICell ;
22
- public Func < T , string , bool > ShouldDisplay ;
20
+ public Func < List < TData > > GetEntries ;
21
+ public Action < TCell , int > SetICell ;
22
+ public Func < TData , string , bool > ShouldDisplay ;
23
23
public Action < int > OnCellClicked ;
24
24
25
25
public string CurrentFilter
@@ -29,8 +29,8 @@ public string CurrentFilter
29
29
}
30
30
private string currentFilter ;
31
31
32
- public ButtonListSource ( ScrollPool < ButtonCell > scrollPool , Func < List < T > > getEntriesMethod ,
33
- Action < ButtonCell , int > setICellMethod , Func < T , string , bool > shouldDisplayMethod ,
32
+ public ButtonListHandler ( ScrollPool < TCell > scrollPool , Func < List < TData > > getEntriesMethod ,
33
+ Action < TCell , int > setICellMethod , Func < TData , string , bool > shouldDisplayMethod ,
34
34
Action < int > onCellClickedMethod )
35
35
{
36
36
ScrollPool = scrollPool ;
@@ -43,14 +43,14 @@ public ButtonListSource(ScrollPool<ButtonCell> scrollPool, Func<List<T>> getEntr
43
43
44
44
public void RefreshData ( )
45
45
{
46
- var allEntries = GetEntries . Invoke ( ) ;
46
+ var allEntries = GetEntries ( ) ;
47
47
currentEntries . Clear ( ) ;
48
48
49
49
foreach ( var entry in allEntries )
50
50
{
51
51
if ( ! string . IsNullOrEmpty ( currentFilter ) )
52
52
{
53
- if ( ! ShouldDisplay . Invoke ( entry , currentFilter ) )
53
+ if ( ! ShouldDisplay ( entry , currentFilter ) )
54
54
continue ;
55
55
56
56
currentEntries . Add ( entry ) ;
@@ -60,17 +60,12 @@ public void RefreshData()
60
60
}
61
61
}
62
62
63
- public void OnCellBorrowed ( ButtonCell cell )
63
+ public virtual void OnCellBorrowed ( TCell cell )
64
64
{
65
65
cell . OnClick += OnCellClicked ;
66
66
}
67
67
68
- public void ReleaseCell ( ButtonCell cell )
69
- {
70
- cell . OnClick -= OnCellClicked ;
71
- }
72
-
73
- public void SetCell ( ButtonCell cell , int index )
68
+ public virtual void SetCell ( TCell cell , int index )
74
69
{
75
70
if ( currentEntries == null )
76
71
RefreshData ( ) ;
@@ -81,10 +76,8 @@ public void SetCell(ButtonCell cell, int index)
81
76
{
82
77
cell . Enable ( ) ;
83
78
cell . CurrentDataIndex = index ;
84
- SetICell . Invoke ( cell , index ) ;
79
+ SetICell ( cell , index ) ;
85
80
}
86
81
}
87
-
88
- //public void DisableCell(ButtonCell cell, int index) => cell.Disable();
89
82
}
90
83
}
0 commit comments