MAUI::Widget Class Reference

#include <MAUI/Widget.h>

Inheritance diagram for MAUI::Widget:

MAP::MapWidget MAUI::Image MAUI::Label MAUI::Layout MAUI::ListBox MAUI::EditBox List of all members.

Detailed Description

A Widget is an object that has a graphical representation and can perform (or be subjected to) (inter)actions by the user. It is abstract, since there is no default implementation of the drawWidget() function.

Examples of components are the images, labels and listboxes you would usually find in a user interface.

The Widget class is the abstract superclass of all MAUI Widgets. It can also be directly inherited to create new Widgets. For simple widgets, all you need to do is to implement the drawWidget() function.

Widgets are rectangular and may not overlap each other. Overlapping widgets lead to undefined rendering behaviour. A widget is clipped by its parent.

Widget constructors take a "parent" argument which, if not NULL, causes the widget being constructed to be added as a child of the parent.

When a Widget is deleted, it deletes all its children as well.

The position of a widget is always expressed relatively to the top left corner of the parent widget.

Widgets have padding parameters, which specify a margin from each side of the widget by which the widgets' content is offset. This applies both to the widgets' own content (such as a the caption of a Label) and its children.

Since mobile devices have different input mechanisms, MAUI Widgets are designed not to depend on any specific form of input. They do not deal with mouse, stylus or key events. Instead, widgets provide logical actions that they can perform. For instance, a listbox does not receive MAK_UP or MAK_DOWN key events - instead, it has the functions selectNextItem() and selectPreviousItem() to move one up or down among the items it contains.


Public Member Functions

 Widget (int x, int y, int width, int height, Widget *parent)
virtual void add (Widget *w)
void setParent (Widget *w)
WidgetgetParent ()
Vector< Widget * > & getChildren ()
const Vector< Widget * > & getChildren () const
virtual void draw (bool forceDraw=false)
virtual void update ()
void requestRepaint ()
virtual bool isTransparent () const
virtual void setSkin (WidgetSkin *widgetSkin)
void setDrawBackground (bool b=true)
void setBackgroundColor (int col)
WidgetwidgetAt (const Point &p)
WidgetwidgetAt (int x, int y)
virtual void setPosition (int x, int y)
const PointgetPosition () const
const PointgetPaddedPosition () const
virtual void setWidth (int width)
int getWidth () const
virtual void setHeight (int height)
int getHeight () const
virtual const RectgetBounds ()
virtual bool contains (const Point &p)
virtual bool contains (int x, int y)
virtual void setSelected (bool selected=true)
bool isSelected () const
virtual void setEnabled (bool enabled=true)
bool isEnabled () const
virtual void trigger ()
void addWidgetListener (WidgetListener *wl)
void removeWidgetListener (WidgetListener *wl)
Vector< WidgetListener * > & getWidgetListeners ()
void setInputManager (InputManager *inputManager)
virtual void setPaddingLeft (int l)
virtual void setPaddingTop (int t)
virtual void setPaddingRight (int r)
virtual void setPaddingBottom (int b)
int getPaddingLeft () const
int getPaddingTop () const
int getPaddingRight () const
int getPaddingBottom () const
const RectgetPaddedBounds () const
virtual void setParameter (const String &name, const String &value)
virtual ~Widget ()

Protected Member Functions

virtual void drawWidget ()=0
void drawBackground ()
void updateAbsolutePosition ()
void updateAbsolutePositionChildren (int x, int y)
void updatePaddedBounds ()
bool isDirty () const
void setDirty (bool d=true)

Protected Attributes

Vector< Widget * > children
Widgetparent
Rect bounds
int relX
int relY
bool dirty
WidgetSkinskin
int backColor
bool shouldDrawBackground
bool selected
bool enabled
Vector< WidgetListener * > widgetListeners
InputManagermInputManager
Rect paddedBounds
int paddingLeft
int paddingTop
int paddingBottom
int paddingRight

Friends

class Screen
class Layout


Constructor & Destructor Documentation

MAUI::Widget::Widget int  x,
int  y,
int  width,
int  height,
Widget parent
 

Constructor for Widget. 'x' and 'y' are the relative position of the top left corner of the widget, and 'width' and 'height' is the dimensions of the widget. 'parent' is the parent to the widget and the widget will be automatically added as a child to the parent. If parent equals NULL no parent will be set.

virtual MAUI::Widget::~Widget  )  [virtual]
 

