3
$\begingroup$

I would like to create a Manipulate slider that iterates over a discrete set of items. Something like the following

Manipulate[u, CharacterRange["a","z"]]

produces a drop-down menu, which doesn't have a great interaction style. I must move the mouse back up to the top to get a new item, taking my eyes off the display back to the controls, rather than being able to just slide around without having to look at the controls too often.

Even better would be some kind of keyboard control that would let me left-and-right arrow my way through a collection. Then I'd never have to take my eyes off the target display. But that would be too intuitive [sarcasm].

$\endgroup$
  • 2
    $\begingroup$ Manipulate[u, {u, CharacterRange["a", "g"], ControlType -> Slider}] $\endgroup$ – Kuba Jun 26 '13 at 19:43
4
$\begingroup$

EventHandler

DynamicModule[
 {u = CharacterRange["a", "e"]},
 EventHandler[
  Framed[Dynamic@First@u],
  {
   {"MouseClicked", 1} :> (u = RotateLeft[u, 1]), 
   {"MouseClicked", 2} :> (u = RotateRight[u, 1])
   }
  ]
 ]

enter image description here

But since second button is showing menu it is not very useful :) It is only a method so You can change event trigger.

You can also take a look at NotebookEventActions. Or CellEventActions:

CellEventActions

DynamicModule[{u = CharacterRange["a", "e"]},
  CellPrint[
   TextCell[Dynamic@First@u, "Output", 
    CellEventActions -> {"LeftArrowKeyDown" :> (u = RotateLeft[u, 1]),
                         "RightArrowKeyDown" :> (u = RotateRight[u, 1])}
]]];

This is what I like the most. But then You are not able to move selection cursor with arrows, not so much important but it depends what are You doing. :)


Standard way

Slider

 Manipulate[u, {u, CharacterRange["a", "g"], ControlType -> Slider}]

enter image description here

Manipulator

Edit "StepLeftButton" does not work here how I expected. Anyone has an idea why? (I will remove it till explanation)

Manipulate[u, {u, CharacterRange["a", "g"], ControlType -> Manipulator, 
   AppearanceElements -> {"StepRightButton"}, Appearance -> "Open"}]

enter image description here

$\endgroup$
  • $\begingroup$ In the "Standard way" Manipulator, answer, the "StepLeftButton" doesn't seem to work :( $\endgroup$ – Reb.Cabin Jun 26 '13 at 21:54
  • $\begingroup$ @Reb.Cabin You are right. I'm not sure why it is so... $\endgroup$ – Kuba Jun 26 '13 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.