- 17.01 (latest) ...
What Is a Widget?
A Widget is the fundamental building block of your application's GUI. Components such as Windows, Buttons, Text fields, Check Boxes, List Boxes and layout Containers are examples of widgets. The widget set in EiffelVision 2 provides you with the flexibility to easily create powerful graphical applications. All widgets in EiffelVision 2 inherit from EV_WIDGET, thus the features provided in
Variations of Widgets
Within EiffelVision 2, widgets have been classified into three different groups:
- Primitives — These are elements of the user interface that are mainly responsible for interaction with the user, such as an EV_BUTTON.
- Containers — These are used to contain other widgets and position them in a certain way, such as an EV_VERTICAL_BOX that stacks its child widgets one by one vertically.
- Dialogs — These are pop up dialog boxes used for interacting with the user for tasks such as opening a file (EV_FILE_OPEN_DIALOG) or displaying a message (EV_MESSAGE_DIALOG). You may also construct your own dialog boxes by inheriting from EV_DIALOG.
How Do I Create a Widget?
All widgets in EiffelVision 2 are based around the default_create mechanism in Eiffel. This means that all that needs to be done to create a widget is to declare a reference to a type (such as EV_BUTTON ) and then call create on that reference. An example of this is as follows.
Along with the default creation, EiffelVision 2 also includes a few additional creation features for convenience. An example of this is
make_with_text for all widgets that may have text associated with them (those that inherit from EV_TEXTABLE ), this saves a call to set_text upon default creation of the textable widget. Thus:
create my_button.make_with_text ("Click Me")
my_button.set_text ("Click Me")
The minimum size of a widget is the smallest possible size that it can be inside its parent container. If an EV_BUTTON was created and set with a minimum_size of width/height (100, 100), if this button was inserted in to an EV_HORIZONTAL_BOX, then the box's size could never be below (100, 100) or it would violate the minimum size of the button. The size of a container must always be greater or equal to the minimum sizes of its children.
Now What Do I Do?
Now that you can create a widget, you will need to actually make it usable to your intended user. This will usually involve these three steps.
- Setting properties for the widget such as color and minimum size.
- Making the widget respond to user events via the use of agents and action sequences.
- Placing the widget inside a container widget (either a window or a child of a window) so it can be shown on the screen.