From d437b67580fc549f3efe67ad0344b1cc3c7a3611 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 25 May 2024 09:09:31 +0300 Subject: [PATCH] minor refactor --- src/graphics/ui/GUI.cpp | 14 ++++++++++---- src/graphics/ui/GUI.hpp | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/graphics/ui/GUI.cpp b/src/graphics/ui/GUI.cpp index 27a58444..9ec6754d 100644 --- a/src/graphics/ui/GUI.cpp +++ b/src/graphics/ui/GUI.cpp @@ -59,10 +59,17 @@ void GUI::onAssetsLoad(Assets* assets) { ), "core:root"); } +void GUI::resetTooltip() { + tooltipTimer = 0.0f; + tooltip->setVisible(false); +} + void GUI::updateTooltip(float delta) { + if (hover == nullptr || !hover->isInside(Events::cursor)) { + return resetTooltip(); + } float mouseDelta = glm::length(Events::delta); - if ((hover && mouseDelta < 1.0f) || - (hover && hover->isInside(Events::cursor) && tooltipTimer >= hover->getTooltipDelay())) { + if (mouseDelta < 1.0f || tooltipTimer >= hover->getTooltipDelay()) { if (tooltipTimer + delta >= hover->getTooltipDelay()) { auto label = std::dynamic_pointer_cast(get("tooltip.label")); const auto& text = hover->getTooltip(); @@ -80,8 +87,7 @@ void GUI::updateTooltip(float delta) { } tooltipTimer += delta; } else { - tooltipTimer = 0.0f; - tooltip->setVisible(false); + resetTooltip(); } } diff --git a/src/graphics/ui/GUI.hpp b/src/graphics/ui/GUI.hpp index 8975533b..c28e5d58 100644 --- a/src/graphics/ui/GUI.hpp +++ b/src/graphics/ui/GUI.hpp @@ -72,6 +72,7 @@ namespace gui { void actMouse(float delta); void actFocused(); void updateTooltip(float delta); + void resetTooltip(); public: GUI(); ~GUI();