Resolve a TODO in `InputRoll.RowCount`
This commit is contained in:
parent
5a236fdbee
commit
d7b0af9f4e
|
@ -1,5 +1,6 @@
|
||||||
#nullable enable
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
using BizHawk.Common;
|
using BizHawk.Common;
|
||||||
|
@ -91,6 +92,11 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
public sealed class CellList : SortedList<Cell>
|
public sealed class CellList : SortedList<Cell>
|
||||||
{
|
{
|
||||||
|
public CellList() {}
|
||||||
|
|
||||||
|
public CellList(IEnumerable<Cell> collection)
|
||||||
|
: base(collection) {}
|
||||||
|
|
||||||
/// <remarks>restore the distinctness invariant from <see cref="System.Collections.Generic.SortedSet{T}"/>; though I don't think we actually rely on it anywhere --yoshi</remarks>
|
/// <remarks>restore the distinctness invariant from <see cref="System.Collections.Generic.SortedSet{T}"/>; though I don't think we actually rely on it anywhere --yoshi</remarks>
|
||||||
public override void Add(Cell item)
|
public override void Add(Cell item)
|
||||||
{
|
{
|
||||||
|
@ -117,6 +123,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return i >= 0 && _list[i].RowIndex == rowIndex;
|
return i >= 0 && _list[i].RowIndex == rowIndex;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
public new CellList Slice(int start, int length)
|
||||||
|
=> new(SliceImpl(start: start, length: length));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CellExtensions
|
public static class CellExtensions
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
private readonly IControlRenderer _renderer;
|
private readonly IControlRenderer _renderer;
|
||||||
|
|
||||||
private readonly CellList _selectedItems = new();
|
private CellList _selectedItems = new();
|
||||||
|
|
||||||
// scrollbar location(s) are calculated later (e.g. on resize)
|
// scrollbar location(s) are calculated later (e.g. on resize)
|
||||||
private readonly VScrollBar _vBar = new VScrollBar { Visible = false };
|
private readonly VScrollBar _vBar = new VScrollBar { Visible = false };
|
||||||
|
@ -269,10 +269,10 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
_rowCount = value;
|
_rowCount = value;
|
||||||
|
|
||||||
//TODO replace this with a binary search + truncate
|
|
||||||
if (_selectedItems.LastOrDefault()?.RowIndex >= _rowCount)
|
if (_selectedItems.LastOrDefault()?.RowIndex >= _rowCount)
|
||||||
{
|
{
|
||||||
_selectedItems.RemoveAll(i => i.RowIndex >= _rowCount);
|
var iLastToKeep = _selectedItems.LowerBoundBinarySearch(static c => c.RowIndex ?? -1, _rowCount);
|
||||||
|
_selectedItems = _selectedItems.Slice(start: 0, length: iLastToKeep + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
RecalculateScrollBars();
|
RecalculateScrollBars();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace BizHawk.Common
|
namespace BizHawk.Common
|
||||||
{
|
{
|
||||||
|
@ -14,11 +15,15 @@ namespace BizHawk.Common
|
||||||
|
|
||||||
public virtual bool IsReadOnly { get; } = false;
|
public virtual bool IsReadOnly { get; } = false;
|
||||||
|
|
||||||
public SortedList() => _list = new List<T>();
|
protected SortedList(List<T> wrapped)
|
||||||
|
=> _list = wrapped;
|
||||||
|
|
||||||
|
public SortedList()
|
||||||
|
: this(new()) {}
|
||||||
|
|
||||||
public SortedList(IEnumerable<T> collection)
|
public SortedList(IEnumerable<T> collection)
|
||||||
|
: this(new(collection))
|
||||||
{
|
{
|
||||||
_list = new List<T>(collection);
|
|
||||||
_list.Sort();
|
_list.Sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,6 +136,12 @@ namespace BizHawk.Common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SortedList<T> Slice(int start, int length)
|
||||||
|
=> new(SliceImpl(start: start, length: length));
|
||||||
|
|
||||||
|
protected List<T> SliceImpl(int start, int length)
|
||||||
|
=> _list.Skip(start).Take(length).ToList();
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue