The Play function defines a toggle button to start and stop:
I'm trying to emulate that, but with a single button. I feel like this is a common enough task that this question should be answered somewhere (but I can't find it).
Question: I'd like a single button that toggles between (at least two) states: where each state has a different image and each performs a different action when clicked. The api could be this:
StateButton[<|ImageA -> ActionA, ImageB -> ActionB, ...|>]
Here was a first attempt using just row which uses nasty hacks to center the "play symbol":
startStop[startAction_,stopAction_] :=
Row[{Button["\!\(\*
StyleBox[AdjustmentBox[\"\[RightPointer]\",\nBoxBaselineShift->0.12313612313612314`,\nBoxMargins->{{0., 0.}, {-0.12313612313612314`, 0.12313612313612314`}}],\nFontSize->24]\)",
startAction,Appearance->"Frameless",ImageSize->{30,30},Alignment->Center],
Button["\!\(\*AdjustmentBox[\(\[FilledSquare]\),\nBoxBaselineShift->-0.1704961704961705,\nBoxMargins->{{0., 0.},
{0.1704961704961705, -0.1704961704961705}}]\)",stopAction,Appearance->"Frameless",ImageSize->{30,30},Alignment->Center]}," ",BaselinePosition->Center]
I have tried wrapping Button
and Toggler
together in various obvious ways e.g. Toggler[Dynamic[x], {Button[1, Print[1]], Button[2, Print[2]]}]
which don't work - I cannot find a solution.