MFunc is a proxy for multiple, modal functions which can replace a single function with easily configurable flexible behavior.
It contains a dictionary of named functions (i.e. a behavior repertoire), an ordered list of the function names, lists of combinations of functions, and lists of the currently active functions and names.
The MFunc's behavior can be reconfigured at any time:
MFunc is intended for use in modal interfaces, so for example, when a single slider has an MFunc as its action, it can have functions that
This is intended to replace complicated cascades of if-statements (which easily accumulate when coding modal user interface functions). Instead of setting flags for modes and reading them in control structure logic, one can use MFuncs to switch between modes by a. enabling the functions desired in the new mode, b. disabling the ones that should be off in the new mode, and c. keeping all other functions independent by leaving them untouched.
make a new MFunc, like this:
the names of the currently active funcs
get name of the currently active mode, set currently active mode by name.
the available modes
the modeLists
the repertoire of all functions
the ordered names of all available functions
the currently active functions
calls .value on the activeFuncs, returns a list of the return values.
enable and disable functions by name(s)
add or replace a function by name, optionally relative to another name.
name |
name by which to store func |
func |
the func to store |
active |
flag whether the func should become active |
addAction |
optional addAction, default is \addLast |
otherName |
addActions \addBefore, \addAfter need a name relative to which to add. |
fully remove functions by name or names
short methods indicating where to add or replace
short methods for adding relative to another name
name |
the name for the new func |
func |
the new func to add |
active |
flag whether active |
otherName |
the name relative to which to add |
get and set flag whether to use .tryValue istead of .value
wrap all function evaluations in try { }, so that if one fails, it posts good info, and all later functions in the list will still be evaluated.