|
| LegendEntity (const sf::Font &font, const sf::Vector2f &position, bool hasFrame=true) |
| Constructs a LegendEntity.
|
virtual | ~LegendEntity ()=default |
| Virtual destructor.
|
void | addItem (const std::string &label, FunctionEntity *function) |
| Adds a new legend item associated with a function.
|
void | addItem (const std::wstring &label, FunctionEntity *function) |
| Adds a new legend item associated with a function (wide string).
|
void | addItem (const std::string &label, DataPlotEntity *plot) |
| Adds a new legend item associated with a data plot.
|
void | addItem (const std::wstring &label, DataPlotEntity *plot) |
| Adds a new legend item associated with a data plot (wide string).
|
void | setFrameEnabled (bool enabled) |
| Enables or disables the surrounding frame of the legend.
|
void | setFrameFillColor (const sf::Color &color) |
| Sets the fill color of the legend frame.
|
void | setFrameOutlineColor (const sf::Color &color) |
| Sets the outline color of the legend frame.
|
void | setFrameThickness (float thickness) |
| Sets the outline thickness of the legend frame.
|
void | setPadding (const sf::Vector2f &padding) |
| Sets the internal padding between items and the frame borders.
|
void | setFont (const sf::Font &font) |
| Updates the font used for all legend labels.
|
void | setCharacterSize (unsigned int size) |
| Sets the character size of the legend text.
|
void | setTextColor (const sf::Color &color) |
| Sets the color of the legend labels.
|
void | render (sf::RenderWindow &window) |
| Renders the legend (all items and optional frame) to the target window.
|
| 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.
|
Represents a legend box that describes functions and data plots.
A LegendEntity provides a visual legend for plotted entities such as FunctionEntity and DataPlotEntity. Each legend item is composed of:
- A sample line (LineEntity) with the same style, thickness, and color as the source entity.
- A text label (sf::Text) describing the entity.
The legend can optionally be surrounded by a frame (FrameEntity) with configurable padding, outline color, thickness, and fill color.
Components and Features:
- Configurable font and text size.
- Support for UTF-8 and wide string labels.
- Dynamic addition of items from existing plotted entities.
- Automatic alignment of line + text pairs inside the legend box.
- See also
- FunctionEntity, DataPlotEntity, LineEntity, FrameEntity
- Note
- The font passed in the constructor must remain valid during the lifetime of the legend, as SFML does not copy font data internally.
- Author
- Wilfried Koch
- Copyright
- © 2025 Wilfried Koch