Fix UI click & focus
This commit is contained in:
parent
07f49d9e7e
commit
4222f4eb14
@ -172,7 +172,7 @@ void UIElement::hoverExitAll() {
|
||||
hoverExit();
|
||||
}
|
||||
|
||||
void UIElement::clickAll(UIPoint pos, UIPoint screenPos, GLFWMouseButton button) {
|
||||
bool UIElement::clickAll(UIPoint pos, UIPoint screenPos, GLFWMouseButton button) {
|
||||
UIElement *clickedChild = nullptr;
|
||||
for(UIElement *child : children) {
|
||||
UIPoint childPos = child->getPosition();
|
||||
@ -185,13 +185,18 @@ void UIElement::clickAll(UIPoint pos, UIPoint screenPos, GLFWMouseButton button)
|
||||
|
||||
if(clickedChild != nullptr) {
|
||||
UIPoint childPos = clickedChild->getPosition();
|
||||
clickedChild->clickAll(UIPoint(pos.x - childPos.x, pos.y - childPos.y), screenPos, button);
|
||||
} else if(clickable) {
|
||||
click(pos, screenPos, button);
|
||||
if(clickedChild->clickAll(UIPoint(pos.x - childPos.x, pos.y - childPos.y), screenPos, button)) return true;
|
||||
}
|
||||
|
||||
if(clickable) {
|
||||
click(pos, screenPos, button);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void UIElement::focusEnterAll(UIPoint pos, UIPoint screenPos) {
|
||||
bool UIElement::focusEnterAll(UIPoint pos, UIPoint screenPos) {
|
||||
UIElement *focusedChild = nullptr;
|
||||
for(UIElement *child : children) {
|
||||
UIPoint childPos = child->getPosition();
|
||||
@ -204,10 +209,15 @@ void UIElement::focusEnterAll(UIPoint pos, UIPoint screenPos) {
|
||||
|
||||
if(focusedChild != nullptr) {
|
||||
UIPoint childPos = focusedChild->getPosition();
|
||||
focusedChild->focusEnterAll(UIPoint(pos.x - childPos.x, pos.y - childPos.y), screenPos);
|
||||
} else if(focusable) {
|
||||
UI::focusElement(this);
|
||||
if(focusedChild->focusEnterAll(UIPoint(pos.x - childPos.x, pos.y - childPos.y), screenPos)) return true;
|
||||
}
|
||||
|
||||
if(focusable) {
|
||||
UI::focusElement(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
UIElement *UIElement::dragEnterAll(UIPoint pos, UIPoint screenPos) {
|
||||
|
@ -181,10 +181,10 @@ class UIElement {
|
||||
virtual void hover(UIPoint pos, UIPoint screenPos){};
|
||||
virtual void hoverExit(){};
|
||||
|
||||
void clickAll(UIPoint pos, UIPoint screenPos, GLFWMouseButton button);
|
||||
bool clickAll(UIPoint pos, UIPoint screenPos, GLFWMouseButton button);
|
||||
virtual void click(UIPoint pos, UIPoint screenPos, GLFWMouseButton button){};
|
||||
|
||||
void focusEnterAll(UIPoint pos, UIPoint screenPos);
|
||||
bool focusEnterAll(UIPoint pos, UIPoint screenPos);
|
||||
virtual void focusEnter(){};
|
||||
virtual void focusExit(){};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user