CPGen
C++ project generator
Loading...
Searching...
No Matches
Component.hpp
Go to the documentation of this file.
1#pragma once
2
19#include "Misc/Defs.hpp"
20#include <string>
21
38class Component {
39public:
40 Component() = default;
41
46 virtual ~Component() = default;
47
48 Component(const Component &) = delete;
49 Component &
50 operator=(const Component &) = delete;
51 Component(Component &&) = delete;
53
62 [[nodiscard]] virtual std::string render() const = 0;
63
71 virtual bool handleInput(Defs::Key key) = 0;
72
82 virtual void setFocused(bool focused) { m_is_focused = focused; }
83
88 [[nodiscard]] bool isFocused() const { return m_is_focused; }
89
90protected:
92 false;
93};
Shared type definitions for the TUI input system.
Abstract base for all TUI widgets.
Definition Component.hpp:38
bool m_is_focused
Current focus state, managed by setFocused.
Definition Component.hpp:91
Component(Component &&)=delete
Non-movable.
Component()=default
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.
Component & operator=(Component &&)=delete
Non-movable.
virtual void setFocused(bool focused)
Change the focus state of this component.
Definition Component.hpp:82
virtual ~Component()=default
Virtual destructor — components are always owned via base-class pointer.
bool isFocused() const
Return whether this component currently has keyboard focus.
Definition Component.hpp:88
Component & operator=(const Component &)=delete
Non-copyable (unique ownership).
Component(const Component &)=delete
Non-copyable (unique ownership).
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