CPGen
C++ project generator
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
Component Class Referenceabstract

Abstract base for all TUI widgets. More...

#include <Component.hpp>

Inheritance diagram for Component:
Inheritance graph
[legend]

Public Member Functions

 Component ()=default
 
virtual ~Component ()=default
 Virtual destructor — components are always owned via base-class pointer.
 
 Component (const Component &)=delete
 Non-copyable (unique ownership).
 
Componentoperator= (const Component &)=delete
 Non-copyable (unique ownership).
 
 Component (Component &&)=delete
 Non-movable.
 
Componentoperator= (Component &&)=delete
 Non-movable.
 
virtual std::string render () const =0
 Produce the full ANSI-formatted rendering of this component.
 
virtual bool handleInput (Defs::Key key)=0
 Process a single key event.
 
virtual void setFocused (bool focused)
 Change the focus state of this component.
 
bool isFocused () const
 Return whether this component currently has keyboard focus.
 

Protected Attributes

bool m_is_focused
 Current focus state, managed by setFocused.
 

Detailed Description

Abstract base for all TUI widgets.

Defines the minimal interface that the View and ComponentGroup containers depend on to render and route input events.

Subclasses must implement:

Subclasses may override:

Constructor & Destructor Documentation

◆ Component() [1/3]

Component::Component ( )
default

◆ ~Component()

virtual Component::~Component ( )
virtualdefault

Virtual destructor — components are always owned via base-class pointer.

◆ Component() [2/3]

Component::Component ( const Component )
delete

Non-copyable (unique ownership).

◆ Component() [3/3]

Component::Component ( Component &&  )
delete

Non-movable.

Member Function Documentation

◆ handleInput()

virtual bool Component::handleInput ( Defs::Key  key)
pure virtual

Process a single key event.

Parameters
keyThe key decoded by Utils::readKey.
Returns
true if the component consumed the key (no further propagation is needed), false if the event should bubble up to the parent.

Implemented in Checkbox, Input, and ComponentGroup.

◆ isFocused()

bool Component::isFocused ( ) const
inline

Return whether this component currently has keyboard focus.

Returns
true if focused.

◆ operator=() [1/2]

Component & Component::operator= ( Component &&  )
delete

Non-movable.

◆ operator=() [2/2]

Component & Component::operator= ( const Component )
delete

Non-copyable (unique ownership).

◆ render()

virtual std::string Component::render ( ) const
pure virtual

Produce the full ANSI-formatted rendering of this component.

The returned string may contain newlines and ANSI escape codes. Callers should not assume a specific line count.

Returns
String suitable for direct output to a terminal.

Implemented in Checkbox, Input, and ComponentGroup.

◆ setFocused()

virtual void Component::setFocused ( bool  focused)
inlinevirtual

Change the focus state of this component.

The default implementation sets m_is_focused and is sufficient for most leaf components. Containers such as ComponentGroup override this to also update their currently focused child.

Parameters
focusedtrue to grant focus, false to remove it.

Reimplemented in ComponentGroup.

Member Data Documentation

◆ m_is_focused

bool Component::m_is_focused
protected
Initial value:
=
false

Current focus state, managed by setFocused.


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