Lysa UI  0.0
Lysa UI —UI components for the Lysa Engine
Widget Class Reference

Detailed Description

Base class for all UI widgets.

+ Inheritance diagram for Widget:

Public Types

enum  Type {
  WIDGET, PANEL, BOX, LINE,
  FRAME, BUTTON, TOGGLEBUTTON, TEXT,
  TEXTEDIT, SCROLLBAR, TREEVIEW, IMAGE,
  POPUP, LIST, LISTBOX, SELECTION,
  PROGRESSBAR, SCROLLBOX
}
 

Public Member Functions

 Widget (Type type=WIDGET)
 
 ~Widget () override = default
 
Type getType () const
 
bool isVisible () const
 
void setVisible (bool show=true)
 
bool isEnabled () const
 
void setEnabled (bool isEnabled=true)
 
virtual void setPos (float x, float y)
 
float getWidth () const
 
float getHeight () const
 
virtual void setSize (float width, float height)
 
void setWidth (const float width)
 
void setHeight (const float height)
 
const Rect & getRect () const
 
void setRect (float x, float y, float width, float height)
 
void setRect (const Rect &rect)
 
Alignment getAlignment () const
 
void setAlignment (Alignment alignment)
 
std::shared_ptr< Font > getFont () const
 
void setFont (const std::shared_ptr< Font > &font)
 
float getFontScale () const
 
virtual void setFontScale (float fontScale)
 
bool isFocused () const
 
Widget * getParent () const
 
template<typename T , typename... Args>
std::shared_ptr< T > create (const std::string &resource, const Alignment alignment, Args &&...args)
 
template<typename T , typename... Args>
std::shared_ptr< T > create (const Alignment alignment, Args &&...args)
 
template<typename T >
std::shared_ptr< T > add (std::shared_ptr< T > child, const Alignment alignment, const std::string &resource="", const bool overlap=false)
 
virtual void remove (const std::shared_ptr< Widget > &child)
 
virtual void removeAll ()
 
void setPadding (float padding)
 
float getPadding () const
 
float getVBorder () const
 
float getHBorder () const
 
void setVBorder (float size)
 
void setHBorder (float size)
 
bool isDrawBackground () const
 
void setDrawBackground (bool drawBackground)
 
bool isPushed () const
 
bool isPointed () const
 
bool isFreezed () const
 
bool isRedrawOnMouseEvent () const
 
bool isOverlapping () const
 
Rect getChildrenRect () const
 
void setFreezed (const bool f)
 
void setPushed (const bool p)
 
void refresh ()
 
void setResource (std::shared_ptr< UIResource > res)
 
uint32 getGroupIndex () const
 
void setGroupIndex (int32 index)
 
void * getUserData () const
 
void setUserData (void *data)
 
float getTransparency () const
 
void setTransparency (float alpha)
 
void resizeChildren ()
 
float getChildrenOffsetX () const
 
float getChildrenOffsetY () const
 
void setChildrenOffset (float x, float y)
 
std::shared_ptr< Widget > setFocus (bool focus=true)
 
virtual void eventCreate ()
 
virtual void eventDestroy (Vector2DRenderer &renderer)
 
virtual void eventShow ()
 
virtual void eventHide ()
 
virtual void eventEnable ()
 
virtual void eventDisable ()
 
virtual void eventMove (float x, float y)
 
virtual void eventResize ()
 
virtual bool eventTextInput (const std::string &text)
 
virtual bool eventKeyDown (Key key)
 
virtual bool eventKeyUp (Key key)
 
virtual bool eventMouseDown (MouseButton button, float x, float y)
 
virtual bool eventMouseUp (MouseButton button, float x, float y)
 
virtual bool eventMouseMove (uint32 buttonsState, float x, float y)
 
virtual void eventGotFocus ()
 
virtual void eventLostFocus ()
 
bool getConsumeMouseEvent () const
 
void setConsumeMouseEvent (const bool consumeMouseEvent)
 
const std::list< std::shared_ptr< Widget > > & getChildren () const
 

