Scripting:User Interface

From Adonthell
Revision as of 17:59, 12 December 2010 by Ksterker (Talk | contribs) (Initial scripters guide to the GUI. Might be expanded once I actually implemented some of Waste's Edges gui :-).)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

While the Gui Module provides individual widgets and container classes to arrange them, the actual GUI needs to be created on Python side. To help with that, an overview is provided below. For more details, consult the API documentation.


Unlike most GUI toolkits you might know, the widgets provided by Adonthell do not have a default look. Instead, an artist will have to provide the skin used to represent a widget. On the bright side, each instance of a widget can have its own skin, so you should be able to implement a GUI that suits the look and feel of your game. Keeping that in mind, the steps to create a widget are no surprise:

 mywidget = widget (<width>, <height>)
 mywidget.set_style ("<skin>.xml")

At present, the following widgets are available:

Widget Hierarchy Description
[+] widget Base class for all widgets. Not much use on its own.
-- [+] canvas Displays any kind of drawable, usually an image or sprite.
-- [+] indicatorbar Displays progress or other percentages.
-- [+] label Displays one or more lines of text.
-- -- [+] button A label that can receive focus and react to user events.
-- -- -- [+] option A button with two possible states.
-- -- [+] textbox An element where the user can type in text.


In order to group widgets and display them to the user, they have to be added to a layout first. As layouts are also widgets, they can get their own individual skin to turn them into toplevel windows or list items of another layout. At present, the following layouts are available:

Layout Hierarchy Description
[+] widget Base class for all layouts. Not much use on its own.
-- [+] layout Layout where widgets can be freely placed.
-- -- [+] scrollview Layout that can have one child, which it can scroll to show hidden parts.

Window Manager

To actually display a layout to the user, it has to be added to the static window_manager instance. This can be used to control focus and z-order if multiple layouts are onscreen at once.