1#include "Constraint.hpp"
2#include "RootDisplay.hpp"
16 positioningFlags |= flags;
17 paddingOffset = padding;
18 this->targets = targets;
21void Constraint::clearFlags() {
25void Constraint::addFlags(
int flags) {
26 positioningFlags |= flags;
29void Constraint::clearTargets() {
33void Constraint::addTarget(
Element* target) {
34 targets.push_back(target);
37void Constraint::apply(
Element* element) {
40 auto target = element->
parent;
41 int posX = 0, posY = 0;
42 int width = RootDisplay::screenWidth, height = RootDisplay::screenHeight;
46 width = target->
width;
47 height = target->height;
51 if (positioningFlags & ALIGN_LEFT) element->x = posX + paddingOffset;
52 if (positioningFlags & ALIGN_RIGHT) element->x = posX + width - element->
width - paddingOffset;
53 if (positioningFlags & ALIGN_TOP) element->y = posY + paddingOffset;
54 if (positioningFlags & ALIGN_BOTTOM) element->y = posY + height - element->height - paddingOffset;
56 if (positioningFlags & ALIGN_CENTER_HORIZONTAL) element->x = posX + width / 2 - element->
width / 2;
57 if (positioningFlags & ALIGN_CENTER_VERTICAL) element->y = posY + height / 2 - element->height / 2;
60 if (positioningFlags & OFFSET_LEFT) element->x += paddingOffset;
61 if (positioningFlags & OFFSET_RIGHT) element->x -= paddingOffset;
62 if (positioningFlags & OFFSET_TOP) element->y += paddingOffset;
63 if (positioningFlags & OFFSET_BOTTOM) element->y -= paddingOffset;
Constraint(int flags, int padding=0, std::vector< Element * > targets={})
int width
width and height of this element (must be manually set, isn't usually calculated (but is in some case...
Element * parent
the parent element (can sometimes be null if it isn't set)