FSM

Finite State Machine. This complex component allows to define a set of states and transitions between them.

Constructor


FSM <id> {
  State <id> {...}
  ...
  <state_id> -> <state_id> (<process_id>, <process_id>) // transition
  ...
}
        

States are containers to which any kind of processes can be added. The transition from one state to another one is triggered by the activation of the first process given in parameter. The second parameter is optional. If specified, the process is activated just before entering the destination state.

Action

Activates the first defined state and all the attached transitions.

Predefined children

  • TextProperty: state whose value is the name of the current active state

Example


use core
use base
use gui

_main_
Component root {
  Frame f ("myButton", 0, 0, 500, 500)
  Spike click
  FSM fsm {
    State idle {
      FillColor red (255, 0, 0)
      Rectangle r (0, 0, 100, 70, 0, 0)
    }
    State pressed
    {
      FillColor green (0, 255, 0)
      Rectangle r (0, 0, 100, 70, 0, 0)
    }
    idle->pressed (idle.r.press)
    pressed->idle (pressed.r.release, click)
    pressed->idle (f.release)
  }
}

run root
run syshook