Making a button grid with Makie?

Ah no Button currently doesn’t have an official option to ignore the text width and just scale with the figure, I assumed that was never needed.

But you can set the internal field layoutobservables.autosize such that you overwrite the x value with nothing, which will make the button behave like it has no intrinsic width. The top row here has that workaround applied and the bottom row not. This will still not look good if you have too many buttons in a row.

The other way you could go is to make the figure big enough for all the buttons you have via resize_to_layout!.

f = Figure()

gl1 = GridLayout(f[1, 1], tellwidth = false)
gl2 = GridLayout(f[2, 1], tellwidth = false)

for i in 1:8
    b = Button(gl1[1, i], label = "$i")
    b.layoutobservables.autosize[] = (nothing, b.layoutobservables.autosize[][2])
    Button(gl2[2, i], label = "$i")
end

f

2 Likes