Lysa  0.0
Lysa 3D 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
}
 Widget type. More...
 
enum  AlignmentType {
  NONE, FILL, CENTER, HCENTER,
  VCENTER, TOP, BOTTOM, LEFT,
  RIGHT, TOPCENTER, BOTTOMCENTER, LEFTCENTER,
  RIGHTCENTER, TOPLEFT, BOTTOMLEFT, BOTTOMRIGHT,
  TOPRIGHT, LEFTTOP, LEFTBOTTOM, RIGHTBOTTOM,
  RIGHTTOP, CORNERTOPLEFT, CORNERTOPRIGHT, CORNERBOTTOMLEFT,
  CORNERBOTTOMRIGHT
}
 Widget placement (relative to the parent widget) More...
 

Public Member Functions

 Widget (Type=WIDGET)
 
 ~Widget () override = default
 
Type getType () const
 
bool isVisible () const
 
void show (bool show=true)
 
bool isEnabled () const
 
void enable (bool isEnabled=true)
 
void setPos (float x, float y)
 
float getWidth () const
 
float getHeight () const
 
virtual void setSize (float width, float height)
 
const RectgetRect () const
 
void setRect (float x, float y, float width, float height)
 
void setRect (const Rect &rect)
 
AlignmentType getAlignment () const
 
void setAlignment (AlignmentType alignment)
 
std::shared_ptr< FontgetFont () 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 >
std::shared_ptr< T > add (std::shared_ptr< T > child, const AlignmentType 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 () const
 
void setResource (std::shared_ptr< Resource >)
 
uint32 getGroupIndex () const
 
void setGroupIndex (int32 index)
 
void * getUserData () const
 
void setUserData (void *data)
 
float getTransparency () const
 
void setTransparency (float alpha)
 
void resizeChildren ()
 
Widget * setFocus (bool=true)
 
virtual void eventCreate ()
 
virtual void eventDestroy ()
 
virtual void eventShow ()
 
virtual void eventHide ()
 
virtual void eventEnable ()
 
virtual void eventDisable ()
 
virtual void eventMove (float x, float y)
 
virtual void eventResize ()
 
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, float x, float y)
 
virtual void eventGotFocus ()
 
virtual void eventLostFocus ()
 
- Public Member Functions inherited from Object
void connect (const Signal::signal &name, const Signal::Handler &handler)
 
void connect (const Signal::signal &name, const std::function< void ()> &handler)
 
void emit (const Signal::signal &name, void *params=nullptr)
 
virtual std::string toString () const
 
 Object () = default
 
virtual ~Object () = default
 

Protected Member Functions

void allowingFocus (bool allow=true)
 

Protected Attributes

const Type type
 
Rect rect
 
Rect defaultRect
 
float hborder {0}
 
float vborder {0}
 
float padding {0}
 
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}
 
AlignmentType alignment {NONE}
 
std::shared_ptr< Resourceresource
 
std::list< std::shared_ptr< Widget > > children
 
Windowwindow {nullptr}
 
void * style {nullptr}
 
bool mouseMoveOnFocus {false}
 
float fontScale {0.0f}
 

Member Enumeration Documentation

Widget placement (relative to the parent widget)

Enum ValuesDocumentation
NONE 
FILL 

The child widget is centered and resized to the parent content size.

CENTER 

The child widget is centered (and take all the parent content size)

HCENTER 

The child widget is horizontally centered.

VCENTER 

The child widget is vertically centered.

TOP 

The children are stack on the top.

BOTTOM 

The children are stack on the bottom.

LEFT 

The children are stack on the left.

RIGHT 

The children are stack on the right.

TOPCENTER 

The children are stack on the top and horizontally centered.

BOTTOMCENTER 

The children are stack on the bottom and horizontally centered.

LEFTCENTER 

The children are stack on the left and vertically centered.

RIGHTCENTER 

The children are stack on the right and vertically centered.

TOPLEFT 

The children are stack on the top and left aligned.

BOTTOMLEFT 

The children are stack on the bottom and left aligned.

BOTTOMRIGHT 

The children are stack on the bottom and right aligned.

TOPRIGHT 

The children are stack on the top and right aligned.

LEFTTOP 

The children are stack on the left then on the top.

LEFTBOTTOM 

The children are stack on the left then on the bottom.

