Skip to content
You are viewing documentation for v3.0.0. Switch to latest (main).

ftxui::Canvas ​

cpp
#include <ftxui/dom/canvas.hpp>

Examples: component/canvas_animated, dom/canvas

Summary ​

SymbolDescription
Stylizer
Canvas
width
height
GetPixelGet the content of a cell.
DrawPointOnDraw a braille dot.
DrawPointOffErase a braille dot.
DrawPointToggleToggle a braille dot. A filled one will be erased, and the other will be drawn.
DrawPointDraw a braille dot.
DrawPointLineDraw a line made of braille dots.
DrawPointCircleDraw a circle made of braille dots.
DrawPointCircleFilledDraw a filled circle made of braille dots.
DrawPointEllipseDraw an ellipse made of braille dots.
DrawPointEllipseFilledDraw a filled ellipse made of braille dots.
DrawBlockOnDraw a block.
DrawBlockOffErase a block.
DrawBlockToggleToggle a block. If it is filled, it will be erased. If it is empty, it will be filled.
DrawBlockDraw a block.
DrawBlockLineDraw a line made of block characters.
DrawBlockCircleDraw a circle made of block characters.
DrawBlockCircleFilledDraw a filled circle made of block characters.
DrawBlockEllipseDraw an ellipse made of block characters.
DrawBlockEllipseFilledDraw a filled ellipse made of block characters.
DrawTextDraw a piece of text.
StyleModify a pixel at a given location.

Public Types ​

Stylizer ​

cpp
using Stylizer = std::function< void(Pixel &)>;

Public Member Functions ​

Canvas ​

cpp
Canvas();

Examples: component/canvas_animated, dom/canvas

Canvas ​

cpp
Canvas(int width, int height);

Constructor.

Parameters:

  • width: the width of the canvas. A cell is a 2x8 braille dot.
  • height: the height of the canvas. A cell is a 2x8 braille dot.

Examples: component/canvas_animated, dom/canvas

width ​

cpp
int width() const;

height ​

cpp
int height() const;

GetPixel ​

cpp
Pixel GetPixel(int x, int y) const;

Get the content of a cell.

Parameters:

  • x: the x coordinate of the cell.
  • y: the y coordinate of the cell.

DrawPointOn ​

cpp
void DrawPointOn(int x, int y);

Draw a braille dot.

Parameters:

  • x: the x coordinate of the dot.
  • y: the y coordinate of the dot.

DrawPointOff ​

cpp
void DrawPointOff(int x, int y);

Erase a braille dot.

Parameters:

  • x: the x coordinate of the dot.
  • y: the y coordinate of the dot.

DrawPointToggle ​

cpp
void DrawPointToggle(int x, int y);

Toggle a braille dot. A filled one will be erased, and the other will be drawn.

Parameters:

  • x: the x coordinate of the dot.
  • y: the y coordinate of the dot.

DrawPoint ​

cpp
void DrawPoint(int x, int y, bool value);

Draw a braille dot.

Parameters:

  • x: the x coordinate of the dot.
  • y: the y coordinate of the dot.
  • value: whether the dot is filled or not.

DrawPoint ​

cpp
void DrawPoint(int x, int y, bool value, const Stylizer & s);

Draw a braille dot.

Parameters:

  • x: the x coordinate of the dot.
  • y: the y coordinate of the dot.
  • value: whether the dot is filled or not.
  • style: the style of the cell.

DrawPoint ​

cpp
void DrawPoint(int x, int y, bool value, const Color & color);

Draw a braille dot.

Parameters:

  • x: the x coordinate of the dot.
  • y: the y coordinate of the dot.
  • value: whether the dot is filled or not.
  • color: the color of the dot.

DrawPointLine ​

cpp
void DrawPointLine(int x1, int y1, int x2, int y2);

Draw a line made of braille dots.

Parameters:

  • x1: the x coordinate of the first dot.
  • y1: the y coordinate of the first dot.
  • x2: the x coordinate of the second dot.
  • y2: the y coordinate of the second dot.

DrawPointLine ​

cpp
void DrawPointLine(int x1, int y1, int x2, int y2, const Stylizer & s);

Draw a line made of braille dots.

