Containers
A container is a EiffelVision 2 widget that may contain other widgets. All containers inherit from EV_CONTAINER. Some containers such as EV_CELL may only hold one widget while containers such as EV_BOX may hold multiple widgets. Since all containers inherit from type EV_WIDGET, this means that a container may be placed inside another container. Windows inherit from EV_CELL and are therefore also classified as containers.
Inheritance from EiffelBase
Wherever possible, EiffelVision 2 containers reuse the container structures provided by EiffelBase. This provides three main advantages:
- Familiarity for operations such as access, insertions, and removals. Anybody who already uses EiffelBase should find it easy to use EiffelVision 2 containers.
- The underlying structures used have been tried and tested for many years and their designs have proven to be robust and effective.
- Containers provide powerful methods of traversing and searching their contents. In the original EiffelVision library, you needed to keep references to widgets since you could not query the contents of their containers.
For example, EV_CONTAINER inherits from
Using Containers
The main role of a container is to position its children in a certain way. An EV_HORIZONTAL_BOX for example positions its children side by side. To achieve vertical stacking you would use an EV_VERTICAL_BOX . A code example of adding widgets to a container is as follows: add_to_container
-- Add 3 buttons to a hbox and then show in window.
local
my_window: EV_TITLED_WINDOW
my_hbox: EV_HORIZONTAL_BOX
my_button: EV_BUTTON
do
create my_window
create my_hbox
create my_button.make_with_text ("Button1")
my_hbox.extend (my_button)
my_hbox.extend (create {EV_BUTTON}.make_with_text ("Button2"))
my_hbox.extend (create {EV_BUTTON}.make_with_text ("Button3"))
my_window.extend (my_hbox)
my_window.show
end
The mapping of a EiffelVision 2 container interface is very close to that of containers in EiffelBase, such as a linked list.
- To add a widget to a container call
extend
. - To remove a widget from the container call
prune
. - To empty a container call
wipe_out
. - To traverse the container, you can use features such as
start
,forth
,item
, andoff
.
Size of a Widget Within a Container
The size of a widget in a container is always at least its minimum size. By default, when a widget is added to a container it is expandable. This means that if the container gets bigger, the widget will expand to fit the extra space. This convenient functionality means that you don't have to worry about handling the size of the widget (such as when a user alters the size of a window) as this is all performed automatically. If, on the other hand, you decide you want the widget to remain at a certain size (its minimum size), EV_BOX (and therefore its descendants) contain the convenient call disable_item_resize
.
Sizing of Containers
Since EV_CONTAINER inherits from type EV_WIDGET, the following facilities are provided for setting the minimum size: set_minimum_width
, set_minimum_height
and set_minimum_size
. It is important to remember that as a general rule, the current size of a container is always at least the minimum size of all its contents.