17class Select :
public Node {
19 explicit Select(
Elements children) :
Node(std::move(children)) {}
21 void ComputeRequirement()
override {
25 selected_box.
x_min = 0;
26 selected_box.y_min = 0;
32 void SetBox(Box box)
override {
39 return std::make_shared<Select>(unpack(std::move(child)));
44class Focus :
public Select {
48 void ComputeRequirement()
override {
49 Select::ComputeRequirement();
53 void Render(Screen& screen)
override {
73#if !defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
74 screen.SetCursor(Screen::Cursor{
84 return std::make_shared<Focus>(unpack(std::move(child)));
89class Frame :
public Node {
91 Frame(
Elements children,
bool x_frame,
bool y_frame)
92 :
Node(std::move(children)), x_frame_(x_frame), y_frame_(y_frame) {}
94 void ComputeRequirement()
override {
99 void SetBox(Box box)
override {
102 Box children_box = box;
105 const int external_dimx = box.x_max - box.x_min;
107 const int focused_dimx = selected_box.x_max - selected_box.x_min;
108 int dx = selected_box.x_min - external_dimx / 2 + focused_dimx / 2;
109 dx = std::max(0, std::min(internal_dimx - external_dimx - 1, dx));
110 children_box.x_min = box.x_min - dx;
111 children_box.x_max = box.x_min + internal_dimx - dx;
115 const int external_dimy = box.y_max - box.y_min;
117 const int focused_dimy = selected_box.y_max - selected_box.y_min;
118 int dy = selected_box.y_min - external_dimy / 2 + focused_dimy / 2;
119 dy = std::max(0, std::min(internal_dimy - external_dimy - 1, dy));
120 children_box.y_min = box.y_min - dy;
121 children_box.y_max = box.y_min + internal_dimy - dy;
127 void Render(Screen& screen)
override {
128 const AutoReset<Box> stencil(&screen.stencil,
143 return std::make_shared<Frame>(unpack(std::move(child)),
true,
true);
147 return std::make_shared<Frame>(unpack(std::move(child)),
true,
false);
151 return std::make_shared<Frame>(unpack(std::move(child)),
false,
true);
154class FocusCursor :
public Focus {
157 : Focus(std::move(children)), shape_(shape) {}
160 void Render(Screen& screen)
override {
162 screen.SetCursor(Screen::Cursor{
172 return std::make_shared<FocusCursor>(unpack(std::move(child)),
176 return std::make_shared<FocusCursor>(unpack(std::move(child)),
180 return std::make_shared<FocusCursor>(unpack(std::move(child)),
184 return std::make_shared<FocusCursor>(unpack(std::move(child)),
188 return std::make_shared<FocusCursor>(unpack(std::move(child)),
192 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.
virtual void Render(Screen &screen)
Display an element on a ftxui::Screen.
std::shared_ptr< Node > Element
Element focusCursorBlock(Element)
Element focusCursorUnderlineBlinking(Element)
Element focusCursorBar(Element)
std::vector< Element > Elements
Element focusCursorBlockBlinking(Element)
Element focusCursorUnderline(Element)
Element frame(Element)
Allow an element to be displayed inside a 'virtual' area. It size can be larger than its container....
Element focusCursorBarBlinking(Element)
static auto Intersection(Box a, Box b) -> Box