guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
mouse_hover_interaction.cpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#include "guillaume/components/mouse_hover_interaction.hpp"
24
26{
27
29 : ecs::Component()
30 {
31 _onHover = nullptr;
32 _onUnhover = nullptr;
33 _isHovered = false;
34 }
35
38 {
39 _onHover = handler;
40 setHasChanged(true);
41 return *this;
42 }
43
45 const UnhoverHandler &handler)
46 {
47 _onUnhover = handler;
48 setHasChanged(true);
49 return *this;
50 }
51
54 {
55 return _onHover;
56 }
57
60 {
61 return _onUnhover;
62 }
63
65 {
66 return _isHovered;
67 }
68
70 {
71 if (_isHovered == isHovered) {
72 return *this;
73 }
74 _isHovered = isHovered;
75 setHasChanged(true);
76 return *this;
77 }
78
79 utility::graphic::SizeUI
81 {
82 return _accessibilityMargin;
83 }
84
86 const utility::graphic::SizeUI &margin)
87 {
88 if (_accessibilityMargin == margin) {
89 return *this;
90 }
91 _accessibilityMargin = margin;
92 setHasChanged(true);
93 return *this;
94 }
95
96} // namespace guillaume::components
Whether the mouse pointer is over an entity, what to call when it enters or leaves,...
HoverHandler getOnHoverHandler(void) const
Get the callback run when the pointer enters the entity.
MouseHoverInteraction & setHovered(bool isHovered)
Record whether the pointer is over the entity.
UnhoverHandler getOnUnhoverHandler(void) const
Get the callback run when the pointer leaves the entity.
MouseHoverInteraction & setOnUnhoverHandler(const UnhoverHandler &handler)
Store the callback run when the pointer leaves the entity.
std::function< void(void)> UnhoverHandler
Called on hover end.
MouseHoverInteraction(void)
Construct a component that is not hovered, has no handler and no margin.
utility::graphic::SizeUI getAccessibilityMargin(void) const
Get the hit area added around the bound.
bool isHovered(void) const
Check whether the pointer is over the entity.
MouseHoverInteraction & setAccessibilityMargin(const utility::graphic::SizeUI &margin)
Grow the hit area past the bound without growing the entity on screen.
std::function< void(void)> HoverHandler
Called on hover start.
MouseHoverInteraction & setOnHoverHandler(const HoverHandler &handler)
Store the callback run when the pointer enters the entity.
Component(void)=default
Create a component that is not marked as changed.
void setHasChanged(bool hasChanged)
Raise or lower the changed flag.
Definition component.cpp:32
State. Every class here is plain data attached to an entity.
The entity-component-system core, independent of any widget.
Definition component.hpp:28