Created
February 28, 2024 14:34
-
-
Save jkrumbiegel/b976e39f68cacfc4566cfc251f9b2aa6 to your computer and use it in GitHub Desktop.
Makie delete gridlayout recursively
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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