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

Static layout helpers for positioning objects relative to one another. More...

#include <Align.h>

Static Public Member Functions

template<class S>
static void centerHorizontally (const sf::FloatRect &bounds, S &obj)
 Center obj horizontally within bounds.
template<class S, class U>
static void centerHorizontally (const sf::Vector2< U > &size, S &obj)
 Center obj horizontally within a size-defined region.
template<class T, class S>
static void centerHorizontally (const T &constObj, S &obj)
 Center obj horizontally within constObj (vertical position unchanged).
template<class S>
static void centerOn (const sf::FloatRect &bounds, S &obj)
 Center obj within bounds (both axes).
template<class S, class U>
static void centerOn (const sf::Vector2< U > &size, S &obj)
 Center obj within a size-defined region (both axes).
template<class T, class S>
static void centerOn (const T &constObj, S &obj)
 Center obj both horizontally and vertically within constObj.
template<class T>
static void centerText (const T &obj, sf::Text &text)
 Center text within the bounds of obj.
template<class S>
static void centerVertically (const sf::FloatRect &bounds, S &obj)
 Center obj vertically within bounds.
template<class S, class U>
static void centerVertically (const sf::Vector2< U > &size, S &obj)
 Center obj vertically within a size-defined region.
template<class T, class S>
static void centerVertically (const T &constObj, S &obj)
 Center obj vertically within constObj (horizontal position unchanged).
template<class S>
static void setAbove (const sf::FloatRect &bounds, S &obj, float spacing=0)
 Place obj above bounds.
template<class S, class U>
static void setAbove (const sf::Vector2< U > &size, S &obj, float spacing=0)
 Place obj above a size-defined region.
template<class T, class S>
static void setAbove (const T &constObj, S &obj, float spacing=0)
 Place obj immediately above constObj.
template<class S>
static void setBelow (const sf::FloatRect &bounds, S &obj, float spacing=0)
 Place obj below bounds.
template<class S, class U>
static void setBelow (const sf::Vector2< U > &size, S &obj, float spacing=0)
 Place obj below a size-defined region.
template<class T, class S>
static void setBelow (const T &constObj, S &obj, float spacing=0)
 Place obj immediately below constObj.
template<class S>
static void setLeftOf (const sf::FloatRect &bounds, S &obj, float spacing=0)
 Place obj to the left of bounds.
template<class S, class U>
static void setLeftOf (const sf::Vector2< U > &size, S &obj, float spacing=0)
 Place obj to the left of a size-defined region.
template<class T, class S>
static void setLeftOf (const T &constObj, S &obj, float spacing=0)
 Place obj immediately to the left of constObj.
template<class S>
static void setRightOf (const sf::FloatRect &bounds, S &obj, float spacing=0)
 Place obj to the right of bounds.
template<class S, class U>
static void setRightOf (const sf::Vector2< U > &size, S &obj, float spacing=0)
 Place obj to the right of a region defined by size.
template<class T, class S>
static void setRightOf (const T &constObj, S &obj, float spacing=0)
 Place obj immediately to the right of constObj.

Detailed Description

Static layout helpers for positioning objects relative to one another.

Align provides a uniform set of spatial operations that work against three kinds of reference:

  • Framework object T — any type with getGlobalBounds()
  • sf::FloatRect — a raw bounding rectangle
  • sf::Vector2 — treated as a size (width × height) anchored at the origin

Each operation calls setPosition on the target object S, so S must provide setPosition(sf::Vector2f) and getGlobalBounds().

These are the static equivalents of the instance methods on Positionable. Use Align when the reference object is not a Positionable (e.g., a raw sf::FloatRect from a window size or a texture region).

Usage

// Place labelB to the right of labelA with 10 px spacing
ml::Align::setRightOf(labelA, labelB, 10.f);
// Center a button within a panel's bounds
ml::Align::centerOn(panel.getGlobalBounds(), button);
// Center text inside a shape
ml::Align::centerText(panel, myText);
// Center horizontally within a known size
static void setRightOf(const T &constObj, S &obj, float spacing=0)
Place obj immediately to the right of constObj.
static void centerOn(const T &constObj, S &obj)
Center obj both horizontally and vertically within constObj.
static void centerHorizontally(const T &constObj, S &obj)
Center obj horizontally within constObj (vertical position unchanged).
static void centerText(const T &obj, sf::Text &text)
Center text within the bounds of obj.
Vector2< float > Vector2f

See also
Positionable

Definition at line 54 of file Align.h.

Member Function Documentation

◆ centerHorizontally() [1/3]

template<class S>
void ml::Align::centerHorizontally ( const sf::FloatRect & bounds,
S & obj )
static

Center obj horizontally within bounds.

◆ centerHorizontally() [2/3]

template<class S, class U>
void ml::Align::centerHorizontally ( const sf::Vector2< U > & size,
S & obj )
static

Center obj horizontally within a size-defined region.

◆ centerHorizontally() [3/3]

