FTXUI  0.10.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
scroll_indicator.cpp
Go to the documentation of this file.
2#include "ftxui/dom/node.hpp"
3#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
6
7namespace ftxui {
8
9/// @brief Add a filter that will invert the foreground and the background
10/// colors.
11/// @ingroup dom
13 class Impl : public NodeDecorator {
14 using NodeDecorator::NodeDecorator;
15
16 void ComputeRequirement() override {
17 Node::ComputeRequirement();
18 requirement_ = children_[0]->requirement();
19 requirement_.min_x++;
20 }
21
22 void SetBox(Box box) override {
23 Node::SetBox(box);
24 if (box_.x_min > box_.x_max)
25 box_.x_max--;
26 children_[0]->SetBox(box);
27 }
28
29 void Render(Screen& screen) final {
30 Node::Render(screen);
31
32 const Box& stencil = screen.stencil;
33
34 int size_inner = box_.y_max - box_.y_min;
35 int size_outter = stencil.y_max - stencil.y_min;
36 if (size_outter >= size_inner)
37 return;
38
39 int start_y = 2 * stencil.y_min + 2 * float(stencil.y_min - box_.y_min) *
40 (size_outter - 1) / size_inner;
41 int size = 2 * float(size_outter) * (size_outter - 1) / size_inner + 2;
42 size = std::max(size, 1);
43
44 const int x = stencil.x_max;
45 for (int y = stencil.y_min; y <= stencil.y_max; ++y) {
46 bool up = (2 * y + -1 >= start_y) && (2 * y - 1 <= start_y + size);
47 bool down = (2 * y - 0 >= start_y) && (2 * y - 0 <= start_y + size);
48
49 const char* c = up ? (down ? "┃" : "╹") : (down ? "╻" : " ");
50 screen.PixelAt(x, y).character = c;
51 screen.PixelAt(x, y).inverted = true;
52 }
53 };
54 };
55 return std::make_shared<Impl>(std::move(child));
56}
57
58} // namespace ftxui
A rectangular grid of Pixel.
Definition screen.hpp:49
Pixel & PixelAt(int x, int y)
Access a Pixel at a given position.
Definition screen.cpp:408
Element vscroll_indicator(Element)
Add a filter that will invert the foreground and the background colors.
std::shared_ptr< Node > Element
Definition elements.hpp:15
void Render(Screen &screen, const Element &node)
Display an element on a ftxui::Screen.
Definition node.cpp:34
Decorator size(Direction, Constraint, int value)
Apply a constraint on the size of an element.
Definition size.cpp:86
int x_max
Definition box.hpp:8
int y_min
Definition box.hpp:9
int y_max
Definition box.hpp:10
bool inverted
Definition screen.hpp:29
std::string character
Definition screen.hpp:19