wPlot2D version: 0.1.0
A lightweight C++ library for clear and customizable 2D scientific plots.
Loading...
Searching...
No Matches
wLabelEntity.hpp
Go to the documentation of this file.
1/*
2+---------------------------------------------------------------------------------------------------------------------------------------------------+
3Created by Wilfried Koch.
4Copyright @ 2025 Wilfried Koch. All rights reserved.
5+---------------------------------------------------------------------------------------------------------------------------------------------------+
6*/
7
8#ifndef W_LABEL_ENTITY_HPP
9#define W_LABEL_ENTITY_HPP
10
12
13#pragma GCC diagnostic push
14#pragma GCC diagnostic ignored "-Wfloat-equal"
15#pragma GCC diagnostic ignored "-Wswitch-default"
16#include <SFML/Graphics.hpp>
17#pragma GCC diagnostic pop
18
19namespace wPlot2D
20{
21
22 enum class AxisType;
23
44 {
45 public:
52 LabelEntity( const sf::Font& font, AxisType type, sf::Vector2f initialPosition );
53
57 virtual ~LabelEntity( ) = default;
58
63 [[nodiscard]] float getValue( ) const;
64
69 [[nodiscard]] unsigned int getCharacterSize( ) const;
70
75 [[nodiscard]] int getDecimalPlaces( ) const;
76
81 void setFont( const sf::Font& font );
82
91 void setLabelText( std::string text );
92
97 void setCharacterSize( unsigned int newSize );
98
103 void setDecimalPlaces( int places );
104
113 void setCustomLabels( const std::string& labels );
114
119 [[nodiscard]] bool usesCustomLabels( ) const;
120
130 std::string formatLabel( float value );
131
136 void render( sf::RenderWindow& window );
137 private:
138 AxisType mAlignment;
139 unsigned int mCharacterSize;
140 float mValue;
141 int mDecimalPlaces;
142 sf::Vector2f mOffset;
143
144 std::string mCustomLabels;
145 bool mUseCustomLabels;
146
147 sf::Text mLabel;
148 };
149
150} // namespace wPlot2D
151
152#endif
Represents an entity in the ECS (Entity-Component System) architecture.
Definition wEntity.hpp:60
int getDecimalPlaces() const
Returns the number of decimal places currently used for numeric formatting.
Definition wLabelEntity.cpp:57
float getValue() const
Returns the numeric value associated with the label.
Definition wLabelEntity.cpp:47
bool usesCustomLabels() const
Indicates whether the entity is currently using custom labels.
Definition wLabelEntity.cpp:95
LabelEntity(const sf::Font &font, AxisType type, sf::Vector2f initialPosition)
Constructs a LabelEntity with a given font, axis orientation and initial position.
Definition wLabelEntity.cpp:23
unsigned int getCharacterSize() const
Returns the current character size of the label text.
Definition wLabelEntity.cpp:52
void setFont(const sf::Font &font)
Sets a new font for the label.
Definition wLabelEntity.cpp:72
void render(sf::RenderWindow &window)
Renders the label on the given SFML window.
Definition wLabelEntity.cpp:116
void setCharacterSize(unsigned int newSize)
Sets a new character size for the labels.
Definition wLabelEntity.cpp:62
std::string formatLabel(float value)
Formats a numeric value into a label string.
Definition wLabelEntity.cpp:100
void setLabelText(std::string text)
Defines the text content of the label.
Definition wLabelEntity.cpp:67
virtual ~LabelEntity()=default
Virtual destructor.
void setDecimalPlaces(int places)
Sets the number of decimal places for numeric labels.
Definition wLabelEntity.cpp:78
void setCustomLabels(const std::string &labels)
Sets a custom label string.
Definition wLabelEntity.cpp:83
Definition wAxisEntity.cpp:17
AxisType
Enum representing the type of axis to render.
Definition wAxisEntity.hpp:35