Makie: Removing gridlayouts

I’m wondering if I can remove a GridLayout from a figure. Elements can be easily removed with delete! but this does not work on an entire GridLayout. If I want the layout of a figure programatically by deleting items that were in a gridlayout, I’m currently left with white space.

You can trim! a layout to remove empty columns and rows. And there’s GridLayoutBase.remove_from_layout! or something like that to remove a GridLayout from a parent layout

Okay I’m still confused. I guess you meant `GridLayoutBase.remove_from_layout!, but I cannot call this on a GridLayout. Secondly, I don’t understand how trim! works. I have a Gridlayout in another GridLayout.

GridLayout[1:4, 1:3] with 7 children
 ┣━ [1:2, 1:3] Box
 ┣━ [1, 2] Button
 ┣━ [2, 2] Button
 ┣━ [1, 1] GridLayout[1:2, 1:1] with 2 children
 ┃ ┣━ [1, 1] Label
 ┃ ┗━ [2, 1] Label
 ┣━ [1:2, 3] GridLayout[1:2, 1:1] with 2 children
 ┃ ┣━ [1, 1] Axis
 ┃ ┗━ [2, 1] Button
 ┣━ [3, 2] GridLayout[1:1, 1:3] with 3 children
 ┃ ┣━ [1, 2] Label
 ┃ ┣━ [1, 1] Button
 ┃ ┗━ [1, 3] Button
 ┗━ [4, 2] GridLayout[1:1, 1:1] with 0 children

I added the gridlayout at [4,2] as a test, and since it has 0 children, I would think It should get trimmed off. However, calling `trim!(gl.parent), doesn’t actually do anything?

Okay, in this case I found deleterow(gl.parent, 4) works. Wouldn’t it make sense for delete! to also offer a method for gridlayouts? I tend to think of them as them as higher order elements, so to me it’d make sense to be able to delete them the same way I can delete a button or some other element.

trim! removes all completely empty rows and columns, you have to remove the nested gridlayouts first or they’ll count as elements. It might actually make sense to add delete! for GridLayout as well, it’s a completely different type than the Blocks that it normally applies to, but you’re right that they sometimes appear in similar contexts.

1 Like

Thanks for the answer. So how do I delete them otherwise at the moment for trim! to work? Removing them by hand with deleteat! from the contents (or something like that) didn’t work as expected.

Ah the signature was remove_from_gridlayout!(gc::GridContent) so the GridContent of a GridLayout is in gridlayout.layoutobservables.gridcontent[], admittedly not user-friendly :slight_smile: Would you mind opening an issue about adding delete! in GridLayoutBase.jl?

1 Like

I’ll open one now!