mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-22 18:59:59 +08:00
Fix automerge in tables. (#333)
This commit is contained in:
parent
9c4218c2a8
commit
5da7b8a59a
@ -17,6 +17,9 @@ Element gaugeUp(float ratio);
|
|||||||
Element gaugeDown(float ratio);
|
Element gaugeDown(float ratio);
|
||||||
Element gaugeDirection(float ratio, GaugeDirection);
|
Element gaugeDirection(float ratio, GaugeDirection);
|
||||||
```
|
```
|
||||||
|
- Add the `automerge` decorator. This makes separator characters to be merged
|
||||||
|
with others nearby.
|
||||||
|
- Fix the `Table` rendering function, to allow automerging characters.
|
||||||
|
|
||||||
#### Component
|
#### Component
|
||||||
- Support SIGTSTP. (ctrl+z).
|
- Support SIGTSTP. (ctrl+z).
|
||||||
|
@ -44,6 +44,7 @@ add_library(dom
|
|||||||
include/ftxui/dom/node.hpp
|
include/ftxui/dom/node.hpp
|
||||||
include/ftxui/dom/requirement.hpp
|
include/ftxui/dom/requirement.hpp
|
||||||
include/ftxui/dom/take_any_args.hpp
|
include/ftxui/dom/take_any_args.hpp
|
||||||
|
src/ftxui/dom/automerge.cpp
|
||||||
src/ftxui/dom/blink.cpp
|
src/ftxui/dom/blink.cpp
|
||||||
src/ftxui/dom/bold.cpp
|
src/ftxui/dom/bold.cpp
|
||||||
src/ftxui/dom/border.cpp
|
src/ftxui/dom/border.cpp
|
||||||
|
@ -81,6 +81,7 @@ Element color(Color, Element);
|
|||||||
Element bgcolor(Color, Element);
|
Element bgcolor(Color, Element);
|
||||||
Decorator focusPosition(int x, int y);
|
Decorator focusPosition(int x, int y);
|
||||||
Decorator focusPositionRelative(float x, float y);
|
Decorator focusPositionRelative(float x, float y);
|
||||||
|
Element automerge(Element);
|
||||||
|
|
||||||
// --- Layout is
|
// --- Layout is
|
||||||
// Horizontal, Vertical or stacked set of elements.
|
// Horizontal, Vertical or stacked set of elements.
|
||||||
|
@ -17,8 +17,8 @@ Component Dropdown(ConstStringListRef entries, int* selected) {
|
|||||||
Impl(ConstStringListRef entries, int* selected)
|
Impl(ConstStringListRef entries, int* selected)
|
||||||
: entries_(std::move(entries)), selected_(selected) {
|
: entries_(std::move(entries)), selected_(selected) {
|
||||||
CheckboxOption option;
|
CheckboxOption option;
|
||||||
option.style_checked = "↓│";
|
option.style_checked = "↓ ";
|
||||||
option.style_unchecked = "→│";
|
option.style_unchecked = "→ ";
|
||||||
checkbox_ = Checkbox(&title_, &show_, option),
|
checkbox_ = Checkbox(&title_, &show_, option),
|
||||||
radiobox_ = Radiobox(entries_, selected_);
|
radiobox_ = Radiobox(entries_, selected_);
|
||||||
|
|
||||||
|
36
src/ftxui/dom/automerge.cpp
Normal file
36
src/ftxui/dom/automerge.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include <memory> // for make_shared
|
||||||
|
#include <utility> // for move
|
||||||
|
|
||||||
|
#include "ftxui/dom/elements.hpp" // for Element, automerge
|
||||||
|
#include "ftxui/dom/node.hpp" // for Node
|
||||||
|
#include "ftxui/dom/node_decorator.hpp" // for NodeDecorator
|
||||||
|
#include "ftxui/screen/box.hpp" // for Box
|
||||||
|
#include "ftxui/screen/screen.hpp" // for Pixel, Screen
|
||||||
|
|
||||||
|
namespace ftxui {
|
||||||
|
|
||||||
|
/// @brief Enable character to be automatically merged with others nearby.
|
||||||
|
/// @ingroup dom
|
||||||
|
Element automerge(Element child) {
|
||||||
|
class Impl : public NodeDecorator {
|
||||||
|
public:
|
||||||
|
using NodeDecorator::NodeDecorator;
|
||||||
|
|
||||||
|
void Render(Screen& screen) override {
|
||||||
|
for (int y = box_.y_min; y <= box_.y_max; ++y) {
|
||||||
|
for (int x = box_.x_min; x <= box_.x_max; ++x) {
|
||||||
|
screen.PixelAt(x, y).automerge = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Node::Render(screen);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return std::make_shared<Impl>(std::move(child));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ftxui
|
||||||
|
|
||||||
|
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
||||||
|
// Use of this source code is governed by the MIT license that can be found in
|
||||||
|
// the LICENSE file.
|
@ -250,10 +250,10 @@ void TableSelection::Border(BorderStyle style) {
|
|||||||
BorderTop(style);
|
BorderTop(style);
|
||||||
BorderBottom(style);
|
BorderBottom(style);
|
||||||
|
|
||||||
table_->elements_[y_min_][x_min_] = text(charset[style][0]);
|
table_->elements_[y_min_][x_min_] = text(charset[style][0]) | automerge;
|
||||||
table_->elements_[y_min_][x_max_] = text(charset[style][1]);
|
table_->elements_[y_min_][x_max_] = text(charset[style][1]) | automerge;
|
||||||
table_->elements_[y_max_][x_min_] = text(charset[style][2]);
|
table_->elements_[y_max_][x_min_] = text(charset[style][2]) | automerge;
|
||||||
table_->elements_[y_max_][x_max_] = text(charset[style][3]);
|
table_->elements_[y_max_][x_max_] = text(charset[style][3]) | automerge;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableSelection::Separator(BorderStyle style) {
|
void TableSelection::Separator(BorderStyle style) {
|
||||||
@ -261,8 +261,8 @@ void TableSelection::Separator(BorderStyle style) {
|
|||||||
for (int x = x_min_ + 1; x <= x_max_ - 1; ++x) {
|
for (int x = x_min_ + 1; x <= x_max_ - 1; ++x) {
|
||||||
if (y % 2 == 0 || x % 2 == 0) {
|
if (y % 2 == 0 || x % 2 == 0) {
|
||||||
Element& e = table_->elements_[y][x];
|
Element& e = table_->elements_[y][x];
|
||||||
e = (y % 2) ? separatorCharacter(charset[style][5])
|
e = (y % 2) ? separatorCharacter(charset[style][5]) | automerge
|
||||||
: separatorCharacter(charset[style][4]);
|
: separatorCharacter(charset[style][4]) | automerge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -272,7 +272,8 @@ void TableSelection::SeparatorVertical(BorderStyle style) {
|
|||||||
for (int y = y_min_ + 1; y <= y_max_ - 1; ++y) {
|
for (int y = y_min_ + 1; y <= y_max_ - 1; ++y) {
|
||||||
for (int x = x_min_ + 1; x <= x_max_ - 1; ++x) {
|
for (int x = x_min_ + 1; x <= x_max_ - 1; ++x) {
|
||||||
if (x % 2 == 0) {
|
if (x % 2 == 0) {
|
||||||
table_->elements_[y][x] = separatorCharacter(charset[style][5]);
|
table_->elements_[y][x] =
|
||||||
|
separatorCharacter(charset[style][5]) | automerge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -282,30 +283,39 @@ void TableSelection::SeparatorHorizontal(BorderStyle style) {
|
|||||||
for (int y = y_min_ + 1; y <= y_max_ - 1; ++y) {
|
for (int y = y_min_ + 1; y <= y_max_ - 1; ++y) {
|
||||||
for (int x = x_min_ + 1; x <= x_max_ - 1; ++x) {
|
for (int x = x_min_ + 1; x <= x_max_ - 1; ++x) {
|
||||||
if (y % 2 == 0) {
|
if (y % 2 == 0) {
|
||||||
table_->elements_[y][x] = separatorCharacter(charset[style][4]);
|
table_->elements_[y][x] =
|
||||||
|
separatorCharacter(charset[style][4]) | automerge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableSelection::BorderLeft(BorderStyle style) {
|
void TableSelection::BorderLeft(BorderStyle style) {
|
||||||
for (int y = y_min_; y <= y_max_; y++)
|
for (int y = y_min_; y <= y_max_; y++) {
|
||||||
table_->elements_[y][x_min_] = separatorCharacter(charset[style][5]);
|
table_->elements_[y][x_min_] =
|
||||||
|
separatorCharacter(charset[style][5]) | automerge;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableSelection::BorderRight(BorderStyle style) {
|
void TableSelection::BorderRight(BorderStyle style) {
|
||||||
for (int y = y_min_; y <= y_max_; y++)
|
for (int y = y_min_; y <= y_max_; y++) {
|
||||||
table_->elements_[y][x_max_] = separatorCharacter(charset[style][5]);
|
table_->elements_[y][x_max_] =
|
||||||
|
separatorCharacter(charset[style][5]) | automerge;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableSelection::BorderTop(BorderStyle style) {
|
void TableSelection::BorderTop(BorderStyle style) {
|
||||||
for (int x = x_min_; x <= x_max_; x++)
|
for (int x = x_min_; x <= x_max_; x++) {
|
||||||
table_->elements_[y_min_][x] = separatorCharacter(charset[style][4]);
|
table_->elements_[y_min_][x] =
|
||||||
|
separatorCharacter(charset[style][4]) | automerge;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableSelection::BorderBottom(BorderStyle style) {
|
void TableSelection::BorderBottom(BorderStyle style) {
|
||||||
for (int x = x_min_; x <= x_max_; x++)
|
for (int x = x_min_; x <= x_max_; x++) {
|
||||||
table_->elements_[y_max_][x] = separatorCharacter(charset[style][4]);
|
table_->elements_[y_max_][x] =
|
||||||
|
separatorCharacter(charset[style][4]) | automerge;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ftxui
|
} // namespace ftxui
|
||||||
|
Loading…
Reference in New Issue
Block a user