From cc27e4b224e68a3a85e22b0a12e4c477f00d2b19 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 25 May 2024 06:24:54 +0300 Subject: [PATCH] fix: tooltip visibility when cursor is hidden --- src/graphics/ui/GUI.cpp | 8 ++++++-- src/graphics/ui/elements/Container.cpp | 2 +- src/graphics/ui/elements/UINode.cpp | 16 ++++++++++++++-- src/graphics/ui/elements/UINode.hpp | 2 ++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/graphics/ui/GUI.cpp b/src/graphics/ui/GUI.cpp index eb83529d..27a58444 100644 --- a/src/graphics/ui/GUI.cpp +++ b/src/graphics/ui/GUI.cpp @@ -87,8 +87,6 @@ void GUI::updateTooltip(float delta) { /// @brief Mouse related input and logic handling void GUI::actMouse(float delta) { - updateTooltip(delta); - float mouseDelta = glm::length(Events::delta); doubleClicked = false; doubleClickTimer += delta + mouseDelta * 0.1f; @@ -177,8 +175,14 @@ void GUI::act(float delta, const Viewport& vp) { container->act(delta); auto prevfocus = focus; + updateTooltip(delta); if (!Events::_cursor_locked) { actMouse(delta); + } else { + if (hover) { + hover->setHover(false); + hover = nullptr; + } } if (focus) { diff --git a/src/graphics/ui/elements/Container.cpp b/src/graphics/ui/elements/Container.cpp index 51341aa3..fe8d77ba 100644 --- a/src/graphics/ui/elements/Container.cpp +++ b/src/graphics/ui/elements/Container.cpp @@ -13,7 +13,7 @@ Container::Container(glm::vec2 size) : UINode(size) { } std::shared_ptr Container::getAt(glm::vec2 pos, std::shared_ptr self) { - if (!interactive || !isEnabled()) { + if (!isInteractive() || !isEnabled()) { return nullptr; } if (!isInside(pos)) return nullptr; diff --git a/src/graphics/ui/elements/UINode.cpp b/src/graphics/ui/elements/UINode.cpp index ddae4ea8..76297154 100644 --- a/src/graphics/ui/elements/UINode.cpp +++ b/src/graphics/ui/elements/UINode.cpp @@ -13,6 +13,9 @@ UINode::~UINode() { } bool UINode::isVisible() const { + if (visible && parent) { + return parent->isVisible(); + } return visible; } @@ -107,7 +110,7 @@ bool UINode::isInside(glm::vec2 point) { } std::shared_ptr UINode::getAt(glm::vec2 point, std::shared_ptr self) { - if (!interactive || !enabled) { + if (!isInteractive() || !enabled) { return nullptr; } return isInside(point) ? self : nullptr; @@ -145,7 +148,6 @@ float UINode::getTooltipDelay() const { return tooltipDelay; } - glm::vec2 UINode::calcPos() const { if (parent) { return pos + parent->calcPos() + parent->contentOffset(); @@ -332,6 +334,16 @@ void UINode::setGravity(Gravity gravity) { } } +bool UINode::isSubnodeOf(const UINode* node) { + if (parent == nullptr) { + return false; + } + if (parent == node) { + return true; + } + return parent->isSubnodeOf(node); +} + void UINode::getIndices( const std::shared_ptr node, std::unordered_map>& map diff --git a/src/graphics/ui/elements/UINode.hpp b/src/graphics/ui/elements/UINode.hpp index 073bd43f..74977b57 100644 --- a/src/graphics/ui/elements/UINode.hpp +++ b/src/graphics/ui/elements/UINode.hpp @@ -245,6 +245,8 @@ namespace gui { virtual void setGravity(Gravity gravity); + bool isSubnodeOf(const UINode* node); + /// @brief collect all nodes having id static void getIndices( const std::shared_ptr node,