Deletes all children.


Member Function Documentation

virtual void MAUI::Widget::add Widget w  )  [virtual]
 

Function used to add childs to a widget. The parent of the children will automatically be set. The widget cannot have a parent already.

Reimplemented in MAUI::Layout, and MAUI::ListBox.

void MAUI::Widget::setParent Widget w  ) 
 

Function used to set the parent of a widget. The widget will not be added to the parent as a child. The widget cannot have a parent already.

Widget* MAUI::Widget::getParent  ) 
 

Function to retrieve the parent of a widget.

Vector<Widget*>& MAUI::Widget::getChildren  ) 
 

Function to retrieve a reference to the list of childrens for a widget.

const Vector<Widget*>& MAUI::Widget::getChildren  )  const
 

const version of getChildren()

virtual void MAUI::Widget::draw bool  forceDraw = false  )  [virtual]
 

Renders the Widget and all its children recursively.

Reimplemented in MAUI::ListBox.

virtual void MAUI::Widget::update  )  [virtual]
 

Reimplemented in MAUI::Label, MAUI::Layout, and MAUI::ListBox.

void MAUI::Widget::requestRepaint  ) 
 

Registers an idle listener with the current environment that will redraw the widget and anything else that may be made dirty by doing so. For instance, if the widget is transparent its parent also has to be repainted, and so on recursively.

virtual bool MAUI::Widget::isTransparent  )  const [virtual]
 

Returns whether or not the widget is transparent. A widget is transparent if it has a skin that is transparent in the current selection state (selected/unselected) or if it has no solid background color.

virtual void MAUI::Widget::setSkin WidgetSkin widgetSkin  )  [virtual]
 

Assigns a widget skin to be used during the rendering of the widget. What The skin applies to varies depending on the widget. Labels extend the skin over their entire area, while listboxes apply the skin to each individual item they contain.

void MAUI::Widget::setDrawBackground bool  b = true  ) 
 

Sets the background drawing state. If b is true, the Widget's background will be drawn - otherwise not. In most cases, the background is either a constant color or a skin.

void MAUI::Widget::setBackgroundColor int  col  ) 
 

Widget* MAUI::Widget::widgetAt const Point p  ) 
 

Returns a pointer to the first child widget or deeper descendant, surrounding the point. Returns NULL if no widget is found.

Widget* MAUI::Widget::widgetAt int  x,
int  y
 

virtual void MAUI::Widget::setPosition int  x,
int  y
[virtual]
 

Sets the widget's position relative to its parent.

Reimplemented in MAUI::Layout.

const Point& MAUI::Widget::getPosition  )  const
 

Gets the widget's position relative to its parent.

const Point& MAUI::Widget::getPaddedPosition  )  const
 

Gets the widget's padded position relative to its parent.

virtual void MAUI::Widget::setWidth int  width  )  [virtual]
 

Sets the width of the widget

Reimplemented in MAUI::Layout, MAUI::ListBox, and MAP::MapWidget.

int MAUI::Widget::getWidth  )  const
 

Returns the width of the widget

virtual void MAUI::Widget::setHeight int  height  )  [virtual]
 

Sets the height of the widget

Reimplemented in MAUI::Layout, MAUI::ListBox, and MAP::MapWidget.

int MAUI::Widget::getHeight  )  const
 

Returns the height of the widget

virtual const Rect& MAUI::Widget::getBounds  )  [virtual]
 

Returns a Rect containing the absolute screen position of the widget together with its dimensions.

virtual bool MAUI::Widget::contains const Point p  )  [virtual]
 

Check if widget surrounds position 'p'.

virtual bool MAUI::Widget::contains int  x,
int  y
[virtual]
 

Check if widget surrounds position 'x' and 'y'.

virtual void MAUI::Widget::setSelected bool  selected = true  )  [virtual]
 

Set widget selected state (default: true).

Reimplemented in MAUI::EditBox.

bool MAUI::Widget::isSelected  )  const
 

Is widget selected?.

virtual void MAUI::Widget::setEnabled bool  enabled = true  )  [virtual]
 

Set Widget enabled state

Reimplemented in MAUI::EditBox.

bool MAUI::Widget::isEnabled  )  const
 

Is Widget enabled ?

virtual void MAUI::Widget::trigger  )  [virtual]
 

This function is called whenever the widget is "triggered", which is roughly equivalent to having been "clicked" on. However, sice MAUI is independant of input facilities, the more input-neutral concept of triggering is used.

