Skip to content

Commit

Permalink
Code cleanup and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Delsin-Yu committed Apr 22, 2024
1 parent fdfdc3e commit 878edb8
Show file tree
Hide file tree
Showing 34 changed files with 149 additions and 142 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Godot;
using Godot;
using GodotViews.VirtualGrid;

namespace GDViews.VirtualGrid.Example.TMI.Storage;
Expand Down
2 changes: 1 addition & 1 deletion GDViews.VirtualGridView.Test/Scripts/TextView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Godot;
using Godot;

namespace GDViews.VirtualGrid.Example.TMI;

Expand Down
28 changes: 13 additions & 15 deletions GDViews.VirtualGridView/Builder/DataLayoutBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,18 @@ internal partial class DataLayoutBuilder<TDataType>(
bool reverseLocalLayout,
bool isHorizontalDataLayout) : IHorizontalDataLayoutBuilder<TDataType>, IVerticalDataLayoutBuilder<TDataType>
{
private record struct AnnotatedDataSet<T>(IDynamicGridViewer<T> DataSet, int LocalIndex);

private readonly List<IDynamicGridViewer<TDataType>> _dataSetDefinitions = [];
public DataLayoutSelectionBuilder DataLayoutSelectionBuilder { get; } = dataLayoutSelectionBuilder;
public IEqualityComparer<TDataType> EqualityComparer { get; } = equalityComparer ?? EqualityComparer<TDataType>.Default;

public IHorizontalDataLayoutBuilder<TDataType> AppendRowDataSet(IDynamicGridViewer<TDataType> dataSetDefinition, int repeatCount = 1)
{
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(repeatCount);
for(var i = 0; i < repeatCount; i++)
for (var i = 0; i < repeatCount; i++)
_dataSetDefinitions.Add(dataSetDefinition);
return this;
}

public IVerticalDataLayoutBuilder<TDataType> AppendColumnDataSet(IDynamicGridViewer<TDataType> dataSetDefinition, int repeatCount = 1)
{
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(repeatCount);
for(var i = 0; i < repeatCount; i++)
_dataSetDefinitions.Add(dataSetDefinition);
return this;
}

public IFinishingArgumentBuilder<TDataType, TButtonType, TExtraArgument> WithArgument<TButtonType, TExtraArgument>(
PackedScene itemPrefab,
Control itemContainer,
Expand All @@ -56,17 +46,15 @@ TExtraArgument extraArgument
dataMap[index] = new(dataSetDefinition, currentCount++);
}

foreach (var (dynamicGridViewer, count) in dataSetCounter)
foreach (var (dynamicGridViewer, count) in dataSetCounter)
dynamicGridViewer.FixedMetric = count;

if (reverseLocalLayout)
{
foreach (ref var annotatedDataSet in dataMap.AsSpan())
{
var count = dataSetCounter[annotatedDataSet.DataSet] - 1;
annotatedDataSet.LocalIndex = count - annotatedDataSet.LocalIndex;
}
}

var viewColumns = DataLayoutSelectionBuilder.ViewHandlerBuilder.ViewportColumns;
var viewRows = DataLayoutSelectionBuilder.ViewHandlerBuilder.ViewportRows;
Expand All @@ -84,4 +72,14 @@ TExtraArgument extraArgument
extraArgument
);
}

public IVerticalDataLayoutBuilder<TDataType> AppendColumnDataSet(IDynamicGridViewer<TDataType> dataSetDefinition, int repeatCount = 1)
{
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(repeatCount);
for (var i = 0; i < repeatCount; i++)
_dataSetDefinitions.Add(dataSetDefinition);
return this;
}