Parameters:

  • x1: the x coordinate of the first dot.
  • y1: the y coordinate of the first dot.o
  • x2: the x coordinate of the second dot.
  • y2: the y coordinate of the second dot.
  • style: the style of the line.

DrawPointLine ​

cpp
void DrawPointLine(int x1, int y1, int x2, int y2, const Color & color);

Draw a line made of braille dots.

Parameters:

  • x1: the x coordinate of the first dot.
  • y1: the y coordinate of the first dot.
  • x2: the x coordinate of the second dot.
  • y2: the y coordinate of the second dot.
  • color: the color of the line.

DrawPointCircle ​

cpp
void DrawPointCircle(int x, int y, int radius);

Draw a circle made of braille dots.

Parameters:

  • x: the x coordinate of the center of the circle.
  • y: the y coordinate of the center of the circle.
  • radius: the radius of the circle.

DrawPointCircle ​

cpp
void DrawPointCircle(int x, int y, int radius, const Stylizer & s);

Draw a circle made of braille dots.

Parameters:

  • x: the x coordinate of the center of the circle.
  • y: the y coordinate of the center of the circle.
  • radius: the radius of the circle.
  • style: the style of the circle.

DrawPointCircle ​

cpp
void DrawPointCircle(int x, int y, int radius, const Color & color);

Draw a circle made of braille dots.

Parameters:

  • x: the x coordinate of the center of the circle.
  • y: the y coordinate of the center of the circle.
  • radius: the radius of the circle.
  • color: the color of the circle.

DrawPointCircleFilled ​

cpp
void DrawPointCircleFilled(int x, int y, int radius);

Draw a filled circle made of braille dots.

Parameters:

  • x: the x coordinate of the center of the circle.
  • y: the y coordinate of the center of the circle.
  • radius: the radius of the circle.

DrawPointCircleFilled ​

cpp
void DrawPointCircleFilled(int x, int y, int radius, const Stylizer & s);

Draw a filled circle made of braille dots.

Parameters:

  • x: the x coordinate of the center of the circle.
  • y: the y coordinate of the center of the circle.
  • radius: the radius of the circle.
  • style: the style of the circle.

DrawPointCircleFilled ​

cpp
void DrawPointCircleFilled(int x, int y, int radius, const Color & color);

Draw a filled circle made of braille dots.

Parameters:

  • x: the x coordinate of the center of the circle.
  • y: the y coordinate of the center of the circle.
  • radius: the radius of the circle.
  • color: the color of the circle.

DrawPointEllipse ​

cpp
void DrawPointEllipse(int x, int y, int r1, int r2);

Draw an ellipse made of braille dots.

Parameters:

  • x: the x coordinate of the center of the ellipse.
  • y: the y coordinate of the center of the ellipse.
  • r1: the radius of the ellipse along the x axis.
  • r2: the radius of the ellipse along the y axis.

DrawPointEllipse ​

cpp
void DrawPointEllipse(int x, int y, int r1, int r2, const Color & color);

Draw an ellipse made of braille dots.

Parameters:

  • x: the x coordinate of the center of the ellipse.
  • y: the y coordinate of the center of the ellipse.
  • r1: the radius of the ellipse along the x axis.
  • r2: the radius of the ellipse along the y axis.
  • color: the color of the ellipse.

DrawPointEllipse ​

cpp
void DrawPointEllipse(int x, int y, int r1, int r2, const Stylizer & s);

Draw an ellipse made of braille dots.

Parameters:

  • x: the x coordinate of the center of the ellipse.
  • y: the y coordinate of the center of the ellipse.
  • r1: the radius of the ellipse along the x axis.
  • r2: the radius of the ellipse along the y axis.
  • style: the style of the ellipse.

DrawPointEllipseFilled ​

cpp
void DrawPointEllipseFilled(int x, int y, int r1, int r2);

Draw a filled ellipse made of braille dots.

Parameters:

  • x: the x coordinate of the center of the ellipse.
  • y: the y coordinate of the center of the ellipse.
  • r1: the radius of the ellipse along the x axis.
  • r2: the radius of the ellipse along the y axis.

DrawPointEllipseFilled ​

cpp
void DrawPointEllipseFilled(int x, int y, int r1, int r2, const Color & color);

Draw a filled ellipse made of braille dots.

