21using SeparatorCharset = std::array<std::string, 2>;
22using SeparatorCharsets = std::array<SeparatorCharset, 6>;
24const SeparatorCharsets charsets = {
26 SeparatorCharset{
"│",
"─"},
27 SeparatorCharset{
"╏",
"╍"},
28 SeparatorCharset{
"┃",
"━"},
29 SeparatorCharset{
"║",
"═"},
30 SeparatorCharset{
"│",
"─"},
31 SeparatorCharset{
" ",
" "},
34class Separator :
public Node {
38 void ComputeRequirement()
override {
39 requirement_.min_x = 1;
40 requirement_.min_y = 1;
43 void Render(Screen& screen)
override {
44 for (
int y = box_.y_min;
y <= box_.y_max; ++
y) {
45 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
46 Cell& pixel = screen.CellAt(x,
y);
48 pixel.automerge =
true;
56class SeparatorAuto :
public Node {
60 void ComputeRequirement()
override {
61 requirement_.min_x = 1;
62 requirement_.min_y = 1;
65 void Render(Screen& screen)
override {
66 const bool is_column = (box_.x_max == box_.x_min);
67 const bool is_line = (box_.y_min == box_.y_max);
70 charsets[
style_][int(is_line && !is_column)];
72 for (
int y = box_.y_min;
y <= box_.y_max; ++
y) {
73 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
74 Cell& pixel = screen.CellAt(x,
y);
76 pixel.automerge =
true;
84class SeparatorWithCell :
public SeparatorAuto {
86 explicit SeparatorWithCell(Cell pixel)
87 : SeparatorAuto(
LIGHT), pixel_(std::move(pixel)) {
88 pixel_.automerge =
true;
90 void Render(Screen& screen)
override {
91 for (
int y = box_.y_min;
y <= box_.y_max; ++
y) {
92 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
93 screen.CellAt(x,
y) = pixel_;
137 return std::make_shared<SeparatorAuto>(
LIGHT);
175 return std::make_shared<SeparatorAuto>(style);
212 return std::make_shared<SeparatorAuto>(
LIGHT);
249 return std::make_shared<SeparatorAuto>(
DASHED);
286 return std::make_shared<SeparatorAuto>(
HEAVY);
323 return std::make_shared<SeparatorAuto>(
DOUBLE);
360 return std::make_shared<SeparatorAuto>(
EMPTY);
398 return std::make_shared<Separator>(std::string(
value));
429 return std::make_shared<SeparatorWithCell>(std::move(pixel));
446 Color unselected_color,
447 Color selected_color) {
448 class Impl :
public Node {
450 Impl(
float left,
float right, Color selected_color, Color unselected_color)
453 unselected_color_(unselected_color),
454 selected_color_(selected_color) {}
455 void ComputeRequirement()
override {
456 requirement_.min_x = 1;
457 requirement_.min_y = 1;
460 void Render(Screen& screen)
override {
461 if (box_.y_max < box_.y_min) {
466 int demi_cell_left = int(left_ * 2.F - 1.F);
467 int demi_cell_right = int(right_ * 2.F + 2.F);
469 const int y = box_.y_min;
470 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
471 Cell& pixel = screen.CellAt(x,
y);
473 const int a = (x - box_.x_min) * 2;
475 const bool a_empty = demi_cell_left == a || demi_cell_right == a;
476 const bool b_empty = demi_cell_left == b || demi_cell_right == b;
478 if (!a_empty && !b_empty) {
479 pixel.character =
"─";
480 pixel.automerge =
true;
482 pixel.character = a_empty ?
"╶" :
"╴";
483 pixel.automerge =
false;
486 if (demi_cell_left <= a && b <= demi_cell_right) {
487 pixel.foreground_color = selected_color_;
489 pixel.foreground_color = unselected_color_;
496 Color unselected_color_;
497 Color selected_color_;
499 return std::make_shared<Impl>(
left,
right, unselected_color, selected_color);
516 Color unselected_color,
517 Color selected_color) {
518 class Impl :
public Node {
520 Impl(
float up,
float down, Color unselected_color, Color selected_color)
523 unselected_color_(unselected_color),
524 selected_color_(selected_color) {}
525 void ComputeRequirement()
override {
526 requirement_.min_x = 1;
527 requirement_.min_y = 1;
530 void Render(Screen& screen)
override {
531 if (box_.x_max < box_.x_min) {
536 const int demi_cell_up = int(up_ * 2 - 1);
537 const int demi_cell_down = int(down_ * 2 + 2);
539 const int x = box_.x_min;
540 for (
int y = box_.y_min;
y <= box_.y_max; ++
y) {
541 Cell& pixel = screen.CellAt(x,
y);
543 const int a = (
y - box_.y_min) * 2;
545 const bool a_empty = demi_cell_up == a || demi_cell_down == a;
546 const bool b_empty = demi_cell_up == b || demi_cell_down == b;
548 if (!a_empty && !b_empty) {
549 pixel.character =
"│";
550 pixel.automerge =
true;
552 pixel.character = a_empty ?
"╷" :
"╵";
553 pixel.automerge =
false;
556 if (demi_cell_up <= a && b <= demi_cell_down) {
557 pixel.foreground_color = selected_color_;
559 pixel.foreground_color = unselected_color_;
566 Color unselected_color_;
567 Color selected_color_;
569 return std::make_shared<Impl>(up,
down, unselected_color, selected_color);
Element separatorStyled(BorderStyle style)
Dessine une séparation verticale ou horizontale entre deux autres éléments.
Element separatorEmpty()
Dessine une séparation verticale ou horizontale entre deux autres éléments, en utilisant le style EMP...
Element separatorLight()
Dessine une séparation verticale ou horizontale entre deux autres éléments, en utilisant le style LIG...
BorderStyle
BorderStyle est une énumération qui représente les différents styles de bordures pouvant être appliqu...
Element separatorDashed()
Dessine une séparation verticale ou horizontale entre deux autres éléments, en utilisant le style DAS...
Element separator()
Dessine une séparation verticale ou horizontale entre deux autres éléments.
Element separatorCharacter(std::string_view value)
Dessine une séparation verticale ou horizontale entre deux autres éléments.
Element separatorDouble()
Dessine une séparation verticale ou horizontale entre deux autres éléments, en utilisant le style DOU...
Element separatorHeavy()
Dessine une séparation verticale ou horizontale entre deux autres éléments, en utilisant le style HEA...
L'espace de noms FTXUI ftxui::
Element separatorVSelector(float up, float down, Color unselected_color, Color selected_color)
Dessine une barre verticale, avec la zone entre le haut et le bas colorée différemment.
std::shared_ptr< Node > Element
FTXUI_EXPORT(DOM) Element separatorCharacter(std Element separatorHSelector(float left, float right, Color unselected_color, Color selected_color)
Dessine une barre horizontale, avec la zone entre la gauche et la droite colorée différemment.
void Render(Screen &screen, Node *node, Selection &selection)
std::function< void(Cell &)> style_