gauge.cpp
ftxui/dom/direction.hpp
memory
string
ftxui/dom/elements.hpp
ftxui/dom/node.hpp
ftxui/dom/requirement.hpp
ftxui/screen/box.hpp
ftxui/screen/screen.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/dom/gauge.cpp
cstddef
cstdint
ftxui/dom/take_any_args.hpp
functional
memory
optional
sstream
string
unordered_map
utility
variant
vector
ftxui

    //Copyright2020ArthurSonzogni.Allrightsreserved.
    //UseofthissourcecodeisgovernedbytheMITlicensethatcanbefoundin
    //theLICENSEfile.
    #include<ftxui/dom/direction.hpp>//forDirection,Direction::Down,Direction::Left,Direction::Right,Direction::Up
    #include<memory>//forallocator,make_shared
    #include<string>//forstring

    #include"ftxui/dom/elements.hpp"//forElement,gauge,gaugeDirection,gaugeDown,gaugeLeft,gaugeRight,gaugeUp
    #include"ftxui/dom/node.hpp"//forNode
    #include"ftxui/dom/requirement.hpp"//forRequirement
    #include"ftxui/screen/box.hpp"//forBox
    #include"ftxui/screen/screen.hpp"//forScreen,Pixel

    namespaceftxui{

    namespace{
    //NOLINTNEXTLINE
    staticconststd::stringcharset_horizontal[11]={
    #ifdefined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
    //Microsoft'sterminalsoftenusefontsnothandlingthe8unicode
    //charactersforrepresentingthewholegauge.Fallbackwithless.
    "","","","","▌","▌","▌","█","█","█",
    #else
    "","","▏","▎","▍","▌","▋","▊","▉","█",
    #endif
    //Anextracharacterincasewhenthefuzzermanagetohave:
    //int(9*(limit-limit_int)=9
    "█"};

    //NOLINTNEXTLINE
    staticconststd::stringcharset_vertical[10]={
    "█",
    "▇",
    "▆",
    "▅",
    "▄",
    "▃",
    "▂",
    "▁",
    "",
    //Anextracharacterincasewhenthefuzzermanagetohave:
    //int(8*(limit-limit_int)=8
    "",
    };

    classGauge:publicNode{
    public:
    Gauge(floatprogress,Directiondirection)
    :progress_(progress),direction_(direction){
    //ThishandleNANcorrectly:
    if(!(progress_>0.F)){
    progress_=0.F;
    }
    if(!(progress_<1.F)){
    progress_=1.F;
    }
    }

    voidComputeRequirement()override{
    switch(direction_){
    caseDirection::Right:
    caseDirection::Left:
    requirement_.flex_grow_x=1;
    requirement_.flex_grow_y=0;
    requirement_.flex_shrink_x=1;
    requirement_.flex_shrink_y=0;
    break;
    caseDirection::Up:
    caseDirection::Down:
    requirement_.flex_grow_x=0;
    requirement_.flex_grow_y=1;
    requirement_.flex_shrink_x=0;
    requirement_.flex_shrink_y=1;
    break;
    }
    requirement_.min_x=1;
    requirement_.min_y=1;
    }

    voidRender(Screen&screen)override{
    switch(direction_){
    caseDirection::Right:
    RenderHorizontal(screen,/*invert=*/false);
    break;
    caseDirection::Up:
    RenderVertical(screen,/*invert=*/false);
    break;
    caseDirection::Left:
    RenderHorizontal(screen,/*invert=*/true);
    break;
    caseDirection::Down:
    RenderVertical(screen,/*invert=*/true);
    break;
    }
    }

    voidRenderHorizontal(Screen&screen,boolinvert){
    constinty=box_.y_min;
    if(y>box_.y_max){
    return;
    }

    //Drawtheprogressbarhorizontally.
    {
    constfloatprogress=invert?1.F-progress_:progress_;
    constautolimit=
    float(box_.x_min)+progress*float(box_.x_max-box_.x_min+1);
    constintlimit_int=static_cast<int>(limit);
    intx=box_.x_min;
    while(x<limit_int){
    screen.at(x++,y)=charset_horizontal[9];//NOLINT
    }
    //NOLINTNEXTLINE
    screen.at(x++,y)=charset_horizontal[int(9*(limit-limit_int))];
    while(x<=box_.x_max){
    screen.at(x++,y)=charset_horizontal[0];
    }
    }

    if(invert){
    for(intx=box_.x_min;x<=box_.x_max;x++){
    screen.PixelAt(x,y).inverted^=true;
    }
    }
    }

    voidRenderVertical(Screen&screen,boolinvert){
    constintx=box_.x_min;
    if(x>box_.x_max){
    return;
    }

    //Drawtheprogressbarvertically:
    {
    constfloatprogress=invert?progress_:1.F-progress_;
    constfloatlimit=
    float(box_.y_min)+progress*float(box_.y_max-box_.y_min+1);
    constintlimit_int=static_cast<int>(limit);
    inty=box_.y_min;
    while(y<limit_int){
    screen.at(x,y++)=charset_vertical[8];//NOLINT
    }
    //NOLINTNEXTLINE
    screen.at(x,y++)=charset_vertical[int(8*(limit-limit_int))];
    while(y<=box_.y_max){
    screen.at(x,y++)=charset_vertical[0];
    }
    }

    if(invert){
    for(inty=box_.y_min;y<=box_.y_max;y++){
    screen.PixelAt(x,y).inverted^=true;
    }
    }
    }

    private:
    floatprogress_;
    Directiondirection_;
    };

    }//namespace

    ///@briefDrawahighdefinitionprogressbarprogressinginspecified
    ///direction.
    ///@paramprogressTheproportionoftheareatobefilled.Belongto[0,1].
    //@paramdirectionDirectionofprogressbarsprogression.
    ///@ingroupdom
    ElementgaugeDirection(floatprogress,Directiondirection){
    returnstd::make_shared<Gauge>(progress,direction);
    }

    ///@briefDrawahighdefinitionprogressbarprogressingfromlefttoright.
    ///@paramprogressTheproportionoftheareatobefilled.Belongto[0,1].
    ///@ingroupdom
    ///
    ///###Example
    ///
    ///Agauge.Itcanbeusedtorepresentaprogressbar.
    ///~~~cpp
    ///border(gaugeRight(0.5))
    ///~~~
    ///
    ///####Output
    ///
    ///~~~bash
    ///┌──────────────────────────────────────────────────────────────────────────┐
    ///│█████████████████████████████████████│
    ///└──────────────────────────────────────────────────────────────────────────┘
    ///~~~
    ElementgaugeRight(floatprogress){
    returngaugeDirection(progress,Direction::Right);
    }

    ///@briefDrawahighdefinitionprogressbarprogressingfromrighttoleft.
    ///@paramprogressTheproportionoftheareatobefilled.Belongto[0,1].
    ///@ingroupdom
    ///
    ///###Example
    ///
    ///Agauge.Itcanbeusedtorepresentaprogressbar.
    ///~~~cpp
    ///border(gaugeLeft(0.5))
    ///~~~
    ///
    ///####Output
    ///
    ///~~~bash
    ///┌──────────────────────────────────────────────────────────────────────────┐
    ///│█████████████████████████████████████│
    ///└──────────────────────────────────────────────────────────────────────────┘
    ///~~~
    ElementgaugeLeft(floatprogress){
    returngaugeDirection(progress,Direction::Left);
    }

    ///@briefDrawahighdefinitionprogressbarprogressingfrombottomtotop.
    ///@paramprogressTheproportionoftheareatobefilled.Belongto[0,1].
    ///@ingroupdom
    ///
    ///###Example
    ///
    ///Agauge.Itcanbeusedtorepresentaprogressbar.
    ///~~~cpp
    ///border(gaugeUp(0.5))
    ///~~~
    ///
    ///####Output
    ///
    ///~~~bash
    ///┌─┐
    ///││
    ///││
    ///││
    ///││
    ///│█│
    ///│█│
    ///│█│
    ///│█│
    ///└─┘
    ///~~~
    ElementgaugeUp(floatprogress){
    returngaugeDirection(progress,Direction::Up);
    }

    ///@briefDrawahighdefinitionprogressbarprogressingfromtoptobottom.
    ///@paramprogressTheproportionoftheareatobefilled.Belongto[0,1].
    ///@ingroupdom
    ///
    ///###Example
    ///
    ///Agauge.Itcanbeusedtorepresentaprogressbar.
    ///~~~cpp
    ///border(gaugeDown(0.5))
    ///~~~
    ///
    ///####Output
    ///
    ///~~~bash
    ///┌─┐
    ///│█│
    ///│█│
    ///│█│
    ///│█│
    ///││
    ///││
    ///││
    ///││
    ///└─┘
    ///~~~
    ElementgaugeDown(floatprogress){
    returngaugeDirection(progress,Direction::Down);
    }

    ///@briefDrawahighdefinitionprogressbar.
    ///@paramprogressTheproportionoftheareatobefilled.Belongto[0,1].
    ///@ingroupdom
    ///
    ///###Example
    ///
    ///Agauge.Itcanbeusedtorepresentaprogressbar.
    ///~~~cpp
    ///border(gauge(0.5))
    ///~~~
    ///
    ///####Output
    ///
    ///~~~bash
    ///┌──────────────────────────────────────────────────────────────────────────┐
    ///│█████████████████████████████████████│
    ///└──────────────────────────────────────────────────────────────────────────┘
    ///~~~
    Elementgauge(floatprogress){
    returngaugeRight(progress);
    }

    }//namespaceftxui