private record struct AnnotatedDataSet<T>(IDynamicGridViewer<T> DataSet, int LocalIndex);
}
3 changes: 1 addition & 2 deletions GDViews.VirtualGridView/Builder/FinishingArgumentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ internal class FinishingArgumentBuilder<TDataType, TButtonType, TExtraArgument>(
TExtraArgument extraArgument) : IFinishingArgumentBuilder<TDataType, TButtonType, TExtraArgument>
where TButtonType : VirtualGridViewItem<TDataType, TExtraArgument>
{
private readonly TExtraArgument? _extraArgument = extraArgument;
private bool _autoHideHorizontalScrollBar;
private bool _autoHideVerticalScrollBar;

private readonly TExtraArgument? _extraArgument = extraArgument;
private ScrollBar? _horizontalScrollBar;
private IElementFader? _horizontalScrollBarFader;
private IScrollBarTweener? _horizontalScrollBarTweener;
Expand Down
4 changes: 2 additions & 2 deletions GDViews.VirtualGridView/Builder/IDataLayoutBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public interface IDataLayoutBuilder
/// [Row 5] [DataSet3: 00, 01, 02, 03, 04, 05]
/// </code></remarks>
IHorizontalDataLayoutBuilder<TDataType> WithHorizontalDataLayout<TDataType>(IEqualityComparer<TDataType>? equalityComparer = null, bool reverseLocalLayout = false);


/// <summary>
/// Instruct the view controller to layout the datasets vertically.
/// </summary>
Expand Down
1 change: 0 additions & 1 deletion GDViews.VirtualGridView/Builder/IViewHandlerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace GodotViews.VirtualGrid.Builder;


/// <summary>
/// The builder that continues the building process of the <see cref="IVirtualGridView{TDataType}"/> instance.<br/>
/// Use the <see cref="WithHandlers"/> method to set up the visual transition behavior for the grid elements.
Expand Down
3 changes: 3 additions & 0 deletions GDViews.VirtualGridView/Core/MoveDirection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ public enum MoveDirection
{
/// <summary> Moving Up. </summary>
Up,

/// <summary> Moving Down. </summary>
Down,

/// <summary> Moving Left. </summary>
Left,

/// <summary> Moving Right. </summary>
Right
}
2 changes: 1 addition & 1 deletion GDViews.VirtualGridView/Core/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal static class Utils
internal static readonly StringName UIRight = "ui_right";

internal static object? CurrentActiveGridView { get; set; }

internal static bool TryGetMoveDirection(ref Vector2I vector, out Vector2I moveDirection)
{
moveDirection = Vector2I.Zero;
Expand Down
39 changes: 21 additions & 18 deletions GDViews.VirtualGridView/Core/VirtualGridViewImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@ internal class VirtualGridViewImpl<TDataType, TButtonType, TExtraArgument> :
private readonly Stack<TButtonType> _pendingRemove = [];
private readonly ScrollBar? _verticalScrollBar;
private readonly Vector2I _viewportSize;

private IElementPositioner _elementPositioner;
private IElementTweener _elementTweener;
private IElementFader _elementFader;
private IScrollBarTweener _hScrollBarTweener;
private IScrollBarTweener _vScrollBarTweener;
private IElementFader _hScrollBarFader;
private IElementFader _vScrollBarFader;

private NullableData<TDataType> _currentSelectedData;
private int _currentSelectedViewColumnIndex;
private int _currentSelectedViewRowIndex;

private DataView[,] _currentView;
private IElementFader _elementFader;

private IElementPositioner _elementPositioner;
private IElementTweener _elementTweener;
private IElementFader _hScrollBarFader;
private IScrollBarTweener _hScrollBarTweener;
private bool _isDragging;

private bool _isHorizontalScrollBarVisible = true;
private bool _isVerticalScrollBarVisible = true;
private DataView[,] _nextView;

private Vector2 _startDragPosition;
private IElementFader _vScrollBarFader;
private IScrollBarTweener _vScrollBarTweener;

internal VirtualGridViewImpl(
int viewportRows,
Expand All @@ -78,11 +78,11 @@ internal VirtualGridViewImpl(
ViewRows = viewportRows;
ViewColumns = viewportColumns;


_elementPositioner = elementPositioner;
_elementTweener = elementTweener;
_elementFader = elementFader;

_hScrollBarTweener = horizontalScrollBarTweener;
_hScrollBarFader = horizontalScrollBarFader;
_vScrollBarTweener = verticalScrollBarTweener;
Expand Down Expand Up @@ -153,7 +153,7 @@ static void InitializeScrollBar(ScrollBar? scrollBar)

public int ViewColumns { get; }
public int ViewRows { get; }

public IElementPositioner ElementPositioner
{
get => _elementPositioner;
Expand Down Expand Up @@ -501,9 +501,9 @@ private void ProcessScrollWheelAndDragInput(InputEvent inputEvent)
switch (inputEvent)
{
case InputEventMouseButton mouseButton:
if(mouseButton.IsReleased()) return;

if (mouseButton.IsReleased()) return;

var mouseButtonButtonIndex = mouseButton.ButtonIndex;

var mapVH = mouseButton.GetModifiersMask().HasFlag(KeyModifierMask.MaskShift);
Expand All @@ -527,16 +527,16 @@ private void ProcessScrollWheelAndDragInput(InputEvent inputEvent)

break;
case InputEventMouseMotion mouseMotion:

if (_isDragging == false) return;

if (!TryGetMoveDirection(
ref _startDragPosition,
mouseMotion.GlobalPosition,
_cellItemSize,
out simulatedMoveDirection
)) return;

break;
default: return;
}
Expand Down Expand Up @@ -615,7 +615,10 @@ int dataSetMaxColumnIndex
instance = _itemPrefab.Instantiate<TButtonType>();
instance.CallCreate();
}
else instance.Show();
else
{
instance.Show();
}

_itemContainer.AddChild(instance);

Expand Down
Loading

0 comments on commit 878edb8

Please sign in to comment.