Broken auto sizing
This commit is contained in:
68
src/dawn/ui/UISubAlignableElement.cpp
Normal file
68
src/dawn/ui/UISubAlignableElement.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "UISubAlignableElement.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void UISubAlignableElement::updateAlignment(
|
||||
const glm::vec2 parentPosition,
|
||||
const glm::vec2 parentSize,
|
||||
const float_t canvasScale
|
||||
) {
|
||||
UIAlignableElement::updateAlignment(parentPosition, parentSize, canvasScale);
|
||||
|
||||
switch(this->subAlignX) {
|
||||
case UISubAlignment::START:
|
||||
this->subAlignedPosition.x = this->position.x;
|
||||
break;
|
||||
|
||||
case UISubAlignment::MIDDLE:
|
||||
this->subAlignedPosition.x = (
|
||||
this->position.x +
|
||||
(this->size.x / 2.0f) -
|
||||
(this->getSelfWidth() / 2.0f)
|
||||
);
|
||||
break;
|
||||
|
||||
case UISubAlignment::END:
|
||||
this->subAlignedPosition.x = (
|
||||
this->position.x +
|
||||
this->size.x -
|
||||
this->getSelfWidth()
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
assertUnreachable("Unknown UISubAlignment!");
|
||||
}
|
||||
|
||||
switch(this->subAlignY) {
|
||||
case UISubAlignment::START:
|
||||
this->subAlignedPosition.y = this->position.y;
|
||||
break;
|
||||
|
||||
case UISubAlignment::MIDDLE:
|
||||
this->subAlignedPosition.y = (
|
||||
this->position.y +
|
||||
(this->size.y / 2.0f) -
|
||||
(this->getSelfHeight() / 2.0f)
|
||||
);
|
||||
break;
|
||||
|
||||
case UISubAlignment::END:
|
||||
this->subAlignedPosition.y = (
|
||||
this->position.y +
|
||||
this->size.y -
|
||||
this->getSelfHeight()
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
assertUnreachable("Unknown UISubAlignment!");
|
||||
}
|
||||
|
||||
this->eventSubAlignmentUpdated.emit(this->subAlignedPosition);
|
||||
}
|
Reference in New Issue
Block a user