Grid alignment, does have a small bug though.
This commit is contained in:
@ -47,7 +47,7 @@ void UIGrid::alignChild(UIComponent *child, struct UIGridPosition pos) {
|
|||||||
// Alignment
|
// Alignment
|
||||||
float_t x, y, sizeX, sizeY;
|
float_t x, y, sizeX, sizeY;
|
||||||
UIComponent::calculateDimensions(
|
UIComponent::calculateDimensions(
|
||||||
UI_COMPONENT_ALIGN_MIDDLE,
|
pos.alignX,
|
||||||
&x,
|
&x,
|
||||||
&sizeX,
|
&sizeX,
|
||||||
this->sizeCol,
|
this->sizeCol,
|
||||||
@ -55,7 +55,7 @@ void UIGrid::alignChild(UIComponent *child, struct UIGridPosition pos) {
|
|||||||
glm::vec2(0, 0)
|
glm::vec2(0, 0)
|
||||||
);
|
);
|
||||||
UIComponent::calculateDimensions(
|
UIComponent::calculateDimensions(
|
||||||
UI_COMPONENT_ALIGN_MIDDLE,
|
pos.alignY,
|
||||||
&y,
|
&y,
|
||||||
&sizeY,
|
&sizeY,
|
||||||
this->sizeRow,
|
this->sizeRow,
|
||||||
@ -83,13 +83,19 @@ void UIGrid::setGridSize(
|
|||||||
this->updatePositions();
|
this->updatePositions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIGrid::addToGrid(UIComponent *ui, int32_t x, int32_t y) {
|
void UIGrid::addToGrid(
|
||||||
|
UIComponent *ui,
|
||||||
|
int32_t x, int32_t y,
|
||||||
|
enum UIComponentAlign alignX, enum UIComponentAlign alignY
|
||||||
|
) {
|
||||||
assertTrue(x >= 0 && x < this->columns);
|
assertTrue(x >= 0 && x < this->columns);
|
||||||
assertTrue(y >= 0 && y < this->rows);
|
assertTrue(y >= 0 && y < this->rows);
|
||||||
this->addChild(ui);
|
this->addChild(ui);
|
||||||
struct UIGridPosition pos;
|
struct UIGridPosition pos;
|
||||||
pos.x = x;
|
pos.x = x;
|
||||||
pos.y = y;
|
pos.y = y;
|
||||||
|
pos.alignX = alignX;
|
||||||
|
pos.alignY = alignY;
|
||||||
this->gridChildren[ui] = pos;
|
this->gridChildren[ui] = pos;
|
||||||
this->alignChild(ui, pos);
|
this->alignChild(ui, pos);
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,8 @@ namespace Dawn {
|
|||||||
struct UIGridPosition {
|
struct UIGridPosition {
|
||||||
int32_t x;
|
int32_t x;
|
||||||
int32_t y;
|
int32_t y;
|
||||||
UIComponentAlign alignX;
|
enum UIComponentAlign alignX;
|
||||||
UIComponentAlign alignY;
|
enum UIComponentAlign alignY;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -63,8 +63,14 @@ namespace Dawn {
|
|||||||
* @param component Component to add to the grid.
|
* @param component Component to add to the grid.
|
||||||
* @param column Column Position.
|
* @param column Column Position.
|
||||||
* @param row Row Position.
|
* @param row Row Position.
|
||||||
|
* @param alignX X alignment of the component within the cell.
|
||||||
|
* @param alignY Y alignment of the component within the cell.
|
||||||
*/
|
*/
|
||||||
void addToGrid(UIComponent *component, int32_t column, int32_t row);
|
void addToGrid(
|
||||||
|
UIComponent *ui,
|
||||||
|
int32_t x, int32_t y,
|
||||||
|
enum UIComponentAlign alignX, enum UIComponentAlign alignY
|
||||||
|
);
|
||||||
|
|
||||||
int32_t getRows();
|
int32_t getRows();
|
||||||
int32_t getColumns();
|
int32_t getColumns();
|
||||||
|
@ -53,8 +53,7 @@ void TestUIScene::stage() {
|
|||||||
label->setFont(&assetFont->font);
|
label->setFont(&assetFont->font);
|
||||||
label->setText("test.1");
|
label->setText("test.1");
|
||||||
label->setFontSize(24);
|
label->setFontSize(24);
|
||||||
|
grid->addToGrid(label, x, y, UI_COMPONENT_ALIGN_END, UI_COMPONENT_ALIGN_END);
|
||||||
grid->addToGrid(label, x, y);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user