Calamity Engine 1.0.0
A cross-platform 2D game engine written in C++ and SDL3.
Loading...
Searching...
No Matches
Label Class Reference

#include <label.hpp>

Inheritance diagram for Label:
Component

Public Member Functions

 Label (const std::string &text, std::shared_ptr< Font > font)
 
 Label (const std::string &text)
 
 Label ()
 
 ~Label ()
 
void update (float dt)
 
void render (std::shared_ptr< Window > window)
 
LabelsetText (const std::string &text)
 
std::string getText () const
 
TTF_Text * getHandle () const
 
LabelsetColor (Color color)
 
Color getColor () const
 
LabelsetDirection (FontDirection direction)
 
LabelsetWrapWidth (int width)
 
int getWrapWidth () const
 
void rebuildTexture ()
 
SDL_Texture * getTexture () const
 
template<class Archive >
void save (Archive &ar) const
 
template<class Archive >
void load (Archive &ar)
 
- Public Member Functions inherited from Component
virtual ~Component ()=default
 
virtual void initialize ()
 
virtual void physicsUpdate ()
 
virtual void input (InputEvent &event)
 
virtual void postLoad ()
 
virtual void exit ()
 
NodegetNode () const
 
void setNode (Node *n)
 
template<class Archive >
void save (Archive &ar) const
 
template<class Archive >
void load (Archive &ar)
 

Public Attributes

Vector2 size
 
Vector2 origin
 
std::shared_ptr< Fontfont
 
bool visible = true
 
bool wrap = true
 
bool screenSpace = false
 

Detailed Description

Label

The Label component renders text to the screen. You can construct it with or without a font, in which case a default font will be used.

Example Usage:

std::shared_ptr<Node> node = std::make_shared<Node>();
std::shared_ptr<Label> label = std::make_shared<Label>("Text goes here");
label->size = {100, 500};
node->transform.position = {20, 20};
node->addComponent(label);

Properties and usages

You can change the Label components origin. I'm really tired of saying what origin does over and over again...

label->origin = {0.0f, 0.5f};

The Label component also exposes a wrap attribute. This defines if the text is rendered using text wrap or not.

label->wrap = false; // Disable text wrapping

You can also make Labels render using screen space positioning. This can be used for UI elements and things like that:

label->screenSpace = true; // Now, the position of the label will directly translate to screen coordinates!

You can also...

label->setColor(Color(255, 0, 0)); // Set the labels color!
label->setDirection(FontDirection::LTR); // And set the text direction.
Definition definitions.hpp:41

Make sure to also check out the text example!

Constructor & Destructor Documentation

◆ Label() [1/3]

Label::Label ( const std::string &  text,
std::shared_ptr< Font font 
)

◆ Label() [2/3]

Label::Label ( const std::string &  text)

◆ Label() [3/3]

Label::Label ( )

◆ ~Label()

Label::~Label ( )

Member Function Documentation

◆ getColor()

Color Label::getColor ( ) const

◆ getHandle()

TTF_Text * Label::getHandle ( ) const

◆ getText()

std::string Label::getText ( ) const

◆ getTexture()

SDL_Texture * Label::getTexture ( ) const

◆ getWrapWidth()

int Label::getWrapWidth ( ) const

◆ load()

template<class Archive >
void Label::load ( Archive &  ar)
inline

◆ rebuildTexture()

void Label::rebuildTexture ( )

◆ render()

void Label::render ( std::shared_ptr< Window window)
virtual

Reimplemented from Component.

◆ save()

template<class Archive >
void Label::save ( Archive &  ar) const
inline

◆ setColor()

Label * Label::setColor ( Color  color)

◆ setDirection()

Label * Label::setDirection ( FontDirection  direction)

◆ setText()

Label * Label::setText ( const std::string &  text)

◆ setWrapWidth()

Label * Label::setWrapWidth ( int  width)

◆ update()

void Label::update ( float  dt)
virtual

Reimplemented from Component.

Member Data Documentation

◆ font

std::shared_ptr<Font> Label::font

◆ origin

Vector2 Label::origin

◆ screenSpace

bool Label::screenSpace = false

◆ size

Vector2 Label::size

◆ visible

bool Label::visible = true

◆ wrap

bool Label::wrap = true

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