This complex component allows to define a set of branches. Only one of it can be active at a time.


Switch <id> (string initial_branch) {
  Component <id> {...}

The branches of a Switch are classic components, that is containers to which any kind of processes can be added. The Switch has a specific text property named state, each time this property is updated the Switch looks for a branch with the same name. If it is found, the current branch is deactivated and the new one is activated.


A switch branch can't have state as a name


Activates the branch with the name given as the parameter of the Switch.

Predefined children

  • TextProperty: state whose value is the name of the current active branch if it exists.


use core
use base
use display
use gui

Component root {
  Frame f ("myButton", 0, 0, 500, 500)
  Exit quit (0, 1)
  Switch button (idle) {
    Component idle {
      FillColor red (255, 0, 0)
      Rectangle r (0, 0, 100, 70, 0, 0)
    Component pressed {
      FillColor green (0, 255, 0)
      Rectangle r (0, 0, 100, 70, 0, 0)

  FSM fsm {
    State idle
    State pressed
    idle->pressed (button.idle.r.press)
    pressed->idle (button.pressed.r.release)
    pressed->idle (f.release)
  fsm.state => button.state