Protected Attributes

const Type type
 
Rect rect
 
float hborder {0}
 
float vborder {0}
 
float padding {0}
 
bool consumeMouseEvent {false}
 
bool overlap {false}
 
bool focused {false}
 
bool allowFocus {false}
 
bool allowChildren {true}
 
bool drawBackground {true}
 
bool moveChildrenOnPush {false}
 
bool redrawOnMouseEvent {false}
 
bool redrawOnMouseMove {false}
 
float transparency {1.0f}
 
Widget * parent {nullptr}
 
Alignment alignment {Alignment::NONE}
 
std::shared_ptr< UIResourceresource
 
std::list< std::shared_ptr< Widget > > children
 
void * window {nullptr}
 
void * style {nullptr}
 
bool mouseMoveOnFocus {false}
 
float fontScale {0.0f}
 
float childrenOffsetX {0}
 
float childrenOffsetY {0}
 

Member Enumeration Documentation

enum Type

Widget type enumeration.

Enum ValuesDocumentation
WIDGET 

transparent widget

PANEL 

rectangular widget with only a background

BOX 

rectangular widget with a border and a background

LINE 

A horizontal or vertical line

FRAME 

A box with a title

BUTTON 

A push button

TOGGLEBUTTON 

A two states button

TEXT 

A single line of text

TEXTEDIT 

An editable single line of text.

SCROLLBAR 

A scroll bar. with min, max & pos

TREEVIEW 

Tree of Widget.

IMAGE 

2D Image

POPUP 

popup panel at fixed (x, y) coordinates, drawn on top of siblings

LIST 

A list of widgets (abstract container)

LISTBOX 

A scrollable list with a selection highlight

SELECTION 

Selection highlight rectangle (internal to LISTBOX)

PROGRESSBAR 

A progress bar with min, max & value

SCROLLBOX 

A scrollable container (horizontal & vertical)

Constructor & Destructor Documentation

Widget ( Type  type = WIDGET)

Creates a widget of a particular type.

Parameters
typeThe type of the widget.
~Widget ( )
overridedefault

Member Function Documentation

std::shared_ptr<T> add ( std::shared_ptr< T >  child,
const Alignment  alignment,
const std::string &  resource = "",
const bool  overlap = false 
)
inline

Adds a child widget.

Children widgets will be destroyed on parent destruction.

Template Parameters
TThe type of the widget to add.
Parameters
childChild widget to add.
alignmentPlacement alignment.
resourceResource string.
overlapOverlap widget on top of other widgets.
Returns
A shared pointer to the added widget.
std::shared_ptr<T> create ( const Alignment  alignment,
Args &&...  args 
)
inline

Creates & adds a child widget.

Template Parameters
TThe type of the widget to create.
ArgsThe types of the arguments to pass to the widget constructor.
Parameters
alignmentThe alignment of the child widget.
argsThe arguments to pass to the widget constructor.
Returns
A shared pointer to the created widget.
std::shared_ptr<T> create ( const std::string &  resource,
const Alignment  alignment,
Args &&...  args 
)
inline

Creates & adds a child widget using a resource string.

Template Parameters
TThe type of the widget to create.
ArgsThe types of the arguments to pass to the widget constructor.
Parameters
resourceThe resource string defining the widget style or properties.
alignmentThe alignment of the child widget.
argsThe arguments to pass to the widget constructor.
Returns
A shared pointer to the created widget.
virtual void eventCreate ( )
virtual

Called after the widget is created and added to its parent.

Reimplemented in lysa::ui::Popup::eventCreate()

virtual void eventDestroy ( Vector2DRenderer &  renderer)
virtual

Called before the widget is destroyed.

Parameters
rendererThe 2D renderer to release any associated resources.
virtual void eventDisable ( )
virtual

Called when the widget is disabled.

virtual void eventEnable ( )
virtual

Called when the widget is enabled.

virtual void eventGotFocus ( )
virtual

Called when the widget gains keyboard focus.

virtual void eventHide ( )
virtual

