guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
guillaume::components::Focus Class Reference

Makes an entity able to own the input focus, and holds whether it owns it and what to call when it gains or loses it. More...

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

Inheritance diagram for guillaume::components::Focus:
Collaboration diagram for guillaume::components::Focus:

Public Types

using Handler = std::function<void(void)>
 Focus change callback.

Public Member Functions

 Focus (void)=default
 Construct an unfocused component without handler.
 ~Focus (void)=default
 Default destructor.
void setOnFocusGainedHandler (const Handler &handler)
 Store the callback run when the entity gains the focus.
Handler getOnFocusGainedHandler (void) const
 Get the callback run when the entity gains the focus.
void setOnFocusLostHandler (const Handler &handler)
 Store the callback run when the entity loses the focus.
Handler getOnFocusLostHandler (void) const
 Get the callback run when the entity loses the focus.
bool isFocused (void) const
 Check whether the entity owns the input focus.
void setFocused (bool focused)
 Record whether the entity owns the input focus.
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

Makes an entity able to own the input focus, and holds whether it owns it and what to call when it gains or loses it.

At most one entity is focused at a time; systems::Focus decides which. It runs in the Event phase, gives the focus to an entity that is clicked (left mouse button, hand button A, B, X or Y, pinch or poke) or reached with Tab / Shift+Tab, then writes the focused flag here and in StyleState and calls the handlers. An entity disabled through StyleState cannot take or keep the focus.

auto &focus = registry.getComponent<components::Focus>(identifier);
focus.setOnFocusGainedHandler([] { showCaret(); });
focus.setOnFocusLostHandler([] { hideCaret(); });
Makes an entity able to own the input focus, and holds whether it owns it and what to call when it ga...
Definition focus.hpp:57
void setOnFocusGainedHandler(const Handler &handler)
Store the callback run when the entity gains the focus.
Definition focus.cpp:27

To move the focus from code, call systems::Focus::setFocus or systems::Focus::clearFocus: setFocused() only stores the flag and does not take the focus away from the entity that owns it. Tab order and exclusion from the Tab traversal are set on Accessibility.

See also
systems::Focus, StyleState, Accessibility

Definition at line 56 of file focus.hpp.

Member Typedef Documentation

◆ Handler

using guillaume::components::Focus::Handler = std::function<void(void)>

Focus change callback.

Definition at line 59 of file focus.hpp.

Member Function Documentation

◆ getOnFocusGainedHandler()

Focus::Handler guillaume::components::Focus::getOnFocusGainedHandler ( void ) const

Get the callback run when the entity gains the focus.

Returns
A copy of the handler; empty when none was set.

Definition at line 33 of file focus.cpp.

◆ getOnFocusLostHandler()

Focus::Handler guillaume::components::Focus::getOnFocusLostHandler ( void ) const

Get the callback run when the entity loses the focus.

Returns
A copy of the handler; empty when none was set.

Definition at line 44 of file focus.cpp.

◆ isFocused()

bool guillaume::components::Focus::isFocused ( void ) const

Check whether the entity owns the input focus.

Returns
True when systems::Focus last gave the focus to this entity.

Definition at line 48 of file focus.cpp.

Here is the caller graph for this function:

◆ setFocused()

void guillaume::components::Focus::setFocused ( bool focused)

Record whether the entity owns the input focus.

Called by systems::Focus; it calls no handler and does not change which entity the system considers focused. Marks the component changed only when the flag differs.

Parameters
focusedTrue when the entity owns the focus.

Definition at line 53 of file focus.cpp.

Here is the call graph for this function:

◆ setOnFocusGainedHandler()

void guillaume::components::Focus::setOnFocusGainedHandler ( const Handler & handler)

Store the callback run when the entity gains the focus.

systems::Focus calls it each time it sets the focus on the entity, including when the entity already owned it. Always marks the component changed.

Parameters
handlerThe callback, or nullptr to remove the current one.

Definition at line 27 of file focus.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setOnFocusLostHandler()

void guillaume::components::Focus::setOnFocusLostHandler ( const Handler & handler)

Store the callback run when the entity loses the focus.

systems::Focus calls it when the focus moves to another entity or is cleared. Always marks the component changed.

Parameters
handlerThe callback, or nullptr to remove the current one.

Definition at line 38 of file focus.cpp.

Here is the call graph for this function:

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