Boost logo

Boost :

From: Mathew Robertson (mathew.robertson_at_[hidden])
Date: 2004-11-15 21:53:14


> >>>The FOX GUI has exactly this capability, you can connect a variable directly to the widget, without requiring any glue code at all. In fact, you can connect the same variable to multiple widgets at the same time (eg a 'spinner' widget and an 'editeline'), without requiring the programmer to write any type of callback mechanism.
> >>>
> >>>This works because all GUI events are bi-directional. For more information, read: http://www.fox-toolkit.org/datatarget.html
> >>>
> >>
> >>That seems a lot of code, compared to:
> >>http://www.torjo.com/win32gui/save_dlg.html
> >>Not to say about validation...
> >
> >
> > The problem with this implementation is that the 'user_name' field cannot (usually)
> > connect to more than one widget at a time.
>
> That is a current limitation, but I don't think you need it so much.
> Anyway, you can work around it, by listening to kill_focus events:
> - you will have temporary variables, and each is bound to a control.
> - You listen for kill_focus from these variables
> - on kill_focus, you synchronize the temporary variables

Thats a hack, plain and simple... and it requires the application programmer to synchronise the state of these variables -> it should be a capability within the GUI library. What I am suggesting is that the technique described, is added as a native capability to the library so that this error-prone code is eliminated (its error-prone because it requires the programmer to remember that he must synchronise the variables not only on kill_focus, but also on any mouse event including left_click and mouse_over, any key event such as key_press and key_release, as well as when the program itself simply updates the value of the variable.

And connecting to more than one widget at a time, is done more frequently than you may expect, eg: anything that allows user input from an editline plus some other widget (a combobox, a scrollbar, a select list, etc). Or you could connect the variable to a statusbar and a tooltip.

> > Also, most widget libraries dont allow you to connect a variable to a widget,
> >and still allow user validation. This is because the widget library
> > doesn't callback into the validation code,
> > since it assumes that if it is connected to a widget, then no validation code is necessary.
> >
>
> That's the win32gui' advantage :)
>
>
> "if it is connected to a widget, then no validation code is necessary."
> - that really sounds silly.

Not really, there are two reasons why validation code is not necessary.

1. User validation always needs to be done by your business/process rules.
   -> When the 'go' event is generated, your app should validate the application variables (some of which will be connected to widgets). The validation will need to reset any variables which are in an out-of-bound condition (this implies that the GUI will need to re-synchronize to the new state of the variables). I wont comment on whether it is good to intertwine business logic within GUI update code....

2. Some widgets dont need validation eg: spinner, combobox, slider... These almost never need validation, since they are only ever populated with valid values.

Mathew


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk