53 lines
1.3 KiB
C#
53 lines
1.3 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace KitsuneCafe.UI
|
|
{
|
|
public class FixedLayout : ILayout
|
|
{
|
|
public FlowDirection Direction { get; set; }
|
|
public float ContentSize { get; private set; }
|
|
|
|
|
|
public float ItemSize { get; set; }
|
|
public float GutterSize { get; set; }
|
|
public int Count { get; set; }
|
|
public int Buffer { get; set; }
|
|
|
|
public FixedLayout(FlowDirection direction, float itemSize, float gutterSize)
|
|
{
|
|
Direction = direction;
|
|
ItemSize = itemSize;
|
|
GutterSize = gutterSize;
|
|
}
|
|
|
|
public FixedLayout(FlowDirection direction, float itemSize) : this(direction, itemSize, 0) { }
|
|
|
|
public float GetItemPosition(int index)
|
|
{
|
|
return index * (ItemSize + GutterSize);
|
|
}
|
|
|
|
public float GetItemSize(int _index)
|
|
{
|
|
return ItemSize;
|
|
}
|
|
|
|
public void Update(int itemCount, VisualElement _container)
|
|
{
|
|
Count = itemCount;
|
|
ContentSize = itemCount * (ItemSize + GutterSize);
|
|
}
|
|
|
|
public Range GetVisibleRange(float offset, float containerSize)
|
|
{
|
|
var size = ItemSize + GutterSize;
|
|
var first = Mathf.FloorToInt(offset / (ItemSize + GutterSize));
|
|
var count = Mathf.CeilToInt(containerSize / size) + Buffer;
|
|
var last = Math.Min(Count, first + count);
|
|
|
|
return new Range(first, last);
|
|
}
|
|
}
|
|
}
|