Parameters:

  • x: the x coordinate of the center of the ellipse.
  • y: the y coordinate of the center of the ellipse.
  • r1: the radius of the ellipse along the x axis.
  • r2: the radius of the ellipse along the y axis.
  • color: the color of the ellipse.

DrawPointEllipseFilled ​

cpp
void DrawPointEllipseFilled(int x, int y, int r1, int r2, const Stylizer & s);

Draw a filled ellipse made of braille dots.

Parameters:

  • x: the x coordinate of the center of the ellipse.
  • y: the y coordinate of the center of the ellipse.
  • r1: the radius of the ellipse along the x axis.
  • r2: the radius of the ellipse along the y axis.
  • style: the style of the ellipse.

DrawBlockOn ​

cpp
void DrawBlockOn(int x, int y);

Draw a block.

Parameters:

  • x: the x coordinate of the block.
  • y: the y coordinate of the block.

DrawBlockOff ​

cpp
void DrawBlockOff(int x, int y);

Erase a block.

Parameters:

  • x: the x coordinate of the block.
  • y: the y coordinate of the block.

DrawBlockToggle ​

cpp
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.

Parameters:

  • x: the x coordinate of the block.
  • y: the y coordinate of the block.

DrawBlock ​

cpp
void DrawBlock(int x, int y, bool value);

Draw a block.

Parameters:

  • x: the x coordinate of the block.
  • y: the y coordinate of the block.
  • value: whether the block is filled or not.

DrawBlock ​

cpp
void DrawBlock(int x, int y, bool value, const Stylizer & s);

Draw a block.

Parameters:

  • x: the x coordinate of the block.
  • y: the y coordinate of the block.
  • value: whether the block is filled or not.
  • style: the style of the block.

DrawBlock ​

cpp
void DrawBlock(int x, int y, bool value, const Color & color);

Draw a block.

Parameters:

  • x: the x coordinate of the block.
  • y: the y coordinate of the block.
  • value: whether the block is filled or not.
  • color: the color of the block.

DrawBlockLine ​

cpp
void DrawBlockLine(int x1, int y1, int x2, int y2);

Draw a line made of block characters.

Parameters:

  • x1: the x coordinate of the first point of the line.
  • y1: the y coordinate of the first point of the line.
  • x2: the x coordinate of the second point of the line.
  • y2: the y coordinate of the second point of the line.

DrawBlockLine ​

cpp
void DrawBlockLine(int x1, int y1, int x2, int y2, const Stylizer & s);

Draw a line made of block characters.

Parameters:

  • x1: the x coordinate of the first point of the line.
  • y1: the y coordinate of the first point of the line.
  • x2: the x coordinate of the second point of the line.
  • y2: the y coordinate of the second point of the line.
  • style: the style of the line.

DrawBlockLine ​

cpp
void DrawBlockLine(int x1, int y1, int x2, int y2, const Color & color);

Draw a line made of block characters.

Parameters:

  • x1: the x coordinate of the first point of the line.
  • y1: the y coordinate of the first point of the line.
  • x2: the x coordinate of the second point of the line.
  • y2: the y coordinate of the second point of the line.
  • color: the color of the line.

DrawBlockCircle ​

cpp
void DrawBlockCircle(int x1, int y1, int radius);

Draw a circle made of block characters.

Parameters:

  • x: the x coordinate of the center of the circle.
  • y: the y coordinate of the center of the circle.
  • radius: the radius of the circle.

DrawBlockCircle ​

cpp
void DrawBlockCircle(int x1, int y1, int radius, const Stylizer & s);

Draw a circle made of block characters.

Parameters:

  • x: the x coordinate of the center of the circle.
  • y: the y coordinate of the center of the circle.
  • radius: the radius of the circle.
  • style: the style of the circle.

DrawBlockCircle ​

cpp
void DrawBlockCircle(int x1, int y1, int radius, const Color & color);

Draw a circle made of block characters.

Parameters:

  • x: the x coordinate of the center of the circle.
  • y: the y coordinate of the center of the circle.
  • radius: the radius of the circle.
  • color: the color of the circle.

DrawBlockCircleFilled ​

cpp
void DrawBlockCircleFilled(int x1, int y1, int radius);

Draw a filled circle made of block characters.

