-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #809 from erri120/workspace-cleanup
Workspace Testing rework
Showing
8 changed files
with
986 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Avalonia; | ||
|
||
namespace NexusMods.App.UI.WorkspaceSystem; | ||
|
||
public record struct PanelGridState(PanelId Id, Rect Rect); | ||
|
||
public class PanelGridStateComparer : IComparer<PanelGridState> | ||
{ | ||
public static readonly IComparer<PanelGridState> Instance = new PanelGridStateComparer(); | ||
|
||
public int Compare(PanelGridState x, PanelGridState y) | ||
{ | ||
var a = x.Rect; | ||
var b = y.Rect; | ||
|
||
var xComparison = a.X.CompareTo(b.X); | ||
if (xComparison != 0) return xComparison; | ||
|
||
var yComparison = a.Y.CompareTo(b.Y); | ||
if (yComparison != 0) return yComparison; | ||
|
||
return x.Id.CompareTo(y.Id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
217 changes: 217 additions & 0 deletions
217
src/NexusMods.App.UI/WorkspaceSystem/WorkspaceGridState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
using System.Collections; | ||
using System.Collections.Immutable; | ||
using System.Diagnostics.CodeAnalysis; | ||
using Avalonia; | ||
|
||
namespace NexusMods.App.UI.WorkspaceSystem; | ||
|
||
public readonly struct WorkspaceGridState : | ||
IImmutableSet<PanelGridState>, | ||
IReadOnlyList<PanelGridState> | ||
{ | ||
public readonly ImmutableSortedSet<PanelGridState> Inner; | ||
public readonly bool IsHorizontal; | ||
|
||
public WorkspaceGridState(ImmutableSortedSet<PanelGridState> inner, bool isHorizontal) | ||
{ | ||
Inner = inner.WithComparer(PanelGridStateComparer.Instance); | ||
IsHorizontal = isHorizontal; | ||
} | ||
|
||
public static WorkspaceGridState From(IEnumerable<KeyValuePair<PanelId, Rect>> values, bool isHorizontal) | ||
{ | ||
return new WorkspaceGridState( | ||
inner: values.Select(kv => new PanelGridState(kv.Key, kv.Value)).ToImmutableSortedSet(PanelGridStateComparer.Instance), | ||
isHorizontal | ||
); | ||
} | ||
|
||
public static WorkspaceGridState From(IEnumerable<IPanelViewModel> panels, bool isHorizontal) | ||
{ | ||
return new WorkspaceGridState( | ||
inner: panels.Select(panel => new PanelGridState(panel.Id, panel.LogicalBounds)).ToImmutableSortedSet(PanelGridStateComparer.Instance), | ||
isHorizontal | ||
); | ||
} | ||
|
||
public static WorkspaceGridState From(IEnumerable<PanelGridState> panels, bool isHorizontal) | ||
{ | ||
return new WorkspaceGridState( | ||
inner: panels.ToImmutableSortedSet(PanelGridStateComparer.Instance), | ||
isHorizontal | ||
); | ||
} | ||
|
||
public static WorkspaceGridState Empty(bool isHorizontal) => new(ImmutableSortedSet<PanelGridState>.Empty, isHorizontal); | ||
|
||
private WorkspaceGridState WithInner(ImmutableSortedSet<PanelGridState> inner) | ||
{ | ||
return new WorkspaceGridState(inner, IsHorizontal); | ||
} | ||
|
||
[SuppressMessage("ReSharper", "ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator")] | ||
public PanelGridState this[PanelId id] | ||
{ | ||
get | ||
{ | ||
foreach (var panel in Inner) | ||
{ | ||
if (panel.Id == id) return panel; | ||
} | ||
|
||
throw new KeyNotFoundException(); | ||
} | ||
} | ||
|
||
[SuppressMessage("ReSharper", "ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator")] | ||
public bool TryGetValue(PanelId id, out PanelGridState panel) | ||
{ | ||
foreach (var item in Inner) | ||
{ | ||
if (item.Id != id) continue; | ||
panel = item; | ||
return true; | ||
} | ||
|
||
panel = default; | ||
return false; | ||
} | ||
|
||
[SuppressMessage("ReSharper", "ParameterTypeCanBeEnumerable.Global")] | ||
public WorkspaceGridState UnionById(PanelGridState[] other) | ||
{ | ||
var builder = Inner.ToBuilder(); | ||
foreach (var panelToAdd in other) | ||
{ | ||
if (TryGetValue(panelToAdd.Id, out var existingPanel)) | ||
{ | ||
builder.Remove(existingPanel); | ||
} | ||
|
||
builder.Add(panelToAdd); | ||
} | ||
|
||
return WithInner(builder.ToImmutable()); | ||
} | ||
|
||
public AdjacentPanelEnumerator EnumerateAdjacentPanels(PanelGridState anchor, bool includeAnchor) => new(this, anchor, includeAnchor); | ||
|
||
[Flags] | ||
public enum AdjacencyKind : byte | ||
{ | ||
None = 0, | ||
SameRow = 1 << 0, | ||
SameColumn = 1 << 1 | ||
} | ||
|
||
public record struct AdjacentPanel(PanelGridState Panel, AdjacencyKind Kind); | ||
|
||
public struct AdjacentPanelEnumerator : IEnumerator<AdjacentPanel> | ||
{ | ||
private ImmutableSortedSet<PanelGridState>.Enumerator _enumerator; | ||
private readonly PanelGridState _anchor; | ||
private readonly bool _includeAnchor; | ||
|
||
internal AdjacentPanelEnumerator(WorkspaceGridState parent, PanelGridState anchor, bool includeAnchor) | ||
{ | ||
_enumerator = parent.GetEnumerator(); | ||
_anchor = anchor; | ||
_includeAnchor = includeAnchor; | ||
} | ||
|
||
public AdjacentPanel Current { get; private set; } | ||
object IEnumerator.Current => Current; | ||
|
||
public bool MoveNext() | ||
{ | ||
while (true) | ||
{ | ||
if (!_enumerator.MoveNext()) return false; | ||
|
||
var other = _enumerator.Current; | ||
if (!_includeAnchor && other.Id == _anchor.Id) continue; | ||
|
||
var (anchorRect, otherRect) = (_anchor.Rect, other.Rect); | ||
var flags = AdjacencyKind.None; | ||
|
||
// same column | ||
// | a | x | | b | x | | ||
// | b | x | | a | x | | ||
if (otherRect.Left.IsGreaterThanOrCloseTo(anchorRect.Left) && otherRect.Right.IsLessThanOrCloseTo(anchorRect.Right)) | ||
{ | ||
if (otherRect.Top.IsCloseTo(anchorRect.Bottom) || otherRect.Bottom.IsCloseTo(anchorRect.Top)) | ||
{ | ||
flags |= AdjacencyKind.SameColumn; | ||
} | ||
} | ||
|
||
// same row | ||
// | a | b | | b | a | | a | b | | ||
// | x | x | | x | x | | a | c | | ||
if (otherRect.Top.IsGreaterThanOrCloseTo(anchorRect.Top) && otherRect.Bottom.IsLessThanOrCloseTo(anchorRect.Bottom)) | ||
{ | ||
if (otherRect.Left.IsCloseTo(anchorRect.Right) || otherRect.Right.IsCloseTo(anchorRect.Left)) | ||
{ | ||
flags |= AdjacencyKind.SameRow; | ||
} | ||
} | ||
|
||
if (flags == AdjacencyKind.None) continue; | ||
|
||
Current = new AdjacentPanel(other, flags); | ||
return true; | ||
} | ||
} | ||
|
||
public void Reset() => _enumerator.Reset(); | ||
public void Dispose() | ||
{ | ||
_enumerator.Dispose(); | ||
} | ||
} | ||
|
||
#region Interface Implementations | ||
|
||
public ImmutableSortedSet<PanelGridState>.Enumerator GetEnumerator() => Inner.GetEnumerator(); | ||
IEnumerator<PanelGridState> IEnumerable<PanelGridState>.GetEnumerator() => Inner.GetEnumerator(); | ||
IEnumerator IEnumerable.GetEnumerator() => Inner.GetEnumerator(); | ||
|
||
public int Count => Inner.Count; | ||
public bool Contains(PanelGridState value) => Inner.Contains(value); | ||
|
||
public bool IsProperSubsetOf(IEnumerable<PanelGridState> other) => Inner.IsProperSubsetOf(other); | ||
public bool IsProperSupersetOf(IEnumerable<PanelGridState> other) => Inner.IsProperSubsetOf(other); | ||
public bool IsSubsetOf(IEnumerable<PanelGridState> other) => Inner.IsSubsetOf(other); | ||
public bool IsSupersetOf(IEnumerable<PanelGridState> other) => Inner.IsSupersetOf(other); | ||
public bool Overlaps(IEnumerable<PanelGridState> other) => Inner.Overlaps(other); | ||
public bool SetEquals(IEnumerable<PanelGridState> other) => Inner.SetEquals(other); | ||
|
||
IImmutableSet<PanelGridState> IImmutableSet<PanelGridState>.Add(PanelGridState value) => Inner.Add(value); | ||
public WorkspaceGridState Add(PanelGridState value) => WithInner(Inner.Add(value)); | ||
|
||
IImmutableSet<PanelGridState> IImmutableSet<PanelGridState>.Clear() => Inner.Clear(); | ||
public WorkspaceGridState Clear() => WithInner(Inner.Clear()); | ||
|
||
IImmutableSet<PanelGridState> IImmutableSet<PanelGridState>.Except(IEnumerable<PanelGridState> other) => Inner.Except(other); | ||
public WorkspaceGridState Except(IEnumerable<PanelGridState> other) => WithInner(Inner.Except(other)); | ||
|
||
IImmutableSet<PanelGridState> IImmutableSet<PanelGridState>.Intersect(IEnumerable<PanelGridState> other) => Inner.Intersect(other); | ||
public WorkspaceGridState Intersect(IEnumerable<PanelGridState> other) => WithInner(Inner.Intersect(other)); | ||
|
||
IImmutableSet<PanelGridState> IImmutableSet<PanelGridState>.Remove(PanelGridState value) => Inner.Remove(value); | ||
public WorkspaceGridState Remove(PanelGridState value) => WithInner(Inner.Remove(value)); | ||
|
||
IImmutableSet<PanelGridState> IImmutableSet<PanelGridState>.SymmetricExcept(IEnumerable<PanelGridState> other) => Inner.SymmetricExcept(other); | ||
public WorkspaceGridState SymmetricExcept(IEnumerable<PanelGridState> other) => WithInner(Inner.SymmetricExcept(other)); | ||
|
||
bool IImmutableSet<PanelGridState>.TryGetValue(PanelGridState equalValue, out PanelGridState actualValue) => Inner.TryGetValue(equalValue, out actualValue); | ||
|
||
IImmutableSet<PanelGridState> IImmutableSet<PanelGridState>.Union(IEnumerable<PanelGridState> other) => Inner.Union(other); | ||
public WorkspaceGridState Union(IEnumerable<PanelGridState> other) => WithInner(Inner.Union(other)); | ||
|
||
public int IndexOf(PanelGridState item) => Inner.IndexOf(item); | ||
|
||
public PanelGridState this[int index] => Inner[index]; | ||
|
||
#endregion | ||
} |
2 changes: 2 additions & 0 deletions
2
tests/NexusMods.UI.Tests/NexusMods.UI.Tests.csproj.DotSettings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=workspacesystem_005Cgridutilstests/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
274 changes: 274 additions & 0 deletions
274
tests/NexusMods.UI.Tests/WorkspaceSystem/GridUtilsTests/GetPossibleStatesTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,274 @@ | ||
using System.Collections.Immutable; | ||
using System.Diagnostics.CodeAnalysis; | ||
using Avalonia; | ||
using FluentAssertions; | ||
using NexusMods.App.UI.WorkspaceSystem; | ||
|
||
namespace NexusMods.UI.Tests.WorkspaceSystem; | ||
|
||
[SuppressMessage("ReSharper", "HeapView.BoxingAllocation")] | ||
[SuppressMessage("ReSharper", "HeapView.ObjectAllocation.Evident")] | ||
[SuppressMessage("ReSharper", "HeapView.ObjectAllocation")] | ||
public partial class GridUtilsTests | ||
{ | ||
[Theory] | ||
[MemberData(nameof(TestData_GetPossibleStates_Generated))] | ||
public void Test_GetPossibleStates( | ||
WorkspaceGridState currentState, | ||
WorkspaceGridState[] expectedOutputs) | ||
{ | ||
GridUtils.IsPerfectGrid(currentState).Should().BeTrue(); | ||
if (expectedOutputs.Length != 0) | ||
{ | ||
expectedOutputs.Should().AllSatisfy(expectedOutput => | ||
{ | ||
expectedOutput.IsHorizontal.Should().Be(currentState.IsHorizontal); | ||
GridUtils.IsPerfectGrid(expectedOutput).Should().BeTrue(); | ||
}); | ||
} | ||
|
||
var actualOutputs = GridUtils.GetPossibleStates( | ||
currentState.Inner.ToImmutableDictionary(x => x.Id, x => x.Rect), | ||
columns: 2, | ||
rows: 2 | ||
).ToArray(); | ||
|
||
var convertedOutputs = actualOutputs | ||
.Select(actualOutput => new WorkspaceGridState(actualOutput.Select(kv => new PanelGridState(kv.Key, kv.Value)).ToImmutableSortedSet(PanelGridStateComparer.Instance), isHorizontal: currentState.IsHorizontal)) | ||
.ToArray(); | ||
|
||
if (convertedOutputs.Length != 0) | ||
{ | ||
convertedOutputs.Should().AllSatisfy(output => | ||
{ | ||
GridUtils.IsPerfectGrid(output).Should().BeTrue(); | ||
}); | ||
} | ||
|
||
convertedOutputs.Should().HaveCount(expectedOutputs.Length); | ||
for (var i = 0; i < convertedOutputs.Length; i++) | ||
{ | ||
convertedOutputs[i].Should().Equal(expectedOutputs[i]); | ||
} | ||
} | ||
|
||
public static IEnumerable<object[]> TestData_GetPossibleStates_Generated() | ||
{ | ||
var newPanelId = PanelId.DefaultValue; | ||
var firstPanelId = PanelId.From(Guid.Parse("11111111-1111-1111-1111-111111111111")); | ||
var secondPanelId = PanelId.From(Guid.Parse("22222222-2222-2222-2222-222222222222")); | ||
var thirdPanelId = PanelId.From(Guid.Parse("33333333-3333-3333-3333-333333333333")); | ||
var fourthPanelId = PanelId.From(Guid.Parse("44444444-4444-4444-4444-444444444444")); | ||
|
||
// TODO: test with variable sized panels | ||
|
||
// Input: one panel | ||
// Possible States: | ||
// 1) split vertically, new panel is in the second column | ||
// 2) split vertically, new panel is in the first column | ||
// 3) split horizontally, new panel is in the second row | ||
// 4) split horizontally, new panel is in the first row | ||
yield return new object[] | ||
{ | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(firstPanelId, MathUtils.One) | ||
), | ||
new[] | ||
{ | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(firstPanelId, new Rect(0, 0, 0.5, 1)), | ||
new PanelGridState(newPanelId, new Rect(0.5, 0, 0.5, 1)) | ||
), | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(newPanelId, new Rect(0, 0, 0.5, 1)), | ||
new PanelGridState(firstPanelId, new Rect(0.5, 0, 0.5, 1)) | ||
), | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(firstPanelId, new Rect(0, 0, 1, 0.5)), | ||
new PanelGridState(newPanelId, new Rect(0, 0.5, 1, 0.5)) | ||
), | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(newPanelId, new Rect(0, 0, 1, 0.5)), | ||
new PanelGridState(firstPanelId, new Rect(0, 0.5, 1, 0.5)) | ||
), | ||
} | ||
}; | ||
|
||
// Input: two columns | ||
// | 1 | 2 | | ||
// | 1 | 2 | | ||
// Possible States: | ||
// 1) split the first panel horizontally, the new panel is in the second row | ||
// 2) split the first panel horizontally, the new panel is in the first row | ||
// 3) split the second panel horizontally, the new panel is in the second row | ||
// 4) split the second panel horizontally, the new panel is in the first row | ||
// TODO: 5) split both the first and second panel horizontally, the new panel will take up the entirety of the second row | ||
// TODO: 6) split both the first and second panel horizontally, the new panel will take up the entirety of the first row | ||
yield return new object[] | ||
{ | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(firstPanelId, new Rect(0, 0, 0.5, 1)), | ||
new PanelGridState(secondPanelId, new Rect(0.5, 0, 0.5, 1)) | ||
), | ||
new[] | ||
{ | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(firstPanelId, new Rect(0, 0, 0.5, 0.5)), | ||
new PanelGridState(newPanelId, new Rect(0, 0.5, 0.5, 0.5)), | ||
new PanelGridState(secondPanelId, new Rect(0.5, 0, 0.5, 1)) | ||
), | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(newPanelId, new Rect(0, 0, 0.5, 0.5)), | ||
new PanelGridState(firstPanelId, new Rect(0, 0.5, 0.5, 0.5)), | ||
new PanelGridState(secondPanelId, new Rect(0.5, 0, 0.5, 1)) | ||
), | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(firstPanelId, new Rect(0, 0, 0.5, 1)), | ||
new PanelGridState(secondPanelId, new Rect(0.5, 0, 0.5, 0.5)), | ||
new PanelGridState(newPanelId, new Rect(0.5, 0.5, 0.5, 0.5)) | ||
), | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(firstPanelId, new Rect(0, 0, 0.5, 1)), | ||
new PanelGridState(newPanelId, new Rect(0.5, 0, 0.5, 0.5)), | ||
new PanelGridState(secondPanelId, new Rect(0.5, 0.5, 0.5, 0.5)) | ||
), | ||
} | ||
}; | ||
|
||
// Input: two rows | ||
// | 1 | 1 | | ||
// | 2 | 2 | | ||
// Possible States: | ||
// 1) split the first panel vertically, the new panel is in the second column | ||
// 2) split the first panel vertically, the new panel is in the first column | ||
// 3) split the second panel vertically, the new panel is in the second column | ||
// 4) split the second panel vertically, the new panel is in the first column | ||
// TODO: 5) split both the first and second panel vertically, the new panel will take up the entirety of the second column | ||
// TODO: 6) split both the first and second panel vertically, the new panel will take up the entirety of the first column | ||
yield return new object[] | ||
{ | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(firstPanelId, new Rect(0, 0, 1, 0.5)), | ||
new PanelGridState(secondPanelId, new Rect(0, 0.5, 1, 0.5)) | ||
), | ||
new[] | ||
{ | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(firstPanelId, new Rect(0, 0, 0.5, 0.5)), | ||
new PanelGridState(secondPanelId, new Rect(0, 0.5, 1, 0.5)), | ||
new PanelGridState(newPanelId, new Rect(0.5, 0, 0.5, 0.5)) | ||
), | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(newPanelId, new Rect(0, 0, 0.5, 0.5)), | ||
new PanelGridState(secondPanelId, new Rect(0, 0.5, 1, 0.5)), | ||
new PanelGridState(firstPanelId, new Rect(0.5, 0, 0.5, 0.5)) | ||
), | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(firstPanelId, new Rect(0, 0, 1, 0.5)), | ||
new PanelGridState(secondPanelId, new Rect(0, 0.5, 0.5, 0.5)), | ||
new PanelGridState(newPanelId, new Rect(0.5, 0.5, 0.5, 0.5)) | ||
), | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(firstPanelId, new Rect(0, 0, 1, 0.5)), | ||
new PanelGridState(newPanelId, new Rect(0, 0.5, 0.5, 0.5)), | ||
new PanelGridState(secondPanelId, new Rect(0.5, 0.5, 0.5, 0.5)) | ||
), | ||
} | ||
}; | ||
|
||
// Input: three panels with one large row | ||
// | 1 | 1 | | ||
// | 2 | 3 | | ||
// Possible States: | ||
// 1) split the first panel vertically, the new panel is in the second column | ||
// 2) split the first panel vertically, the new panel is in the first column | ||
yield return new object[] | ||
{ | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(firstPanelId, new Rect(0, 0, 1, 0.5)), | ||
new PanelGridState(secondPanelId, new Rect(0, 0.5, 0.5, 0.5)), | ||
new PanelGridState(thirdPanelId, new Rect(0.5, 0.5, 0.5, 0.5)) | ||
), | ||
new[] | ||
{ | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(firstPanelId, new Rect(0, 0, 0.5, 0.5)), | ||
new PanelGridState(newPanelId, new Rect(0.5, 0, 0.5, 0.5)), | ||
new PanelGridState(secondPanelId, new Rect(0, 0.5, 0.5, 0.5)), | ||
new PanelGridState(thirdPanelId, new Rect(0.5, 0.5, 0.5, 0.5)) | ||
), | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(newPanelId, new Rect(0, 0, 0.5, 0.5)), | ||
new PanelGridState(firstPanelId, new Rect(0.5, 0, 0.5, 0.5)), | ||
new PanelGridState(secondPanelId, new Rect(0, 0.5, 0.5, 0.5)), | ||
new PanelGridState(thirdPanelId, new Rect(0.5, 0.5, 0.5, 0.5)) | ||
) | ||
} | ||
}; | ||
|
||
// Input: three panels with one large column | ||
// | 1 | 2 | | ||
// | 1 | 3 | | ||
// Possible States: | ||
// 1) split the first panel horizontally, the new panel is in the second row | ||
// 2) split the first panel horizontally, the new panel is in the first row | ||
yield return new object[] | ||
{ | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(firstPanelId, new Rect(0, 0, 0.5, 1)), | ||
new PanelGridState(secondPanelId, new Rect(0.5, 0, 0.5, 0.5)), | ||
new PanelGridState(thirdPanelId, new Rect(0.5, 0.5, 0.5, 0.5)) | ||
), | ||
new[] | ||
{ | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(firstPanelId, new Rect(0, 0, 0.5, 0.5)), | ||
new PanelGridState(newPanelId, new Rect(0, 0.5, 0.5, 0.5)), | ||
new PanelGridState(secondPanelId, new Rect(0.5, 0, 0.5, 0.5)), | ||
new PanelGridState(thirdPanelId, new Rect(0.5, 0.5, 0.5, 0.5)) | ||
), | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(newPanelId, new Rect(0, 0, 0.5, 0.5)), | ||
new PanelGridState(firstPanelId, new Rect(0, 0.5, 0.5, 0.5)), | ||
new PanelGridState(secondPanelId, new Rect(0.5, 0, 0.5, 0.5)), | ||
new PanelGridState(thirdPanelId, new Rect(0.5, 0.5, 0.5, 0.5)) | ||
), | ||
} | ||
}; | ||
|
||
// Input: four panels | ||
// Possible States: none | ||
yield return new object[] | ||
{ | ||
CreateState( | ||
isHorizontal: true, | ||
new PanelGridState(firstPanelId, new Rect(0, 0, 0.5, 0.5)), | ||
new PanelGridState(secondPanelId, new Rect(0, 0.5, 0.5, 0.5)), | ||
new PanelGridState(thirdPanelId, new Rect(0.5, 0, 0.5, 0.5)), | ||
new PanelGridState(fourthPanelId, new Rect(0.5, 0.5, 0.5, 0.5)) | ||
), | ||
Array.Empty<WorkspaceGridState>() | ||
}; | ||
} | ||
} |
387 changes: 387 additions & 0 deletions
387
tests/NexusMods.UI.Tests/WorkspaceSystem/GridUtilsTests/GetStateWithoutPanelTests.cs
Large diffs are not rendered by default.
Oops, something went wrong.