20void Post(std::function<
void()> f) {
22 screen->Post(std::move(f));
48 : component_(std::move(component)), hover_(hover) {
57 bool OnEvent(
Event event)
override {
59 *hover_ = box_.Contain(event.
mouse().
x, event.
mouse().
y) &&
71 return Make<Impl>(component, hover);
88 std::function<
void()> on_enter,
89 std::function<
void()> on_leave) {
93 std::function<
void()> on_enter,
94 std::function<
void()> on_leave)
95 : component_(std::move(component)),
96 on_enter_(std::move(on_enter)),
97 on_leave_(std::move(on_leave)) {
106 bool OnEvent(
Event event)
override {
108 const bool hover = box_.Contain(event.
mouse().
x, event.
mouse().
y) &&
110 if (hover != hover_) {
111 Post(hover ? on_enter_ : on_leave_);
122 std::function<void()> on_enter_;
123 std::function<void()> on_leave_;
126 return Make<Impl>(std::move(component), std::move(on_enter),
127 std::move(on_leave));
144 return Hoverable(std::move(component), hover);
168 std::function<
void()> on_leave) {
169 return [on_enter, on_leave](
Component component) {
170 return Hoverable(std::move(component), on_enter, on_leave);
191 std::move(component),
192 [on_change] { on_change(
true); },
193 [on_change] { on_change(
false); }
211 return [on_change](
Component component) {
212 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 ...