19class Select :
public Node {
21 explicit Select(
Elements children) : Node(std::move(children)) {}
23 void ComputeRequirement()
override {
25 requirement_ = children_[0]->requirement();
26 auto& selected_box = requirement_.selected_box;
27 selected_box.x_min = 0;
28 selected_box.y_min = 0;
29 selected_box.x_max = requirement_.min_x - 1;
30 selected_box.y_max = requirement_.min_y - 1;
34 void SetBox(Box box)
override {
36 children_[0]->SetBox(box);
40class Focus :
public Select {
44 void ComputeRequirement()
override {
45 Select::ComputeRequirement();
49 void Render(Screen& screen)
override {
69#if !defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
70 screen.SetCursor(Screen::Cursor{
73 Screen::Cursor::Shape::Hidden,
79class Frame :
public Node {
81 Frame(
Elements children,
bool x_frame,
bool y_frame)
82 : Node(std::move(children)), x_frame_(x_frame), y_frame_(y_frame) {}
84 void ComputeRequirement()
override {
86 requirement_ = children_[0]->requirement();
89 void SetBox(Box box)
override {
91 auto& selected_box = requirement_.selected_box;
92 Box children_box = box;
95 const int external_dimx = box.x_max - box.x_min;
96 const int internal_dimx = std::max(requirement_.min_x, external_dimx);
97 const int focused_dimx = selected_box.x_max - selected_box.x_min;
98 int dx = selected_box.x_min - external_dimx / 2 + focused_dimx / 2;
99 dx = std::max(0, std::min(internal_dimx - external_dimx - 1, dx));
100 children_box.x_min = box.x_min - dx;
101 children_box.x_max = box.x_min + internal_dimx - dx;
105 const int external_dimy = box.y_max - box.y_min;
106 const int internal_dimy = std::max(requirement_.min_y, external_dimy);
107 const int focused_dimy = selected_box.y_max - selected_box.y_min;
108 int dy = selected_box.y_min - external_dimy / 2 + focused_dimy / 2;
109 dy = std::max(0, std::min(internal_dimy - external_dimy - 1, dy));
110 children_box.y_min = box.y_min - dy;
111 children_box.y_max = box.y_min + internal_dimy - dy;
114 children_[0]->SetBox(children_box);
117 void Render(Screen& screen)
override {
118 const AutoReset<Box> stencil(&screen.stencil,
120 children_[0]->Render(screen);
128class FocusCursor :
public Focus {
131 : Focus(std::move(children)), shape_(shape) {}
134 void Render(Screen& screen)
override {
136 screen.SetCursor(Screen::Cursor{
151 return std::make_shared<Select>(unpack(std::move(child)));
158 return std::make_shared<Focus>(unpack(std::move(child)));
168 return std::make_shared<Frame>(unpack(std::move(child)),
true,
true);
176 return std::make_shared<Frame>(unpack(std::move(child)),
true,
false);
184 return std::make_shared<Frame>(unpack(std::move(child)),
false,
true);
197 return std::make_shared<FocusCursor>(unpack(std::move(child)),
211 return std::make_shared<FocusCursor>(unpack(std::move(child)),
225 return std::make_shared<FocusCursor>(unpack(std::move(child)),
239 return std::make_shared<FocusCursor>(unpack(std::move(child)),
253 return std::make_shared<FocusCursor>(unpack(std::move(child)),
267 return std::make_shared<FocusCursor>(unpack(std::move(child)),
virtual void SetBox(Box box)
Assign a position and a dimension to an element for drawing.
virtual void ComputeRequirement()
Compute how much space an elements needs.
Element focusCursorBarBlinking(Element)
Same as focus, but set the cursor shape to be a blinking bar.
std::shared_ptr< Node > Element
Element xframe(Element)
Same as frame, but only on the x-axis.
Element focusCursorUnderlineBlinking(Element)
Same as focus, but set the cursor shape to be a blinking underline.
Element focusCursorBar(Element)
Same as focus, but set the cursor shape to be a still block.
Element focusCursorBlock(Element)
Same as focus, but set the cursor shape to be a still block.
Element focusCursorUnderline(Element)
Same as focus, but set the cursor shape to be a still underline.
std::vector< Element > Elements
Element yframe(Element)
Same as frame, but only on the y-axis.
Element select(Element)
Set the child to be the one selected among its siblings.
Element focus(Element)
Set the child to be the one in focus globally.
Element frame(Element)
Allow an element to be displayed inside a 'virtual' area. It size can be larger than its container....
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
Element focusCursorBlockBlinking(Element)
Same as focus, but set the cursor shape to be a blinking block.
static auto Intersection(Box a, Box b) -> Box