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);
45 pixel.automerge =
true;
53class SeparatorAuto :
public Node {
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);
67 charsets[
style_][int(is_line && !is_column)];
69 for (
int y = box_.y_min; y <= box_.y_max; ++y) {
70 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
71 Pixel& pixel = screen.PixelAt(x, y);
73 pixel.automerge =
true;
81class SeparatorWithPixel :
public SeparatorAuto {
83 explicit SeparatorWithPixel(Pixel pixel)
84 : SeparatorAuto(
LIGHT), pixel_(std::move(pixel)) {
85 pixel_.automerge =
true;
87 void Render(Screen& screen)
override {
88 for (
int y = box_.y_min; y <= box_.y_max; ++y) {
89 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
90 screen.PixelAt(x, y) = pixel_;
133 return std::make_shared<SeparatorAuto>(
LIGHT);
170 return std::make_shared<SeparatorAuto>(style);
206 return std::make_shared<SeparatorAuto>(
LIGHT);
242 return std::make_shared<SeparatorAuto>(
DASHED);
278 return std::make_shared<SeparatorAuto>(
HEAVY);
314 return std::make_shared<SeparatorAuto>(
DOUBLE);
350 return std::make_shared<SeparatorAuto>(
EMPTY);
387 return std::make_shared<Separator>(std::move(value));
418 return std::make_shared<SeparatorWithPixel>(std::move(pixel));
434 Color unselected_color,
435 Color selected_color) {
436 class Impl :
public Node {
441 unselected_color_(unselected_color),
442 selected_color_(selected_color) {}
443 void ComputeRequirement()
override {
444 requirement_.min_x = 1;
445 requirement_.min_y = 1;
448 void Render(
Screen& screen)
override {
449 if (box_.y_max < box_.y_min) {
454 int demi_cell_left = int(left_ * 2.F - 1.F);
455 int demi_cell_right = int(right_ * 2.F + 2.F);
457 const int y = box_.y_min;
458 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
461 const int a = (x - box_.x_min) * 2;
463 const bool a_empty = demi_cell_left == a || demi_cell_right == a;
464 const bool b_empty = demi_cell_left == b || demi_cell_right == b;
466 if (!a_empty && !b_empty) {
474 if (demi_cell_left <= a && b <= demi_cell_right) {
484 Color unselected_color_;
485 Color selected_color_;
487 return std::make_shared<Impl>(
left,
right, unselected_color, selected_color);
503 Color unselected_color,
504 Color selected_color) {
505 class Impl :
public Node {
507 Impl(
float up,
float down,
Color unselected_color,
Color selected_color)
510 unselected_color_(unselected_color),
511 selected_color_(selected_color) {}
512 void ComputeRequirement()
override {
513 requirement_.min_x = 1;
514 requirement_.min_y = 1;
517 void Render(
Screen& screen)
override {
518 if (box_.x_max < box_.x_min) {
523 const int demi_cell_up = int(up_ * 2 - 1);
524 const int demi_cell_down = int(down_ * 2 + 2);
526 const int x = box_.x_min;
527 for (
int y = box_.y_min; y <= box_.y_max; ++y) {
530 const int a = (y - box_.y_min) * 2;
532 const bool a_empty = demi_cell_up == a || demi_cell_down == a;
533 const bool b_empty = demi_cell_up == b || demi_cell_down == b;
535 if (!a_empty && !b_empty) {
543 if (demi_cell_up <= a && b <= demi_cell_down) {
553 Color unselected_color_;
554 Color selected_color_;
556 return std::make_shared<Impl>(up,
down, unselected_color, selected_color);
Element separatorStyled(BorderStyle)
在两个其他元素之间绘制垂直或水平分隔线。
Element separatorEmpty()
使用 EMPTY 样式在两个其他元素之间绘制垂直或水平分隔线。
Element separatorLight()
使用 LIGHT 样式在两个其他元素之间绘制垂直或水平分隔线。
Element separatorDashed()
使用 DASHED 样式在两个其他元素之间绘制垂直或水平分隔线。
Element separatorCharacter(std::string)
在两个其他元素之间绘制垂直或水平分隔线。
Element separator()
在两个其他元素之间绘制垂直或水平分隔线。
void Render(Screen &screen, const Element &element)
在 ftxui::Screen 上显示元素。
Element separatorDouble()
使用 DOUBLE 样式在两个其他元素之间绘制垂直或水平分隔线。
Element separatorHeavy()
使用 HEAVY 样式在两个其他元素之间绘制垂直或水平分隔线。
BorderStyle
BorderStyle 是一个枚举,表示可应用于终端 UI 中元素的不同边框样式。
Pixel & PixelAt(int x, int y)
访问给定位置的单元格 (Pixel)。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
Element separatorVSelector(float up, float down, Color unselected_color, Color selected_color)
绘制一个垂直条,上下区域颜色不同。
std::shared_ptr< Node > Element
Element separatorHSelector(float left, float right, Color unselected_color, Color selected_color)
绘制一个水平条,左右区域颜色不同。
std::function< void(Pixel &)> style_