diff --git a/src/kekengine/cpp/ui/ui.cpp b/src/kekengine/cpp/ui/ui.cpp index 9263639..8de1d86 100644 --- a/src/kekengine/cpp/ui/ui.cpp +++ b/src/kekengine/cpp/ui/ui.cpp @@ -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) { diff --git a/src/kekengine/include/ui.h b/src/kekengine/include/ui.h index 3c7a439..f20279b 100644 --- a/src/kekengine/include/ui.h +++ b/src/kekengine/include/ui.h @@ -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(){};