Organizing variables
All the classes in the wrapper are sealed. In most cases you should favor composing variables together to extend their functionality, as done for instance in the sample, where a complex variable type is created by composing two DoubleVariable
instances, and a polynomial variable type is implemented by adding custom validation logic to a StringVariable
to make it only accept polynomial formulas. In general, the Validating
event can be used to introduce additional requirements on the contents of the variable. The variable's value will be changed if and only if it passes validation by all event handlers attached to the variable's Validating
event.
If user input fails validation, the variable will gracefully revert to its previous value. On the other hand, if you manually try to set an invalid value from code, it will throw an ArgumentException
. The following example shows how to make the value of myVar
be a multiple of five:
myVar.Validating += (s, e) => { e.Valid = (e.Value % 5 == 0); }; /* for IntVariable */
You must refer to e.Value
(or e.R
, e.X
, etc. as appropriate) to perform validation, as the variable's value has not yet been updated when the validation handlers are called. Note you can of course refer to external objects in your handler to implement context-sensitive validation logic. Most variables already have built-in validators, for instance numeric variables validate against their Min
and Max
properties, StringVariable
rejects null strings, etc.
Also consider using the StructVariable
if you have structs that you want to make entirely configurable.
- High-level wrapper
-
Integration
- [Event handling](Event handling)
- [Organizing variables](Organizing variables)
- [Error handling](Error handling)
- Scripting
- [Exception safety](Exception safety)
- [Thread safety](Thread safety)
-
Technical manual
- Context
- Bar
- Group
- IntVariable
- FloatVariable
- DoubleVariable
- BoolVariable
- EnumVariable
- StringVariable
- ColorVariable
- Color4Variable
- VectorVariable
- QuaternionVariable
- StructVariable
- Button
- Separator
- ...
- [Low-level wrapper](Low-level wrapper)