Widgets
Overview
Since all widgets inherit from EM_COMPONENT, they can be used directly on a
component scene.
Differences to EM_COMPONENT
Althouhg a widget is an EM_COMPONENT there are some important differences which apply to most widgets:
- Widgets can be nested. You can add widgets to all other widget using add_widget. All coordinates on a nested widget are relative to its parent.
- Widgets are not necessarily redrawn every frame. To improve performance a widgets is only drawn when it or a nested widget is changed. This is important to remember when a custom widget is implemented, since you have to set the is_changed status in order to provoke a redrawing.
-
By default a widget is not keyboard sensitive
(except EM_TEXTBOX, EM_TEXTAREA, EM_TEXTLIST and EM_COMBOBOX). If you want a widget to receive keyboard focus, you have to use set_keyboard_sensitive (True).
Hint: If your main widget is a game screen which needs the keyboard focus all the times it is not necessary to set it to be keyboard sensitive. You can set it to be the default keyboard focus.
Widgets
-
EM_PANEL
An empty widget to group other widgets. Use this class to implement custom widgets.
Use: Add nested widgets with add_widget.
-
EM_DRAWABLE_PANEL
A display of EM_DRAWABLEs.
Use: All drawables which are added to the container are displayed. To use EM_ANIMATABLEs you still have to call start_animation on the scene.
-
EM_SCROLLPANEL
A scrollpanel can display scrollbars if a widget's optimal dimension is bigger than its screen dimension.
Use: Create an instance of EM_SCROLLPANEL and call set_widget with the widget which should have scrollbars. Then you have to place the scrollpanel instead of the widget on the scene. If the scrollpanel's dimension is smaller than the widget's optimal dimension, scrollbars are displayed.
Hint: Remeber that you can override the optimal dimension of any widget with set_optimal_dimension. -
EM_LABEL
A display of a string. The label can display a string over multiple lines.
Use: Set the displayed string at creation or with set_text.
The font and color of the text can be set by calling set_font and set_foreground_color.
To change the alignement of the text use the various align_* features.
To enable a shadoweffect call enable_shadow. To override the default shadow color use set_shadow_color.
-
EM_TEXTBOX
An single line text input box.
Use: Set the displayed text either at creation or by calling set_text.
Hint: To react on a special key input - i.e. enter - subscribe on the key down eventand check the pressed key.
Note: To solve some problems with the unicode setting on some computers, unicode is enabled when creating a textbox. This will be removed and thus it is recommended to enable unicode in the root class. -
EM_TEXTAREA
A multiline text input box.
Use: Set the displayed text either at creation or by calling set_text.
-
EM_BUTTON
A push button with a text and/or image.
Use: The text and image can either be set on creation or by calling set_text and set_image.
A button press will trigger a clicked event.
-
EM_CHECKBOX
A titled box with a checked and unchecked state.
Use: The text can either be set on creation or by calling set_text.
A press on the checkbox will trigger a checked eventor an unchecked event
-
EM_TEXTLIST
A list which can display a string per element it contains.
Use: The elements can be inserted with put and extend. To clear the list call wipe_out.
Per default the feature out of the inserted elements is used to display a string. But this behaviour can be changed by providing an agent which converts list elements to strings. To set such an agent use set_to_string_agent. -
EM_COMBOBOX
A list which displays only the currently selected element and provides a drop-down list to select elements.
Use: The elements can be inserted with put and extend. To clear the list call wipe_out.
The feature out of the inserted elements is used to display a string. -
EM_SLIDER
A slider can select an integer value inside a bounded interval.
Use: Set the range either at creation or with set_range.
When the slider's position changes, a position changed eventis triggered.
-
EM_PROGRESS_BAR
Use: Set the number of progress steps at creation or with set_steps.
Then you can call advance and reset to control the progress bar.