Working on assets

This commit is contained in:
2022-12-01 22:37:42 -08:00
parent 535e2b2dc5
commit ba9881e39d
18 changed files with 355 additions and 42 deletions

View File

@ -11,4 +11,5 @@ target_sources(${DAWN_TARGET_NAME}
UILabel.cpp
UISprite.cpp
UIEmpty.cpp
UIGrid.cpp
)

35
src/dawn/ui/UIGrid.cpp Normal file
View File

@ -0,0 +1,35 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "UIGrid.hpp"
using namespace Dawn;
UIGrid::UIGrid(UICanvas *canvas) : UIComponent(canvas) {
}
void UIGrid::setSize(int32_t rows, int32_t columns) {
this->gridArea.clear();
this->rows = rows;
this->columns = columns;
int32_t i, l;
l = rows * columns;
for(i = 0; i < l; i++) {
struct GridArea area;
area.uiComponent = nullptr;
this->gridArea.push_back(area);
}
}
void UIGrid::setItem(int32_t x, int32_t y, UIComponent *comp) {
auto item = &this->gridArea[(y * this->rows) + x];
//Too lazy to support re setting. Need to mod setSize too
assertNull(item->uiComponent);
item->uiComponent = comp;
}

41
src/dawn/ui/UIGrid.hpp Normal file
View File

@ -0,0 +1,41 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "UIComponent.hpp"
namespace Dawn {
enum GridAlign {
ALIGN_GROW,
ALIGN_CONTENT,
ALIGN_FIXED
};
struct GridArea {
enum GridAlignment xAlign;
enum GridAlignment yAlign;
float_t width, height;
float_t x, y;
UIComponent *uiComponent;
};
class UIGrid : public UIComponent {
protected:
void alignChildren();
public:
glm::vec2 cellPadding;
glm::vec2 cellMargin;
int32_t rows = 1;
int32_t columns = 1;
std::vector<struct GridArea> gridArea;
UIGrid(UICanvas *canvas);
void setSize(int32_t rows, int32_t columns);
void setItem(int32_t row, int32_t col, UIComponent *comp);
};
}