17class Focus :
public Node {
19 explicit Focus(
Elements children) : Node(std::move(children)) {}
21 void ComputeRequirement()
override {
23 requirement_ = children_[0]->requirement();
24 requirement_.focused.enabled =
true;
25 requirement_.focused.node =
this;
26 requirement_.focused.box.x_min = 0;
27 requirement_.focused.box.y_min = 0;
28 requirement_.focused.box.x_max = requirement_.min_x - 1;
29 requirement_.focused.box.y_max = requirement_.min_y - 1;
32 void SetBox(Box box)
override {
34 children_[0]->SetBox(box);
38class Frame :
public Node {
40 Frame(
Elements children,
bool x_frame,
bool y_frame)
41 : Node(std::move(children)), x_frame_(x_frame), y_frame_(y_frame) {}
43 void SetBox(Box box)
override {
45 auto& focused_box = requirement_.focused.box;
46 Box children_box = box;
49 const int external_dimx = box.x_max - box.x_min;
50 const int internal_dimx = std::max(requirement_.min_x, external_dimx);
51 const int focused_dimx = focused_box.x_max - focused_box.x_min;
52 int dx = focused_box.x_min - external_dimx / 2 + focused_dimx / 2;
53 dx = std::max(0, std::min(internal_dimx - external_dimx - 1, dx));
54 children_box.x_min = box.x_min - dx;
55 children_box.x_max = box.x_min + internal_dimx - dx;
59 const int external_dimy = box.y_max - box.y_min;
60 const int internal_dimy = std::max(requirement_.min_y, external_dimy);
61 const int focused_dimy = focused_box.y_max - focused_box.y_min;
62 int dy = focused_box.y_min - external_dimy / 2 + focused_dimy / 2;
63 dy = std::max(0, std::min(internal_dimy - external_dimy - 1, dy));
64 children_box.y_min = box.y_min - dy;
65 children_box.y_max = box.y_min + internal_dimy - dy;
68 children_[0]->SetBox(children_box);
71 void Render(Screen& screen)
override {
72 const AutoReset<Box> stencil(&screen.stencil,
74 children_[0]->Render(screen);
82class FocusCursor :
public Focus {
85 : Focus(std::move(children)), shape_(shape) {}
88 void ComputeRequirement()
override {
89 Focus::ComputeRequirement();
90 requirement_.focused.cursor_shape = shape_;
101 return std::make_shared<Focus>(unpack(std::move(child)));
108 return focus(std::move(child));
118 return std::make_shared<Frame>(unpack(std::move(child)),
true,
true);
126 return std::make_shared<Frame>(unpack(std::move(child)),
true,
false);
134 return std::make_shared<Frame>(unpack(std::move(child)),
false,
true);
146 return std::make_shared<FocusCursor>(unpack(std::move(child)),
160 return std::make_shared<FocusCursor>(unpack(std::move(child)),
161 Screen::Cursor::BlockBlinking);
174 return std::make_shared<FocusCursor>(unpack(std::move(child)),
175 Screen::Cursor::Bar);
188 return std::make_shared<FocusCursor>(unpack(std::move(child)),
189 Screen::Cursor::BarBlinking);
202 return std::make_shared<FocusCursor>(unpack(std::move(child)),
203 Screen::Cursor::Underline);
216 return std::make_shared<FocusCursor>(unpack(std::move(child)),
217 Screen::Cursor::UnderlineBlinking);
virtual void SetBox(Box box)
为绘图元素分配位置和尺寸。
virtual void ComputeRequirement()
计算元素所需的空间。
Element focusCursorBarBlinking(Element child)
与 focus 相同,但将光标形状设置为闪烁竖线。
Element focusCursorUnderlineBlinking(Element child)
与 focus 相同,但将光标形状设置为闪烁下划线。
Element focusCursorBar(Element child)
与 focus 相同,但将光标形状设置为静态竖线。
Element focusCursorUnderline(Element child)
与 focus 相同,但将光标形状设置为静态下划线。
Element focus(Element)
将 child 设置为其同级元素中获得焦点的元素。
void Render(Screen &screen, const Element &element)
在 ftxui::Screen 上显示元素。
Element focusCursorBlockBlinking(Element child)
与 focus 相同,但将光标形状设置为闪烁块。
static auto Intersection(Box a, Box b) -> Box
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
std::shared_ptr< Node > Element
Element xframe(Element)
与 frame 相同,但仅限于 x 轴。
std::vector< Element > Elements
Element yframe(Element)
与 frame 相同,但仅限于 y 轴。
Element select(Element e)
将 child 设置为其同级元素中获得焦点的元素。
Element frame(Element)
允许元素显示在“虚拟”区域内。其大小可以 大于其容器。在这种情况下,只显示较小的部分。 视图是可滚动的,以使获得焦点的元素可见。