19 void Post(std::function<
void()> f) {
21 screen->Post(std::move(f));
47 : component_(std::move(component)), hover_(hover) {
56 bool OnEvent(
Event event)
override {
58 *hover_ = box_.Contain(event.
mouse().
x, event.
mouse().
y) &&
70 return Make<Impl>(component, hover);
87 std::function<
void()> on_enter,
88 std::function<
void()> on_leave) {
92 std::function<
void()> on_enter,
93 std::function<
void()> on_leave)
94 : component_(std::move(component)),
95 on_enter_(std::move(on_enter)),
96 on_leave_(std::move(on_leave)) {
105 bool OnEvent(
Event event)
override {
107 const bool hover = box_.Contain(event.
mouse().
x, event.
mouse().
y) &&
109 if (hover != hover_) {
110 Post(hover ? on_enter_ : on_leave_);
121 std::function<void()> on_enter_;
122 std::function<void()> on_leave_;
125 return Make<Impl>(std::move(component), std::move(on_enter),
126 std::move(on_leave));
143 return Hoverable(std::move(component), hover);
167 std::function<
void()> on_leave) {
168 return [on_enter, on_leave](
Component component) {
169 return Hoverable(std::move(component), on_enter, on_leave);
190 std::move(component),
191 [on_change] { on_change(
true); },
192 [on_change] { on_change(
false); }
210 return [on_change](
Component component) {
211 return Hoverable(std::move(component), on_change);
It implement rendering itself as ftxui::Element. It implement keyboard navigation by responding to ft...
virtual Element Render()
Draw the component. Build a ftxui::Element to be drawn on the ftxi::Screen representing this ftxui::C...
virtual bool OnEvent(Event)
Called in response to an event.
static ScreenInteractive * Active()
Return the currently active screen, or null if none.
std::shared_ptr< Node > Element
std::shared_ptr< ComponentBase > Component
Component Hoverable(Component component, bool *hover)
Wrap a component. Gives the ability to know if it is hovered by the mouse.
Decorator reflect(Box &box)
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
std::function< Component(Component)> ComponentDecorator
Represent an event. It can be key press event, a terminal resize, or more ...