# Graphics Primitive Selector

## Goal and motivation

I want to build something that would intuitively work like:

Graphics @ PaneSelector[{True -> something, False -> {}}, Dynamic @ show]


as opposed to

Graphics @ Dynamic[If[show, something, {}]


The difference is that once PaneSelector is formatted then only information about show needs to travel between Kernel and FrontEnd.

With Dynamic@If[... whole If[...] needs to go back and forth. You can imagine that for large something that is a waste of time and may affect UX.

## Ideas and problems

My idea was to build something based on FrontEnd functions:

DynamicBox[FEPrivateIf[x, something, somethingElse]]


And it works in some cases:

With[{
something     = First@ToBoxes@Graphics@Disk[],
somethingElse = First@ToBoxes@Graphics@Circle[]
},
DynamicModule[{x = True},
{
Checkbox@Dynamic@x,
Graphics[RawBoxes@DynamicBox[FEPrivateIf[x, something, somethingElse]]]
}
]
]


It does not work when:

• x is not a DynamicModule variable

Sometimes you just can't use DynamicModule and want x to be a regular global symbol. Sometimes DynamicModule variables have troubles of updating dynamic so you want to avoid it even if you could use it. So you can see that is a quite limiting factor.

• x is a nested association.

Assuming using DynamicModule you can use

• x = {True} FEPrivateIf[x[[1]],... or
• x = <|"a"->True|> FEPrivateIf[x["a"],...

It will work fine but it can't handle:

• x = <|"a" -> <|"b" -> True|>|> and FEPrivateIf[x["a", "b"],...

## Requirements

My solution is limited to DynamicModule variables which are arrays/lists or 'flat' associations.

Desired solution should work with arbitrary expression similarly to

PaneSelector[{...}, Dynamic @ expression]
`

If not it should at minimum support global symbols and nested associations.