// 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->getContentWidth() / 2.0f) ); break; case UISubAlignment::END: this->subAlignedPosition.x = ( this->position.x + this->size.x - this->getContentWidth() ); 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->getContentHeight() / 2.0f) ); break; case UISubAlignment::END: this->subAlignedPosition.y = ( this->position.y + this->size.y - this->getContentHeight() ); break; default: assertUnreachable("Unknown UISubAlignment!"); } this->eventSubAlignmentUpdated.emit(this->subAlignedPosition); }