I have a tiny first step that shows an example for changing the color of a button on mouse over and changing it back to the original color on mouse out.
Evaluate this for executing the example:
SMButton openWithStateMachineInteraction
And here is the code of the state machine for that example:
SMButton class >> openWithStateMachineInteraction
|button stateMachine iddle hover |
button := self new.
stateMachine := SMStateMachine newForWidget: button.
iddle := (SMState newWithName:'iddle')
enter:[:stMachine | stMachine widget color: Color yellow ];
addTransition: ((SMTransition forEvent: 'mouse enter' withOutputState: 'hover')
transitionAction: [:stMachine | stMachine widget color: Color red ]).
hover := (SMState newWithName:'hover')
addTransition: (SMTransition forEvent: 'mouse out' withOutputState: 'iddle');
addTransition: (SMTransition forEvent: 'mouse enter' withOutputState: 'hover').
stateMachine addState: iddle; addState: hover.
stateMachine attachTo: button.
^button openInWorld
That code corresponds to the following states diagram:
<Screen Shot 2013-05-06 at 2.27.20 AM.png>
I will keep experimenting with this during the next weeks, and specially try to compare the pros and cons with regular event handling.
Something cool about this approach is that the same widget could change its interactive behaviour on the fly by just attaching a different interaction state machine to it :)
Also, I'm doing this for programming user interface interactions, but it could be useful for anything that can be modelled with a state pattern.
Is there something similar out there already working? I was so eager to try this that I didn't look for related existing projects.
Cheers!
Carla.