Working on UI

This commit is contained in:
Vladislav Khorev committed 2026-05-30 22:27:09 +03:00
1 parent 9425f9b19a
commit a0550daf4b
6 files changed
+111 -23

No files matched your search

+17 -12
View File
@@ -821,6 +821,7 @@ namespace ZL {
);
buttons.clear();
textButtons.clear();
allInteractives.clear();
sliders.clear();
textViews.clear();
textFields.clear();
@@ -1066,9 +1067,11 @@ namespace ZL {
void UiManager::collectButtonsAndSliders(const std::shared_ptr<UiNode>& node) {
if (node->button) {
buttons.push_back(node->button);
allInteractives.push_back(node->button);
}
if (node->textButton) {
textButtons.push_back(node->textButton);
allInteractives.push_back(node->textButton);
}
if (node->slider) {
sliders.push_back(node->slider);
@@ -1191,6 +1194,7 @@ namespace ZL {
prev.root = root;
prev.buttons = buttons;
prev.textButtons = textButtons;
prev.allInteractives = allInteractives;
prev.sliders = sliders;
prev.textViews = textViews;
prev.textFields = textFields;
@@ -1255,6 +1259,7 @@ namespace ZL {
root = s.root;
buttons = s.buttons;
textButtons = s.textButtons;
allInteractives = s.allInteractives;
sliders = s.sliders;
textViews = s.textViews;
textFields = s.textFields;
@@ -1646,22 +1651,22 @@ namespace ZL {
void UiManager::onTouchDown(int64_t fingerId, int x, int y) {
for (auto& b : buttons) {
if (b->state != ButtonState::Disabled)
{
if (b->getClickZoneRect().containsConsideringBorder((float)x, (float)y, b->border)) {
// Iterate allInteractives in reverse DFS order: later-declared elements have higher priority.
// At most one button or textButton is pressed per touch.
for (auto it = allInteractives.rbegin(); it != allInteractives.rend(); ++it) {
if (std::holds_alternative<std::shared_ptr<UiButton>>(*it)) {
auto& b = std::get<std::shared_ptr<UiButton>>(*it);
if (b->state != ButtonState::Disabled &&
b->getClickZoneRect().containsConsideringBorder((float)x, (float)y, b->border)) {
b->state = ButtonState::Pressed;
pressedButtons[fingerId] = b;
if (b->onPress) b->onPress(b->name);
break; // a single finger can only press one button
break;
}
}
}
for (auto& tb : textButtons) {
if (tb->state != ButtonState::Disabled)
{
if (tb->getClickZoneRect().containsConsideringBorder((float)x, (float)y, tb->border)) {
} else {
auto& tb = std::get<std::shared_ptr<UiTextButton>>(*it);
if (tb->state != ButtonState::Disabled &&
tb->getClickZoneRect().containsConsideringBorder((float)x, (float)y, tb->border)) {
tb->state = ButtonState::Pressed;
pressedTextButtons[fingerId] = tb;
if (tb->onPress) tb->onPress(tb->name);