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

Detailed Description

A virtual UI Window displayed inside a rendering Window.

All UI widgets must belong to a UI window.

+ Inheritance diagram for Window:

Public Types

enum  ResizeableBorder {
  RESIZEABLE_NONE = 0b0000, RESIZEABLE_LEFT = 0b0001, RESIZEABLE_RIGHT = 0b0010, RESIZEABLE_TOP = 0b0100,
  RESIZEABLE_BOTTOM = 0b1000
}
 

Public Member Functions

 Window (const Rect &rect)
 
 ~Window () override
 
void setResizeableBorders (const uint32 borders)
 
auto getResizeableBorders () const
 
std::shared_ptr< StylegetStyle () const
 
void setStyle (const std::shared_ptr< Style > &style)
 
WidgetgetWidget () const
 
void setWidget (std::shared_ptr< Widget > child=nullptr, const std::string &resources="", float padding=0)
 
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 (const std::shared_ptr< T > &child, const Alignment alignment, const std::string &resource="", const bool overlap=false) const
 
void remove (const std::shared_ptr< Widget > &child) const
 
void setFocusedWidget (const std::shared_ptr< Widget > &widget)
 
auto getWidth () const
 
auto getHeight () const
 
void setRect (const Rect &newRect)
 
void setWidth (float width)
 
void setHeight (float height)
 
void setPos (float x, float y)
 
void setPos (const float2 &pos)
 
void setX (float x)
 
void setY (float y)
 
const auto & getRect () const
 
auto isVisible () const
 
void setVisible (bool isVisible)
 
void hide ()
 
void show ()
 
void setTransparency (float alpha)
 
virtual void onCreate ()
 
virtual void onDestroy ()
 
virtual void onShow ()
 
virtual void onHide ()
 
virtual void onResize ()
 
virtual void onMove ()
 
virtual bool onKeyDown (Key key)
 
virtual bool onTextInput (const std::string &text)
 
virtual bool onKeyUp (Key key)
 
virtual bool onMouseDown (MouseButton button, float x, float y)
 
virtual bool onMouseUp (MouseButton button, float x, float y)
 
virtual bool onMouseMove (uint32 buttonsState, float x, float y)
 
virtual void onGotFocus ()
 
virtual void onLostFocus ()
 
void setMinimumSize (float width, float height)
 
void setMaximumSize (float width, float height)
 
auto getMinimumWidth () const
 
auto getMinimumHeight () const
 
auto getMaximumWidth () const
 
auto getMaximumHeight () const
 
std::shared_ptr< Font > getFont () const
 
void setFont (const std::shared_ptr< Font > &font)
 
float getFontScale () const
 
void setFontScale (float fontScale)
 
auto & getTextColor () const
 
void setTextColor (const float4 &color)
 
void refresh () const
 
void eventCreate ()
 
void eventDestroy ()
 
void eventShow ()
 
void eventResize ()
 
void eventMove ()
 
void eventHide ()
 
bool eventKeyDown (Key)
 
bool eventKeyUp (Key)
 
bool eventTextInput (const std::string &text)
 
bool eventMouseDown (MouseButton, float, float)
 
bool eventMouseUp (MouseButton, float, float)
 
bool eventMouseMove (uint32, float, float)
 
void eventGotFocus ()
 
void eventLostFocus ()
 
void draw () const
 
void attach (void *windowManager)
 
void detach ()
 

Member Enumeration Documentation

Which Window borders can be used to resize the Window.

Enum ValuesDocumentation
RESIZEABLE_NONE 
RESIZEABLE_LEFT 

No resizing.

RESIZEABLE_RIGHT 

Left border resizable.

RESIZEABLE_TOP 

Right border resizable.

RESIZEABLE_BOTTOM 

Top border resizable.

Constructor & Destructor Documentation

Window ( const Rect &  rect)

Creates a virtual UI window with a given position & size.

Parameters
rectThe initial rectangle (position and size).
~Window ( )
override

Member Function Documentation

std::shared_ptr<T> add ( const std::shared_ptr< T > &  child,
const Alignment  alignment,
const std::string &  resource = "",
const bool  overlap = false 
) const
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
Shared pointer to the added widget.
void attach ( void *  windowManager)
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
alignmentPlacement alignment.
argsArguments to pass to the widget constructor.
Returns
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
resourceResource string.
alignmentPlacement alignment.
argsArguments to pass to the widget constructor.
Returns
Shared pointer to the created widget.
void detach ( )
void draw ( ) const
void eventCreate ( )
void eventDestroy ( )
void eventGotFocus ( )
void eventHide ( )
bool eventKeyDown ( Key  )
bool eventKeyUp ( Key  )
void eventLostFocus ( )
bool eventMouseDown ( MouseButton  ,
float  ,
float   
)
bool eventMouseMove ( uint32  ,
float  ,
float   
)
bool eventMouseUp ( MouseButton  ,
float  ,
float   
)
void eventMove ( )
void eventResize ( )
void eventShow ( )
bool eventTextInput ( const std::string &  text)
std::shared_ptr<Font> getFont ( ) const