Reimplemented in MAUI::Layout.

void MAUI::Widget::addWidgetListener WidgetListener wl  ) 
 

Add WidgetListener.

void MAUI::Widget::removeWidgetListener WidgetListener wl  ) 
 

Remove WidgetListener.

Vector<WidgetListener*>& MAUI::Widget::getWidgetListeners  ) 
 

returns a reference the the vector of Widget listeners

void MAUI::Widget::setInputManager InputManager inputManager  ) 
 

Sets the input manager to use for this widget

virtual void MAUI::Widget::setPaddingLeft int  l  )  [virtual]
 

Set left padding width.

Reimplemented in MAUI::Label.

virtual void MAUI::Widget::setPaddingTop int  t  )  [virtual]
 

Set top padding height.

Reimplemented in MAUI::Label.

virtual void MAUI::Widget::setPaddingRight int  r  )  [virtual]
 

Set right padding width.

Reimplemented in MAUI::Label.

virtual void MAUI::Widget::setPaddingBottom int  b  )  [virtual]
 

Set bottom padding height.

Reimplemented in MAUI::Label.

int MAUI::Widget::getPaddingLeft  )  const
 

Get left padding width.

int MAUI::Widget::getPaddingTop  )  const
 

Get top padding height.

int MAUI::Widget::getPaddingRight  )  const
 

Get right padding width.

int MAUI::Widget::getPaddingBottom  )  const
 

Get bottom padding height.

const Rect& MAUI::Widget::getPaddedBounds  )  const
 

virtual void MAUI::Widget::setParameter const String name,
const String value
[virtual]
 

Reimplemented in MAUI::Label.

virtual void MAUI::Widget::drawWidget  )  [protected, pure virtual]
 

This is the only function that is absolutely neccesary to implement when inheriting Widget to create a custom widget. It is responsible for painting the widget. When it is called, the widget must respect its own padded bounds and not extend rendering beyond that area.

Implemented in MAUI::Image, MAUI::Label, MAUI::Layout, MAUI::ListBox, and MAP::MapWidget.

void MAUI::Widget::drawBackground  )  [protected]
 

void MAUI::Widget::updateAbsolutePosition  )  [protected]
 

This function is used to regenerate the absolute positions of each widget in the tree. This is done in a depth first manner where each widget takes the parent absolute position and adds it to their own relative position to calculate their absolute position.

void MAUI::Widget::updateAbsolutePositionChildren int  x,
int  y
[protected]
 

the recursive function used by updateAbsolutePosition().

void MAUI::Widget::updatePaddedBounds  )  [protected]
 

Used to recalculate the padded bounds from the global bounds.

bool MAUI::Widget::isDirty  )  const [protected]
 

Returns the dirty state of the widget, indicating whether it requires to be redrawn or not. When a widget calls requestRepaint(), it's dirty state is set to true. Normally, you shouldn't have to use isDirty() or setDirty() unless possibly when implementing your own widgets.

void MAUI::Widget::setDirty bool  d = true  )  [protected]
 

Sets the dirty state of the widget.


Friends And Related Function Documentation

friend class Screen [friend]
 

friend class Layout [friend]
 


Member Data Documentation

Vector<Widget*> MAUI::Widget::children [protected]
 

Widget* MAUI::Widget::parent [protected]
 

Rect MAUI::Widget::bounds [protected]
 

int MAUI::Widget::relX [protected]
 

int MAUI::Widget::relY [protected]
 

bool MAUI::Widget::dirty [protected]
 

WidgetSkin* MAUI::Widget::skin [protected]
 

int MAUI::Widget::backColor [protected]
 

bool MAUI::Widget::shouldDrawBackground [protected]
 

bool MAUI::Widget::selected [protected]
 

bool MAUI::Widget::enabled [protected]
 

Vector<WidgetListener*> MAUI::Widget::widgetListeners [protected]
 

InputManager* MAUI::Widget::mInputManager [protected]
 

Rect MAUI::Widget::paddedBounds [protected]
 

int MAUI::Widget::paddingLeft [protected]
 

int MAUI::Widget::paddingTop [protected]
 

int MAUI::Widget::paddingBottom [protected]
 

int MAUI::Widget::paddingRight [protected]
 


Generated on Sat Feb 13 00:15:39 2010 for MoSync 2 beta 1 by  doxygen 1.4.6-NO