53 {0b00000000, 0b00000001},
54 {0b00000000, 0b00000010},
55 {0b00000000, 0b00000100},
56 {0b00000001, 0b00000000},
59 {0b00000000, 0b00001000},
60 {0b00000000, 0b00010000},
61 {0b00000000, 0b00100000},
62 {0b00000010, 0b00000000},
68 " ",
"▘",
"▖",
"▌",
"▝",
"▀",
"▞",
"▛",
69 "▗",
"▚",
"▄",
"▙",
"▐",
"▜",
"▟",
"█",
74 {
" ", 0b0000}, {
"▘", 0b0001}, {
"▖", 0b0010}, {
"▌", 0b0011},
75 {
"▝", 0b0100}, {
"▀", 0b0101}, {
"▞", 0b0110}, {
"▛", 0b0111},
76 {
"▗", 0b1000}, {
"▚", 0b1001}, {
"▄", 0b1010}, {
"▙", 0b1011},
77 {
"▐", 0b1100}, {
"▜", 0b1101}, {
"▟", 0b1110}, {
"█", 0b1111},
80constexpr auto nostyle = [](Pixel& ) {};
90 storage_(width_ * height_ / 8 ) {}
96 auto it = storage_.find(XY{x, y});
97 return (
it == storage_.end()) ?
Pixel() :
it->second.content;
138 Cell&
cell = storage_[XY{x / 2, y / 4}];
139 if (
cell.type != CellType::kBraille) {
140 cell.content.character =
"⠀";
141 cell.type = CellType::kBraille;
155 Cell&
cell = storage_[XY{x / 2, y / 4}];
156 if (
cell.type != CellType::kBraille) {
157 cell.content.character =
"⠀";
158 cell.type = CellType::kBraille;
173 Cell&
cell = storage_[XY{x / 2, y / 4}];
174 if (
cell.type != CellType::kBraille) {
175 cell.content.character =
"⠀";
176 cell.type = CellType::kBraille;
214 const int dx = std::abs(
x2 -
x1);
215 const int dy = std::abs(
y2 -
y1);
216 const int sx =
x1 <
x2 ? 1 : -1;
217 const int sy =
y1 <
y2 ? 1 : -1;
220 if (!IsIn(
x1,
y1) && !IsIn(
x2,
y2)) {
223 if (
dx +
dx > width_ * height_) {
340 int dx = (1 + 2 * x) *
e2 *
e2;
404 int dx = (1 + 2 * x) *
e2 *
e2;
470 Cell&
cell = storage_[XY{x / 2, y / 2}];
471 if (
cell.type != CellType::kBlock) {
472 cell.content.character =
" ";
473 cell.type = CellType::kBlock;
489 Cell&
cell = storage_[XY{x / 2, y / 4}];
490 if (
cell.type != CellType::kBlock) {
491 cell.content.character =
" ";
492 cell.type = CellType::kBlock;
498 value &= ~(1U <<
bit);
510 Cell&
cell = storage_[XY{x / 2, y / 4}];
511 if (
cell.type != CellType::kBlock) {
512 cell.content.character =
" ";
513 cell.type = CellType::kBlock;
557 const int dx = std::abs(
x2 -
x1);
558 const int dy = std::abs(
y2 -
y1);
559 const int sx =
x1 <
x2 ? 1 : -1;
560 const int sy =
y1 <
y2 ? 1 : -1;
563 if (!IsIn(
x1,
y1) && !IsIn(
x2,
y2)) {
566 if (
dx +
dx > width_ * height_) {
685 int dx = (1 + 2 * x) *
e2 *
e2;
751 int dx = (1 + 2 * x) *
e2 *
e2;
793 const std::string& value,
805 const std::string& value,
812 Cell&
cell = storage_[XY{x / 2, y / 4}];
813 cell.type = CellType::kText;
814 cell.content.character =
it;
824 style(storage_[XY{x / 2, y / 4}].content);
830class CanvasNodeBase :
public Node {
832 CanvasNodeBase() =
default;
836 const int y_max = std::min(
c.height() / 4, box_.y_max - box_.y_min + 1);
837 const int x_max = std::min(
c.width() / 2, box_.x_max - box_.x_min + 1);
838 for (
int y = 0; y < y_max; ++y) {
839 for (
int x = 0; x < x_max; ++x) {
840 screen.PixelAt(box_.x_min + x, box_.y_min + y) =
c.GetPixel(x, y);
845 virtual const Canvas&
canvas() = 0;
853 class Impl :
public CanvasNodeBase {
856 requirement_.min_x = (
canvas_->width() + 1) / 2;
857 requirement_.min_y = (
canvas_->height() + 3) / 4;
862 return std::make_shared<Impl>(
canvas);
870 class Impl :
public CanvasNodeBase {
872 Impl(
int width,
int height, std::function<
void(
Canvas&)>
fn)
873 : width_(width), height_(height),
fn_(std::move(
fn)) {}
875 void ComputeRequirement()
final {
876 requirement_.min_x = (width_ + 1) / 2;
877 requirement_.min_y = (height_ + 3) / 4;
881 const int width = (box_.x_max - box_.x_min + 1) * 2;
882 const int height = (box_.y_max - box_.y_min + 1) * 4;
885 CanvasNodeBase::Render(
screen);
894 return std::make_shared<Impl>(width, height, std::move(
fn));
A class representing terminal colors.
An adapter. Own or reference an immutable object.
A rectangular grid of Pixel.
std::shared_ptr< Node > Element
std::vector< std::string > Utf8ToGlyphs(const std::string &input)
Element canvas(ConstRef< Canvas >)
Produce an element from a Canvas, or a reference to a Canvas.
Component Slider(SliderOption< T > options)
A slider in any direction.
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
Decorator color(Color)
Decorate using a foreground color.
void DrawBlockLine(int x1, int y1, int x2, int y2)
Draw a line made of block characters.
void DrawPointEllipseFilled(int x, int y, int r1, int r2)
Draw a filled ellipse made of braille dots.
void DrawPointLine(int x1, int y1, int x2, int y2)
Draw a line made of braille dots.
void DrawText(int x, int y, const std::string &value)
Draw a piece of text.
std::function< void(Pixel &)> Stylizer
void DrawBlockOn(int x, int y)
Draw a block.
void DrawPointCircleFilled(int x, int y, int radius)
Draw a filled circle made of braille dots.
void DrawPointOn(int x, int y)
Draw a braille dot.
void DrawPointOff(int x, int y)
Erase a braille dot.
Pixel GetPixel(int x, int y) const
Get the content of a cell.
void DrawBlockEllipseFilled(int x1, int y1, int r1, int r2)
Draw a filled ellipse made of block characters.
void DrawPointEllipse(int x, int y, int r1, int r2)
Draw an ellipse made of braille dots.
void DrawPoint(int x, int y, bool value)
Draw a braille dot.
void DrawBlockEllipse(int x1, int y1, int r1, int r2)
Draw an ellipse made of block characters.
void DrawBlockToggle(int x, int y)
Toggle a block. If it is filled, it will be erased. If it is empty, it will be filled.
void DrawBlockCircle(int x1, int y1, int radius)
Draw a circle made of block characters.
void DrawBlockCircleFilled(int x1, int y1, int radius)
Draw a filled circle made of block characters.
void DrawPointCircle(int x, int y, int radius)
Draw a circle made of braille dots.
void DrawBlockOff(int x, int y)
Erase a block.
void DrawBlock(int x, int y, bool value)
Draw a block.
void Style(int x, int y, const Stylizer &style)
Modify a pixel at a given location.
void DrawPointToggle(int x, int y)
Toggle a braille dot. A filled one will be erased, and the other will be drawn.
A unicode character and its associated style.