RIGHTBOTTOM 

The children are stack on the right then on the bottom.

RIGHTTOP 

The children are stack on the right then on the top.

CORNERTOPLEFT 
CORNERTOPRIGHT 
CORNERBOTTOMLEFT 
CORNERBOTTOMRIGHT 
enum Type

Widget type.

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

Constructor & Destructor Documentation

Widget ( Type  = WIDGET)

Creates a widget of a particular type

~Widget ( )
overridedefault

Member Function Documentation

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

Adds a child widget. Children widgets will be destroyed on parent destruction.

Parameters
child: child widget to add
alignmentplacement
resource: resource string
overlap: overlap widget on top of other widgets
void allowingFocus ( bool  allow = true)
protected
void enable ( bool  isEnabled = true)

Enables or disables widget reactions to input events

virtual void eventCreate ( )
virtual
virtual void eventDestroy ( )
virtual
virtual void eventDisable ( )
virtual
virtual void eventEnable ( )
virtual
virtual void eventGotFocus ( )
virtual
virtual void eventHide ( )
virtual
virtual bool eventKeyDown ( Key  key)
virtual
virtual bool eventKeyUp ( Key  key)
virtual
virtual void eventLostFocus ( )
virtual
virtual bool eventMouseDown ( MouseButton  button,
float  x,
float  y 
)
virtual
virtual bool eventMouseMove ( uint32  ,
float  x,
float  y 
)
virtual
virtual bool eventMouseUp ( MouseButton  button,
float  x,
float  y 
)
virtual
virtual void eventMove ( float  x,
float  y 
)
virtual
virtual void eventResize ( )
virtual
virtual void eventShow ( )
virtual
AlignmentType getAlignment ( ) const

Returns the current widget placement

Rect getChildrenRect ( ) const
std::shared_ptr<Font> getFont ( ) const

Returns the current font of the widget

float getFontScale ( ) const
uint32 getGroupIndex ( ) const

Return the user defined group index

float getHBorder ( ) const
float getHeight ( ) const
inline

Returns the height of the widget, in pixels

float getPadding ( ) const

Returns current children padding (space between children)

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

Return the transparency alpha value

Type getType ( ) const

Returns the type of the widget

void* getUserData ( ) const

Returns the user data

float getVBorder ( ) const
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 is the widget is reactive to user action (mouse & keyboard)

bool isFocused ( ) const

Returns true if the widget has keyboard focus

bool isFreezed ( ) const
bool isOverlapping ( ) const
inline
bool isPointed ( ) const
bool isPushed ( ) const
bool isRedrawOnMouseEvent ( ) const
bool isVisible ( ) const

Returns true if the widget is visible

void refresh ( ) const

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's widgets recursively

void resizeChildren ( )
void setAlignment ( AlignmentType  alignment)

Sets the widget placement. Calling this method involve redrawing the parent widget & resizing all the children widgets

void setDrawBackground ( bool  drawBackground)

Sets to false make the widget background transparent

Widget* setFocus ( bool  = true)
void setFont ( const std::shared_ptr< Font > &  font)

Sets the current font of the widget

virtual void setFontScale ( float  fontScale)
virtual
void setFreezed ( const bool  f)
inline
void setGroupIndex ( int32  index)

Set the user defined group index

void setHBorder ( float  size)
void setPadding ( float  padding)

Changes children padding (space between children)

void setPos ( float  x,
float  y 
)

Moves the widget to a particular position.

void setPushed ( const bool  p)
inline
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< Resource )

Changes widget resources. Use with caution !

virtual void setSize ( float  width,
float  height 
)
virtual

Resizes the widget

void setTransparency ( float  alpha)

Changes the transparency alpha value

void setUserData ( void *  data)

set user data

void setVBorder ( float  size)
void show ( bool  show = true)

Shows or hides the widget

Friends And Related Function Documentation

friend class Window
friend

Member Data Documentation

AlignmentType alignment {NONE}
protected
bool allowChildren {true}
protected
bool allowFocus {false}
protected
std::list<std::shared_ptr<Widget> > children
protected
Rect defaultRect
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<Resource> resource
protected
void* style {nullptr}
protected
float transparency {1.0f}
protected
const Type type
protected
float vborder {0}
protected
Window* window {nullptr}
protected