GridLayout was inspired by the GridBagLayout manager. It is equally flexible but more intuitive for my taste and it also requires less boilerplate code.
Each cell is a uicontainer and can hold only one child. Unlike GridBagLayout, children are added at creation time by passing the cell container handle as their parent. No 'Add' methods are needed, which reduces the amount of code.
Cell sizes can be specified in pixels or as relative values. Merging and removing cells are supported, as well as various alignment options: stretch, center, left, right, top, bottom.
The archive also includes demos illustrating the GridLayout capabilities . Bug reports and suggestion for improvement are very much appreciated. Download, unpack, and enjoy!
Mihail Petrov (2021). GridLayout (https://www.mathworks.com/matlabcentral/fileexchange/29472-gridlayout), MATLAB Central File Exchange. Retrieved .
Eric, the Layout.Cell property itself is an array of uicontainers. This is one of the the main features of GridLayout. You don't need any additional function.
To make it easier to wrap child objects, such as nested GridLayout's and plots, I think a function such as GridLayout.WrapCell(Row, Col) would help. It would create a uicontainer() inside the cell, and then return a handle to that container.
Another change was to replace the HMargin and VMargin parameters with LMargin, RMargin, TMargin, and BMargin, that is, left, right, top, and bottom. This is very useful for axes in particular. See demo 7 for an example.
Sounds awesome, can't wait to give it a try! Thanks Mihail!
Hi David & Eric,
Give me a few days still and I'll upload the fixed version. I've been really busy these days...
Thanks for your feedback!
Pretty cool library, thanks! I'm having problem #2 mentioned above by Eric Cousineau. Really needs to be able to handle multiple children in an axes object to be functional for plotting purposes.
Sure thing! I commented a small portion in the constructor to allow ~ishghandle() objects to contain a GridLayout.
I also updated the UpdateLayout() method to allow for plots.
I have uploaded a diff file: http://pastebin.com/knn05prR
However, I think it would probably be easier if both plots and child GridLayouts were wrapped in uicontainers() - that way they can be contained by a GridLayout. I was thinking that this wrapping could happen at the first call to UpdateLayout().
Eric, thanks for the feedback and rating.
Could you indicate what exactly you changed in the code? In the past months I made several small changes myself and I'd like to merge them with yours before uploading a new version.
Just realized a couple of things:
1) You can nest GridLayout's by disabling the check (ishghandle()) in the constructor and wrap it in a uicontainer.
2) If you add legends for your plot, it will introduce additional children into the cell, causing errors. The best fix for this is to wrap it in a container. This is also another bugfix towards adding plots without the little workaround.
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!