Loading...
Searching...
No Matches
Positionable.h
Go to the documentation of this file.
1// Copyright (c) 2025 Dave R. Smith.
2// Malena Framework — Licensed under PolyForm Noncommercial 1.0.0; commercial use requires a paid license. See LICENSE.
3
4//
5// Created by Dave Smith on 11/13/22.
6//
7
8#ifndef MALENA_PORTFOLIO_POSITIONABLE_H
9#define MALENA_PORTFOLIO_POSITIONABLE_H
10
11#pragma once
12
14#include <SFML/Graphics.hpp>
15#include <memory>
17
18namespace ml
19{
20 class Animate;
67 {
68 public:
69 // Positionable stores NO animation member (that would delete the copy
70 // assignment the framework relies on for value-type shapes). The Animate
71 // controller is owned in an external pointer-keyed registry; this destructor
72 // releases it. Declared out-of-line so Animate stays a forward declaration here.
73 virtual ~Positionable();
74
88
89 // ── Retained-anchor control ──────────────────────────────────────────
90 // The relative-layout helpers below (setBelow/center*/…) are RETAINED by
91 // default: each records a live constraint against its reference and is
92 // re-solved on window resize, so layouts stay correct when the window
93 // changes. A direct setPosition detaches them (manual control wins).
94
96 void unanchored();
97
101 void centerXInWindow(float offset = 0.f);
103 void centerYInWindow(float offset = 0.f);
104
105 // Pin an edge to the window's inside edge, @p margin px inward (retained).
106 void anchorLeftInWindow(float margin = 0.f);
107 void anchorRightInWindow(float margin = 0.f);
108 void anchorTopInWindow(float margin = 0.f);
109 void anchorBottomInWindow(float margin = 0.f);
110
118 virtual void setPosition(const sf::Vector2f& position) {}
119
125 virtual sf::Vector2f getPosition() const { return {}; }
126
136 virtual sf::FloatRect getGlobalBounds() const { return {}; }
137
138 // ── Relative layout helpers ──────────────────────────────────────────
139
146 template<class T>
147 void setRightOf(T& obj, float spacing = 0);
148
155 template<class T>
156 void setLeftOf(T& obj, float spacing = 0);
157
164 template<class T>
165 void setBelow(T& obj, float spacing = 0);
166
173 template<class T>
174 void setAbove(T& obj, float spacing = 0);
175
181 template<class T>
182 void center(T& obj);
183
189 template<class T>
190 void centerHorizonally(T& obj);
191
197 template<class T>
198 void centerVertically(T& obj);
199
209 };
210
211} // namespace ml
212
213#include "../../../../src/Traits/Spatial/Positionable.tpp"
214#endif // MALENA_PORTFOLIO_POSITIONABLE_H
Fluent animation controller bound to one object.
Definition Animate.h:44
Trait that provides position, bounds, and animated movement.
Animate & animate()
Access this object's animation controller.
virtual void setPosition(const sf::Vector2f &position)
Set the world-space position immediately (no animation).
void anchorTopInWindow(float margin=0.f)
void setBelow(T &obj, float spacing=0)
Position this object immediately below obj.
void center(T &obj)
Center this object within obj (both axes).
void centerXInWindow(float offset=0.f)
Center this object horizontally within the window, plus offset px (retained).
void unanchored()
Drop every retained anchor on this object, freezing its current place.
virtual sf::Vector2f getPosition() const
Return the current world-space position.
void setAbove(T &obj, float spacing=0)
Position this object immediately above obj.
void centerVertically(T &obj)
Center this object vertically within obj.
void anchorRightInWindow(float margin=0.f)
void anchorLeftInWindow(float margin=0.f)
virtual ~Positionable()
void centerHorizonally(T &obj)
Center this object horizontally within obj.
void centerInWindow()
Center this object within the window (retained; re-solves on resize).
void setRightOf(T &obj, float spacing=0)
Position this object immediately to the right of obj.
virtual sf::FloatRect getGlobalBounds() const
Return the axis-aligned bounding box in world space.
void setLeftOf(T &obj, float spacing=0)
Position this object immediately to the left of obj.
void anchorBottomInWindow(float margin=0.f)
void centerText(sf::Text &obj)
Center an sf::Text object within this object's bounds.
void centerYInWindow(float offset=0.f)
Center this object vertically within the window, plus offset px (retained).
Empty marker base class for all Malena traits.
Definition Trait.h:35
#define MALENA_API
Definition Animate.h:25
Rect< float > FloatRect
Vector2< float > Vector2f