Working on UI and web game
This commit is contained in:
1 parent
6b4b549b3c
commit
bb0f584bf6
15 files changed
+566
-382
No files matched your search
+51
-10
@@ -244,6 +244,20 @@ namespace ZL {
|
||||
if (valign == "center") node->layoutSettings.vAlign = VerticalAlign::Center;
|
||||
else if (valign == "bottom") node->layoutSettings.vAlign = VerticalAlign::Bottom;
|
||||
}
|
||||
|
||||
if (j.contains("horizontal_gravity")) {
|
||||
std::string hg = j["horizontal_gravity"].get<std::string>();
|
||||
if (hg == "right") node->layoutSettings.hGravity = HorizontalGravity::Right;
|
||||
else node->layoutSettings.hGravity = HorizontalGravity::Left;
|
||||
}
|
||||
|
||||
// Читаем Vertical Gravity
|
||||
if (j.contains("vertical_gravity")) {
|
||||
std::string vg = j["vertical_gravity"].get<std::string>();
|
||||
if (vg == "bottom") node->layoutSettings.vGravity = VerticalGravity::Bottom;
|
||||
else node->layoutSettings.vGravity = VerticalGravity::Top;
|
||||
}
|
||||
|
||||
// Подготавливаем базовый rect для компонентов (кнопок и т.д.)
|
||||
// На этапе парсинга мы даем им "желаемый" размер
|
||||
UiRect initialRect = { node->localX, node->localY, node->width, node->height };
|
||||
@@ -462,7 +476,14 @@ namespace ZL {
|
||||
|
||||
void UiManager::replaceRoot(std::shared_ptr<UiNode> newRoot) {
|
||||
root = newRoot;
|
||||
layoutNode(root, 0, 0, Environment::projectionWidth, Environment::projectionHeight);
|
||||
layoutNode(
|
||||
root,
|
||||
0.0f, 0.0f, // parentX, parentY (экран начинается с 0,0)
|
||||
Environment::projectionWidth, // parentW
|
||||
Environment::projectionHeight, // parentH
|
||||
root->localX, // finalLocalX
|
||||
root->localY // finalLocalY
|
||||
);
|
||||
buttons.clear();
|
||||
sliders.clear();
|
||||
textViews.clear();
|
||||
@@ -487,15 +508,15 @@ namespace ZL {
|
||||
}
|
||||
|
||||
|
||||
void UiManager::layoutNode(const std::shared_ptr<UiNode>& node, float parentX, float parentY, float parentW, float parentH) {
|
||||
void UiManager::layoutNode(const std::shared_ptr<UiNode>& node, float parentX, float parentY, float parentW, float parentH, float finalLocalX, float finalLocalY) {
|
||||
|
||||
node->screenRect.w = (node->width < 0) ? parentW : node->width;
|
||||
node->screenRect.h = (node->height < 0) ? parentH : node->height;
|
||||
|
||||
// 2. Позиция относительно родителя
|
||||
node->screenRect.x = parentX + node->localX;
|
||||
node->screenRect.y = parentY + node->localY;
|
||||
// ТЕПЕРЬ используем переданные координаты, а не node->localX напрямую
|
||||
node->screenRect.x = parentX + finalLocalX;
|
||||
node->screenRect.y = parentY + finalLocalY;
|
||||
|
||||
// Используем удобные локальные переменные для расчетов детей
|
||||
float currentW = node->screenRect.w;
|
||||
float currentH = node->screenRect.h;
|
||||
|
||||
@@ -579,13 +600,26 @@ namespace ZL {
|
||||
// Сдвигаем курсор вправо для следующего элемента
|
||||
cursorX += childW + node->spacing;
|
||||
}
|
||||
layoutNode(child, node->screenRect.x, node->screenRect.y, currentW, currentH);
|
||||
layoutNode(child, node->screenRect.x, node->screenRect.y, currentW, currentH, child->localX, child->localY);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Если Frame, просто идем по детям с их фиксированными координатами
|
||||
for (auto& child : node->children) {
|
||||
layoutNode(child, node->screenRect.x, node->screenRect.y, node->width, node->height);
|
||||
float childW = (child->width < 0) ? currentW : child->width;
|
||||
float childH = (child->height < 0) ? currentH : child->height;
|
||||
|
||||
float fLX = child->localX;
|
||||
float fLY = child->localY;
|
||||
|
||||
if (child->layoutSettings.hGravity == HorizontalGravity::Right) {
|
||||
fLX = currentW - childW - child->localX;
|
||||
}
|
||||
if (child->layoutSettings.vGravity == VerticalGravity::Top) {
|
||||
fLY = currentH - childH - child->localY;
|
||||
}
|
||||
|
||||
// Передаем рассчитанные fLX, fLY в рекурсию
|
||||
layoutNode(child, node->screenRect.x, node->screenRect.y, currentW, currentH, fLX, fLY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -629,7 +663,14 @@ namespace ZL {
|
||||
if (!root) return;
|
||||
|
||||
// Запускаем расчет от корня, передавая размеры экрана как "родительские"
|
||||
layoutNode(root, 0, 0, Environment::projectionWidth, Environment::projectionHeight);
|
||||
layoutNode(
|
||||
root,
|
||||
0.0f, 0.0f, // parentX, parentY (экран начинается с 0,0)
|
||||
Environment::projectionWidth, // parentW
|
||||
Environment::projectionHeight, // parentH
|
||||
root->localX, // finalLocalX
|
||||
root->localY // finalLocalY
|
||||
);
|
||||
}
|
||||
|
||||
void UiManager::collectButtonsAndSliders(const std::shared_ptr<UiNode>& node) {
|
||||
|
||||
Reference in new issue
Block a user