Called when the widget is hidden.

virtual bool eventKeyDown ( Key  key)
virtual

Called when a keyboard key is pressed.

Parameters
keyThe key pressed.
Returns
True if the event was consumed.

Reimplemented in lysa::ui::TextEdit::eventKeyDown()

virtual bool eventKeyUp ( Key  key)
virtual

Called when a keyboard key is released.

Parameters
keyThe key released.
Returns
True if the event was consumed.
virtual void eventLostFocus ( )
virtual

Called when the widget loses keyboard focus.

virtual bool eventMouseDown ( MouseButton  button,
float  x,
float  y 
)
virtual

Called when a mouse button is pressed over the widget.

Parameters
buttonThe mouse button pressed.
xMouse X coordinate.
yMouse Y coordinate.
Returns
True if the event was consumed.

Reimplemented in lysa::ui::CheckWidget::eventMouseDown()

virtual bool eventMouseMove ( uint32  buttonsState,
float  x,
float  y 
)
virtual

Called when the mouse is moved over the widget.

Parameters
buttonsStateState of mouse buttons.
xMouse X coordinate.
yMouse Y coordinate.
Returns
True if the event was consumed.
virtual bool eventMouseUp ( MouseButton  button,
float  x,
float  y 
)
virtual

Called when a mouse button is released over the widget.

Parameters
buttonThe mouse button released.
xMouse X coordinate.
yMouse Y coordinate.
Returns
True if the event was consumed.

Reimplemented in lysa::ui::Button::eventMouseUp(), lysa::ui::ToggleButton::eventMouseUp()

virtual void eventMove ( float  x,
float  y 
)
virtual

Called when the widget position changes.

Parameters
xNew X position.
yNew Y position.
virtual void eventResize ( )
virtual

Called when the widget is resized.

Reimplemented in lysa::ui::ValueSelect::eventResize()

virtual void eventShow ( )
virtual

Called when the widget becomes visible.

virtual bool eventTextInput ( const std::string &  text)
virtual

Called on a text input event.

Parameters
textThe input text.
Returns
True if the event was consumed.

Reimplemented in lysa::ui::TextEdit::eventTextInput()

Alignment getAlignment ( ) const

Returns the current widget placement.

const std::list<std::shared_ptr<Widget> >& getChildren ( ) const
inline
float getChildrenOffsetX ( ) const
inline

Returns the horizontal children scroll offset (subtracted from child positions).

float getChildrenOffsetY ( ) const
inline

Returns the vertical children scroll offset (subtracted from child positions).

Rect getChildrenRect ( ) const

Returns the rectangle enclosing all children.

bool getConsumeMouseEvent ( ) const
inline

Returns true if the widget consumes mouse events (prevents propagation to parent).

std::shared_ptr<Font> getFont ( ) const

Returns the current font of the widget.

float getFontScale ( ) const

Returns the font scale.

uint32 getGroupIndex ( ) const

Returns the user defined group index.

float getHBorder ( ) const

Returns horizontal border size.

float getHeight ( ) const
inline

Returns the height of the widget, in pixels.

float getPadding ( ) const

Returns current children padding.

Widget* getParent ( ) const
inline

Returns the parent widget, or nullptr.

const Rect& getRect ( ) const

Returns the size & the position of the widget.

float getTransparency ( ) const
inline

Returns the transparency alpha value.

Type getType ( ) const

Returns the type of the widget.

void* getUserData ( ) const

Returns the user data.

float getVBorder ( ) const

Returns vertical border size.

float getWidth ( ) const
inline

Returns the width of the widget, in pixels.

bool isDrawBackground ( ) const

Returns false if the background is transparent.

bool isEnabled ( ) const

Returns true if the widget is reactive to user action (mouse & keyboard).

bool isFocused ( ) const

Returns true if the widget has keyboard focus.

bool isFreezed ( ) const

Returns true if the widget is freezed (not responding to events).

bool isOverlapping ( ) const
inline

Returns true if the widget is overlapping other widgets.

