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

Represents a textual label (typically an axis title or main plot title) in a 2D plot. More...

#include <wTitleEntity.hpp>

Inheritance diagram for wPlot2D::TitleEntity:
Inheritance graph

Public Member Functions

 TitleEntity (const sf::Font &font, const std::string &title, bool hasFrame=false)
 Constructs a title entity with specified font and text (UTF-8).
 TitleEntity (const sf::Font &font, const std::wstring &title, bool hasFrame=false)
 Constructs a title entity with specified font and wide string (UTF-16/32).
virtual ~TitleEntity ()=default
 Virtual destructor.
unsigned int getCharacterSize () const
 Returns the current character size.
sf::FloatRect getTextSize () const
 Returns the local bounding box of the title text.
void setTextColor (sf::Color textColor)
 Sets the text color.
void setOffset (sf::Vector2f offset)
 Sets the offset relative to the base anchor position.
void setCharacterSize (unsigned int size)
 Sets the font size (character size) of the title.
void setFont (const sf::Font &font)
 Sets the font reference for the title.
sf::Color getFrameOutlineColor () const
 Returns the current outline color of the frame.
sf::Color getFrameFillColor () const
 Returns the current fill color of the frame.
float getFrameThickness () const
 Returns the frame's outline thickness.
sf::Vector2f getPadding () const
 Returns the internal padding of the frame.
bool isFrameEnabled () const
 Returns whether the title has a visible frame.
void setFrameEnabled (bool enabled)
 Enables or disables the visual frame.
void setFrameOutlineColor (const sf::Color &color)
 Sets the frame's outline color.
void setFrameFillColor (const sf::Color &color)
 Sets the fill color of the frame.
void setFrameThickness (float thickness)
 Sets the thickness of the frame's outline.
void setPadding (sf::Vector2f padding)
 Sets the internal padding of the frame (horizontal and vertical).
void render (sf::RenderWindow &window)
 Renders the title and its frame (if enabled) to the 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 (typically an axis title or main plot title) in a 2D plot.

A TitleEntity displays text using SFML's sf::Text, styled and positioned using ECS components (PositionComponent, OffsetComponent, ColorComponent, FontComponent). Optionally, it can display a surrounding rectangular frame (FrameEntity) with customizable outline, fill color, thickness, and padding.

Notes:

  • The font passed to the constructor must remain valid during the lifetime of the entity (SFML does not copy font data).
  • The frame is disabled by default unless explicitly enabled at construction or later.
See also
FrameEntity, AxisEntity, GraphicsEntity
Author
Wilfried Koch

Constructor & Destructor Documentation

◆ TitleEntity() [1/2]

wPlot2D::TitleEntity::TitleEntity ( const sf::Font & font,
const std::string & title,
bool hasFrame = false )

Constructs a title entity with specified font and text (UTF-8).

Parameters
fontReference to an externally managed font (must remain valid).
titleThe string to display.
hasFrameWhether a surrounding frame should be displayed.

◆ TitleEntity() [2/2]

wPlot2D::TitleEntity::TitleEntity ( const sf::Font & font,
const std::wstring & title,
bool hasFrame = false )

Constructs a title entity with specified font and wide string (UTF-16/32).

Parameters
fontReference to an externally managed font (must remain valid).
titleThe wide string to display.
hasFrameWhether a surrounding frame should be displayed.

◆ ~TitleEntity()

virtual wPlot2D::TitleEntity::~TitleEntity ( )
virtualdefault

Virtual destructor.

Member Function Documentation

◆ getCharacterSize()

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

Returns the current character size.

Returns
Character size (font size in pixels).

◆ getTextSize()

sf::FloatRect wPlot2D::TitleEntity::getTextSize ( ) const
nodiscard

Returns the local bounding box of the title text.

Returns
A FloatRect representing the size and local origin of the text.

◆ setTextColor()

void wPlot2D::TitleEntity::setTextColor ( sf::Color textColor)

Sets the text color.

Parameters
textColorNew SFML color.

◆ setOffset()

void wPlot2D::TitleEntity::setOffset ( sf::Vector2f offset)

Sets the offset relative to the base anchor position.

Parameters
offsetDisplacement vector in pixels.

◆ setCharacterSize()

void wPlot2D::TitleEntity::setCharacterSize ( unsigned int size)

Sets the font size (character size) of the title.

Parameters
sizeSize in pixels.

◆ setFont()

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

Sets the font reference for the title.

Parameters
fontReference to an externally managed font (must remain valid).
Note
The font must outlive this entity, otherwise rendering will be invalid.

◆ getFrameOutlineColor()

sf::Color wPlot2D::TitleEntity::getFrameOutlineColor ( ) const
nodiscard

Returns the current outline color of the frame.

Returns
SFML color.

◆ getFrameFillColor()

sf::Color wPlot2D::TitleEntity::getFrameFillColor ( ) const
nodiscard

Returns the current fill color of the frame.

Returns
SFML color.

◆ getFrameThickness()

float wPlot2D::TitleEntity::getFrameThickness ( ) const
nodiscard

Returns the frame's outline thickness.

Returns
Thickness in pixels.

◆ getPadding()

sf::Vector2f wPlot2D::TitleEntity::getPadding ( ) const
nodiscard

Returns the internal padding of the frame.

Returns
Padding vector { x, y } in pixels.

◆ isFrameEnabled()

bool wPlot2D::TitleEntity::isFrameEnabled ( ) const
nodiscard

Returns whether the title has a visible frame.

Returns
True if frame is enabled.

◆ setFrameEnabled()

void wPlot2D::TitleEntity::setFrameEnabled ( bool enabled)

Enables or disables the visual frame.

Parameters
enabledTrue to show the frame, false to hide it.

◆ setFrameOutlineColor()

void wPlot2D::TitleEntity::setFrameOutlineColor ( const sf::Color & color)

Sets the frame's outline color.

Parameters
colorSFML color.

◆ setFrameFillColor()

void wPlot2D::TitleEntity::setFrameFillColor ( const sf::Color & color)

Sets the fill color of the frame.

Parameters
colorSFML color.

◆ setFrameThickness()

void wPlot2D::TitleEntity::setFrameThickness ( float thickness)

Sets the thickness of the frame's outline.

Parameters
thicknessOutline thickness in pixels.

◆ setPadding()

void wPlot2D::TitleEntity::setPadding ( sf::Vector2f padding)

Sets the internal padding of the frame (horizontal and vertical).

This creates a margin between the text and the frame borders. Expressed as (horizontal, vertical) padding in pixels.

Parameters
paddingVector of type (left/right, top/bottom) padding.

◆ render()

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

Renders the title and its frame (if enabled) to the window.

The title position is computed from:

  • PositionComponent (anchor point),
  • OffsetComponent (displacement),
  • the text's local bounds (centered origin).

If the frame is enabled, it is rendered behind the text, centered with the same anchor point and adjusted using the specified padding.

Parameters
windowThe target SFML render window.

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