/// Josh's User Interface Library /// A C++20 Library for creating, styling, and rendering of a UI/UX widgets. /// Developed and Maintained by Josh O'Leary @ Redacted Software. /// Special Thanks to William Tomasine II and Maxine Hayes. /// (c) 2024 Redacted Software /// This work is dedicated to the public domain. /// @file Hoverable.hpp /// @desc Hoverable Mixin Helper Class - Added to widgets that should have special behavior when hovered by the mouse. /// @edit 2024-10-11 #pragma once #include #include #include namespace JUI { /// Interface for anything that can report mouse presence. class IMouseAware { public: virtual ~IMouseAware() = default; virtual bool IsMouseAware() const = 0; }; /// A mixin helper class that provides behavior for hoverable objects. /// A hoverable object pays attention to when the mouse enters and leaves it's bounds. class Hoverable { public: Event OnHoverEvent; Event OnExitEvent; Event OnHoverChildrenEvent; Event OnExitChildrenEvent; Event OnHoverDescendantsEvent; Event OnExitDescendantsEvent; public: bool IsHovered() const { return hovered; }; public: virtual void OnHover(const Vector2& MousePos); virtual void OnExit(const Vector2& MousePos); virtual void OnHoverChildren(const Vector2& mouse); virtual void OnHoverDescendants(const Vector2& mouse); virtual void OnExitChildren(const Vector2& mouse); virtual void OnExitDescendants(const Vector2& mouse); void Update(bool mouse_inside, float delta); /// @note This member function **must** be implemented for classes that implement Hoverable. //[[nodiscard]] virtual bool IsMouseInside() const = 0; //virtual void SetTooltip(const std::string& content, float delay) {} protected: //Tooltip* tooltip = nullptr; //float tooltip_threshold = 0.f; //float tooltip_limit = 0.125f; bool hovered = false; bool hover_debounce = false; }; }