How to delete! in GLMakie

I am attempting to create an GUI with GLMakie, where elements can be added and removed interactively. I specifically want to remove groups of several Blocks at a time, but I can’t seem to be able to remove even a single Block. Here is a minimum working example:

using GLMakie
f = Figure()
b = Button(f[1, 1]; label = "Delete Me!")
delete!(b) # doesn't delete b :(
display(f)

The docs seem to indicate that this should work?

I am running the latest version of GLMakie (v0.8.0) on macOS Monetery (v12.5).

Your code works fine for me (opens an empty figure and if I comment the delete! statement, the button is visible). Julia 1.9 release branch + GLMakie 0.8 + macOs Ventura…

Hmm, I’m still on 1.8.4. I’m going to try upgrading.

Doesn’t seem to work for me on 1.9.0 either. Anything else I should check?

Should not be necessary (I’m just to hyped for the new native code caching and 1.9 is actually quite stable already for my work)…

I have just switched back to 1.8 (still GLMakie 0.8) and run your code… Still works here!? The only remaining difference is the macOS version (which should not matter). I’m running the M1 version of Julia, not Rosetta.

Deleting blocks doesn’t work reliably currently, I think if it was working before the refactor it didn’t work anymore afterwards. It’s tricky to correctly clean up all observable traces and there hasn’t been a focus on it, yet.

After a great deal of tinkering, I have found that the following solution works for me:

using GLMakie
f = Figure()
b1 = Button(f[1, 1]; label = "Delete Me!")
b2 = Button(f[2, 1]; label = "Don't Delete Me!")
delete!(b1)
empty!(b1.blockscene)
trim!(f.layout)
display(f)

(The order of the delete! and empty! calls does not matter.)

Although b1 is no longer visible and the rest of f is adjusted accordingly, I suspect that there are still traces of b1 remaining in f. Any suggestions for how to easily locate all of them?

Here is a hackish solution I crafted a while ago to remove Blocks: Makie workflow to access and change attributes of objects - #5 by fatteneder

Not 100% sure if it really cuts all ties. It also uses internals of GridLayoutBase, so don’t expect this to run on all versions. I think I developed this on Makie@v0.18.x.