template<class T, class S>
void ml::Align::centerHorizontally ( const T & constObj,
S & obj )
static

Center obj horizontally within constObj (vertical position unchanged).

Template Parameters
TReference type.
STarget type.

◆ centerOn() [1/3]

template<class S>
void ml::Align::centerOn ( const sf::FloatRect & bounds,
S & obj )
static

Center obj within bounds (both axes).

◆ centerOn() [2/3]

template<class S, class U>
void ml::Align::centerOn ( const sf::Vector2< U > & size,
S & obj )
static

Center obj within a size-defined region (both axes).

◆ centerOn() [3/3]

template<class T, class S>
void ml::Align::centerOn ( const T & constObj,
S & obj )
static

Center obj both horizontally and vertically within constObj.

Template Parameters
TReference type.
STarget type.

◆ centerText()

template<class T>
void ml::Align::centerText ( const T & obj,
sf::Text & text )
static

Center text within the bounds of obj.

Template Parameters
TReference type with getGlobalBounds().
Parameters
objReference object.
textThe sf::Text to reposition.

◆ centerVertically() [1/3]

template<class S>
void ml::Align::centerVertically ( const sf::FloatRect & bounds,
S & obj )
static

Center obj vertically within bounds.

◆ centerVertically() [2/3]

template<class S, class U>
void ml::Align::centerVertically ( const sf::Vector2< U > & size,
S & obj )
static

Center obj vertically within a size-defined region.

◆ centerVertically() [3/3]

template<class T, class S>
void ml::Align::centerVertically ( const T & constObj,
S & obj )
static

Center obj vertically within constObj (horizontal position unchanged).

Template Parameters
TReference type.
STarget type.

◆ setAbove() [1/3]

template<class S>
void ml::Align::setAbove ( const sf::FloatRect & bounds,
S & obj,
float spacing = 0 )
static

Place obj above bounds.

◆ setAbove() [2/3]

template<class S, class U>
void ml::Align::setAbove ( const sf::Vector2< U > & size,
S & obj,
float spacing = 0 )
static

Place obj above a size-defined region.

◆ setAbove() [3/3]

template<class T, class S>
void ml::Align::setAbove ( const T & constObj,
S & obj,
float spacing = 0 )
static

Place obj immediately above constObj.

Template Parameters
TReference type.
STarget type.
Parameters
constObjReference object.
objObject to reposition.
spacingGap in pixels between the two objects.

◆ setBelow() [1/3]

template<class S>
void ml::Align::setBelow ( const sf::FloatRect & bounds,
S & obj,
float spacing = 0 )
static

Place obj below bounds.

◆ setBelow() [2/3]

template<class S, class U>
void ml::Align::setBelow ( const sf::Vector2< U > & size,
S & obj,
float spacing = 0 )
static

Place obj below a size-defined region.

◆ setBelow() [3/3]

template<class T, class S>
void ml::Align::setBelow ( const T & constObj,
S & obj,
float spacing = 0 )
static

Place obj immediately below constObj.

Template Parameters
TReference type.
STarget type.
Parameters
constObjReference object.
objObject to reposition.
spacingGap in pixels between the two objects.

◆ setLeftOf() [1/3]

template<class S>
void ml::Align::setLeftOf ( const sf::FloatRect & bounds,
S & obj,
float spacing = 0 )
static

Place obj to the left of bounds.

◆ setLeftOf() [2/3]

template<class S, class U>
void ml::Align::setLeftOf ( const sf::Vector2< U > & size,
S & obj,
float spacing = 0 )
static

Place obj to the left of a size-defined region.

◆ setLeftOf() [3/3]

template<class T, class S>
void ml::Align::setLeftOf ( const T & constObj,
S & obj,
float spacing = 0 )
static

Place obj immediately to the left of constObj.

Template Parameters
TReference type.
STarget type.
Parameters
constObjReference object.
objObject to reposition.
spacingGap in pixels between the two objects.

◆ setRightOf() [1/3]

template<class S>
void ml::Align::setRightOf ( const sf::FloatRect & bounds,
S & obj,
float spacing = 0 )
static

Place obj to the right of bounds.

See also
setRightOf(const T&, S&, float)

◆ setRightOf() [2/3]

template<class S, class U>
void ml::Align::setRightOf ( const sf::Vector2< U > & size,
S & obj,
float spacing = 0 )
static

Place obj to the right of a region defined by size.

The region is treated as anchored at the origin with the given size, i.e., equivalent to sf::FloatRect{{0,0}, size}.

Template Parameters
STarget type.
UVector component type (e.g., float, unsigned).

◆ setRightOf() [3/3]

template<class T, class S>
void ml::Align::setRightOf ( const T & constObj,
S & obj,
float spacing = 0 )
static

Place obj immediately to the right of constObj.

Template Parameters
TReference type.
STarget type.
Parameters
constObjReference object.
objObject to reposition.
spacingGap in pixels between the two objects.

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