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_;
136 return std::make_shared<SeparatorAuto>(
LIGHT);
173 return std::make_shared<SeparatorAuto>(style);
209 return std::make_shared<SeparatorAuto>(
LIGHT);
245 return std::make_shared<SeparatorAuto>(
DASHED);
281 return std::make_shared<SeparatorAuto>(
HEAVY);
317 return std::make_shared<SeparatorAuto>(
DOUBLE);
353 return std::make_shared<SeparatorAuto>(
EMPTY);
390 return std::make_shared<Separator>(std::string(
value));
421 return std::make_shared<SeparatorWithCell>(std::move(pixel));
437 Color unselected_color,
438 Color selected_color) {
439 class Impl :
public Node {
441 Impl(
float left,
float right, Color selected_color, Color unselected_color)
444 unselected_color_(unselected_color),
445 selected_color_(selected_color) {}
446 void ComputeRequirement()
override {
447 requirement_.min_x = 1;
448 requirement_.min_y = 1;
451 void Render(Screen& screen)
override {
452 if (box_.y_max < box_.y_min) {
457 int demi_cell_left = int(left_ * 2.F - 1.F);
458 int demi_cell_right = int(right_ * 2.F + 2.F);
460 const int y = box_.y_min;
461 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
462 Cell& pixel = screen.CellAt(x,
y);
464 const int a = (x - box_.x_min) * 2;
466 const bool a_empty = demi_cell_left == a || demi_cell_right == a;
467 const bool b_empty = demi_cell_left == b || demi_cell_right == b;
469 if (!a_empty && !b_empty) {
470 pixel.character =
"─";
471 pixel.automerge =
true;
473 pixel.character = a_empty ?
"╶" :
"╴";
474 pixel.automerge =
false;
477 if (demi_cell_left <= a && b <= demi_cell_right) {
478 pixel.foreground_color = selected_color_;
480 pixel.foreground_color = unselected_color_;
487 Color unselected_color_;
488 Color selected_color_;
490 return std::make_shared<Impl>(
left,
right, unselected_color, selected_color);
506 Color unselected_color,
507 Color selected_color) {
508 class Impl :
public Node {
510 Impl(
float up,
float down, Color unselected_color, Color selected_color)
513 unselected_color_(unselected_color),
514 selected_color_(selected_color) {}
515 void ComputeRequirement()
override {
516 requirement_.min_x = 1;
517 requirement_.min_y = 1;
520 void Render(Screen& screen)
override {
521 if (box_.x_max < box_.x_min) {
526 const int demi_cell_up = int(up_ * 2 - 1);
527 const int demi_cell_down = int(down_ * 2 + 2);
529 const int x = box_.x_min;
530 for (
int y = box_.y_min;
y <= box_.y_max; ++
y) {
531 Cell& pixel = screen.CellAt(x,
y);
533 const int a = (
y - box_.y_min) * 2;
535 const bool a_empty = demi_cell_up == a || demi_cell_down == a;
536 const bool b_empty = demi_cell_up == b || demi_cell_down == b;
538 if (!a_empty && !b_empty) {
539 pixel.character =
"│";
540 pixel.automerge =
true;
542 pixel.character = a_empty ?
"╷" :
"╵";
543 pixel.automerge =
false;
546 if (demi_cell_up <= a && b <= demi_cell_down) {
547 pixel.foreground_color = selected_color_;
549 pixel.foreground_color = unselected_color_;
556 Color unselected_color_;
557 Color selected_color_;
559 return std::make_shared<Impl>(up,
down, unselected_color, selected_color);
Element separatorStyled(BorderStyle style)
在兩個元素之間繪製垂直或水平分隔線。
Element separatorEmpty()
使用 EMPTY 樣式在兩個元素之間繪製垂直或水平分隔線。
Element separatorLight()
使用 LIGHT 樣式在兩個元素之間繪製垂直或水平分隔線。
BorderStyle
BorderStyle 是一個列舉,表示可以應用於終端機 UI 元素的不同邊框樣式。
Element separatorDashed()
使用 DASHED 樣式在兩個元素之間繪製垂直或水平分隔線。
Element separator()
在兩個元素之間繪製垂直或水平分隔線。
Element separatorCharacter(std::string_view value)
在兩個元素之間繪製垂直或水平分隔線。
Element separatorDouble()
使用 DOUBLE 樣式在兩個元素之間繪製垂直或水平分隔線。
Element separatorHeavy()
使用 HEAVY 樣式在兩個元素之間繪製垂直或水平分隔線。
Element separatorVSelector(float up, float down, Color unselected_color, Color selected_color)
繪製一個垂直條,其中上方/下方之間的區域以不同顏色顯示。
std::shared_ptr< Node > Element
FTXUI_EXPORT(DOM) Element separatorCharacter(std Element separatorHSelector(float left, float right, Color unselected_color, Color selected_color)
繪製一個水平條,其中左右兩側之間的區域以不同顏色顯示。
void Render(Screen &screen, Node *node, Selection &selection)
std::function< void(Cell &)> style_