undoing some auto align stuff
This commit is contained in:
@ -26,11 +26,8 @@ void UIAlignableElement::updateSelfAlignment(
|
||||
const enum UIAlignmentUnit unit,
|
||||
const float_t alignment,
|
||||
const float_t parentSize,
|
||||
const float_t ratioSize,
|
||||
const float_t selfSize
|
||||
const float_t ratioSize
|
||||
) {
|
||||
if(alignment == UI_ALIGN_AUTO) return selfSize;
|
||||
|
||||
switch(unit) {
|
||||
case UIAlignmentUnit::PIXEL:
|
||||
return alignment;
|
||||
@ -68,15 +65,13 @@ void UIAlignableElement::updateSelfAlignment(
|
||||
unit0,
|
||||
alignment0,
|
||||
parentSize,
|
||||
ratioSize,
|
||||
selfSize
|
||||
ratioSize
|
||||
);
|
||||
outSize = valueAxis(
|
||||
unit1,
|
||||
alignment1,
|
||||
parentSize,
|
||||
ratioSize,
|
||||
selfSize
|
||||
ratioSize
|
||||
);
|
||||
break;
|
||||
|
||||
@ -85,15 +80,13 @@ void UIAlignableElement::updateSelfAlignment(
|
||||
unit1,
|
||||
alignment1,
|
||||
parentSize,
|
||||
ratioSize,
|
||||
selfSize
|
||||
ratioSize
|
||||
);
|
||||
outPosition = (parentSize / 2.0f) - (selfSize / 2.0f) + valueAxis(
|
||||
unit0,
|
||||
alignment0,
|
||||
parentSize,
|
||||
ratioSize,
|
||||
selfSize
|
||||
ratioSize
|
||||
);
|
||||
break;
|
||||
|
||||
@ -102,15 +95,13 @@ void UIAlignableElement::updateSelfAlignment(
|
||||
unit0,
|
||||
alignment0,
|
||||
parentSize,
|
||||
ratioSize,
|
||||
selfSize
|
||||
ratioSize
|
||||
);
|
||||
outPosition = parentSize - outSize - valueAxis(
|
||||
unit1,
|
||||
alignment1,
|
||||
parentSize,
|
||||
ratioSize,
|
||||
selfSize
|
||||
ratioSize
|
||||
);
|
||||
break;
|
||||
|
||||
@ -119,15 +110,13 @@ void UIAlignableElement::updateSelfAlignment(
|
||||
unit0,
|
||||
alignment0,
|
||||
parentSize,
|
||||
ratioSize,
|
||||
selfSize
|
||||
ratioSize
|
||||
);
|
||||
outSize = parentSize - (outPosition + valueAxis(
|
||||
unit1,
|
||||
alignment1,
|
||||
parentSize,
|
||||
ratioSize,
|
||||
selfSize
|
||||
ratioSize
|
||||
));
|
||||
break;
|
||||
|
||||
@ -152,7 +141,7 @@ void UIAlignableElement::updateSelfAlignment(
|
||||
align[3],
|
||||
pSize.y,
|
||||
0,
|
||||
this->getSelfHeight(),
|
||||
this->getContentHeight(),
|
||||
position.y,
|
||||
size.y
|
||||
);
|
||||
@ -164,7 +153,7 @@ void UIAlignableElement::updateSelfAlignment(
|
||||
align[2],
|
||||
pSize.x,
|
||||
size.y,
|
||||
this->getSelfWidth(),
|
||||
this->getContentWidth(),
|
||||
position.x,
|
||||
size.x
|
||||
);
|
||||
@ -177,7 +166,7 @@ void UIAlignableElement::updateSelfAlignment(
|
||||
align[2],
|
||||
pSize.x,
|
||||
0,
|
||||
this->getSelfWidth(),
|
||||
this->getContentWidth(),
|
||||
position.x,
|
||||
size.x
|
||||
);
|
||||
@ -189,7 +178,7 @@ void UIAlignableElement::updateSelfAlignment(
|
||||
align[3],
|
||||
pSize.y,
|
||||
size.x,
|
||||
this->getSelfHeight(),
|
||||
this->getContentWidth(),
|
||||
position.y,
|
||||
size.y
|
||||
);
|
||||
@ -199,14 +188,6 @@ void UIAlignableElement::updateSelfAlignment(
|
||||
this->eventAlignmentUpdated(position, size);
|
||||
}
|
||||
|
||||
float_t UIAlignableElement::getSelfWidth() {
|
||||
return size.x;
|
||||
}
|
||||
|
||||
float_t UIAlignableElement::getSelfHeight() {
|
||||
return size.y;
|
||||
}
|
||||
|
||||
void UIAlignableElement::updateAlignment(
|
||||
const glm::vec2 pPos,
|
||||
const glm::vec2 pSize,
|
||||
|
@ -6,8 +6,6 @@
|
||||
#pragma once
|
||||
#include "ui/UIElement.hpp"
|
||||
|
||||
#define UI_ALIGN_AUTO -1
|
||||
|
||||
namespace Dawn {
|
||||
enum class UIAlignmentType {
|
||||
START,
|
||||
@ -43,9 +41,9 @@ namespace Dawn {
|
||||
|
||||
public:
|
||||
// Primary alignment controls
|
||||
glm::vec4 align = glm::vec4(0, 0, UI_ALIGN_AUTO, UI_ALIGN_AUTO);
|
||||
enum UIAlignmentType alignX = UIAlignmentType::START;
|
||||
enum UIAlignmentType alignY = UIAlignmentType::START;
|
||||
glm::vec4 align = glm::vec4(0, 0, 0, 0);
|
||||
enum UIAlignmentType alignX = UIAlignmentType::STRETCH;
|
||||
enum UIAlignmentType alignY = UIAlignmentType::STRETCH;
|
||||
enum UIAlignmentUnit alignUnit[4];
|
||||
|
||||
std::function<
|
||||
@ -57,8 +55,6 @@ namespace Dawn {
|
||||
*/
|
||||
UIAlignableElement();
|
||||
|
||||
float_t getSelfWidth() override;
|
||||
float_t getSelfHeight() override;
|
||||
void updateAlignment(
|
||||
const glm::vec2 parentPosition,
|
||||
const glm::vec2 parentSize,
|
||||
|
@ -16,20 +16,20 @@ void UIElement::getSelfQuads(UICanvas &ctx) {
|
||||
//Do nothing
|
||||
}
|
||||
|
||||
float_t UIElement::getSelfWidth() {
|
||||
float_t UIElement::getContentWidth() {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
float_t UIElement::getSelfHeight() {
|
||||
float_t UIElement::getContentHeight() {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
float_t UIElement::getWidth() {
|
||||
return this->getSelfWidth();
|
||||
return this->getContentWidth();
|
||||
}
|
||||
|
||||
float_t UIElement::getHeight() {
|
||||
return this->getSelfHeight();
|
||||
return this->getContentHeight();
|
||||
}
|
||||
|
||||
void UIElement::getQuads(UICanvas &ctx) {
|
||||
|
@ -23,7 +23,7 @@ void UISubAlignableElement::updateAlignment(
|
||||
this->subAlignedPosition.x = (
|
||||
this->position.x +
|
||||
(this->size.x / 2.0f) -
|
||||
(this->getSelfWidth() / 2.0f)
|
||||
(this->getContentWidth() / 2.0f)
|
||||
);
|
||||
break;
|
||||
|
||||
@ -31,7 +31,7 @@ void UISubAlignableElement::updateAlignment(
|
||||
this->subAlignedPosition.x = (
|
||||
this->position.x +
|
||||
this->size.x -
|
||||
this->getSelfWidth()
|
||||
this->getContentWidth()
|
||||
);
|
||||
break;
|
||||
|
||||
@ -48,7 +48,7 @@ void UISubAlignableElement::updateAlignment(
|
||||
this->subAlignedPosition.y = (
|
||||
this->position.y +
|
||||
(this->size.y / 2.0f) -
|
||||
(this->getSelfHeight() / 2.0f)
|
||||
(this->getContentHeight() / 2.0f)
|
||||
);
|
||||
break;
|
||||
|
||||
@ -56,7 +56,7 @@ void UISubAlignableElement::updateAlignment(
|
||||
this->subAlignedPosition.y = (
|
||||
this->position.y +
|
||||
this->size.y -
|
||||
this->getSelfHeight()
|
||||
this->getContentHeight()
|
||||
);
|
||||
break;
|
||||
|
||||
|
@ -12,23 +12,23 @@ std::vector<std::shared_ptr<UIElement>> UIContainer::getChildren() {
|
||||
return this->children;
|
||||
}
|
||||
|
||||
float_t UIContainer::getSelfWidth() {
|
||||
float_t width = 0;
|
||||
auto children = this->getChildren();
|
||||
for(auto child : children) {
|
||||
width = Math::max(width, child->getWidth());
|
||||
}
|
||||
return width;
|
||||
}
|
||||
// float_t UIContainer::getSelfWidth() {
|
||||
// float_t width = 0;
|
||||
// auto children = this->getChildren();
|
||||
// for(auto child : children) {
|
||||
// width = Math::max(width, child->getWidth());
|
||||
// }
|
||||
// return width;
|
||||
// }
|
||||
|
||||
float_t UIContainer::getSelfHeight() {
|
||||
float_t height = 0;
|
||||
auto children = this->getChildren();
|
||||
for(auto child : children) {
|
||||
height = Math::max(height, child->getHeight());
|
||||
}
|
||||
return height;
|
||||
}
|
||||
// float_t UIContainer::getSelfHeight() {
|
||||
// float_t height = 0;
|
||||
// auto children = this->getChildren();
|
||||
// for(auto child : children) {
|
||||
// height = Math::max(height, child->getHeight());
|
||||
// }
|
||||
// return height;
|
||||
// }
|
||||
|
||||
void UIContainer::appendChild(std::shared_ptr<UIElement> child) {
|
||||
assertNotNull(child, "Cannot append a null child!");
|
||||
|
@ -14,9 +14,6 @@ namespace Dawn {
|
||||
public:
|
||||
std::vector<std::shared_ptr<UIElement>> getChildren() override;
|
||||
|
||||
float_t getSelfWidth() override;
|
||||
float_t getSelfHeight() override;
|
||||
|
||||
/**
|
||||
* Appends a child to this container.
|
||||
*
|
||||
|
@ -7,6 +7,22 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
float_t UIPaddingContainer::getContentWidth() {
|
||||
float_t width = 0.0f;
|
||||
for(auto &child : getChildren()) {
|
||||
width = Math::max(width, child->getWidth());
|
||||
}
|
||||
return width + padding.x + padding.z;
|
||||
}
|
||||
|
||||
float_t UIPaddingContainer::getContentHeight() {
|
||||
float_t height = 0.0f;
|
||||
for(auto &child : getChildren()) {
|
||||
height = Math::max(height, child->getHeight());
|
||||
}
|
||||
return height + padding.y + padding.w;
|
||||
}
|
||||
|
||||
void UIPaddingContainer::updateAlignment(
|
||||
const glm::vec2 parentPosition,
|
||||
const glm::vec2 parentSize,
|
||||
|
@ -10,7 +10,9 @@ namespace Dawn {
|
||||
class UIPaddingContainer final : public UIContainer {
|
||||
public:
|
||||
glm::vec4 padding = { 0, 0, 0, 0 };
|
||||
|
||||
|
||||
float_t getContentWidth() override;
|
||||
float_t getContentHeight() override;
|
||||
void updateAlignment(
|
||||
const glm::vec2 parentPosition,
|
||||
const glm::vec2 parentSize,
|
||||
|
@ -7,18 +7,18 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
float_t UIRowContainer::getSelfWidth() {
|
||||
float_t UIRowContainer::getContentWidth() {
|
||||
float_t width = 0.0f;
|
||||
for(auto &child : this->getChildren()) {
|
||||
width += child->getWidth();
|
||||
width = Math::max(width, child->getWidth());
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
float_t UIRowContainer::getSelfHeight() {
|
||||
float_t UIRowContainer::getContentHeight() {
|
||||
float_t height = 0.0f;
|
||||
for(auto &child : this->getChildren()) {
|
||||
height = std::max(height, child->getHeight());
|
||||
height += child->getHeight();
|
||||
}
|
||||
return height;
|
||||
}
|
||||
|
@ -9,9 +9,8 @@
|
||||
namespace Dawn {
|
||||
class UIRowContainer final : public UIContainer {
|
||||
public:
|
||||
float_t getSelfWidth() override;
|
||||
float_t getSelfHeight() override;
|
||||
|
||||
float_t getContentWidth() override;
|
||||
float_t getContentHeight() override;
|
||||
void updateAlignment(
|
||||
const glm::vec2 parentPosition,
|
||||
const glm::vec2 parentSize,
|
||||
|
Reference in New Issue
Block a user