CPGen
C++ project generator
Loading...
Searching...
No Matches
Checkbox.hpp
Go to the documentation of this file.
1#pragma once
2
10#include <functional>
11#include <string>
12
32class Checkbox : public Component {
33public:
40 Checkbox(std::string label, std::function<void(bool)> on_change);
41
46 [[nodiscard]] bool isChecked() const;
47
53 [[nodiscard]] std::string render() const override;
54
64 bool handleInput(Defs::Key key) override;
65
66private:
70 void toggle();
71
72 std::string m_label;
73 bool m_is_checked = false;
74 std::function<void(bool)> m_on_change;
75};
Abstract base class for all TUI components.
A toggleable checkbox component.
Definition Checkbox.hpp:32
bool isChecked() const
Return the current checked state.
Definition Checkbox.cpp:18
bool handleInput(Defs::Key key) override
Handle a key event.
Definition Checkbox.cpp:36
std::string render() const override
Render the checkbox as an ANSI string.
Definition Checkbox.cpp:20
Abstract base for all TUI widgets.
Definition Component.hpp:38
std::variant< char, Special > Key
A single keypress from stdin, represented as either a printable character or a Special control key.
Definition Defs.hpp:45