wPlot2D version: 0.1.0
A lightweight C++ library for clear and customizable 2D scientific plots.
Loading...
Searching...
No Matches
wPlot2D::LabelEntity Class Reference

Represents a textual label or a collection of axis labels. More...

#include <wLabelEntity.hpp>

Inheritance diagram for wPlot2D::LabelEntity:
Inheritance graph

Public Member Functions

 LabelEntity (const sf::Font &font, AxisType type, sf::Vector2f initialPosition)
 Constructs a LabelEntity with a given font, axis orientation and initial position.
virtual ~LabelEntity ()=default
 Virtual destructor.
float getValue () const
 Returns the numeric value associated with the label.
unsigned int getCharacterSize () const
 Returns the current character size of the label text.
int getDecimalPlaces () const
 Returns the number of decimal places currently used for numeric formatting.
void setFont (const sf::Font &font)
 Sets a new font for the label.
void setLabelText (std::string text)
 Defines the text content of the label.
void setCharacterSize (unsigned int newSize)
 Sets a new character size for the labels.
void setDecimalPlaces (int places)
 Sets the number of decimal places for numeric labels.
void setCustomLabels (const std::string &labels)
 Sets a custom label string.
bool usesCustomLabels () const
 Indicates whether the entity is currently using custom labels.
std::string formatLabel (float value)
 Formats a numeric value into a label string.
void render (sf::RenderWindow &window)
 Renders the label on the given SFML window.
Public Member Functions inherited from wEngine::Entity
 Entity ()
virtual ~Entity ()
unsigned int getEntityID () const
 Returns the unique ID associated with this entity.
void clearComponents ()
 Removes all components currently attached to the entity.
template<typename T, typename... Args>
std::shared_ptr< T > addComponent (Args &&... args)
 Adds a new component of type T to the entity.
template<typename T>
void removeComponent ()
 Removes the component of type T from the entity.
template<typename T>
bool hasComponent () const noexcept
 Checks whether the entity has a component of type T.
template<typename T>
std::shared_ptr< T > getComponent () const
 Retrieves the component of type T attached to the entity.
template<typename T>
std::shared_ptr< T > requireComponent (const std::string &context="") const
 Retrieves the component of type T and throws if it's missing.
template<typename Interface>
std::shared_ptr< Interface > getInterfaceComponent () const
 Returns the first component that implements the specified interface.

Additional Inherited Members

Static Public Member Functions inherited from wEngine::Entity
static void resetEntityIDCounter ()
 Resets the global entity ID counter to zero.

Detailed Description

Represents a textual label or a collection of axis labels.

A LabelEntity manages the rendering of formatted text associated with axis notches. Labels can be generated dynamically (from numeric values, with controlled precision) or defined manually via custom strings.

The class relies on SFML's sf::Text for rendering and provides customization of style (font, color, character size) and placement (axis orientation, offset relative to the axis).

Note
Typically, a LabelEntity is aggregated inside an AxisEntity to display labels alongside axis notches.
See also
AxisEntity
Author
Wilfried Koch

Constructor & Destructor Documentation

◆ LabelEntity()

wPlot2D::LabelEntity::LabelEntity ( const sf::Font & font,
AxisType type,
sf::Vector2f initialPosition )

Constructs a LabelEntity with a given font, axis orientation and initial position.

Parameters
fontReference to an SFML font (must remain valid during the lifetime of the entity).
typeAxis orientation (AxisType::X_AXIS or AxisType::Y_AXIS).
initialPositionPosition where the label will be anchored.

◆ ~LabelEntity()

virtual wPlot2D::LabelEntity::~LabelEntity ( )
virtualdefault

Virtual destructor.

Member Function Documentation

◆ getValue()

float wPlot2D::LabelEntity::getValue ( ) const
nodiscard

Returns the numeric value associated with the label.

Returns
The value stored in the label.

◆ getCharacterSize()

unsigned int wPlot2D::LabelEntity::getCharacterSize ( ) const
nodiscard

Returns the current character size of the label text.

Returns
Character size in pixels.

◆ getDecimalPlaces()

int wPlot2D::LabelEntity::getDecimalPlaces ( ) const
nodiscard

Returns the number of decimal places currently used for numeric formatting.

Returns
Number of digits after the decimal point.

◆ setFont()

void wPlot2D::LabelEntity::setFont ( const sf::Font & font)

Sets a new font for the label.

Parameters
fontReference to an SFML font (must remain valid during the lifetime of the entity).

◆ setLabelText()

void wPlot2D::LabelEntity::setLabelText ( std::string text)

Defines the text content of the label.

If custom labels are enabled, this method updates the string that will be rendered. Otherwise, it is generally managed internally via numeric formatting.

Parameters
textThe new string to assign to the label.

◆ setCharacterSize()

void wPlot2D::LabelEntity::setCharacterSize ( unsigned int newSize)

Sets a new character size for the labels.

Parameters
newSizeCharacter size in pixels.

◆ setDecimalPlaces()

void wPlot2D::LabelEntity::setDecimalPlaces ( int places)

Sets the number of decimal places for numeric labels.

Parameters
placesDigits after the decimal point (must be >= 0).

◆ setCustomLabels()

void wPlot2D::LabelEntity::setCustomLabels ( const std::string & labels)

Sets a custom label string.

This enables "custom label mode". When active, numeric formatting is ignored and the provided string is displayed instead.

Parameters
labelsCustom string to display as a label.

◆ usesCustomLabels()

bool wPlot2D::LabelEntity::usesCustomLabels ( ) const
nodiscard

Indicates whether the entity is currently using custom labels.

Returns
True if custom labels are active, false if numeric formatting is used.

◆ formatLabel()

std::string wPlot2D::LabelEntity::formatLabel ( float value)

Formats a numeric value into a label string.

If custom labels are active, the stored custom string is returned. Otherwise, the numeric value is converted using the current number of decimal places.

Parameters
valueNumeric value to format.
Returns
A string ready to be displayed as a label.

◆ render()

void wPlot2D::LabelEntity::render ( sf::RenderWindow & window)

Renders the label on the given SFML window.

Parameters
windowReference to the render window.

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