button.cpp
functional
utility
ftxui/component/animation.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/screen_interactive.hpp
ftxui/dom/elements.hpp
ftxui/screen/box.hpp
ftxui/screen/color.hpp
ftxui/util/ref.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/button.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

    //Copyright2020ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.

    #include<functional>//forfunction
    #include<utility>//formove

    #include"ftxui/component/animation.hpp"//forAnimator,Params(ptronly)
    #include"ftxui/component/component.hpp"//forMake,Button
    #include"ftxui/component/component_base.hpp"//forComponentBase
    #include"ftxui/component/component_options.hpp"//forButtonOption,AnimatedColorOption,AnimatedColorsOption,EntryState
    #include"ftxui/component/event.hpp"//forEvent,Event::Return
    #include"ftxui/component/mouse.hpp"//forMouse,Mouse::Left,Mouse::Pressed
    #include"ftxui/component/screen_interactive.hpp"//forComponent
    #include"ftxui/dom/elements.hpp"//foroperator|,Decorator,Element,operator|=,bgcolor,color,reflect,text,bold,border,inverted,nothing
    #include"ftxui/screen/box.hpp"//forBox
    #include"ftxui/screen/color.hpp"//forColor
    #include"ftxui/util/ref.hpp"//forRef,ConstStringRef

    namespaceftxui{

    namespace{

    ElementDefaultTransform(EntryStateparams){//NOLINT
    autoelement=text(params.label)|border;
    if(params.active){
    element|=bold;
    }
    if(params.focused){
    element|=inverted;
    }
    returnelement;
    }

    classButtonBase:publicComponentBase,publicButtonOption{
    public:
    explicitButtonBase(ButtonOptionoption):ButtonOption(std::move(option)){}

    //Componentimplementation:
    ElementOnRender()override{
    constboolactive=Active();
    constboolfocused=Focused();
    constboolfocused_or_hover=focused||mouse_hover_;

    floattarget=focused_or_hover?1.f:0.f;//NOLINT
    if(target!=animator_background_.to()){
    SetAnimationTarget(target);
    }

    constEntryStatestate{
    *label,false,active,focused_or_hover,Index(),
    };

    autoelement=(transform?transform:DefaultTransform)//
    (state);
    element|=AnimatedColorStyle();
    element|=focus;
    element|=reflect(box_);
    returnelement;
    }

    DecoratorAnimatedColorStyle(){
    Decoratorstyle=nothing;
    if(animated_colors.background.enabled){
    style=style|
    bgcolor(Color::Interpolate(animation_foreground_,//
    animated_colors.background.inactive,
    animated_colors.background.active));
    }
    if(animated_colors.foreground.enabled){
    style=
    style|color(Color::Interpolate(animation_foreground_,//
    animated_colors.foreground.inactive,
    animated_colors.foreground.active));
    }
    returnstyle;
    }

    voidSetAnimationTarget(floattarget){
    if(animated_colors.foreground.enabled){
    animator_foreground_=animation::Animator(
    &animation_foreground_,target,animated_colors.foreground.duration,
    animated_colors.foreground.function);
    }
    if(animated_colors.background.enabled){
    animator_background_=animation::Animator(
    &animation_background_,target,animated_colors.background.duration,
    animated_colors.background.function);
    }
    }

    voidOnAnimation(animation::Params&p)override{
    animator_background_.OnAnimation(p);
    animator_foreground_.OnAnimation(p);
    }

    voidOnClick(){
    animation_background_=0.5F;//NOLINT
    animation_foreground_=0.5F;//NOLINT
    SetAnimationTarget(1.F);//NOLINT

    //TODO(arthursonzogni):Considerpostingthetasktothemainloop,instead
    //ofinvokingitimmediately.
    on_click();//Maydeletethis.
    }

    boolOnEvent(Eventevent)override{
    if(event.is_mouse()){
    returnOnMouseEvent(event);
    }

    if(event==Event::Return){
    OnClick();//Maydeletethis.
    returntrue;
    }
    returnfalse;
    }

    boolOnMouseEvent(Eventevent){
    mouse_hover_=
    box_.Contain(event.mouse().x,event.mouse().y)&&CaptureMouse(event);

    if(!mouse_hover_){
    returnfalse;
    }

    if(event.mouse().button==Mouse::Left&&
    event.mouse().motion==Mouse::Pressed){
    TakeFocus();
    OnClick();//Maydeletethis.
    returntrue;
    }

    returnfalse;
    }

    boolFocusable()constfinal{returntrue;}

    private:
    boolmouse_hover_=false;
    Boxbox_;
    ButtonOptionoption_;
    floatanimation_background_=0;
    floatanimation_foreground_=0;
    animation::Animatoranimator_background_=
    animation::Animator(&animation_background_);
    animation::Animatoranimator_foreground_=
    animation::Animator(&animation_foreground_);
    };

    }//namespace

    ///@briefDrawabutton.Executeafunctionwhenclicked.
    ///@paramoptionAdditionaloptionalparameters.
    ///@ingroupcomponent
    ///@seeButtonBase
    ///
    ///###Example
    ///
    ///```cpp
    ///autoscreen=ScreenInteractive::FitComponent();
    ///Componentbutton=Button({
    ///.label="Clicktoquit",
    ///.on_click=screen.ExitLoopClosure(),
    ///});
    ///screen.Loop(button)
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///┌─────────────┐
    ///│Clicktoquit│
    ///└─────────────┘
    ///```
    ComponentButton(ButtonOptionoption){
    returnMake<ButtonBase>(std::move(option));
    }

    ///@briefDrawabutton.Executeafunctionwhenclicked.
    ///@paramlabelThelabelofthebutton.
    ///@paramon_clickTheactiontoexecutewhenclicked.
    ///@paramoptionAdditionaloptionalparameters.
    ///@ingroupcomponent
    ///@seeButtonBase
    ///
    ///###Example
    ///
    ///```cpp
    ///autoscreen=ScreenInteractive::FitComponent();
    ///std::stringlabel="Clicktoquit";
    ///Componentbutton=Button(&label,screen.ExitLoopClosure());
    ///screen.Loop(button)
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///┌─────────────┐
    ///│Clicktoquit│
    ///└─────────────┘
    ///```
    //NOLINTNEXTLINE
    ComponentButton(ConstStringReflabel,
    std::function<void()>on_click,
    ButtonOptionoption){
    option.label=std::move(label);
    option.on_click=std::move(on_click);
    returnMake<ButtonBase>(std::move(option));
    }

    }//namespaceftxui