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_;
127 return std::make_shared<SeparatorAuto>(
LIGHT);
155 return std::make_shared<SeparatorAuto>(style);
182 return std::make_shared<SeparatorAuto>(
LIGHT);
209 return std::make_shared<SeparatorAuto>(
DASHED);
236 return std::make_shared<SeparatorAuto>(
HEAVY);
263 return std::make_shared<SeparatorAuto>(
DOUBLE);
299 return std::make_shared<SeparatorAuto>(
EMPTY);
335 return std::make_shared<Separator>(std::string(
value));
366 return std::make_shared<SeparatorWithCell>(std::move(pixel));
382 Color unselected_color,
383 Color selected_color) {
384 class Impl :
public Node {
386 Impl(
float left,
float right, Color selected_color, Color unselected_color)
389 unselected_color_(unselected_color),
390 selected_color_(selected_color) {}
391 void ComputeRequirement()
override {
392 requirement_.min_x = 1;
393 requirement_.min_y = 1;
396 void Render(Screen& screen)
override {
397 if (box_.y_max < box_.y_min) {
402 int demi_cell_left = int(left_ * 2.F - 1.F);
403 int demi_cell_right = int(right_ * 2.F + 2.F);
405 const int y = box_.y_min;
406 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
407 Cell& pixel = screen.CellAt(x, y);
409 const int a = (x - box_.x_min) * 2;
411 const bool a_empty = demi_cell_left == a || demi_cell_right == a;
412 const bool b_empty = demi_cell_left == b || demi_cell_right == b;
414 if (!a_empty && !b_empty) {
415 pixel.character =
"─";
416 pixel.automerge =
true;
418 pixel.character = a_empty ?
"╶" :
"╴";
419 pixel.automerge =
false;
422 if (demi_cell_left <= a && b <= demi_cell_right) {
423 pixel.foreground_color = selected_color_;
425 pixel.foreground_color = unselected_color_;
432 Color unselected_color_;
433 Color selected_color_;
435 return std::make_shared<Impl>(
left,
right, unselected_color, selected_color);
451 Color unselected_color,
452 Color selected_color) {
453 class Impl :
public Node {
455 Impl(
float up,
float down, Color unselected_color, Color selected_color)
458 unselected_color_(unselected_color),
459 selected_color_(selected_color) {}
460 void ComputeRequirement()
override {
461 requirement_.min_x = 1;
462 requirement_.min_y = 1;
465 void Render(Screen& screen)
override {
466 if (box_.x_max < box_.x_min) {
471 const int demi_cell_up = int(up_ * 2 - 1);
472 const int demi_cell_down = int(down_ * 2 + 2);
474 const int x = box_.x_min;
475 for (
int y = box_.y_min; y <= box_.y_max; ++y) {
476 Cell& pixel = screen.CellAt(x, y);
478 const int a = (
y - box_.y_min) * 2;
480 const bool a_empty = demi_cell_up == a || demi_cell_down == a;
481 const bool b_empty = demi_cell_up == b || demi_cell_down == b;
483 if (!a_empty && !b_empty) {
484 pixel.character =
"│";
485 pixel.automerge =
true;
487 pixel.character = a_empty ?
"╷" :
"╵";
488 pixel.automerge =
false;
491 if (demi_cell_up <= a && b <= demi_cell_down) {
492 pixel.foreground_color = selected_color_;
494 pixel.foreground_color = unselected_color_;
501 Color unselected_color_;
502 Color selected_color_;
504 return std::make_shared<Impl>(up,
down, unselected_color, selected_color);
Element separatorStyled(BorderStyle style)
他の2つの要素の間に垂直または水平の区切り線を描画します。
Element separatorEmpty()
他の2つの要素の間にEMPTYスタイルで垂直または水平の区切り線を描画します。
BorderStyle
BorderStyleは、ターミナルUIの要素に適用できる様々なボーダースタイルを表す列挙型です。
Element separatorDashed()
他の2つの要素の間にLIGHTスタイルで垂直または水平の区切り線を描画します。
Element separatorDouble()
他の2つの要素の間にHEAVYスタイルで垂直または水平の区切り線を描画します。
Element separatorVSelector(float up, float down, Color unselected_color, Color selected_color)
std::shared_ptr< Node > Element
void Render(Screen &screen, Node *node, Selection &selection)
FTXUI_EXPORT(DOM) Element separatorCharacter(std Element separatorHSelector(float left, float right, Color unselected_color, Color selected_color)
std::function< void(Cell &)> style_