16using Charset = std::array<std::string, 2>;
17using Charsets = std::array<Charset, 6>;
30class Separator :
public Node {
32 explicit Separator(std::string value) : value_(std::move(value)) {}
34 void ComputeRequirement()
override {
39 void Render(Screen& screen)
override {
42 Pixel& pixel = screen.PixelAt(x, y);
43 pixel.character = value_;
44 pixel.automerge =
true;
52class SeparatorAuto :
public Node {
54 explicit SeparatorAuto(
BorderStyle style) : style_(style) {}
56 void ComputeRequirement()
override {
61 void Render(Screen& screen)
override {
65 const std::string c = charsets[style_][int(is_line && !is_column)];
69 Pixel& pixel = screen.PixelAt(x, y);
71 pixel.automerge =
true;
79class SeparatorWithPixel :
public SeparatorAuto {
81 explicit SeparatorWithPixel(Pixel pixel)
82 : SeparatorAuto(
LIGHT), pixel_(std::move(pixel)) {
85 void Render(Screen& screen)
override {
88 screen.PixelAt(x, y) = pixel_;
131 return std::make_shared<SeparatorAuto>(
LIGHT);
169 return std::make_shared<SeparatorAuto>(style);
206 return std::make_shared<SeparatorAuto>(
LIGHT);
243 return std::make_shared<SeparatorAuto>(
DASHED);
280 return std::make_shared<SeparatorAuto>(
HEAVY);
317 return std::make_shared<SeparatorAuto>(
DOUBLE);
354 return std::make_shared<SeparatorAuto>(
EMPTY);
392 return std::make_shared<Separator>(std::move(value));
423 return std::make_shared<SeparatorWithPixel>(std::move(pixel));
440 Color unselected_color,
441 Color selected_color) {
442 class Impl :
public Node {
444 Impl(
float left,
float right,
Color selected_color,
Color unselected_color)
447 unselected_color_(unselected_color),
448 selected_color_(selected_color) {}
449 void ComputeRequirement()
override {
450 requirement_.min_x = 1;
451 requirement_.min_y = 1;
455 if (box_.y_max < box_.y_min) {
460 int demi_cell_left = int(left_ * 2.F - 1.F);
461 int demi_cell_right = int(right_ * 2.F + 2.F);
463 const int y = box_.y_min;
464 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
467 const int a = (x - box_.x_min) * 2;
469 const bool a_empty = demi_cell_left == a || demi_cell_right == a;
470 const bool b_empty = demi_cell_left == b || demi_cell_right == b;
472 if (!a_empty && !b_empty) {
480 if (demi_cell_left <= a && b <= demi_cell_right) {
490 Color unselected_color_;
491 Color selected_color_;
493 return std::make_shared<Impl>(left, right, unselected_color, selected_color);
510 Color unselected_color,
511 Color selected_color) {
512 class Impl :
public Node {
514 Impl(
float up,
float down,
Color unselected_color,
Color selected_color)
517 unselected_color_(unselected_color),
518 selected_color_(selected_color) {}
519 void ComputeRequirement()
override {
520 requirement_.min_x = 1;
521 requirement_.min_y = 1;
525 if (box_.x_max < box_.x_min) {
530 const int demi_cell_up = int(up_ * 2 - 1);
531 const int demi_cell_down = int(down_ * 2 + 2);
533 const int x = box_.x_min;
534 for (
int y = box_.y_min; y <= box_.y_max; ++y) {
537 const int a = (y - box_.y_min) * 2;
539 const bool a_empty = demi_cell_up == a || demi_cell_down == a;
540 const bool b_empty = demi_cell_up == b || demi_cell_down == b;
542 if (!a_empty && !b_empty) {
550 if (demi_cell_up <= a && b <= demi_cell_down) {
560 Color unselected_color_;
561 Color selected_color_;
563 return std::make_shared<Impl>(up, down, unselected_color, selected_color);
A class representing terminal colors.
A rectangular grid of Pixel.
Pixel & PixelAt(int x, int y)
Access a Pixel at a given position.
Element separatorStyled(BorderStyle)
Draw a vertical or horizontal separation in between two other elements.
Element separatorEmpty()
Draw a vertical or horizontal separation in between two other elements, using the EMPTY style.
Element separatorVSelector(float up, float down, Color unselected_color, Color selected_color)
Draw an vertical bar, with the area in between up/downcolored differently.
std::shared_ptr< Node > Element
Element separatorLight()
Draw a vertical or horizontal separation in between two other elements, using the LIGHT style.
Element separatorHSelector(float left, float right, Color unselected_color, Color selected_color)
Draw an horizontal bar, with the area in between left/right colored differently.
std::array< Charset, 6 > Charsets
Element separatorDashed()
Draw a vertical or horizontal separation in between two other elements, using the DASHED style.
Element separatorCharacter(std::string)
Draw a vertical or horizontal separation in between two other elements.
Element separator()
Draw a vertical or horizontal separation in between two other elements.
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
Element separatorDouble()
Draw a vertical or horizontal separation in between two other elements, using the DOUBLE style.
std::array< std::string, 6 > Charset
Element separatorHeavy()
Draw a vertical or horizontal separation in between two other elements, using the HEAVY style.
A unicode character and its associated style.