Parameters:

  • x: the x coordinate of the center of the circle.
  • y: the y coordinate of the center of the circle.
  • radius: the radius of the circle.

DrawBlockCircleFilled ​

cpp
void DrawBlockCircleFilled(int x1, int y1, int radius, const Stylizer & s);

Draw a filled circle made of block characters.

Parameters:

  • x: the x coordinate of the center of the circle.
  • y: the y coordinate of the center of the circle.
  • radius: the radius of the circle.
  • style: the style of the circle.

DrawBlockCircleFilled ​

cpp
void DrawBlockCircleFilled(int x1, int y1, int radius, const Color & color);

Draw a filled circle made of block characters.

Parameters:

  • x: the x coordinate of the center of the circle.
  • y: the y coordinate of the center of the circle.
  • radius: the radius of the circle.
  • color: the color of the circle.

DrawBlockEllipse ​

cpp
void DrawBlockEllipse(int x1, int y1, int r1, int r2);

Draw an ellipse made of block characters.

Parameters:

  • x: the x coordinate of the center of the ellipse.
  • y: the y coordinate of the center of the ellipse.
  • r1: the radius of the ellipse along the x axis.
  • r2: the radius of the ellipse along the y axis.

DrawBlockEllipse ​

cpp
void DrawBlockEllipse(int x1, int y1, int r1, int r2, const Stylizer & s);

Draw an ellipse made of block characters.

Parameters:

  • x: the x coordinate of the center of the ellipse.
  • y: the y coordinate of the center of the ellipse.
  • r1: the radius of the ellipse along the x axis.
  • r2: the radius of the ellipse along the y axis.
  • style: the style of the ellipse.

DrawBlockEllipse ​

cpp
void DrawBlockEllipse(int x1, int y1, int r1, int r2, const Color & color);

Draw an ellipse made of block characters.

Parameters:

  • x: the x coordinate of the center of the ellipse.
  • y: the y coordinate of the center of the ellipse.
  • r1: the radius of the ellipse along the x axis.
  • r2: the radius of the ellipse along the y axis.
  • color: the color of the ellipse.

DrawBlockEllipseFilled ​

cpp
void DrawBlockEllipseFilled(int x1, int y1, int r1, int r2);

Draw a filled ellipse made of block characters.

Parameters:

  • x: the x coordinate of the center of the ellipse.
  • y: the y coordinate of the center of the ellipse.
  • r1: the radius of the ellipse along the x axis.
  • r2: the radius of the ellipse along the y axis.

DrawBlockEllipseFilled ​

cpp
void DrawBlockEllipseFilled(int x1, int y1, int r1, int r2, const Stylizer & s);

Draw a filled ellipse made of block characters.

Parameters:

  • x: the x coordinate of the center of the ellipse.
  • y: the y coordinate of the center of the ellipse.
  • r1: the radius of the ellipse along the x axis.
  • r2: the radius of the ellipse along the y axis.
  • style: the style of the ellipse.

DrawBlockEllipseFilled ​

cpp
void DrawBlockEllipseFilled(int x1, int y1, int r1, int r2, const Color & color);

Draw a filled ellipse made of block characters.

Parameters:

  • x: the x coordinate of the center of the ellipse.
  • y: the y coordinate of the center of the ellipse.
  • r1: the radius of the ellipse along the x axis.
  • r2: the radius of the ellipse along the y axis.
  • color: the color of the ellipse.

DrawText ​

cpp
void DrawText(int x, int y, const std::string & value);

Draw a piece of text.

Parameters:

  • x: the x coordinate of the text.
  • y: the y coordinate of the text.
  • value: the text to draw.

DrawText ​

cpp
void DrawText(int x, int y, const std::string & value, const Color & color);

Draw a piece of text.

Parameters:

  • x: the x coordinate of the text.
  • y: the y coordinate of the text.
  • value: the text to draw.
  • color: the color of the text.

DrawText ​

cpp
void DrawText(int x, int y, const std::string & value, const Stylizer & style);

Draw a piece of text.

Parameters:

  • x: the x coordinate of the text.
  • y: the y coordinate of the text.
  • value: the text to draw.
  • style: the style of the text.

Style ​

cpp
void Style(int x, int y, const Stylizer & style);

Modify a pixel at a given location.

Parameters:

  • style: a function that modifies the pixel.