bool isPointed ( ) const

Returns true if the widget is currently pointed by the mouse.

bool isPushed ( ) const

Returns true if the widget is currently pushed (e.g. mouse button down).

bool isRedrawOnMouseEvent ( ) const

Returns true if the widget should redraw on mouse events.

bool isVisible ( ) const

Returns true if the widget is visible.

void refresh ( )

Force a refresh of the entire widget.

virtual void remove ( const std::shared_ptr< Widget > &  child)
virtual

Removes a child widget.

virtual void removeAll ( )
virtual

Removes all children widgets recursively.

void resizeChildren ( )

Resizes children widgets.

void setAlignment ( Alignment  alignment)

Sets the widget placement.

Calling this method involves redrawing the parent widget & resizing all the children widgets.

void setChildrenOffset ( float  x,
float  y 
)

Sets the children scroll offset. Children are laid out by resizeChildren() starting from the client rect minus this offset, enabling scrollable content. Default is (0, 0): no effect.

void setConsumeMouseEvent ( const bool  consumeMouseEvent)
inline

Sets whether mouse events are consumed by this widget (preventing propagation to parent).

void setDrawBackground ( bool  drawBackground)

Sets whether to draw the widget background.

void setEnabled ( bool  isEnabled = true)

Enables or disables widget reactions to input events.

std::shared_ptr<Widget> setFocus ( bool  focus = true)

Requests keyboard focus for this widget.

Parameters
focusTrue to request focus, false to release it.
Returns
Shared pointer to this widget.
void setFont ( const std::shared_ptr< Font > &  font)

Sets the current font of the widget.

virtual void setFontScale ( float  fontScale)
virtual

Sets the font scale.

Reimplemented in lysa::ui::Text::setFontScale()

void setFreezed ( const bool  f)
inline

Sets whether the widget is freezed.

void setGroupIndex ( int32  index)

Sets the user defined group index.

void setHBorder ( float  size)

Sets horizontal border size.

void setHeight ( const float  height)
inline

Resizes the widget height, in pixels.

void setPadding ( float  padding)

Changes children padding (space between children).

virtual void setPos ( float  x,
float  y 
)
virtual

Moves the widget to a particular position.

void setPushed ( const bool  p)
inline

Sets whether the widget is pushed.

void setRect ( const Rect &  rect)

Changes the size & position of the widget.

void setRect ( float  x,
float  y,
float  width,
float  height 
)

Changes the size & position of the widget.

void setResource ( std::shared_ptr< UIResource res)

Changes widget resources.

virtual void setSize ( float  width,
float  height 
)
virtual

Resizes the widget, in pixels.

Reimplemented in lysa::ui::Image::setSize(), lysa::ui::Text::setSize()

void setTransparency ( float  alpha)

Changes the transparency alpha value.

void setUserData ( void *  data)

Sets user data.

void setVBorder ( float  size)

Sets vertical border size.

void setVisible ( bool  show = true)

Shows or hides the widget.

void setWidth ( const float  width)
inline

Resizes the widget width, in pixels.

Member Data Documentation

Alignment alignment {Alignment::NONE}
protected
bool allowChildren {true}
protected
bool allowFocus {false}
protected
std::list<std::shared_ptr<Widget> > children
protected
float childrenOffsetX {0}
protected
float childrenOffsetY {0}
protected
bool consumeMouseEvent {false}
protected
bool drawBackground {true}
protected
bool focused {false}
protected
float fontScale {0.0f}
protected
float hborder {0}
protected
bool mouseMoveOnFocus {false}
protected
bool moveChildrenOnPush {false}
protected
bool overlap {false}
protected
float padding {0}
protected
Widget* parent {nullptr}
protected
Rect rect
protected
bool redrawOnMouseEvent {false}
protected
bool redrawOnMouseMove {false}
protected
std::shared_ptr<UIResource> resource
protected
void* style {nullptr}
protected
float transparency {1.0f}
protected
const Type type
protected
float vborder {0}
protected
void* window {nullptr}
protected