Loading...
Searching...
No Matches
Hoverable.h
Go to the documentation of this file.
1// Copyright (c) 2025 Dave R. Smith.
2// Malena Framework — Licensed under PolyForm Noncommercial 1.0.0; commercial use requires a paid license. See LICENSE.
3
4//
5// Created by Dave Smith on 3/20/26.
6//
7
8#ifndef MALENA_HOVERABLE_H
9#define MALENA_HOVERABLE_H
10
15#include <optional>
16namespace ml
17{
47 {
48 public:
56 void onHover(std::function<void()> callback, bool overwrite = true);
57
65 void onHover(std::function<void(const std::optional<sf::Event>& event)> callback, bool overwrite = true);
66
74 void onUnhover(std::function<void()> callback, bool overwrite = true);
75
83 void onUnhover(std::function<void(const std::optional<sf::Event>& event)> callback, bool overwrite = true);
84 };
85
87 class MALENA_API HoverableDispatcher : public EventDispatcher
88 {
89 public:
90 bool occurred(const std::optional<sf::Event>& event) override;
91 bool filter(const std::optional<sf::Event>& event, Core* component) override;
92 void fire(const std::optional<sf::Event>& event) override;
93 };
95
96} // namespace ml
97
98ML_EXPORT(HoverableDispatcher)
99#endif // MALENA_HOVERABLE_H
#define ML_EXPORT(ClassName)
Register a Malena type with the framework.
Definition Export.h:43
Virtual base class for all Malena framework objects.
Definition Core.h:97
Base class for all per-event dispatchers in the Malena event system.
Base class for all event-receiving traits.
Trait that adds mouse-hover and mouse-leave callbacks to any Core object.
Definition Hoverable.h:47
void onUnhover(std::function< void(const std::optional< sf::Event > &event)> callback, bool overwrite=true)
Register a callback invoked when the mouse leaves this component's bounds, receiving the raw SFML eve...
void onHover(std::function< void(const std::optional< sf::Event > &event)> callback, bool overwrite=true)
Register a callback invoked when the mouse enters this component's bounds, receiving the raw SFML eve...
void onHover(std::function< void()> callback, bool overwrite=true)
Register a no-argument callback invoked when the mouse enters this component's bounds.
void onUnhover(std::function< void()> callback, bool overwrite=true)
Register a no-argument callback invoked when the mouse leaves this component's bounds.
#define MALENA_API
Definition Component.h:22