20using Charset = std::array<std::string, 2>;
21using Charsets = std::array<Charset, 6>;
23const Charsets charsets = {
32class Separator :
public Node {
34 explicit Separator(std::string value) :
value_(std::move(value)) {}
36 void ComputeRequirement()
override {
37 requirement_.min_x = 1;
38 requirement_.min_y = 1;
41 void Render(Screen& screen)
override {
42 for (
int y = box_.y_min; y <= box_.y_max; ++y) {
43 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
44 Pixel& pixel = screen.PixelAt(x, y);
46 pixel.automerge =
true;
54class SeparatorAuto :
public Node {
58 void ComputeRequirement()
override {
59 requirement_.min_x = 1;
60 requirement_.min_y = 1;
63 void Render(Screen& screen)
override {
64 const bool is_column = (box_.x_max == box_.x_min);
65 const bool is_line = (box_.y_min == box_.y_max);
68 charsets[
style_][int(is_line && !is_column)];
70 for (
int y = box_.y_min; y <= box_.y_max; ++y) {
71 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
72 Pixel& pixel = screen.PixelAt(x, y);
74 pixel.automerge =
true;
82class SeparatorWithPixel :
public SeparatorAuto {
84 explicit SeparatorWithPixel(Pixel pixel)
85 : SeparatorAuto(
LIGHT), pixel_(std::move(pixel)) {
86 pixel_.automerge =
true;
88 void Render(Screen& screen)
override {
89 for (
int y = box_.y_min; y <= box_.y_max; ++y) {
90 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
91 screen.PixelAt(x, y) = pixel_;
134 return std::make_shared<SeparatorAuto>(
LIGHT);
171 return std::make_shared<SeparatorAuto>(style);
207 return std::make_shared<SeparatorAuto>(
LIGHT);
243 return std::make_shared<SeparatorAuto>(
DASHED);
279 return std::make_shared<SeparatorAuto>(
HEAVY);
315 return std::make_shared<SeparatorAuto>(
DOUBLE);
351 return std::make_shared<SeparatorAuto>(
EMPTY);
388 return std::make_shared<Separator>(std::move(value));
419 return std::make_shared<SeparatorWithPixel>(std::move(pixel));
435 Color unselected_color,
436 Color selected_color) {
437 class Impl :
public Node {
442 unselected_color_(unselected_color),
443 selected_color_(selected_color) {}
444 void ComputeRequirement()
override {
445 requirement_.min_x = 1;
446 requirement_.min_y = 1;
450 if (box_.y_max < box_.y_min) {
455 int demi_cell_left = int(left_ * 2.F - 1.F);
456 int demi_cell_right = int(right_ * 2.F + 2.F);
458 const int y = box_.y_min;
459 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
462 const int a = (x - box_.x_min) * 2;
464 const bool a_empty = demi_cell_left == a || demi_cell_right == a;
465 const bool b_empty = demi_cell_left == b || demi_cell_right == b;
467 if (!a_empty && !b_empty) {
475 if (demi_cell_left <= a && b <= demi_cell_right) {
485 Color unselected_color_;
486 Color selected_color_;
488 return std::make_shared<Impl>(
left,
right, unselected_color, selected_color);
504 Color unselected_color,
505 Color selected_color) {
506 class Impl :
public Node {
508 Impl(
float up,
float down,
Color unselected_color,
Color selected_color)
511 unselected_color_(unselected_color),
512 selected_color_(selected_color) {}
513 void ComputeRequirement()
override {
514 requirement_.min_x = 1;
515 requirement_.min_y = 1;
519 if (box_.x_max < box_.x_min) {
524 const int demi_cell_up = int(up_ * 2 - 1);
525 const int demi_cell_down = int(down_ * 2 + 2);
527 const int x = box_.x_min;
528 for (
int y = box_.y_min; y <= box_.y_max; ++y) {
531 const int a = (y - box_.y_min) * 2;
533 const bool a_empty = demi_cell_up == a || demi_cell_down == a;
534 const bool b_empty = demi_cell_up == b || demi_cell_down == b;
536 if (!a_empty && !b_empty) {
544 if (demi_cell_up <= a && b <= demi_cell_down) {
554 Color unselected_color_;
555 Color selected_color_;
557 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)。
Color 是一個在終端使用者介面中表示顏色的類別。
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)
繪製一個水平條,其中左右兩側之間的區域以不同顏色顯示。
void Render(Screen &screen, const Element &element)
std::function< void(Pixel &)> style_