Velvet 0.1a
A beginner-friendly C++ GUI framework built on SFML.
Loading...
Searching...
No Matches
Widget Class Referenceabstract

Base class for all Velvet UI elements. More...

#include <Widget.hpp>

+ Inheritance diagram for Widget:

Public Member Functions

 Widget ()
 Construct a widget with default font loading.
 
virtual void handleEvent (const sf::Event &event, sf::RenderWindow &window)
 Handle an SFML event.
 
virtual void render (sf::RenderWindow &window)
 Render this widget.
 
virtual void setPosition (float x, float y)=0
 Set top-left position of widget in window coordinates.
 
virtual sf::Vector2< float > getDimensions ()=0
 Get widget dimensions used by layout containers.
 

Public Attributes

sf::Font font
 Shared font loaded by the base widget.
 

Protected Attributes

float x
 
float y
 

Detailed Description

Base class for all Velvet UI elements.

Widget defines the minimal lifecycle used by Velvet:

Custom widgets should derive from Widget and implement the internal update, setPosition, and getDimensions.

Constructor & Destructor Documentation

◆ Widget()

Widget::Widget ( )

Construct a widget with default font loading.

Member Function Documentation

◆ getDimensions()

virtual sf::Vector2< float > Widget::getDimensions ( )
pure virtual

Get widget dimensions used by layout containers.

Returns
Width and height.

Implemented in Button, Image, InputField, Label, Slider, and Stack.

◆ handleEvent()

virtual void Widget::handleEvent ( const sf::Event &  event,
sf::RenderWindow &  window 
)
virtual

Handle an SFML event.

Parameters
eventEvent propagated from Window.
windowRender window used for coordinate mapping.

Reimplemented in Button, InputField, Slider, and Stack.

◆ render()

virtual void Widget::render ( sf::RenderWindow &  window)
virtual

Render this widget.

Default implementation calls update(window) then draw(window).

Reimplemented in Button, Image, InputField, Label, Slider, and Stack.

◆ setPosition()

virtual void Widget::setPosition ( float  x,
float  y 
)
pure virtual

Set top-left position of widget in window coordinates.

Implemented in Button, Image, InputField, Label, Slider, and Stack.

Member Data Documentation

◆ font

sf::Font Widget::font

Shared font loaded by the base widget.

◆ x

float Widget::x
protected

◆ y

float Widget::y
protected

The documentation for this class was generated from the following file: