How to make a grid system with scalable sizes

Hi, im trying to make and inventory grid system that when something is added or removed from the inventory the items (the images for now) automatically arranges like how a uigridlayout would, but as you can see different images take up different ammount of grids so a uigrid layout wont work. How would I go about making this?