parent
328d36d0ca
commit
2a67cf93ec
|
@ -1,11 +1,14 @@
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
using BizHawk.Common;
|
||||||
|
|
||||||
namespace BizHawk.Client.EmuHawk
|
namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a single cell of the <see cref="InputRoll"/>
|
/// Represents a single cell of the <see cref="InputRoll"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Cell
|
public sealed class Cell : IComparable<Cell>
|
||||||
{
|
{
|
||||||
public RollColumn Column { get; internal set; }
|
public RollColumn Column { get; internal set; }
|
||||||
public int? RowIndex { get; internal set; }
|
public int? RowIndex { get; internal set; }
|
||||||
|
@ -19,6 +22,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
RowIndex = cell.RowIndex;
|
RowIndex = cell.RowIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int CompareTo(Cell other)
|
||||||
|
=> SortCell.Compare(this, other);
|
||||||
|
|
||||||
public override bool Equals(object obj)
|
public override bool Equals(object obj)
|
||||||
{
|
{
|
||||||
if (obj is Cell cell)
|
if (obj is Cell cell)
|
||||||
|
@ -45,9 +51,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class SortCell : IComparer<Cell>
|
internal static class SortCell
|
||||||
{
|
{
|
||||||
int IComparer<Cell>.Compare(Cell c1, Cell c2)
|
public static int Compare(Cell c1, Cell c2)
|
||||||
{
|
{
|
||||||
if (c1 is null && c2 is null)
|
if (c1 is null && c2 is null)
|
||||||
{
|
{
|
||||||
|
@ -86,6 +92,21 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public sealed class CellList : SortedList<Cell>
|
||||||
|
{
|
||||||
|
/// <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)
|
||||||
|
{
|
||||||
|
var i = _list.BinarySearch(item);
|
||||||
|
if (i >= 0)
|
||||||
|
{
|
||||||
|
Debug.Assert(false, $"{nameof(CellList)}'s distinctness invariant was almost broken! CellList.Add({(item is null ? "null" : $"Cell(r: {item.RowIndex}, c: \"{item.Column?.Name ?? "(unnamed)"}\")")})");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_list.Insert(~i, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class CellExtensions
|
public static class CellExtensions
|
||||||
{
|
{
|
||||||
public static bool IsDataCell(this Cell cell)
|
public static bool IsDataCell(this Cell cell)
|
||||||
|
|
|
@ -22,7 +22,8 @@ namespace BizHawk.Client.EmuHawk
|
||||||
public partial class InputRoll : Control
|
public partial class InputRoll : Control
|
||||||
{
|
{
|
||||||
private readonly IControlRenderer _renderer;
|
private readonly IControlRenderer _renderer;
|
||||||
private readonly SortedSet<Cell> _selectedItems = new SortedSet<Cell>(new SortCell());
|
|
||||||
|
private readonly 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 };
|
||||||
|
@ -265,13 +266,10 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
_rowCount = value;
|
_rowCount = value;
|
||||||
|
|
||||||
|
//TODO replace this with a binary search + truncate
|
||||||
if (_selectedItems.Max(s => s.RowIndex) >= _rowCount)
|
if (_selectedItems.Max(s => s.RowIndex) >= _rowCount)
|
||||||
{
|
{
|
||||||
#if NETFRAMEWORK
|
|
||||||
_selectedItems.RemoveAll(i => i.RowIndex >= _rowCount);
|
_selectedItems.RemoveAll(i => i.RowIndex >= _rowCount);
|
||||||
#else
|
|
||||||
_selectedItems.RemoveWhere(i => i.RowIndex >= _rowCount);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RecalculateScrollBars();
|
RecalculateScrollBars();
|
||||||
|
@ -576,7 +574,8 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_selectedItems.RemoveWhere(cell => cell.RowIndex == index);
|
IEnumerable<Cell> items = _selectedItems.Where(cell => cell.RowIndex == index);
|
||||||
|
_selectedItems.RemoveAll(items.Contains);
|
||||||
_lastSelectedRow = _selectedItems.LastOrDefault()?.RowIndex;
|
_lastSelectedRow = _selectedItems.LastOrDefault()?.RowIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -612,7 +611,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
public void TruncateSelection(int index)
|
public void TruncateSelection(int index)
|
||||||
{
|
{
|
||||||
_selectedItems.RemoveWhere(cell => cell.RowIndex > index);
|
_selectedItems.RemoveAll(cell => cell.RowIndex > index);
|
||||||
_lastSelectedRow = _selectedItems.LastOrDefault()?.RowIndex;
|
_lastSelectedRow = _selectedItems.LastOrDefault()?.RowIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1788,7 +1787,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
if (FullRowSelect)
|
if (FullRowSelect)
|
||||||
{
|
{
|
||||||
if (toggle && (_selectedItems.RemoveWhere(x => x.RowIndex == row) is not 0))
|
if (toggle && (_selectedItems.RemoveAll(x => x.RowIndex == row) is not 0))
|
||||||
{
|
{
|
||||||
_lastSelectedRow = _selectedItems.LastOrDefault()?.RowIndex;
|
_lastSelectedRow = _selectedItems.LastOrDefault()?.RowIndex;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue