guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
guillaume::components::ButtonInteraction< EventType, ButtonEnum, N, ButtonsArray > Class Template Reference

Which buttons of an input device are held on an entity, and what to call when one is pressed or released on it. More...

#include <headers/guillaume/components/button_interaction.hpp>

Inheritance diagram for guillaume::components::ButtonInteraction< EventType, ButtonEnum, N, ButtonsArray >:
Collaboration diagram for guillaume::components::ButtonInteraction< EventType, ButtonEnum, N, ButtonsArray >:

Public Types

using ButtonPressHandler = std::function<void(void)>
 Callback run when a button is pressed on the entity.
using ButtonReleaseHandler = std::function<void(void)>
 Callback run when a button pressed on the entity is released on it.

Public Member Functions

 ButtonInteraction (void)
 Construct the component with every button of ButtonsArray released and without handler.
 ~ButtonInteraction (void)=default
 Default destructor.
ButtonInteraction & setOnButtonPressHandler (const ButtonEnum &button, const ButtonPressHandler &handler)
 Store the callback run when a button is pressed on the entity.
const ButtonPressHandler & getOnButtonPressHandler (const ButtonEnum &button) const
 Get the callback run when a button is pressed on the entity.
ButtonInteraction & setOnButtonReleaseHandler (const ButtonEnum &button, const ButtonReleaseHandler &handler)
 Store the callback run when a button pressed on the entity is released on it.
const ButtonReleaseHandler & getOnButtonReleaseHandler (const ButtonEnum &button) const
 Get the callback run when a button pressed on the entity is released on it.
bool isButtonPressed (const ButtonEnum &button) const
 Check whether a button is held on the entity.
ButtonInteraction & setButtonPressed (const ButtonEnum &button, bool pressed)
 Record whether a button is held on the entity.
Public Member Functions inherited from guillaume::ecs::Component
bool hasChanged (void) const
 Tell whether a value of the component changed since the flags were last reset (the end of the previous frame).
void setHasChanged (bool hasChanged)
 Raise or lower the changed flag.
 Component (void)=default
 Create a component that is not marked as changed.
virtual ~Component (void)=default
 Virtual destructor, so components can be destroyed through the base class.

Detailed Description

template<utility::event::InheritFromEvent EventType, IsEnum ButtonEnum, std::size_t N, const std::array< ButtonEnum, N > & ButtonsArray>
class guillaume::components::ButtonInteraction< EventType, ButtonEnum, N, ButtonsArray >

Which buttons of an input device are held on an entity, and what to call when one is pressed or released on it.

It is used through its two aliases, MouseButtonInteraction and HandButtonInteraction. The system of the device (systems::MouseButton, systems::HandButton) writes it in the Event phase, when a button event arrives:

  • a press whose ray hits the entity sets the button pressed and calls the press handler;
  • a release that hits the entity while the button is pressed clears it and calls the release handler: this is the "click";
  • a release anywhere else clears the button and calls nothing.

systems::StyleState, systems::Focus and systems::Drag read the pressed state of the primary button (left mouse button, hand button A).

using Button = utility::event::MouseButtonEvent::Button;
registry.getComponent<components::MouseButtonInteraction>(identifier)
.setOnButtonReleaseHandler(Button::Left, [] { save(); });
ButtonInteraction & setOnButtonReleaseHandler(const ButtonEnum &button, const ButtonReleaseHandler &handler)
Store the callback run when a button pressed on the entity is released on it.
State shared by every pressable button, whatever its look.
Definition button.hpp:77
ButtonInteraction< utility::event::MouseButtonEvent, utility::event::MouseButtonEvent::Button, MouseButtons.size(), MouseButtons > MouseButtonInteraction
Which mouse buttons are held on an entity, with a press and a release handler per button.

Widgets wire the primary button with systems::interaction::makeInteractive, which replaces the press and release handlers of that button.

Template Parameters
EventTypeThe button event of the device. It only makes the mouse and hand components distinct types.
ButtonEnumThe enumeration naming the buttons of the device.
NNumber of buttons in ButtonsArray.
ButtonsArrayThe buttons the component tracks. Each one starts released and without handler.
See also
MouseButtonInteraction, HandButtonInteraction, StyleState

Definition at line 83 of file button_interaction.hpp.

Member Typedef Documentation

◆ ButtonPressHandler

template<utility::event::InheritFromEvent EventType, IsEnum ButtonEnum, std::size_t N, const std::array< ButtonEnum, N > & ButtonsArray>
using guillaume::components::ButtonInteraction< EventType, ButtonEnum, N, ButtonsArray >::ButtonPressHandler = std::function<void(void)>

Callback run when a button is pressed on the entity.

Definition at line 89 of file button_interaction.hpp.

◆ ButtonReleaseHandler

template<utility::event::InheritFromEvent EventType, IsEnum ButtonEnum, std::size_t N, const std::array< ButtonEnum, N > & ButtonsArray>
using guillaume::components::ButtonInteraction< EventType, ButtonEnum, N, ButtonsArray >::ButtonReleaseHandler = std::function<void(void)>

Callback run when a button pressed on the entity is released on it.

Definition at line 94 of file button_interaction.hpp.

Member Function Documentation

◆ getOnButtonPressHandler()

template<utility::event::InheritFromEvent EventType, IsEnum ButtonEnum, std::size_t N, const std::array< ButtonEnum, N > & ButtonsArray>
const ButtonPressHandler & guillaume::components::ButtonInteraction< EventType, ButtonEnum, N, ButtonsArray >::getOnButtonPressHandler ( const ButtonEnum & button) const

Get the callback run when a button is pressed on the entity.

Parameters
buttonThe button to look up.
Returns
The handler; empty (nullptr) when none was set.
Exceptions
std::invalid_argumentIf button is neither in ButtonsArray nor a button a handler was set for.

◆ getOnButtonReleaseHandler()

template<utility::event::InheritFromEvent EventType, IsEnum ButtonEnum, std::size_t N, const std::array< ButtonEnum, N > & ButtonsArray>
const ButtonReleaseHandler & guillaume::components::ButtonInteraction< EventType, ButtonEnum, N, ButtonsArray >::getOnButtonReleaseHandler ( const ButtonEnum & button) const

Get the callback run when a button pressed on the entity is released on it.

Parameters
buttonThe button to look up.
Returns
The handler; empty (nullptr) when none was set.
Exceptions
std::invalid_argumentIf button is neither in ButtonsArray nor a button a handler was set for.

◆ isButtonPressed()

template<utility::event::InheritFromEvent EventType, IsEnum ButtonEnum, std::size_t N, const std::array< ButtonEnum, N > & ButtonsArray>
bool guillaume::components::ButtonInteraction< EventType, ButtonEnum, N, ButtonsArray >::isButtonPressed ( const ButtonEnum & button) const

Check whether a button is held on the entity.

Parameters
buttonThe button to check.
Returns
True from the press on the entity until the release; false for a button the component does not track.

◆ setButtonPressed()

template<utility::event::InheritFromEvent EventType, IsEnum ButtonEnum, std::size_t N, const std::array< ButtonEnum, N > & ButtonsArray>
ButtonInteraction & guillaume::components::ButtonInteraction< EventType, ButtonEnum, N, ButtonsArray >::setButtonPressed ( const ButtonEnum & button,
bool pressed )

Record whether a button is held on the entity.

Called by the input system of the device; it calls no handler. Marks the component changed only when the state differs.

Parameters
buttonThe button to update.
pressedTrue when the button is held on the entity.
Returns
This component, to chain calls.

◆ setOnButtonPressHandler()

template<utility::event::InheritFromEvent EventType, IsEnum ButtonEnum, std::size_t N, const std::array< ButtonEnum, N > & ButtonsArray>
ButtonInteraction & guillaume::components::ButtonInteraction< EventType, ButtonEnum, N, ButtonsArray >::setOnButtonPressHandler ( const ButtonEnum & button,
const ButtonPressHandler & handler )

Store the callback run when a button is pressed on the entity.

Always marks the component changed.

Parameters
buttonThe button the handler is for.
handlerThe callback, or nullptr to remove the current one.
Returns
This component, to chain calls.

◆ setOnButtonReleaseHandler()

template<utility::event::InheritFromEvent EventType, IsEnum ButtonEnum, std::size_t N, const std::array< ButtonEnum, N > & ButtonsArray>
ButtonInteraction & guillaume::components::ButtonInteraction< EventType, ButtonEnum, N, ButtonsArray >::setOnButtonReleaseHandler ( const ButtonEnum & button,
const ButtonReleaseHandler & handler )

Store the callback run when a button pressed on the entity is released on it.

Always marks the component changed.

Parameters
buttonThe button the handler is for.
handlerThe callback, or nullptr to remove the current one.
Returns
This component, to chain calls.

The documentation for this class was generated from the following file: