19using Charset = std::array<std::string, 2>;
20using Charsets = std::array<Charset, 6>;
22const Charsets charsets = {
31class Separator :
public Node {
33 explicit Separator(std::string value) : value_(std::move(value)) {}
35 void ComputeRequirement()
override {
36 requirement_.min_x = 1;
37 requirement_.min_y = 1;
40 void Render(Screen& screen)
override {
41 for (
int y = box_.y_min; y <= box_.y_max; ++y) {
42 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
43 Pixel& pixel = screen.PixelAt(x, y);
44 pixel.character = value_;
45 pixel.automerge =
true;
53class SeparatorAuto :
public Node {
55 explicit SeparatorAuto(
BorderStyle style) : style_(style) {}
57 void ComputeRequirement()
override {
58 requirement_.min_x = 1;
59 requirement_.min_y = 1;
62 void Render(Screen& screen)
override {
63 const bool is_column = (box_.x_max == box_.x_min);
64 const bool is_line = (box_.y_min == box_.y_max);
66 const std::string c = charsets[style_][int(is_line && !is_column)];
68 for (
int y = box_.y_min; y <= box_.y_max; ++y) {
69 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
70 Pixel& pixel = screen.PixelAt(x, y);
72 pixel.automerge =
true;
80class SeparatorWithPixel :
public SeparatorAuto {
82 explicit SeparatorWithPixel(Pixel pixel)
83 : SeparatorAuto(
LIGHT), pixel_(std::move(pixel)) {
84 pixel_.automerge =
true;
86 void Render(Screen& screen)
override {
87 for (
int y = box_.y_min; y <= box_.y_max; ++y) {
88 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
89 screen.PixelAt(x, y) = pixel_;
133 return std::make_shared<SeparatorAuto>(
LIGHT);
171 return std::make_shared<SeparatorAuto>(style);
208 return std::make_shared<SeparatorAuto>(
LIGHT);
245 return std::make_shared<SeparatorAuto>(
DASHED);
282 return std::make_shared<SeparatorAuto>(
HEAVY);
319 return std::make_shared<SeparatorAuto>(
DOUBLE);
356 return std::make_shared<SeparatorAuto>(
EMPTY);
394 return std::make_shared<Separator>(std::move(value));
425 return std::make_shared<SeparatorWithPixel>(std::move(pixel));
442 Color unselected_color,
443 Color selected_color) {
444 class Impl :
public Node {
446 Impl(
float left,
float right,
Color selected_color,
Color unselected_color)
449 unselected_color_(unselected_color),
450 selected_color_(selected_color) {}
451 void ComputeRequirement()
override {
452 requirement_.min_x = 1;
453 requirement_.min_y = 1;
457 if (box_.y_max < box_.y_min) {
462 int demi_cell_left = int(left_ * 2.F - 1.F);
463 int demi_cell_right = int(right_ * 2.F + 2.F);
465 const int y = box_.y_min;
466 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
469 const int a = (x - box_.x_min) * 2;
471 const bool a_empty = demi_cell_left == a || demi_cell_right == a;
472 const bool b_empty = demi_cell_left == b || demi_cell_right == b;
474 if (!a_empty && !b_empty) {
482 if (demi_cell_left <= a && b <= demi_cell_right) {
492 Color unselected_color_;
493 Color selected_color_;
495 return std::make_shared<Impl>(left, right, unselected_color, selected_color);
512 Color unselected_color,
513 Color selected_color) {
514 class Impl :
public Node {
516 Impl(
float up,
float down,
Color unselected_color,
Color selected_color)
519 unselected_color_(unselected_color),
520 selected_color_(selected_color) {}
521 void ComputeRequirement()
override {
522 requirement_.min_x = 1;
523 requirement_.min_y = 1;
527 if (box_.x_max < box_.x_min) {
532 const int demi_cell_up = int(up_ * 2 - 1);
533 const int demi_cell_down = int(down_ * 2 + 2);
535 const int x = box_.x_min;
536 for (
int y = box_.y_min; y <= box_.y_max; ++y) {
539 const int a = (y - box_.y_min) * 2;
541 const bool a_empty = demi_cell_up == a || demi_cell_down == a;
542 const bool b_empty = demi_cell_up == b || demi_cell_down == b;
544 if (!a_empty && !b_empty) {
552 if (demi_cell_up <= a && b <= demi_cell_down) {
562 Color unselected_color_;
563 Color selected_color_;
565 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 cell (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.
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.
Element separatorHeavy()
Draw a vertical or horizontal separation in between two other elements, using the HEAVY style.
A unicode character and its associated style.