setchi / FancyScrollView

[Unity] Scroll view component that can implement highly flexible animations.
https://setchi.jp/FancyScrollView/
MIT License
3.04k stars 385 forks source link

how to implement n columns m row scroll view #31

Closed mcaisw closed 4 years ago

mcaisw commented 5 years ago

Is it possible to creat a n columns m row scroll view

setchi commented 5 years ago

@mcaisw Not officially supported. But it can be implemented as follows.

public class Entity
{
    public string Message; // Entity Data
    public Entity(string message) => Message = message;
}

public class Row
{
    public Entity[] Entities;
    public Row(Entity[] entities) => Entities = entities;
}

public class ScrollView : FancyScrollView<Row>
{
    void Start()
    {
        const int DataCount = 20;
        const int ColumnCount = 3;

        var rows = Enumerable.Range(0, DataCount)
            .GroupBy(i => i / ColumnCount)
            .Select(group => group
                .Select(i => new Entity($"Entity {i}")).ToArray())
            .Select(entities => new Row(entities))
            .ToArray();

        base.UpdateContents(rows);
    }
}

public class RowCell : FancyScrollViewCell<Row>
{
    public override void UpdateContent(Row row)
    {
        // Show row.Entities[] data
    }
}
mcaisw commented 5 years ago

image Hope adding this feature to subsequent updates. @setchi

setchi commented 4 years ago

@mcaisw Hi, Added Grid Layout demo.

Demo: https://setchi.jp/FancyScrollView/08_GridView Code: https://github.com/setchi/FancyScrollView/tree/master/Assets/FancyScrollView/Examples/Sources/08_GridView

anim

Thanks.