ID:273699
 
I've seen a few libraries and demos but I cant quite grasp how to display any list in a grid.

I know like winset(src,"src.whatevers","grid:1,1") but it's not enough to display the whole list on the grid.


I'm not a very good explainer but any help?
If you are just displaying the raw contents of a list in a grid, you'll want to of course loop through all objects/entries in the list in question. You will want to assign each object its own Y location in the grid while giving it an X location of 1. This will display the objects in a descending order. For example:


var/i = 0 // we want to assign a variable to keep track of how many times you loop.
for(var/obj/items/item in contents) // loops through every item in contents
winset(src, "grid", {"current-cell=1,[++i]"}) // shifts the cell we will output the item to to 1, i. ++i increases the i variable, so that we may have an increasing Y value
src << output(item, "grid") // we finally output the item in the grid, to the location we assigned in the above winset()
In response to Duelmaster409
Is that better than setting the grid's dimensions ahead of time?
verb/update_inventory()
var/i=1
winset(src,"inventory.grid",{"cells="1x[src.contents.len]""})
for(var/atom/a in src.contents)
src<<output(a,"inventory.grid:1x[i]")
i++
In response to Spunky_Girl
I don't think it honestly matters, but your method would make more sense when briefly skimmed as apposed to mine.
In response to Spunky_Girl
I've always set the grid's size after doing everything. It makes no difference since the final value of i is the same as src.contents.len by the end of the loop.

If you check "is-list" in the grid's properties, you can use this instead, and not have things go only horizontally:
mob/proc/update_inventory()
var i
winset(src, "inventory.grid", "cells='[contents.len]'")
for(var/atom/a in src.contents)
src << output(a, "inventory.grid:[++i]") // no need for column x row

I also just put ++i inside the expression because it saves a line while doing the same thing.