18using Charset = std::array<std::string, 2>;
19using Charsets = std::array<Charset, 5>;
31class Separator :
public Node {
33 explicit Separator(std::string value) : value_(std::move(value)) {}
35 void ComputeRequirement()
override {
40 void Render(Screen& screen)
override {
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 {
62 void Render(Screen& screen)
override {
66 const std::string c = charsets[style_][int(is_line && !is_column)];
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)) {
86 void Render(Screen& screen)
override {
89 screen.PixelAt(x, y) = pixel_;
131 return std::make_shared<SeparatorAuto>(
LIGHT);
168 return std::make_shared<SeparatorAuto>(style);
204 return std::make_shared<SeparatorAuto>(
LIGHT);
240 return std::make_shared<SeparatorAuto>(
HEAVY);
276 return std::make_shared<SeparatorAuto>(
DOUBLE);
312 return std::make_shared<SeparatorAuto>(
EMPTY);
349 return std::make_shared<Separator>(std::move(value));
379 return std::make_shared<SeparatorWithPixel>(std::move(pixel));
396 Color unselected_color,
397 Color selected_color) {
398 class Impl :
public Node {
400 Impl(
float left,
float right,
Color selected_color,
Color unselected_color)
403 unselected_color_(unselected_color),
404 selected_color_(selected_color) {}
405 void ComputeRequirement()
override {
406 requirement_.min_x = 1;
407 requirement_.min_y = 1;
411 if (box_.y_max < box_.y_min) {
416 int demi_cell_left = int(left_ * 2.F - 1.F);
417 int demi_cell_right = int(right_ * 2.F + 2.F);
420 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
423 int a = (x - box_.x_min) * 2;
425 bool a_empty = demi_cell_left == a || demi_cell_right == a;
426 bool b_empty = demi_cell_left == b || demi_cell_right == b;
428 if (!a_empty && !b_empty) {
436 if (demi_cell_left <= a && b <= demi_cell_right) {
446 Color unselected_color_;
447 Color selected_color_;
449 return std::make_shared<Impl>(left, right, unselected_color, selected_color);
466 Color unselected_color,
467 Color selected_color) {
468 class Impl :
public Node {
470 Impl(
float up,
float down,
Color unselected_color,
Color selected_color)
473 unselected_color_(unselected_color),
474 selected_color_(selected_color) {}
475 void ComputeRequirement()
override {
476 requirement_.min_x = 1;
477 requirement_.min_y = 1;
481 if (box_.x_max < box_.x_min) {
486 int demi_cell_up = int(up_ * 2 - 1);
487 int demi_cell_down = int(down_ * 2 + 2);
490 for (
int y = box_.y_min; y <= box_.y_max; ++y) {
493 int a = (y - box_.y_min) * 2;
495 bool a_empty = demi_cell_up == a || demi_cell_down == a;
496 bool b_empty = demi_cell_up == b || demi_cell_down == b;
498 if (!a_empty && !b_empty) {
506 if (demi_cell_up <= a && b <= demi_cell_down) {
516 Color unselected_color_;
517 Color selected_color_;
519 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 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.