While I have created quite a few widgets so far (inventory, equipment, skill window, and a few more niche things) I’m definitely no expert.
When it comes to the canvas panel, in a sense it has to be the top most parent, but not for each individual widget.
What I mean is, say you have an inventory and equipment window. They can either have a canvas panel each, and you add each of them to the viewport. Or you can have another “main widget” which you then add these inventory & equipment widgets to. What’s the best practice in that case, I really do not know.
But when it comes to inventory with inventory slots, definitely don’t use canvas panel for the slots.
You create the main inventory, which is a vertical box. Which would look something like
Canvas panel - border (visualizing the inventory) - vertical box (storing the slots).
Then, I suppose during the construction event of the inventory widget, you create the inventory slots you want and add them as children to the vertical box.
These inventory slots does not have a canvas panel, but instead (can) have a sizebox as the base so you can determine their size, a button (or something else) for the interaction and then maybe some image.
The button will stretch over the whole view, making it look a bit weird, but it will look good when added to the vertical box.
Of course, to have it look better, you might want to add a border inside a border so it’s not too sterile. Those black outlines though, I have no idea how to do.
The vertical box should be expanding automatically as you add new slots.
The size box is a bit tricky to use. Sometimes the buttons (let’s say you’re using buttons) will fill as much as they can, as long as they keep square. Other times, they will stretch into rectangles. It’s a fiddly business. I’d say try without it first and see how it works.
Example: inventory widget and slot widget. And also a debug window…
Oh yeah, I forgot;
If you add 2 elements to say a vertical box, you can choose if they should fill or have some other alignment. But in the case of a header and body situation, you probably don’t want them to divide the space in half. The header should only be at the top. That’s a good situation for the size box, if the “align to top” doesn’t do its job properly.