checkbox.cpp
functional
utility
ftxui/component/component.hpp
ftxui/component/component_base.hpp
ftxui/component/component_options.hpp
ftxui/component/event.hpp
ftxui/component/mouse.hpp
ftxui/dom/elements.hpp
ftxui/screen/box.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/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/checkbox.cpp
chrono
cstddef
cstdint
ftxui/dom/take_any_args.hpp
functional
memory
optional
sstream
string
unordered_map
utility
variant
vector
ftxui

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

    #include"ftxui/component/component.hpp"//forMake,Checkbox
    #include"ftxui/component/component_base.hpp"//forComponent,ComponentBase
    #include"ftxui/component/component_options.hpp"//forCheckboxOption,EntryState
    #include"ftxui/component/event.hpp"//forEvent,Event::Return
    #include"ftxui/component/mouse.hpp"//forMouse,Mouse::Left,Mouse::Pressed
    #include"ftxui/dom/elements.hpp"//foroperator|,Element,reflect,focus,nothing,select
    #include"ftxui/screen/box.hpp"//forBox
    #include"ftxui/util/ref.hpp"//forRef,ConstStringRef

    namespaceftxui{

    namespace{
    classCheckboxBase:publicComponentBase,publicCheckboxOption{
    public:
    explicitCheckboxBase(CheckboxOptionoption)
    :CheckboxOption(std::move(option)){}

    private:
    //Componentimplementation.
    ElementOnRender()override{
    constboolis_focused=Focused();
    constboolis_active=Active();
    autoentry_state=EntryState{
    *label,*checked,is_active,is_focused||hovered_,-1,
    };
    autoelement=(transform?transform:CheckboxOption::Simple().transform)(
    entry_state);
    element|=focus;
    element|=reflect(box_);
    returnelement;
    }

    boolOnEvent(Eventevent)override{
    if(!CaptureMouse(event)){
    returnfalse;
    }

    if(event.is_mouse()){
    returnOnMouseEvent(event);
    }

    hovered_=false;
    if(event==Event::Character('')||event==Event::Return){
    *checked=!*checked;
    on_change();
    TakeFocus();
    returntrue;
    }
    returnfalse;
    }

    boolOnMouseEvent(Eventevent){
    hovered_=box_.Contain(event.mouse().x,event.mouse().y);

    if(!CaptureMouse(event)){
    returnfalse;
    }

    if(!hovered_){
    returnfalse;
    }

    if(event.mouse().button==Mouse::Left&&
    event.mouse().motion==Mouse::Pressed){
    *checked=!*checked;
    on_change();
    returntrue;
    }

    returnfalse;
    }

    boolFocusable()constfinal{returntrue;}

    boolhovered_=false;
    Boxbox_;
    };
    }//namespace

    ///@briefDrawcheckableelement.
    ///@paramoptionAdditionaloptionalparameters.
    ///@ingroupcomponent
    ///@seeCheckboxBase
    ///
    ///###Example
    ///
    ///```cpp
    ///autoscreen=ScreenInteractive::FitComponent();
    ///CheckboxOptionoption;
    ///option.label="Makeasandwidth";
    ///option.checked=false;
    ///Componentcheckbox=Checkbox(option);
    ///screen.Loop(checkbox)
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///☐Makeasandwitch
    ///```
    //NOLINTNEXTLINE
    ComponentCheckbox(CheckboxOptionoption){
    returnMake<CheckboxBase>(std::move(option));
    }

    ///@briefDrawcheckableelement.
    ///@paramlabelThelabelofthecheckbox.
    ///@paramcheckedWhetherthecheckboxischeckedornot.
    ///@paramoptionAdditionaloptionalparameters.
    ///@ingroupcomponent
    ///@seeCheckboxBase
    ///
    ///###Example
    ///
    ///```cpp
    ///autoscreen=ScreenInteractive::FitComponent();
    ///std::stringlabel="Makeasandwidth";
    ///boolchecked=false;
    ///Componentcheckbox=Checkbox(&label,&checked);
    ///screen.Loop(checkbox)
    ///```
    ///
    ///###Output
    ///
    ///```bash
    ///☐Makeasandwitch
    ///```
    //NOLINTNEXTLINE
    ComponentCheckbox(ConstStringReflabel,bool*checked,CheckboxOptionoption){
    option.label=std::move(label);
    option.checked=checked;
    returnMake<CheckboxBase>(std::move(option));
    }

    }//namespaceftxui