Returns the default font loaded at startup.

float getFontScale ( ) const

Returns the default font scale.

auto getHeight ( ) const
inline

Returns the height of the client area.

auto getMaximumHeight ( ) const
inline

Returns the maximum height of the Window.

auto getMaximumWidth ( ) const
inline

Returns the maximum width of the Window.

auto getMinimumHeight ( ) const
inline

Returns the minimum height of the Window.

auto getMinimumWidth ( ) const
inline

Returns the minimum width of the Window.

const auto& getRect ( ) const
inline

Returns the size & position of the widget.

auto getResizeableBorders ( ) const
inline

Returns the borders that can be used to resize the Window.

Returns
Bitmask of ResizeableBorder.
std::shared_ptr<Style> getStyle ( ) const

Returns the current style layout.

Returns
The style pointer, or null if none.
auto& getTextColor ( ) const
inline

Returns the default text color.

Widget& getWidget ( ) const

Returns the root widget.

This is the widget that covers the entire Window and is the parent of all the widgets in the Window.

auto getWidth ( ) const
inline

Returns the width of the client area.

void hide ( )

Hides the Window.

The change will be effective at the start of the next frame. It needs to be called before adding the Window to the manager if you want the Window to be hidden at startup.

auto isVisible ( ) const
inline

Returns true if Window is currently visible.

virtual void onCreate ( )
inlinevirtual

Event called after Window creation (by the Window manager).

virtual void onDestroy ( )
inlinevirtual

Event called after Window destruction (by the Window manager).

virtual void onGotFocus ( )
inlinevirtual

Event called when the Window got the keyboard focus.

virtual void onHide ( )
inlinevirtual

Event called when (after) the Window manager need to hide the Window.

virtual bool onKeyDown ( Key  key)
inlinevirtual

Event called when a key was pressed.

Parameters
keyThe key pressed.
Returns
True if event was handled.
virtual bool onKeyUp ( Key  key)
inlinevirtual

Event called when a key was released.

Parameters
keyThe key released.
Returns
True if event was handled.
virtual void onLostFocus ( )
inlinevirtual

Event called when the Window lost the keyboard focus.

virtual bool onMouseDown ( MouseButton  button,
float  x,
float  y 
)
inlinevirtual

Event called when a mouse button was pressed inside the Window.

Parameters
buttonThe mouse button.
xMouse X coordinate.
yMouse Y coordinate.
Returns
True if event was handled.
virtual bool onMouseMove ( uint32  buttonsState,
float  x,
float  y 
)
inlinevirtual

Event called when the mouse is moved above the Window client area.

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

Event called when a mouse button was released inside the Window.

Parameters
buttonThe mouse button.
xMouse X coordinate.
yMouse Y coordinate.
Returns
True if event was handled.
virtual void onMove ( )
inlinevirtual

Event called after a position change.

virtual void onResize ( )
inlinevirtual

Event called after a size change.

virtual void onShow ( )
inlinevirtual

Event called when (before) the Window manager need to show the Window.

virtual bool onTextInput ( const std::string &  text)
inlinevirtual

Event called on user input

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

Removes a child widget.

void setFocusedWidget ( const std::shared_ptr< Widget > &  widget)

Changes the focus to a specific widget.

void setFont ( const std::shared_ptr< Font > &  font)

Sets the default font.

void setFontScale ( float  fontScale)

Sets the default font scale.

void setHeight ( float  height)

Sets the height of the client area.

void setMaximumSize ( float  width,
float  height 
)

Sets the maximum size of the Window (default to VECTOR_SCALE).

void setMinimumSize ( float  width,
float  height 
)

Sets the minimum size of the Window (default to {2.0f, 2.0f}).

void setPos ( const float2 &  pos)

Sets the position of the Window, bottom-left.

void setPos ( float  x,
float  y 
)

Sets the position of the Window, bottom-left.

void setRect ( const Rect &  newRect)

Sets the client area position & size.

void setResizeableBorders ( const uint32  borders)
inline

Sets the borders that can be used to resize the Window.

Parameters
bordersBitmask of ResizeableBorder.
void setStyle ( const std::shared_ptr< Style > &  style)

Sets the current style layout.

If null, installs a default layout.

void setTextColor ( const float4 &  color)
inline
void setTransparency ( float  alpha)

Sets the alpha value for transparency.

void setVisible ( bool  isVisible)

Sets the Window visibility.

The change will be effective at the start of the next frame.

void setWidget ( std::shared_ptr< Widget child = nullptr,
const std::string &  resources = "",
float  padding = 0 
)

Sets the root widget with optional resource string.

Call setStyle(nullptr) if no layout have been set previously.

Parameters
childChild widget to set as root.
resourcesResource string for the root widget.
paddingPadding for the root widget
void setWidth ( float  width)

Sets the width of the client area.

void setX ( float  x)

Sets the X position of the Window, bottom-left.

void setY ( float  y)

Sets the Y position of the Window, bottom-left.

void show ( )

Shows the Window.

The change will be effective at the start of the next frame.