21using SeparatorCharset = std::array<std::string, 2>;
22using SeparatorCharsets = std::array<SeparatorCharset, 6>;
24const SeparatorCharsets charsets = {
25 SeparatorCharset{
"│",
"─"},
26 SeparatorCharset{
"╏",
"╍"},
27 SeparatorCharset{
"┃",
"━"},
28 SeparatorCharset{
"║",
"═"},
29 SeparatorCharset{
"│",
"─"},
30 SeparatorCharset{
" ",
" "},
33class Separator :
public Node {
37 void ComputeRequirement()
override {
38 requirement_.min_x = 1;
39 requirement_.min_y = 1;
42 void Render(Screen& screen)
override {
43 for (
int y = box_.y_min;
y <= box_.y_max; ++
y) {
44 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
45 Cell& pixel = screen.CellAt(x,
y);
47 pixel.automerge =
true;
55class SeparatorAuto :
public Node {
59 void ComputeRequirement()
override {
60 requirement_.min_x = 1;
61 requirement_.min_y = 1;
64 void Render(Screen& screen)
override {
65 const bool is_column = (box_.x_max == box_.x_min);
66 const bool is_line = (box_.y_min == box_.y_max);
69 charsets[
style_][int(is_line && !is_column)];
71 for (
int y = box_.y_min;
y <= box_.y_max; ++
y) {
72 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
73 Cell& pixel = screen.CellAt(x,
y);
75 pixel.automerge =
true;
83class SeparatorWithCell :
public SeparatorAuto {
85 explicit SeparatorWithCell(Cell pixel)
86 : SeparatorAuto(
LIGHT), pixel_(std::move(pixel)) {
87 pixel_.automerge =
true;
89 void Render(Screen& screen)
override {
90 for (
int y = box_.y_min;
y <= box_.y_max; ++
y) {
91 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
92 screen.CellAt(x,
y) = pixel_;
136 return std::make_shared<SeparatorAuto>(
LIGHT);
174 return std::make_shared<SeparatorAuto>(style);
211 return std::make_shared<SeparatorAuto>(
LIGHT);
248 return std::make_shared<SeparatorAuto>(
DASHED);
285 return std::make_shared<SeparatorAuto>(
HEAVY);
322 return std::make_shared<SeparatorAuto>(
DOUBLE);
359 return std::make_shared<SeparatorAuto>(
EMPTY);
397 return std::make_shared<Separator>(std::string(
value));
428 return std::make_shared<SeparatorWithCell>(std::move(pixel));
445 Color unselected_color,
446 Color selected_color) {
447 class Impl :
public Node {
449 Impl(
float left,
float right, Color selected_color, Color unselected_color)
452 unselected_color_(unselected_color),
453 selected_color_(selected_color) {}
454 void ComputeRequirement()
override {
455 requirement_.min_x = 1;
456 requirement_.min_y = 1;
459 void Render(Screen& screen)
override {
460 if (box_.y_max < box_.y_min) {
465 int demi_cell_left = int(left_ * 2.F - 1.F);
466 int demi_cell_right = int(right_ * 2.F + 2.F);
468 const int y = box_.y_min;
469 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
470 Cell& pixel = screen.CellAt(x,
y);
472 const int a = (x - box_.x_min) * 2;
474 const bool a_empty = demi_cell_left == a || demi_cell_right == a;
475 const bool b_empty = demi_cell_left == b || demi_cell_right == b;
477 if (!a_empty && !b_empty) {
478 pixel.character =
"─";
479 pixel.automerge =
true;
481 pixel.character = a_empty ?
"╶" :
"╴";
482 pixel.automerge =
false;
485 if (demi_cell_left <= a && b <= demi_cell_right) {
486 pixel.foreground_color = selected_color_;
488 pixel.foreground_color = unselected_color_;
495 Color unselected_color_;
496 Color selected_color_;
498 return std::make_shared<Impl>(
left,
right, unselected_color, selected_color);
515 Color unselected_color,
516 Color selected_color) {
517 class Impl :
public Node {
519 Impl(
float up,
float down, Color unselected_color, Color selected_color)
522 unselected_color_(unselected_color),
523 selected_color_(selected_color) {}
524 void ComputeRequirement()
override {
525 requirement_.min_x = 1;
526 requirement_.min_y = 1;
529 void Render(Screen& screen)
override {
530 if (box_.x_max < box_.x_min) {
535 const int demi_cell_up = int(up_ * 2 - 1);
536 const int demi_cell_down = int(down_ * 2 + 2);
538 const int x = box_.x_min;
539 for (
int y = box_.y_min;
y <= box_.y_max; ++
y) {
540 Cell& pixel = screen.CellAt(x,
y);
542 const int a = (
y - box_.y_min) * 2;
544 const bool a_empty = demi_cell_up == a || demi_cell_down == a;
545 const bool b_empty = demi_cell_up == b || demi_cell_down == b;
547 if (!a_empty && !b_empty) {
548 pixel.character =
"│";
549 pixel.automerge =
true;
551 pixel.character = a_empty ?
"╷" :
"╵";
552 pixel.automerge =
false;
555 if (demi_cell_up <= a && b <= demi_cell_down) {
556 pixel.foreground_color = selected_color_;
558 pixel.foreground_color = unselected_color_;
565 Color unselected_color_;
566 Color selected_color_;
568 return std::make_shared<Impl>(up,
down, unselected_color, selected_color);
Element separatorStyled(BorderStyle style)
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 separatorLight()
Draw a vertical or horizontal separation in between two other elements, using the LIGHT style.
Element separatorDashed()
Draw a vertical or horizontal separation in between two other elements, using the DASHED style.
Element separator()
Draw a vertical or horizontal separation in between two other elements.
Element separatorCharacter(std::string_view value)
Draw a vertical or horizontal separation in between two other elements.
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.
BorderStyle
BorderStyle is an enumeration that represents the different styles of borders that can be applied to ...
The FTXUI ftxui:: namespace.
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
FTXUI_EXPORT(DOM) Element separatorCharacter(std Element separatorHSelector(float left, float right, Color unselected_color, Color selected_color)
Draw a horizontal bar, with the area in between left/right colored differently.
void Render(Screen &screen, Node *node, Selection &selection)
std::function< void(Cell &)> style_