mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-05 04:42:54 +08:00
Rename ButtonListSource
This commit is contained in:
@ -10,16 +10,16 @@ using UnityExplorer.UI.Widgets;
|
|||||||
|
|
||||||
namespace UnityExplorer.UI.Widgets
|
namespace UnityExplorer.UI.Widgets
|
||||||
{
|
{
|
||||||
public class ButtonListSource<T> : ICellPoolDataSource<ButtonCell>
|
public class ButtonListHandler<TData, TCell> : ICellPoolDataSource<TCell> where TCell : ButtonCell
|
||||||
{
|
{
|
||||||
internal ScrollPool<ButtonCell> ScrollPool;
|
internal ScrollPool<TCell> ScrollPool;
|
||||||
|
|
||||||
public int ItemCount => currentEntries.Count;
|
public int ItemCount => currentEntries.Count;
|
||||||
public readonly List<T> currentEntries = new List<T>();
|
public readonly List<TData> currentEntries = new List<TData>();
|
||||||
|
|
||||||
public Func<List<T>> GetEntries;
|
public Func<List<TData>> GetEntries;
|
||||||
public Action<ButtonCell, int> SetICell;
|
public Action<TCell, int> SetICell;
|
||||||
public Func<T, string, bool> ShouldDisplay;
|
public Func<TData, string, bool> ShouldDisplay;
|
||||||
public Action<int> OnCellClicked;
|
public Action<int> OnCellClicked;
|
||||||
|
|
||||||
public string CurrentFilter
|
public string CurrentFilter
|
||||||
@ -29,8 +29,8 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
}
|
}
|
||||||
private string currentFilter;
|
private string currentFilter;
|
||||||
|
|
||||||
public ButtonListSource(ScrollPool<ButtonCell> scrollPool, Func<List<T>> getEntriesMethod,
|
public ButtonListHandler(ScrollPool<TCell> scrollPool, Func<List<TData>> getEntriesMethod,
|
||||||
Action<ButtonCell, int> setICellMethod, Func<T, string, bool> shouldDisplayMethod,
|
Action<TCell, int> setICellMethod, Func<TData, string, bool> shouldDisplayMethod,
|
||||||
Action<int> onCellClickedMethod)
|
Action<int> onCellClickedMethod)
|
||||||
{
|
{
|
||||||
ScrollPool = scrollPool;
|
ScrollPool = scrollPool;
|
||||||
@ -43,14 +43,14 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
|
|
||||||
public void RefreshData()
|
public void RefreshData()
|
||||||
{
|
{
|
||||||
var allEntries = GetEntries.Invoke();
|
var allEntries = GetEntries();
|
||||||
currentEntries.Clear();
|
currentEntries.Clear();
|
||||||
|
|
||||||
foreach (var entry in allEntries)
|
foreach (var entry in allEntries)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(currentFilter))
|
if (!string.IsNullOrEmpty(currentFilter))
|
||||||
{
|
{
|
||||||
if (!ShouldDisplay.Invoke(entry, currentFilter))
|
if (!ShouldDisplay(entry, currentFilter))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
currentEntries.Add(entry);
|
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;
|
cell.OnClick += OnCellClicked;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReleaseCell(ButtonCell cell)
|
public virtual void SetCell(TCell cell, int index)
|
||||||
{
|
|
||||||
cell.OnClick -= OnCellClicked;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetCell(ButtonCell cell, int index)
|
|
||||||
{
|
{
|
||||||
if (currentEntries == null)
|
if (currentEntries == null)
|
||||||
RefreshData();
|
RefreshData();
|
||||||
@ -81,10 +76,8 @@ namespace UnityExplorer.UI.Widgets
|
|||||||
{
|
{
|
||||||
cell.Enable();
|
cell.Enable();
|
||||||
cell.CurrentDataIndex = index;
|
cell.CurrentDataIndex = index;
|
||||||
SetICell.Invoke(cell, index);
|
SetICell(cell, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//public void DisableCell(ButtonCell cell, int index) => cell.Disable();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user