SwitchRange

This complex component allows to define a set of branches corresponding to a set of numerical ranges.

Constructor


SwitchRange <id> (int init_val) {
   <id> [|]<number>,<number>[|]{...}
  ...
}
        

The branches of a SwitchRange are specific components named Range, they are containers to which any kind of processes can be added. Ranges have two predefined children: lower and upper that are DoubleProperty. The SwitchRange has a state corresponding to the name of the current branch and an input value. Each time the input changes, the SwitchRange look for the range to which it belongs then changes the branch accordingly.

Warning

A switch range branch can't have input, state as a name

Action

Activates the branch of the SwitchRange corresponding to the range of the given init_val.

Predefined children

  • DoubleProperty: input value used to evaluate the branch to be activated.
  • TextProperty: state name of the current branch.

Example


use core
use base
use display
use gui

_main_
Component root {
  Frame f ("my frame", 0, 0, 400, 600)
  Exit ex (0, 1)
  f.close -> ex
  FillColor c (0, 0, 0)
  
  SwitchRange swr (0) {
    _ [0, 33[ {
      210 =: c.r
      34  =: c.g
      45  =: c.b
    }
    _ [33, 66[
    {
      255 =: c.r
      191 =: c.g
      0   =: c.b
    }
    _ [66, 100]
    {
      25  =: c.r
      136 =: c.g
      35  =: c.b
    }
  }

  Rectangle r (0, 0, 70, 50, 5, 5)
  r.y => swr.input
  FSM fsm {
    State idle
    State drag {
      Double init_y (0)
      BoundedValue bv (0, 100, 0)
      r.press.y =: init_y
      f.move.y - init_y => bv.input
      bv.result => r.y
    }
    idle->drag (r.press)
    drag->idle (f.release)
  }
}