FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
scroll_indicator.cpp
Go to the documentation of this file.
1// Copyright 2021 Arthur Sonzogni. All rights reserved.
2// このソースコードの使用は、LICENSE ファイルにある MIT ライセンスによって管理されています。
3#include <algorithm> // for max
4#include <memory> // for make_shared, __shared_ptr_access
5#include <string> // for string
6#include <utility> // for move
7
8#include "ftxui/dom/elements.hpp" // for Element, vscroll_indicator, hscroll_indicator
9#include "ftxui/dom/node.hpp" // for Node, Elements
10#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
11#include "ftxui/dom/requirement.hpp" // for Requirement
12#include "ftxui/screen/box.hpp" // for Box
13#include "ftxui/screen/screen.hpp" // for Screen, Pixel
14
15namespace ftxui {
16
17/// @brief 右側に垂直スクロールバーを表示します。
18/// 色はコンテンツに従います。
19/// @ingroup dom
21 class Impl : public NodeDecorator {
22 using NodeDecorator::NodeDecorator;
23
24 void ComputeRequirement() override {
25 NodeDecorator::ComputeRequirement();
26 requirement_ = children_[0]->requirement();
27 requirement_.min_x++;
28 }
29
30 void SetBox(Box box) override {
31 box_ = box;
32 box.x_max--;
33 children_[0]->SetBox(box);
34 }
35
36 void Render(Screen& screen) final {
37 NodeDecorator::Render(screen);
38
39 const Box& stencil = screen.stencil;
40
41 const int size_inner = box_.y_max - box_.y_min;
42 if (size_inner <= 0) {
43 return;
44 }
45 const int size_outter = stencil.y_max - stencil.y_min + 1;
46 if (size_outter >= size_inner) {
47 return;
48 }
49
50 int size = 2 * size_outter * size_outter / size_inner;
51 size = std::max(size, 1);
52
53 const int start_y =
54 2 * stencil.y_min + //
55 2 * (stencil.y_min - box_.y_min) * size_outter / size_inner;
56
57 const int x = stencil.x_max;
58 for (int y = stencil.y_min; y <= stencil.y_max; ++y) {
59 const int y_up = 2 * y + 0;
60 const int y_down = 2 * y + 1;
61 const bool up = (start_y <= y_up) && (y_up <= start_y + size);
62 const bool down = (start_y <= y_down) && (y_down <= start_y + size);
63
64 const char* c = up ? (down ? "┃" : "╹") : (down ? "╻" : " "); // NOLINT
65 screen.PixelAt(x, y).character = c;
66 }
67 }
68 };
69 return std::make_shared<Impl>(std::move(child));
70}
71
72/// @brief 下部に水平スクロールバーを表示します。
73/// 色はコンテンツに従います。
74/// @ingroup dom
76 class Impl : public NodeDecorator {
77 using NodeDecorator::NodeDecorator;
78
79 void ComputeRequirement() override {
80 NodeDecorator::ComputeRequirement();
81 requirement_ = children_[0]->requirement();
82 requirement_.min_y++;
83 }
84
85 void SetBox(Box box) override {
86 box_ = box;
87 box.y_max--;
88 children_[0]->SetBox(box);
89 }
90
91 void Render(Screen& screen) final {
92 NodeDecorator::Render(screen);
93
94 const Box& stencil = screen.stencil;
95
96 const int size_inner = box_.x_max - box_.x_min;
97 if (size_inner <= 0) {
98 return;
99 }
100 const int size_outter = stencil.x_max - stencil.x_min + 1;
101 if (size_outter >= size_inner) {
102 return;
103 }
104
105 int size = 2 * size_outter * size_outter / size_inner;
106 size = std::max(size, 1);
107
108 const int start_x =
109 2 * stencil.x_min + //
110 2 * (stencil.x_min - box_.x_min) * size_outter / size_inner;
111
112 const int y = stencil.y_max;
113 for (int x = stencil.x_min; x <= stencil.x_max; ++x) {
114 const int x_left = 2 * x + 0;
115 const int x_right = 2 * x + 1;
116 const bool left = (start_x <= x_left) && (x_left <= start_x + size);
117 const bool right = (start_x <= x_right) && (x_right <= start_x + size);
118
119 const char* c =
120 left ? (right ? "─" : "╴") : (right ? "╶" : " "); // NOLINT
121 screen.PixelAt(x, y).character = c;
122 }
123 }
124 };
125 return std::make_shared<Impl>(std::move(child));
126}
127
128} // namespace ftxui
Element vscroll_indicator(Element)
右側に垂直スクロールバーを表示します。 色はコンテンツに従います。
Element hscroll_indicator(Element)
下部に水平スクロールバーを表示します。 色はコンテンツに従います。
std::string character
Definition pixel.hpp:44
Pixel & PixelAt(int x, int y)
指定された位置のセル (ピクセル) にアクセスします。
Definition image.cpp:41
int x_max
Definition box.hpp:16
int y_min
Definition box.hpp:17
Box stencil
Definition image.hpp:41
int y_max
Definition box.hpp:18
int x_min
Definition box.hpp:15
ピクセルの長方形グリッド。
Definition screen.hpp:25
Boxは、2D空間における矩形領域を表す構造体です。
Definition box.hpp:14
FTXUI ftxui:: 名前空間
Definition animation.hpp:9
std::shared_ptr< Node > Element
Definition elements.hpp:21
std::uint8_t left
Definition screen.cpp:129
std::uint8_t down
Definition screen.cpp:132
std::uint8_t right
Definition screen.cpp:131