16using Charset = std::array<std::string, 2>;
17using Charsets = std::array<Charset, 5>;
29class Separator :
public Node {
31 explicit Separator(std::string value) : value_(std::move(value)) {}
33 void ComputeRequirement()
override {
38 void Render(Screen& screen)
override {
41 Pixel& pixel = screen.PixelAt(x, y);
42 pixel.character = value_;
43 pixel.automerge =
true;
51class SeparatorAuto :
public Node {
53 explicit SeparatorAuto(
BorderStyle style) : style_(style) {}
55 void ComputeRequirement()
override {
60 void Render(Screen& screen)
override {
64 const std::string c = charsets[style_][int(is_line && !is_column)];
68 Pixel& pixel = screen.PixelAt(x, y);
70 pixel.automerge =
true;
78class SeparatorWithPixel :
public SeparatorAuto {
80 explicit SeparatorWithPixel(Pixel pixel)
81 : SeparatorAuto(
LIGHT), pixel_(std::move(pixel)) {
84 void Render(Screen& screen)
override {
87 screen.PixelAt(x, y) = pixel_;
129 return std::make_shared<SeparatorAuto>(
LIGHT);
166 return std::make_shared<SeparatorAuto>(style);
202 return std::make_shared<SeparatorAuto>(
LIGHT);
238 return std::make_shared<SeparatorAuto>(
HEAVY);
274 return std::make_shared<SeparatorAuto>(
DOUBLE);
310 return std::make_shared<SeparatorAuto>(
EMPTY);
347 return std::make_shared<Separator>(std::move(value));
377 return std::make_shared<SeparatorWithPixel>(std::move(pixel));
394 Color unselected_color,
395 Color selected_color) {
396 class Impl :
public Node {
398 Impl(
float left,
float right,
Color selected_color,
Color unselected_color)
401 unselected_color_(unselected_color),
402 selected_color_(selected_color) {}
403 void ComputeRequirement()
override {
404 requirement_.min_x = 1;
405 requirement_.min_y = 1;
409 if (box_.y_max < box_.y_min) {
414 int demi_cell_left = int(left_ * 2.F - 1.F);
415 int demi_cell_right = int(right_ * 2.F + 2.F);
417 const int y = box_.y_min;
418 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
421 const int a = (x - box_.x_min) * 2;
423 const bool a_empty = demi_cell_left == a || demi_cell_right == a;
424 const bool b_empty = demi_cell_left == b || demi_cell_right == b;
426 if (!a_empty && !b_empty) {
434 if (demi_cell_left <= a && b <= demi_cell_right) {
444 Color unselected_color_;
445 Color selected_color_;
447 return std::make_shared<Impl>(left, right, unselected_color, selected_color);
464 Color unselected_color,
465 Color selected_color) {
466 class Impl :
public Node {
468 Impl(
float up,
float down,
Color unselected_color,
Color selected_color)
471 unselected_color_(unselected_color),
472 selected_color_(selected_color) {}
473 void ComputeRequirement()
override {
474 requirement_.min_x = 1;
475 requirement_.min_y = 1;
479 if (box_.x_max < box_.x_min) {
484 const int demi_cell_up = int(up_ * 2 - 1);
485 const int demi_cell_down = int(down_ * 2 + 2);
487 const int x = box_.x_min;
488 for (
int y = box_.y_min; y <= box_.y_max; ++y) {
491 const int a = (y - box_.y_min) * 2;
493 const bool a_empty = demi_cell_up == a || demi_cell_down == a;
494 const bool b_empty = demi_cell_up == b || demi_cell_down == b;
496 if (!a_empty && !b_empty) {
504 if (demi_cell_up <= a && b <= demi_cell_down) {
514 Color unselected_color_;
515 Color selected_color_;
517 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, 5 > 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.