Stripped back old shader code for now.
This commit is contained in:
12
archive/ui/container/CMakeLists.txt
Normal file
12
archive/ui/container/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
UIColumnContainer.cpp
|
||||
UIContainer.cpp
|
||||
UIPaddingContainer.cpp
|
||||
UIRowContainer.cpp
|
||||
)
|
36
archive/ui/container/UIColumnContainer.cpp
Normal file
36
archive/ui/container/UIColumnContainer.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "assert/assert.hpp"
|
||||
#include "UIColumnContainer.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void UIColumnContainer::updateAlignment(
|
||||
const glm::vec2 parentPosition,
|
||||
const glm::vec2 parentSize,
|
||||
const float_t canvasScale
|
||||
) {
|
||||
this->updateSelfAlignment(parentPosition, parentSize, canvasScale);
|
||||
|
||||
// Now we have our dimensions, divide evenly
|
||||
auto children = this->getChildren();
|
||||
|
||||
float_t x = 0.0f;
|
||||
float_t xPiece = this->size.x / (float_t)children.size();
|
||||
|
||||
// Update all children
|
||||
for(auto &child : children) {
|
||||
child->updateAlignment(
|
||||
this->position + glm::vec2(x, 0),
|
||||
glm::vec2(
|
||||
xPiece,
|
||||
this->size.y
|
||||
),
|
||||
canvasScale
|
||||
);
|
||||
x += xPiece;
|
||||
}
|
||||
}
|
18
archive/ui/container/UIColumnContainer.hpp
Normal file
18
archive/ui/container/UIColumnContainer.hpp
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "ui/container/UIContainer.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class UIColumnContainer final : public UIContainer {
|
||||
public:
|
||||
void updateAlignment(
|
||||
const glm::vec2 parentPosition,
|
||||
const glm::vec2 parentSize,
|
||||
const float_t canvasScale
|
||||
) override;
|
||||
};
|
||||
}
|
47
archive/ui/container/UIContainer.cpp
Normal file
47
archive/ui/container/UIContainer.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "assert/assert.hpp"
|
||||
#include "UIContainer.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::shared_ptr<UIElement>> UIContainer::getChildren() {
|
||||
return this->children;
|
||||
}
|
||||
|
||||
float_t UIContainer::getContentWidth() {
|
||||
float_t width = 0;
|
||||
auto children = this->getChildren();
|
||||
for(auto child : children) {
|
||||
width = Math::max(width, child->getWidth());
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
float_t UIContainer::getContentHeight() {
|
||||
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!");
|
||||
this->children.push_back(child);
|
||||
}
|
||||
|
||||
void UIContainer::removeChild(std::shared_ptr<UIElement> child) {
|
||||
assertNotNull(child, "Cannot remove a null child!");
|
||||
auto it = std::find(this->children.begin(), this->children.end(), child);
|
||||
if(it == this->children.end()) return;
|
||||
this->children.erase(it);
|
||||
}
|
||||
|
||||
void UIContainer::clearChildren() {
|
||||
this->children.clear();
|
||||
}
|
39
archive/ui/container/UIContainer.hpp
Normal file
39
archive/ui/container/UIContainer.hpp
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "ui/UIAlignableElement.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class UIContainer : public UIAlignableElement {
|
||||
private:
|
||||
std::vector<std::shared_ptr<UIElement>> children;
|
||||
|
||||
public:
|
||||
std::vector<std::shared_ptr<UIElement>> getChildren() override;
|
||||
|
||||
float_t getContentWidth() override;
|
||||
float_t getContentHeight() override;
|
||||
|
||||
/**
|
||||
* Appends a child to this container.
|
||||
*
|
||||
* @param child Child to append.
|
||||
*/
|
||||
void appendChild(std::shared_ptr<UIElement> child);
|
||||
|
||||
/**
|
||||
* Removes a child from this container.
|
||||
*
|
||||
* @param child Child to remove.
|
||||
*/
|
||||
void removeChild(std::shared_ptr<UIElement> child);
|
||||
|
||||
/**
|
||||
* Removes all children from this container.
|
||||
*/
|
||||
void clearChildren();
|
||||
};
|
||||
}
|
38
archive/ui/container/UIPaddingContainer.cpp
Normal file
38
archive/ui/container/UIPaddingContainer.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "UIPaddingContainer.hpp"
|
||||
|
||||
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,
|
||||
const float_t canvasScale
|
||||
) {
|
||||
glm::vec2 childPosition = parentPosition + glm::vec2(padding.x, padding.y);
|
||||
glm::vec2 childSize = parentSize - glm::vec2(padding.x + padding.z, padding.y + padding.w);
|
||||
|
||||
auto children = getChildren();
|
||||
for(auto &child : children) {
|
||||
child->updateAlignment(childPosition, childSize, canvasScale);
|
||||
}
|
||||
}
|
22
archive/ui/container/UIPaddingContainer.hpp
Normal file
22
archive/ui/container/UIPaddingContainer.hpp
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "ui/container/UIContainer.hpp"
|
||||
|
||||
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,
|
||||
const float_t canvasScale
|
||||
) override;
|
||||
};
|
||||
}
|
51
archive/ui/container/UIRowContainer.cpp
Normal file
51
archive/ui/container/UIRowContainer.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "UIRowContainer.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
float_t UIRowContainer::getContentWidth() {
|
||||
float_t width = 0.0f;
|
||||
for(auto &child : this->getChildren()) {
|
||||
width = Math::max(width, child->getWidth());
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
float_t UIRowContainer::getContentHeight() {
|
||||
float_t height = 0.0f;
|
||||
for(auto &child : this->getChildren()) {
|
||||
height += child->getHeight();
|
||||
}
|
||||
return height;
|
||||
}
|
||||
|
||||
void UIRowContainer::updateAlignment(
|
||||
const glm::vec2 parentPosition,
|
||||
const glm::vec2 parentSize,
|
||||
const float_t canvasScale
|
||||
) {
|
||||
this->updateSelfAlignment(parentPosition, parentSize, canvasScale);
|
||||
|
||||
// Now we have our dimensions, divide evenly
|
||||
auto children = this->getChildren();
|
||||
|
||||
float_t y = 0.0f;
|
||||
float_t yPiece = this->size.y / (float_t)children.size();
|
||||
|
||||
// Update all children
|
||||
for(auto &child : children) {
|
||||
child->updateAlignment(
|
||||
this->position + glm::vec2(0, y),
|
||||
glm::vec2(
|
||||
this->size.x,
|
||||
yPiece
|
||||
),
|
||||
canvasScale
|
||||
);
|
||||
y += yPiece;
|
||||
}
|
||||
}
|
20
archive/ui/container/UIRowContainer.hpp
Normal file
20
archive/ui/container/UIRowContainer.hpp
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "ui/container/UIContainer.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class UIRowContainer final : public UIContainer {
|
||||
public:
|
||||
float_t getContentWidth() override;
|
||||
float_t getContentHeight() override;
|
||||
void updateAlignment(
|
||||
const glm::vec2 parentPosition,
|
||||
const glm::vec2 parentSize,
|
||||
const float_t canvasScale
|
||||
) override;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user