Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
UIInteractable Class Reference

Base class for interactive UI elements. More...

#include <ui_interactable.h>

Inheritance diagram for UIInteractable:
[legend]

Public Member Functions

 UIInteractable (Scene &scene, float width, float height, Point pivot, Point anchor)
 
void update_interaction (float dt)
 Update interaction state based on input.
 
UIInteractionStatestate ()
 
const UIInteractionStatestate () const
 
void disable ()
 Disable the interactable element.
 
void enable ()
 Enable the interactable element.
 
virtual void on_hover ()
 Event hook for when the element is hovered.
 
virtual void on_unhover ()
 Event hook for when the element is unhovered.
 
virtual void on_press ()
 Event hook for when the element is pressed.
 
virtual void on_release ()
 Event hook for when the element is released.
 
virtual void on_hold ()
 Event hook for when the element is held down.
 
virtual void on_focus ()
 Event hook for when the element gains focus.
 
virtual void on_unfocus ()
 Event hook for when the element loses focus.
 
void add_on_hover (const std::function< void(UIInteractable &)> &handler)
 
void add_on_unhover (const std::function< void(UIInteractable &)> &handler)
 
void add_on_press (const std::function< void(UIInteractable &)> &handler)
 
void add_on_release (const std::function< void(UIInteractable &)> &handler)
 
void add_on_focus (const std::function< void(UIInteractable &)> &handler)
 
void add_on_unfocus (const std::function< void(UIInteractable &)> &handler)
 
- Public Member Functions inherited from UIObject
 UIObject (Scene &scene, float width, float height, Point pivot, Point anchor)
 
virtual void update (float dt)
 Update the UI object.
 
virtual void render () const
 Render the UI object.
 
float width () const
 
UIObjectwidth (float width)
 
float height () const
 
UIObjectheight (float height)
 
Point pivot () const
 
UIObjectpivot (Point pivot)
 
Point anchor () const
 
UIObjectanchor (Point anchor)
 
- Public Member Functions inherited from GameObject
 GameObject (Scene &scene)
 
virtual ~GameObject ()=default
 
 GameObject (const GameObject &)=delete
 
GameObjectoperator= (const GameObject &)=delete
 
 GameObject (GameObject &&)=default
 
GameObjectoperator= (GameObject &&)=default
 
std::optional< std::reference_wrapper< GameObject > > parent () const
 
GameObjectparent (GameObject &parent)
 
GameObjectparent (std::nullopt_t null_opt)
 
std::string id () const noexcept
 
bool is_active_in_world () const noexcept
 Retrieves whether the GameObject is active in the world.
 
bool is_active () const noexcept
 Retrieves whether the GameObject is active.
 
void set_inactive () noexcept
 
void set_active () noexcept
 
void set_active_in_world () noexcept
 
void set_inactive_in_world () noexcept
 
GameObjectmark_for_deletion () noexcept
 Marks the GameObject for deletion.
 
bool marked_for_deletion () const noexcept
 
void mark_dont_destroy_on_load (bool dont_destroy) noexcept
 Sets whether the GameObject should not be destroyed on scene load.
 
bool dont_destroy_on_load () const noexcept
 
GameObjectname (const std::string &name)
 
const std::string & name () const
 
GameObjecttag (const std::string &tag)
 
const std::string & tag () const
 
GameObjectprefab_type_id (const std::string &id)
 
const std::string & prefab_type_id () const
 
GameObjectlayer (int layer)
 
int layer () const
 
GameObjecttransform (Transform transform)
 
Transformtransform ()
 
const Transformtransform () const
 
Scenescene () const noexcept
 
void scene (Scene &scene) noexcept
 
std::vector< std::reference_wrapper< GameObject > > & children ()
 
GameObjectadd_child (GameObject &child)
 
GameObjectremove_child (GameObject &child)
 
template<IsComponent T>
std::optional< std::reference_wrapper< T > > get_component () const noexcept
 Get the first component of type T attached to this GameObject.
 
template<IsComponent T>
std::vector< std::reference_wrapper< T > > get_components () const
 Get all components of type T attached to this GameObject.
 
template<IsComponent BS, typename B >
std::optional< std::reference_wrapper< B > > get_script () const noexcept
 Get the first script component of base type BS with behavior of type B.
 
std::vector< std::reference_wrapper< Component > > get_components_all () const
 Get all components attached to this GameObject.
 
template<IsComponent T>
std::vector< std::reference_wrapper< T > > get_components_from_children () const
 Get all components of type T attached to this GameObject and its children.
 
template<IsComponent T, typename... Args>
Tadd_component (Args &&... args)
 Adds a component of type T to this GameObject.
 
template<IsComponent T>
void remove_component (T &component)
 Removes a component of type T from this GameObject.
 
void remove_all_components ()
 
void serialize (std::vector< uint8_t > &out) const
 Serialize this GameObject's own state and its components into out. The format produced is: uint16_t name_len, name bytes uint16_t tag_len, tag bytes uint8_t is_active int32_t layer uint16_t component_count for each component: uint16_t type_name_len, type_name bytes uint32_t payload_len, payload bytes.
 
