62 lines
2.2 KiB
C++
62 lines
2.2 KiB
C++
/// 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 <J3ML/LinearAlgebra/Vector2.hpp>
|
|
#include <Event.h>
|
|
#include <JUI/Widgets/Tooltip.hpp>
|
|
|
|
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<Vector2> OnHoverEvent;
|
|
Event<Vector2> OnExitEvent;
|
|
|
|
Event<Vector2> OnHoverChildrenEvent;
|
|
Event<Vector2> OnExitChildrenEvent;
|
|
Event<Vector2> OnHoverDescendantsEvent;
|
|
Event<Vector2> 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;
|
|
};
|
|
} |