diff --git a/src/UI/Widgets/ButtonList/ButtonListSource.cs b/src/UI/Widgets/ButtonList/ButtonListHandler.cs similarity index 61% rename from src/UI/Widgets/ButtonList/ButtonListSource.cs rename to src/UI/Widgets/ButtonList/ButtonListHandler.cs index c11e04b..b7391bb 100644 --- a/src/UI/Widgets/ButtonList/ButtonListSource.cs +++ b/src/UI/Widgets/ButtonList/ButtonListHandler.cs @@ -10,16 +10,16 @@ using UnityExplorer.UI.Widgets; namespace UnityExplorer.UI.Widgets { - public class ButtonListSource : ICellPoolDataSource + public class ButtonListHandler : ICellPoolDataSource where TCell : ButtonCell { - internal ScrollPool ScrollPool; + internal ScrollPool ScrollPool; public int ItemCount => currentEntries.Count; - public readonly List currentEntries = new List(); + public readonly List currentEntries = new List(); - public Func> GetEntries; - public Action SetICell; - public Func ShouldDisplay; + public Func> GetEntries; + public Action SetICell; + public Func ShouldDisplay; public Action OnCellClicked; public string CurrentFilter @@ -29,8 +29,8 @@ namespace UnityExplorer.UI.Widgets } private string currentFilter; - public ButtonListSource(ScrollPool scrollPool, Func> getEntriesMethod, - Action setICellMethod, Func shouldDisplayMethod, + public ButtonListHandler(ScrollPool scrollPool, Func> getEntriesMethod, + Action setICellMethod, Func shouldDisplayMethod, Action onCellClickedMethod) { ScrollPool = scrollPool; @@ -43,14 +43,14 @@ namespace UnityExplorer.UI.Widgets public void RefreshData() { - var allEntries = GetEntries.Invoke(); + var allEntries = GetEntries(); currentEntries.Clear(); foreach (var entry in allEntries) { if (!string.IsNullOrEmpty(currentFilter)) { - if (!ShouldDisplay.Invoke(entry, currentFilter)) + if (!ShouldDisplay(entry, currentFilter)) continue; currentEntries.Add(entry); @@ -60,17 +60,12 @@ namespace UnityExplorer.UI.Widgets } } - public void OnCellBorrowed(ButtonCell cell) + public virtual void OnCellBorrowed(TCell cell) { cell.OnClick += OnCellClicked; } - public void ReleaseCell(ButtonCell cell) - { - cell.OnClick -= OnCellClicked; - } - - public void SetCell(ButtonCell cell, int index) + public virtual void SetCell(TCell cell, int index) { if (currentEntries == null) RefreshData(); @@ -81,10 +76,8 @@ namespace UnityExplorer.UI.Widgets { cell.Enable(); cell.CurrentDataIndex = index; - SetICell.Invoke(cell, index); + SetICell(cell, index); } } - - //public void DisableCell(ButtonCell cell, int index) => cell.Disable(); } }