Is it possible to use a VoronoiMesh
to define a TogglerBar
or SetterBar
type Control
?
For example, I can customise the looks of a TogglerBar
Control[{{a, 0, ""},
{1 -> Spacer[{.1, .1}], 4 -> Spacer[{.1, 20}],
7 -> Spacer[{.1, .1}], 2 -> Spacer[{20, .1}],
5 -> Spacer[{20, 20}], 8 -> Spacer[{20, .1}],
3 -> Spacer[{.1, .1}], 6 -> Spacer[{.1, 20}],
9 -> Spacer[{.1, .1}]},
Appearance -> "Vertical" -> {3, 3}, ControlType -> TogglerBar}]
But this doesn't change the rectangle-shaped buttons and I don't think this is the way to go about if I want to define a VoronoiMesh
with clickable and "toggleable" cells.
I want something like
where each cell is selected/unselected whenever I click it, adding/removing a correspondent number to a list, for example, in the case of a TogglerBar
. I would like this to also work as a SetterBar
.
Any ideas?
Edit 1: Thank you all for your answers. As a follow up, I'm now interested in developing a TogglerBar
-type object that allows users to hold and drag the mouse to select/deselect several cells. If you have time, please take a look at it, I'm a bit a clueless on how to do this, so any hint or idea is welcome.
Edit 2: Following Lukas Lang's answer below, I also tried to vary the grid size in Manipulate
Manipulate[x,
Control[{n, 2, 10, 1}],
Control[{{x, 3, ""},
MeshSetterBar[VoronoiMesh@RandomReal[{0, 1}, {n, 2}]]}]]
However, this doesn't seem to behave as expected. Instead, I get
Any idea why, and how to fix this? I tried Dynamic
, but didn't work.
Edit 3: As a third and (hopefully) final edit, thanks to Lukas Lang's answer, I was able to solve the original question. Now I just need to define several toggler-type meshes of the same shape. One naive attempt is simply
Manipulate[Null, Dynamic@Grid[{
{Control[{n, 2, 10, 1}]},
{Control[{{x, {}, ""},
MeshTogglerBar[VoronoiMesh@RandomReal[{0, 1}, {n, 2}]]}]},
{Control[{{y, {}, ""},
MeshTogglerBar[VoronoiMesh@RandomReal[{0, 1}, {n, 2}]]}]}
}]]
Which naturally doesn't yield meshes with the same shape, due to the randomness in defining the points. How can I solve this? I have tried to define the mesh outside, then I lose the dynamic update of the mesh-dependent control. I would like something like the following, where I'm able to independently update similarly shaped meshes
Manipulate
implementation? $\endgroup$ClickPane
to handle the mouse clicks and toggling. $\endgroup$mesh=VoronoiMesh@RandomReal[{0, 1}, {n, 2}]
in theTrackingFunction
forn
. If you want the same mesh every time you come back to the samen
, then you'll need to do something else, like definemesh[n_] := mesh[n] = VoronoiMesh@RandomReal[{0, 1}, {n, 2}]
or useSeedRandom[]
ormeshTogglerBar[VoronoiMesh@Take[myBigListOfPoints, n]]
and so forth. $\endgroup$