# GLMakie: hide control widgets before saving?

**URL:** <https://discourse.julialang.org/t/glmakie-hide-control-widgets-before-saving/101721>\
**Category:** Visualization\
**Tags:** glmakie\
**Created:** [July 18, 2023, 9:28am UTC](https://discourse.julialang.org/t/glmakie-hide-control-widgets-before-saving/101721 "2023-07-18T09:28:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwlidar](https://avatars.discourse-cdn.com/v4/letter/m/6de8d8/32.png) [@mwlidar](https://discourse.julialang.org/u/mwlidar)\
**Post date:** [July 18, 2023, 9:28am UTC](https://discourse.julialang.org/t/glmakie-hide-control-widgets-before-saving/101721/1 "2023-07-18T09:28:19Z")

</div>

Using GLMakie I created a nice 3D view of my data surrounded by some widget (Sliders, Textboxes) to control the appearance (see below). If I now want to save this to a file I would like to only the data, the title and the color bar be included. My first idea was to hide the controls before calling save(), but unfortunately only a few widget support the visible property. Does somebody have an idea how to solve this problem? Are there some other means than visible to hide widgets? Or is it possible to only call save for a subselection of objects in a Figure?

 ![test3d](https://global.discourse-cdn.com/julialang/original/3X/2/3/23e77a289e0e17aea108e2f6615900935262fc79.png)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [July 18, 2023, 9:53am UTC](https://discourse.julialang.org/t/glmakie-hide-control-widgets-before-saving/101721/2 "2023-07-18T09:53:01Z")

</div>

Hm you can probably set `obj.blockscene.visible[] = false` on every control widget (`blockscene` is the container scene for all visual objects of a `Block` widget).

You don’t mind that you will have whitespace in all the places where widgets are hidden? If you do, you could also delete all those objects instead.

Easiest might be:

```julia
for i in reverse(eachindex(fig.content))
    c = fig.content[i]
    if !(c in list_of_objs_to_keep)
        delete!(c)
    end
end
trim!(fig.layout)

```

If you want to keep the figure intact because you need it after saving, another option might be to save the whole figure but crop the png to the boundingbox of the objects you want to keep (in your example that could work I guess?). You could get the boundingboxes of each by accessing `obj.layoutobservables.computedbbox[]` I think which you could then `union` together

---

<div class="post-metadata">

**Author:** ![mwlidar](https://avatars.discourse-cdn.com/v4/letter/m/6de8d8/32.png) [@mwlidar](https://discourse.julialang.org/u/mwlidar)\
**Post date:** [July 18, 2023, 1:30pm UTC](https://discourse.julialang.org/t/glmakie-hide-control-widgets-before-saving/101721/3 "2023-07-18T13:30:50Z")

</div>

Thanks very much for the various hints! Unfortunately, the first method leaves a lot of whitespace for the hidden widgets, as you already anticipated. And funnily for Textboxes only the box is hidden, not the text…

The second method is not optimal as I want to choose different views on the data and save each. So, deleting the widgets is a not a real option.

I’m now using the third method, as for my layout it’s possible to cut away the widgets with a simple crop. Implementing this I saw that `obj.layoutobservables.computedbbox[]` for colorbars only includes the bar but not the labels. For my layout this is not a problem, as they are always on the right side, so I simply can expand the crop-box to the right end of the window. But how could this be made working in general?

And I noticed that the call to save() closes the window. I can open it again in the same state and continue work. But is this expected behavior or a bug?

Thanks again!

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [July 18, 2023, 2:17pm UTC](https://discourse.julialang.org/t/glmakie-hide-control-widgets-before-saving/101721/4 "2023-07-18T14:17:20Z")

</div>

> I saw that `obj.layoutobservables.computedbbox[]` for colorbars only includes the bar but not the labels.

Ah right you have to also take protrusions into account, so plus the values in `obj.layoutobservables.protrusions`.

And you can save this way without closing:

```julia
screen = display(figure)
save("image.png", Makie.colorbuffer(screen))

```

---

<div class="post-metadata">

**Author:** ![mwlidar](https://avatars.discourse-cdn.com/v4/letter/m/6de8d8/32.png) [@mwlidar](https://discourse.julialang.org/u/mwlidar)\
**Post date:** [July 19, 2023, 11:54am UTC](https://discourse.julialang.org/t/glmakie-hide-control-widgets-before-saving/101721/5 "2023-07-19T11:54:12Z")

</div>

Ah, cool! Directly accessing `Makie.colorbuffer(screen)` allows me also to skip the temporary file. And getting the screen from the fig itself via `fig.scene.current_screens` makes it easy to add a save button to the window widgets. (Hope both are a halfway stable interface, since they not documented or exported…)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [July 19, 2023, 12:22pm UTC](https://discourse.julialang.org/t/glmakie-hide-control-widgets-before-saving/101721/6 "2023-07-19T12:22:19Z")

</div>

> [@mwlidar](#):
>
> Hope both are a halfway stable interface, since they not documented or exported…)

I think so, and at least `colorbuffer` should probably be documented right @sdanisch ?
