HeinrichApfelmus/threepenny-gui — pull request #53 by Daniel-Diaz (2013-09-11 21:55:05+00:00)
Title: Widgets API

*I submit this as a pull request, but please note that this is actually an API proposal.*

The attached code shows an example of how it can be implemented in a particular
simple case, and explains the general idea. Below I copy of the text that can be found
at the source code. Module and function names and other details are provisional and
I do not expect to keep them like they are right now. My only intention is to propose
an idea.

If the proposal looks reasonable, I will continue working on it.

---

The idea is to organize elements as *widgets*. Instead of having every element
with the same type, each kind of widget would have a type of its own. In the example
above, a simple checkbox widget is implemented. It consists in the following
parts:

1. Widget Type. It contains all the necessary elements that the given widget
needs to work properly. It may contain several elements, or even other
widgets. The type must be kept abstract.

2. Widget Class Instance. To fit in the picture, a widget must be converted
to a single element, so it can be included in the layout of the program and
interact with other elements.

3. Widget Attributes. Attribute setters and/or getters of the widget. In the
example above, checkboxes have the 'checked' and 'text' attributes.

About attributes, I think plenty of widgets are going to share some of them.
In the example above, properties like 'checked' and 'text' may apply to other
widgets as well. Type classes can solve this problem in an elegant way. A great
consequence of implementing it this way is that users will be only allowed
to apply attributes only to those type that makes sense to apply them to.
Currently, attributes can be applied freely to any element, which might make the user
wonder in each execution if the attribute will work or not, and then go back to code
and try another one.

Note that elements will still be used, but certain tasks (like using lists, checkboxes,
buttons, etc) can be achieved in a better way.