void deserialize (const std::vector< uint8_t > &data, size_t &offset)
 Deserialize this GameObject's state and dispatch component payloads from data starting at offset. Implementations should advance offset by the number of bytes consumed. Subclasses overriding this method should call GameObject::deserialize first to keep base behavior.
 

Protected Member Functions

bool in_range (const Point &mouse_pos) const
 

Protected Attributes

UIInteractionState interaction_state_
 
std::vector< std::function< void(UIInteractable &)> > on_hover_handlers_
 
std::vector< std::function< void(UIInteractable &)> > on_unhover_handlers_
 
std::vector< std::function< void(UIInteractable &)> > on_press_handlers_
 
std::vector< std::function< void(UIInteractable &)> > on_release_handlers_
 
std::vector< std::function< void(UIInteractable &)> > on_focus_handlers_
 
std::vector< std::function< void(UIInteractable &)> > on_unfocus_handlers_
 
- Protected Attributes inherited from UIObject
float width_
 
float height_
 
Point pivot_
 
Point anchor_
 

Detailed Description

Base class for interactive UI elements.

UIInteractable extends UIObject to provide interaction capabilities such as hover, press, hold, and focus states. It includes event hooks that can be overridden by derived classes or have handlers attached.

Constructor & Destructor Documentation

◆ UIInteractable()

UIInteractable::UIInteractable ( Scene scene,
float  width,
float  height,
Point  pivot,
Point  anchor 
)

Member Function Documentation

◆ add_on_focus()

void UIInteractable::add_on_focus ( const std::function< void(UIInteractable &)> &  handler)

◆ add_on_hover()

void UIInteractable::add_on_hover ( const std::function< void(UIInteractable &)> &  handler)

◆ add_on_press()

void UIInteractable::add_on_press ( const std::function< void(UIInteractable &)> &  handler)

◆ add_on_release()

void UIInteractable::add_on_release ( const std::function< void(UIInteractable &)> &  handler)

◆ add_on_unfocus()

void UIInteractable::add_on_unfocus ( const std::function< void(UIInteractable &)> &  handler)

◆ add_on_unhover()

void UIInteractable::add_on_unhover ( const std::function< void(UIInteractable &)> &  handler)

◆ disable()

void UIInteractable::disable ( )

Disable the interactable element.

◆ enable()

void UIInteractable::enable ( )

Enable the interactable element.

◆ in_range()

bool UIInteractable::in_range ( const Point mouse_pos) const
protected

◆ on_focus()

virtual void UIInteractable::on_focus ( )
inlinevirtual

Event hook for when the element gains focus.

Reimplemented in UIInput.

◆ on_hold()

virtual void UIInteractable::on_hold ( )
inlinevirtual

Event hook for when the element is held down.

◆ on_hover()

virtual void UIInteractable::on_hover ( )
inlinevirtual

Event hook for when the element is hovered.

Reimplemented in UIButton, and UIInput.

◆ on_press()

virtual void UIInteractable::on_press ( )
inlinevirtual

Event hook for when the element is pressed.

Reimplemented in UIButton.

◆ on_release()

virtual void UIInteractable::on_release ( )
inlinevirtual

Event hook for when the element is released.

Reimplemented in UIButton.

◆ on_unfocus()

virtual void UIInteractable::on_unfocus ( )
inlinevirtual

Event hook for when the element loses focus.

Reimplemented in UIInput.

◆ on_unhover()

virtual void UIInteractable::on_unhover ( )
inlinevirtual

Event hook for when the element is unhovered.

Reimplemented in UIButton, and UIInput.

◆ state() [1/2]

UIInteractionState & UIInteractable::state ( )

◆ state() [2/2]

const UIInteractionState & UIInteractable::state ( ) const

◆ update_interaction()

void UIInteractable::update_interaction ( float  dt)

Update interaction state based on input.

The update_interaction method checks for mouse position and button states to update the interaction state of the UI element accordingly.

Member Data Documentation

◆ interaction_state_

UIInteractionState UIInteractable::interaction_state_
protected

◆ on_focus_handlers_

std::vector<std::function<void(UIInteractable&)> > UIInteractable::on_focus_handlers_
protected

◆ on_hover_handlers_

std::vector<std::function<void(UIInteractable&)> > UIInteractable::on_hover_handlers_
protected

◆ on_press_handlers_

std::vector<std::function<void(UIInteractable&)> > UIInteractable::on_press_handlers_
protected

◆ on_release_handlers_

std::vector<std::function<void(UIInteractable&)> > UIInteractable::on_release_handlers_
protected

◆ on_unfocus_handlers_

std::vector<std::function<void(UIInteractable&)> > UIInteractable::on_unfocus_handlers_
protected

◆ on_unhover_handlers_

std::vector<std::function<void(UIInteractable&)> > UIInteractable::on_unhover_handlers_
protected

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