Skip to content

Instantly share code, notes, and snippets.

@jkrumbiegel
Created February 28, 2024 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkrumbiegel/b976e39f68cacfc4566cfc251f9b2aa6 to your computer and use it in GitHub Desktop.
Save jkrumbiegel/b976e39f68cacfc4566cfc251f9b2aa6 to your computer and use it in GitHub Desktop.
Makie delete gridlayout recursively
using GLMakie
f = Figure()
b = Button(f[1, 1], tellwidth = false)
gl = GridLayout(f[2, 1])
function delete_contents!(gl::GridLayout)
for c in contents(gl)
if c isa GridLayout
delete_contents!(c)
Makie.GridLayoutBase.remove_from_gridlayout!(c.layoutobservables.gridcontent[])
else
delete!(c)
end
end
trim!(gl)
return
end
function populate_gl!(gl::GridLayout)
for i in 1:2, j in 1:2
if rand() < 0.10
subgl = GridLayout(gl[i, j])
populate_gl!(subgl)
else
(rand() > 0.5 ? Axis : PolarAxis)(gl[i, j])
end
end
end
on(b.clicks) do _
delete_contents!(gl)
populate_gl!(gl)
end
populate_gl!(gl)
f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment