Loading...
Searching...
No Matches
ml::Positionable Class Reference

Trait that provides position, bounds, and animated movement. More...

#include <Malena/Traits/Spatial/Positionable.h>

Inheritance diagram for ml::Positionable:
[legend]

Public Member Functions

virtual ~Positionable ()
void anchorBottomInWindow (float margin=0.f)
void anchorLeftInWindow (float margin=0.f)
void anchorRightInWindow (float margin=0.f)
void anchorTopInWindow (float margin=0.f)
Animateanimate ()
 Access this object's animation controller.
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 centerInWindow ()
 Center this object within the window (retained; re-solves on resize).
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.
void centerXInWindow (float offset=0.f)
 Center this object horizontally within the window, plus offset px (retained).
void centerYInWindow (float offset=0.f)
 Center this object vertically within the window, plus offset px (retained).
virtual sf::FloatRect getGlobalBounds () const
 Return the axis-aligned bounding box in world space.
virtual sf::Vector2f getPosition () const
 Return the current 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.
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)
 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.
void unanchored ()
 Drop every retained anchor on this object, freezing its current place.

Detailed Description

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:

  1. Spatial contract — declares the pure virtual setPosition, getPosition, and getGlobalBounds methods that the rest of the framework (hit-testing, layout, drag) depend on.
  2. Animated movement — provides moveTo and moveDistance for tweened position animation, with support for axis locking, easing curves, and a configurable framerate target.

Immediate positioning

// Implemented by the concrete shape/component class
myRect.setPosition({100.f, 200.f});
sf::Vector2f pos = myRect.getPosition();
sf::FloatRect bounds = myRect.getGlobalBounds();
Rect< float > FloatRect
Vector2< float > Vector2f

Animated movement

// Animate to an absolute position over 0.5 seconds
myRect.moveTo({400.f, 300.f}, 0.5f);
// Animate by a relative offset over 1 second (default)
myRect.moveDistance({50.f, 0.f});
// Poll whether animation is still running
if (myRect.isScrolling()) { ... }

Relative layout helpers

labelB.setRightOf(labelA, 10.f); // place B 10px to the right of A
button.setBelow(header, 20.f); // place button 20px below header
icon.center(panel); // center icon inside panel
icon.centerHorizonally(panel); // center horizontally only
See also
Draggable, CoreAdapter, Component

Definition at line 66 of file Positionable.h.

Constructor & Destructor Documentation

◆ ~Positionable()

virtual ml::Positionable::~Positionable ( )
virtual

Member Function Documentation

◆ anchorBottomInWindow()

void ml::Positionable::anchorBottomInWindow ( float margin = 0.f)

◆ anchorLeftInWindow()

void ml::Positionable::anchorLeftInWindow ( float margin = 0.f)

◆ anchorRightInWindow()

void ml::Positionable::anchorRightInWindow ( float margin = 0.f)

◆ anchorTopInWindow()

void ml::Positionable::anchorTopInWindow ( float margin = 0.f)

◆ animate()

Animate & ml::Positionable::animate ( )

Access this object's animation controller.

Lazily created on first use. Drives tweened position (and any app-supplied property) via delta-time Tweener / Easing.

comp.animate().move({400.f, 300.f}, 0.4f, ml::Easing::EaseOutCubic);
static float EaseOutCubic(float t)
Definition Easing.h:50
Returns
Reference to this object's Animate controller.

◆ center()

template<class T>
void ml::Positionable::center ( T & obj)

Center this object within obj (both axes).

Template Parameters
TAny type with getGlobalBounds().
Parameters
objContainer to center within.

◆ centerHorizonally()

template<class T>
void ml::Positionable::centerHorizonally ( T & obj)

Center this object horizontally within obj.

Template Parameters
TAny type with getGlobalBounds().
Parameters
objContainer to center within.

◆ centerInWindow()

void ml::Positionable::centerInWindow ( )

Center this object within the window (retained; re-solves on resize).

◆ centerText()

void ml::Positionable::centerText ( sf::Text & obj)

Center an sf::Text object within this object's bounds.

Convenience overload for the common pattern of centering a text label inside a button or panel.

Parameters
objThe sf::Text to reposition.

◆ centerVertically()

template<class T>
void ml::Positionable::centerVertically ( T & obj)

Center this object vertically within obj.

Template Parameters
TAny type with getGlobalBounds().
Parameters
objContainer to center within.

◆ centerXInWindow()

void ml::Positionable::centerXInWindow ( float offset = 0.f)

Center this object horizontally within the window, plus offset px (retained).

◆ centerYInWindow()

void ml::Positionable::centerYInWindow ( float offset = 0.f)

Center this object vertically within the window, plus offset px (retained).

◆ getGlobalBounds()

virtual sf::FloatRect ml::Positionable::getGlobalBounds ( ) const
inlinevirtual

Return the axis-aligned bounding box in world space.

Used by AppManager for hit-testing (click, hover) and by layout helpers for relative placement. Returns a zero-size rect by default, opting the component out of event routing.

Returns
Bounding rectangle in world coordinates.

Reimplemented in ml::ColorButton, ml::ColorPicker, ml::ContextMenu, ml::CoreAdapter, ml::DrawableWrapper< ENTITY >, ml::GradientColorPicker, ml::Graphic< T >, ml::Graphic< ml::RoundedRectangle >, ml::Graphic< sf::CircleShape >, ml::Graphic< sf::ConvexShape >, ml::Graphic< sf::RectangleShape >, ml::Graphic< sf::Sprite >, ml::Graphic< sf::Text >, ml::Grid, and ml::InfoButton.

Definition at line 136 of file Positionable.h.

◆ getPosition()

◆ setAbove()

template<class T>
void ml::Positionable::setAbove ( T & obj,
float spacing = 0 )

Position this object immediately above obj.

Template Parameters
TAny type with getGlobalBounds().
Parameters
objReference object.
spacingGap in pixels between the two objects. Defaults to 0.

◆ setBelow()

template<class T>
void ml::Positionable::setBelow ( T & obj,
float spacing = 0 )

Position this object immediately below obj.

Template Parameters
TAny type with getGlobalBounds().
Parameters
objReference object.
spacingGap in pixels between the two objects. Defaults to 0.

◆ setLeftOf()

template<class T>
void ml::Positionable::setLeftOf ( T & obj,
float spacing = 0 )

Position this object immediately to the left of obj.

Template Parameters
TAny type with getGlobalBounds().
Parameters
objReference object.
spacingGap in pixels between the two objects. Defaults to 0.

◆ setPosition()

virtual void ml::Positionable::setPosition ( const sf::Vector2f & position)
inlinevirtual

◆ setRightOf()

template<class T>
void ml::Positionable::setRightOf ( T & obj,
float spacing = 0 )

Position this object immediately to the right of obj.

Template Parameters
TAny type with getGlobalBounds().
Parameters
objReference object.
spacingGap in pixels between the two objects. Defaults to 0.

◆ unanchored()

void ml::Positionable::unanchored ( )

Drop every retained anchor on this object, freezing its current place.


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