User interface widgets


introduction, concepts, components, examples, patterns, experience, conclusions, references
The (hush) widget library contains classes for a variety of user interface widgets, including the classes button, menu, text, canvas, filechooser and many more. As explained before, a widget allows for binding an independently defined handler to user actions. This may result in a code fragment like:
  button* b = new button(".b");
  handler* h = new help_handler(b);
  b->text("Help");
  b->bind(h);
We assume that help_handler does something meaningful, like displaying a hypertext help file.

Alternatively, a widget may declare itself to be its own handler. In that case we derive a new class from button and define the functionality (previously defined externally in the help_handler) in the new class itself, as illustrated below:

  class help_button : public button {
  public:
  help_button( char* path ) : button( path ) {
	this->text("help");
	this->bind(this);
	}
  int operator()(); // does what help_handler did
  };
Dependent on circumstances, either one of the approaches may be the most convenient. Allowing for delegating to an external handler helps to avoid cluttering the class name space. On the other hand, employing inheritance may result in a significant reuse of initialization code.
introduction, concepts, components, examples, patterns, experience, conclusions, references