hoverable.cpp
functional
utility
ftxui/component/component.hpp
ftxui/component/component_base.hpp
ftxui/component/event.hpp
ftxui/component/mouse.hpp
ftxui/component/screen_interactive.hpp
ftxui/dom/elements.hpp
ftxui/screen/box.hpp
ftxui/component/animation.hpp
ftxui/component/captured_mouse.hpp
ftxui/component/component.hpp
ftxui/component/component_base.hpp
ftxui/component/component_options.hpp
ftxui/component/event.hpp
ftxui/component/mouse.hpp
ftxui/component/receiver.hpp
ftxui/component/screen_interactive.hpp
ftxui/component/task.hpp
ftxui/dom/canvas.hpp
ftxui/dom/deprecated.hpp
ftxui/dom/direction.hpp
ftxui/dom/elements.hpp
ftxui/dom/flexbox_config.hpp
ftxui/dom/linear_gradient.hpp
ftxui/dom/node.hpp
ftxui/dom/requirement.hpp
ftxui/dom/selection.hpp
ftxui/screen/box.hpp
ftxui/screen/color.hpp
ftxui/screen/image.hpp
ftxui/screen/pixel.hpp
ftxui/screen/screen.hpp
ftxui/screen/string.hpp
ftxui/screen/terminal.hpp
ftxui/util/autoreset.hpp
ftxui/util/ref.hpp
src/ftxui/component/hoverable.cpp
algorithm
atomic
chrono
condition_variable
cstddef
cstdint
ftxui/dom/take_any_args.hpp
functional
memory
mutex
optional
queue
sstream
string
thread
unordered_map
utility
variant
vector
ftxui

    //Copyright2022ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.
    #include<functional>//forfunction
    #include<utility>//formove

    #include"ftxui/component/component.hpp"//forComponentDecorator,Hoverable,Make
    #include"ftxui/component/component_base.hpp"//forComponentBase
    #include"ftxui/component/event.hpp"//forEvent
    #include"ftxui/component/mouse.hpp"//forMouse
    #include"ftxui/component/screen_interactive.hpp"//forComponent,ScreenInteractive
    #include"ftxui/dom/elements.hpp"//foroperator|,reflect,Element
    #include"ftxui/screen/box.hpp"//forBox

    namespaceftxui{

    namespace{

    voidPost(std::function<void()>f){
    if(auto*screen=ScreenInteractive::Active()){
    screen->Post(std::move(f));
    return;
    }
    f();
    }

    }//namespace

    ///@briefWrapacomponent.Givestheabilitytoknowifitishoveredbythe
    ///mouse.
    ///@paramcomponentThewrappedcomponent.
    ///@paramhoverThevaluetoreflectwhetherthecomponentishoveredornot.
    ///@ingroupcomponent
    ///
    ///###Example
    ///
    ///```cpp
    ///autobutton=Button("exit",screen.ExitLoopClosure());
    ///boolhover=false;
    ///autobutton_hover=Hoverable(button,&hover);
    ///```
    //NOLINTNEXTLINE
    ComponentHoverable(Componentcomponent,bool*hover){
    classImpl:publicComponentBase{
    public:
    Impl(Componentcomponent,bool*hover)
    :component_(std::move(component)),hover_(hover){
    Add(component_);
    }

    private:
    ElementOnRender()override{
    returnComponentBase::OnRender()|reflect(box_);
    }

    boolOnEvent(Eventevent)override{
    if(event.is_mouse()){
    *hover_=box_.Contain(event.mouse().x,event.mouse().y)&&
    CaptureMouse(event);
    }

    returnComponentBase::OnEvent(event);
    }

    Componentcomponent_;
    bool*hover_;
    Boxbox_;
    };

    returnMake<Impl>(component,hover);
    }

    ///@briefWrapacomponent.Usescallbacks.
    ///@paramcomponentThewrappedcomponent.
    ///@paramon_enterCallbackOnEnter
    ///@paramon_leaveCallbackOnLeave
    ///@ingroupcomponent
    ///
    ///###Example
    ///
    ///```cpp
    ///autobutton=Button("exit",screen.ExitLoopClosure());
    ///boolhover=false;
    ///autobutton_hover=Hoverable(button,&hover);
    ///```
    ComponentHoverable(Componentcomponent,
    std::function<void()>on_enter,
    std::function<void()>on_leave){
    classImpl:publicComponentBase{
    public:
    Impl(Componentcomponent,
    std::function<void()>on_enter,
    std::function<void()>on_leave)
    :component_(std::move(component)),
    on_enter_(std::move(on_enter)),
    on_leave_(std::move(on_leave)){
    Add(component_);
    }

    private:
    ElementOnRender()override{
    returnComponentBase::OnRender()|reflect(box_);
    }

    boolOnEvent(Eventevent)override{
    if(event.is_mouse()){
    constboolhover=box_.Contain(event.mouse().x,event.mouse().y)&&
    CaptureMouse(event);
    if(hover!=hover_){
    Post(hover?on_enter_:on_leave_);
    }
    hover_=hover;
    }

    returnComponentBase::OnEvent(event);
    }

    Componentcomponent_;
    Boxbox_;
    boolhover_=false;
    std::function<void()>on_enter_;
    std::function<void()>on_leave_;
    };

    returnMake<Impl>(std::move(component),std::move(on_enter),
    std::move(on_leave));
    }

    ///@briefWrapacomponent.Givestheabilitytoknowifitishoveredbythe
    ///mouse.
    ///@paramhoverThevaluetoreflectwhetherthecomponentishoveredornot.
    ///@ingroupcomponent
    ///
    ///###Example
    ///
    ///```cpp
    ///boolhover=false;
    ///autobutton=Button("exit",screen.ExitLoopClosure());
    ///button|=Hoverable(&hover);
    ///```
    ComponentDecoratorHoverable(bool*hover){
    return[hover](Componentcomponent){
    returnHoverable(std::move(component),hover);
    };
    }

    ///@briefWrapacomponent.Givestheabilitytoknowifitishoveredbythe
    ///mouse.
    ///@paramon_enteriscalledwhenthemousehoverthecomponent.
    ///@paramon_leaveiscalledwhenthemouseleavethecomponent.
    ///@ingroupcomponent
    ///
    ///###Example
    ///
    ///```cpp
    ///autobutton=Button("exit",screen.ExitLoopClosure());
    ///inton_enter_cnt=0;
    ///inton_leave_cnt=0;
    ///button|=Hoverable(
    ///[&]{on_enter_cnt++; },
    ///[&]{on_leave_cnt++; }
    //);
    ///```
    //NOLINTNEXTLINE
    ComponentDecoratorHoverable(std::function<void()>on_enter,
    //NOLINTNEXTLINE
    std::function<void()>on_leave){
    return[on_enter,on_leave](Componentcomponent){
    returnHoverable(std::move(component),on_enter,on_leave);
    };
    }

    ///@briefWrapacomponent.Givestheabilitytoknowifitishoveredbythe
    ///mouse.
    ///@paramcomponentthewrappedcomponent.
    ///@paramon_changeiscalledwhenthemouseenterorleavethecomponent.
    ///@ingroupcomponent
    ///
    ///###Example
    ///
    ///```cpp
    ///autobutton=Button("exit",screen.ExitLoopClosure());
    ///boolhovered=false;
    ///autobutton_hoverable=Hoverable(button,
    //[&](boolhover){hovered=hover;});
    ///```
    //NOLINTNEXTLINE
    ComponentHoverable(Componentcomponent,std::function<void(bool)>on_change){
    returnHoverable(
    std::move(component),//
    [on_change]{on_change(true);},//
    [on_change]{on_change(false);}//
    );
    }

    ///@briefWrapacomponent.Givestheabilitytoknowifitishoveredbythe
    ///mouse.
    ///@paramon_changeiscalledwhenthemouseenterorleavethecomponent.
    ///@ingroupcomponent
    ///
    ///###Example
    ///
    ///```cpp
    ///autobutton=Button("exit",screen.ExitLoopClosure());
    ///boolhovered=false;
    ///button|=Hoverable([&](boolhover){hovered=hover;});
    ///```
    //NOLINTNEXTLINE
    ComponentDecoratorHoverable(std::function<void(bool)>on_change){
    return[on_change](Componentcomponent){
    returnHoverable(std::move(component),on_change);
    };
    }

    }//namespaceftxui