Display Inventory Window ?

I’m working on an inventory system for a project of mine and haven’t been able to figure out how I can get items stored in a list and display the icon of each as a GUI Button with x amount of rows, and y amount of columns.

What I can’t get is to display, say 4 buttons, in a row then go down and make another row of buttons. So basically you’d end up with a grid of buttons 4 buttons wide, and however tall it needs to be to fit all the items in the list.

All of the other things such as replacing the button look with a 2D Texture is easy.

If you have any advice/code snippets I’d appreciate the help.

Something like this:

public void OnGUI()
    List<InventoryItem> items = new List<InventoryItem>();
    items.Add(new InventoryItem("Sword"));
    items.Add(new InventoryItem("Shield"));
    items.Add(new InventoryItem("Boots"));
    items.Add(new InventoryItem("Skull"));
    items.Add(new InventoryItem("Socks"));
    items.Add(new InventoryItem("Cheese"));
    items.Add(new InventoryItem("Tea"));
    items.Add(new InventoryItem("Hat"));
    items.Add(new InventoryItem("Glasses"));
    items.Add(new InventoryItem("Scrolls(c)"));

    for (int x = 0; x < (items.Count - 1) / 4 + 1; x++) // rows
        GUILayout.Label("Row " + (x + 1), GUILayout.Width(50));
        for (int y = 0; y < 4; y++) // columns
            int index = x * 4 + y;
            if (index >= items.Count)
            GUILayout.Button(items[index].name, GUILayout.Width(75));

public class InventoryItem
    public string name;
    public InventoryItem(string givenName) { name = givenName; }