Trait that provides position, bounds, and animated movement. More...
#include <Positionable.h>
Public Member Functions | |
| template<class T> | |
| void | center (T &obj) |
Center this object within obj (both axes). | |
| template<class T> | |
| void | centerHorizonally (T &obj) |
Center this object horizontally within obj. | |
| void | centerText (sf::Text &obj) |
Center an sf::Text object within this object's bounds. | |
| template<class T> | |
| void | centerVertically (T &obj) |
Center this object vertically within obj. | |
| virtual sf::FloatRect | getGlobalBounds () const =0 |
| Return the axis-aligned bounding box in world space. | |
| virtual sf::Vector2f | getPosition () const =0 |
| Return the current world-space position. | |
| bool | isScrolling () |
Return true while a moveTo or moveDistance animation is in progress. | |
| void | moveDistance (sf::Vector2f distance, float seconds=1.f) |
| Animate by a relative offset from the current position. | |
| void | moveTo (sf::FloatRect position, float seconds=1.f) |
Animate to a position defined by a FloatRect origin. | |
| void | moveTo (sf::Vector2f position, float seconds=1.f) |
| Animate to an absolute world-space position. | |
| template<class T> | |
| void | setAbove (T &obj, float spacing=0) |
Position this object immediately above obj. | |
| template<class T> | |
| void | setBelow (T &obj, float spacing=0) |
Position this object immediately below obj. | |
| void | setFramerate (float framerate) |
| Set the assumed framerate for movement interpolation. | |
| template<class T> | |
| void | setLeftOf (T &obj, float spacing=0) |
Position this object immediately to the left of obj. | |
| virtual void | setPosition (const sf::Vector2f &position)=0 |
| Set the world-space position immediately (no animation). | |
| template<class T> | |
| void | setRightOf (T &obj, float spacing=0) |
Position this object immediately to the right of obj. | |
Trait that provides position, bounds, and animated movement.
Positionable is one of the three core traits on every ml::Core object. It serves two purposes:
setPosition, getPosition, and getGlobalBounds methods that the rest of the framework (hit-testing, layout, drag) depend on.moveTo and moveDistance for tweened position animation, with support for axis locking, easing curves, and a configurable framerate target.Definition at line 66 of file Positionable.h.
| void ml::Positionable::center | ( | T & | obj | ) |
Center this object within obj (both axes).
| T | Any type with getGlobalBounds(). |
| obj | Container to center within. |
| void ml::Positionable::centerHorizonally | ( | T & | obj | ) |
Center this object horizontally within obj.
| T | Any type with getGlobalBounds(). |
| obj | Container to center within. |
| void ml::Positionable::centerText | ( | sf::Text & | obj | ) |
| void ml::Positionable::centerVertically | ( | T & | obj | ) |
Center this object vertically within obj.
| T | Any type with getGlobalBounds(). |
| obj | Container to center within. |
|
pure virtual |
Return the axis-aligned bounding box in world space.
Used by UIManager for hit-testing (click, hover) and by layout helpers for relative placement. Pure virtual — implemented by the concrete shape or adapter class.
Implemented in ml::CoreAdapter, ml::DrawableWrapper< ENTITY >, ml::Graphic< T >, ml::Graphic< ml::RoundedRectangle >, ml::Graphic< sf::CircleShape >, ml::Graphic< sf::ConvexShape >, ml::Graphic< sf::Sprite >, ml::Graphic< sf::Text >, ml::Grid, and ml::TextInput.
|
pure virtual |
Return the current world-space position.
Pure virtual — implemented by the concrete shape or adapter class.
Implemented in ml::CoreAdapter, ml::DrawableWrapper< ENTITY >, ml::Graphic< T >, ml::Graphic< ml::RoundedRectangle >, ml::Graphic< sf::CircleShape >, ml::Graphic< sf::ConvexShape >, ml::Graphic< sf::Sprite >, ml::Graphic< sf::Text >, ml::Grid, and ml::TextInput.
| bool ml::Positionable::isScrolling | ( | ) |
Return true while a moveTo or moveDistance animation is in progress.
true if the waypoint queue is non-empty. | void ml::Positionable::moveDistance | ( | sf::Vector2f | distance, |
| float | seconds = 1.f ) |
Animate by a relative offset from the current position.
Equivalent to moveTo(getPosition() + distance, seconds).
| distance | Offset in world coordinates to move by. |
| seconds | Duration of the animation. Defaults to 1.0 s. |
| void ml::Positionable::moveTo | ( | sf::FloatRect | position, |
| float | seconds = 1.f ) |
Animate to a position defined by a FloatRect origin.
Convenience overload that uses the top-left of position as the target. Useful when positioning relative to layout rects.
| position | Rect whose origin is the animation target. |
| seconds | Duration of the animation. Defaults to 1.0 s. |
| void ml::Positionable::moveTo | ( | sf::Vector2f | position, |
| float | seconds = 1.f ) |
Animate to an absolute world-space position.
Populates an internal waypoint queue and advances through it on successive onUpdate ticks. The object's position at the start of the call is the implicit start point.
| position | Target position in world coordinates. |
| seconds | Duration of the animation. Defaults to 1.0 s. |
| void ml::Positionable::setAbove | ( | T & | obj, |
| float | spacing = 0 ) |
Position this object immediately above obj.
| T | Any type with getGlobalBounds(). |
| obj | Reference object. |
| spacing | Gap in pixels between the two objects. Defaults to 0. |
| void ml::Positionable::setBelow | ( | T & | obj, |
| float | spacing = 0 ) |
Position this object immediately below obj.
| T | Any type with getGlobalBounds(). |
| obj | Reference object. |
| spacing | Gap in pixels between the two objects. Defaults to 0. |
| void ml::Positionable::setFramerate | ( | float | framerate | ) |
Set the assumed framerate for movement interpolation.
moveTo generates a queue of intermediate positions based on this value. Defaults to 60 fps. Call this if your application runs at a different target rate to keep animation timing accurate.
| framerate | Target framerate in frames per second. |
| void ml::Positionable::setLeftOf | ( | T & | obj, |
| float | spacing = 0 ) |
Position this object immediately to the left of obj.
| T | Any type with getGlobalBounds(). |
| obj | Reference object. |
| spacing | Gap in pixels between the two objects. Defaults to 0. |
|
pure virtual |
Set the world-space position immediately (no animation).
Pure virtual — implemented by the concrete shape or adapter class.
| position | New position in world coordinates. |
Implemented in ml::Button< Circle, float >, ml::Button< Convex, std::size_t >, ml::Button< Rectangle, sf::Vector2f >, ml::CoreAdapter, ml::DrawableWrapper< ENTITY >, ml::Graphic< T >, ml::Graphic< ml::RoundedRectangle >, ml::Graphic< sf::CircleShape >, ml::Graphic< sf::ConvexShape >, ml::Graphic< sf::Sprite >, ml::Graphic< sf::Text >, ml::Grid, and ml::TextInput.
| void ml::Positionable::setRightOf | ( | T & | obj, |
| float | spacing = 0 ) |
Position this object immediately to the right of obj.
| T | Any type with getGlobalBounds(). |
| obj | Reference object. |
| spacing | Gap in pixels between the two objects. Defaults to 0. |