Thursday, July 28, 2005

Input Validation

This is kinda neat.

With the new Properties editor for primitives,
there's a number of input fields which need to have the user's input validated before being used.

For example, maybe the user types in a word where a number is wanted,
or enters a value outside of the allowed range,
(or, because i thought it might come in handy, the user types in 0 when 0 in particular is disallowed).

Validation becomes somewhat trickier when the fields affect the scene immediately - that is, as soon as the user hits a key, it's reflected in the scene. In this situation, you absolutely need validation.

For example, in the case of TSphere segments, the minimum value is 2 (altho i'm using 3).
A natural and frequent user interaction will be to delete the value currently in the field and then type in a new value. After deletion but before typing, the value of the field is invalid, and so must be handled.

I subclassed CNumberConverter and added members for min, max, zero disallowment, as well as a pointer (?) back to the CInputField itself, and some helper variables.
When the input goes invalid, the CInputField background is changed to lightRed (the man's pink!) and the last valid value is reported. The text content of the input field is left unchanged, however, because changing would interfere with the user's typing.
When the input goes valid, the background color is changed to the CInputField's container's background color, and the current value is stored as the last valid value.

Basically, it works fairly nicely.

The file-outs of the new classes are here.

2 Comments:

Blogger orion said...

This comment has been removed by a blog administrator.

4:41 PM  
Blogger orion said...

This comment has been removed by a blog administrator.

4:45 PM  

Post a Comment

<< Home