CPGen
C++ project generator
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Checkbox Class Reference

A toggleable checkbox component. More...

#include <Checkbox.hpp>

Inheritance diagram for Checkbox:
Inheritance graph
[legend]
Collaboration diagram for Checkbox:
Collaboration graph
[legend]

Public Member Functions

 Checkbox (std::string label, std::function< void(bool)> on_change)
 Construct a Checkbox with a label and a change callback.
 
bool isChecked () const
 Return the current checked state.
 
std::string render () const override
 Render the checkbox as an ANSI string.
 
bool handleInput (Defs::Key key) override
 Handle a key event.
 
- Public Member Functions inherited from Component
 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 void setFocused (bool focused)
 Change the focus state of this component.
 
bool isFocused () const
 Return whether this component currently has keyboard focus.
 

Additional Inherited Members

- Protected Attributes inherited from Component
bool m_is_focused
 Current focus state, managed by setFocused.
 

Detailed Description

A toggleable checkbox component.

Renders a Unicode checkbox glyph (checked or unchecked) followed by a text label. When the component is focused, an arrow cursor is prepended to indicate selection. Pressing Defs::Special::Enter toggles the state and fires the on_change callback.

Rendering example (focused, unchecked)

➡ ☐ Enable git ?

Rendering example (unfocused, checked)

✔ Enable git ?

Constructor & Destructor Documentation

◆ Checkbox()

Checkbox::Checkbox ( std::string  label,
std::function< void(bool)>  on_change 
)

Construct a Checkbox with a label and a change callback.

Parameters
labelDescriptive text displayed next to the checkbox glyph.
on_changeCallback invoked with the new checked state whenever the checkbox is toggled.

Member Function Documentation

◆ handleInput()

bool Checkbox::handleInput ( Defs::Key  key)
overridevirtual

Handle a key event.

Toggles the checked state when Defs::Special::Enter is pressed. All other keys are ignored (returns false).

Parameters
keyThe key to process.
Returns
true if Enter was consumed, false otherwise.

Implements Component.

◆ isChecked()

bool Checkbox::isChecked ( ) const

Return the current checked state.

Returns
true if the checkbox is checked.

◆ render()

std::string Checkbox::render ( ) const
overridevirtual

Render the checkbox as an ANSI string.

Returns
A single-line string containing the cursor (if focused), the checkbox glyph, and the label.

Implements Component.

Here is the call graph for this function:

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