skip to content
==> include/tui/canvas.h <==
1/* @ajax/tui-canvas: ratatui's Canvas Context. Shapes are drawn in world coordinates (x_bounds,
2 * y_bounds) onto a grid of the marker's resolution: braille (2x4 dots a cell), half blocks (1x2),
3 * or one character a cell (dot, block, bar). Changing the marker starts a new layer; layers are
4 * drawn in order, each cell taking the latest layer's symbol and colours. */
5#ifndef TUI_CANVAS_H
6#define TUI_CANVAS_H
7
8#include "tui/block.h"
9
10typedef enum {
11    TUI_MARKER_DOT,
12    TUI_MARKER_BLOCK,
13    TUI_MARKER_BAR,
14    TUI_MARKER_BRAILLE,
15    TUI_MARKER_HALF_BLOCK,
16} tui_marker;
17
18typedef struct tui_canvas tui_canvas;
19
20/* A point in world coordinates (ratatui's (f64, f64)). */
21typedef struct {
22    double x, y;
23} tui_point;
24
25/* A context for a canvas of width x height cells (Context::new). Lives in the arena. */
26tui_canvas *tui_canvas_new(tui_arena *a, uint16_t width, uint16_t height, const double x_bounds[2],
27                           const double y_bounds[2], tui_marker marker);
28void tui_canvas_marker(tui_canvas *c, tui_marker m); /* Context::marker */
29void tui_canvas_points(tui_canvas *c, const tui_point *pts, size_t n, tui_color color);
30void tui_canvas_line(tui_canvas *c, double x1, double y1, double x2, double y2, tui_color color);
31void tui_canvas_filled_line(tui_canvas *c, double x1, double y1, double x2, double y2, double fill_to_y, tui_color color);
32void tui_canvas_bar(tui_canvas *c, double x, double y, tui_color color); /* a line from (x, 0) to (x, y) */
33void tui_canvas_print(tui_canvas *c, double x, double y, tui_line line);
34/* Canvas::render with the context painted: the block, the background, every layer, the labels. */
35void tui_canvas_render(tui_arena *a, tui_canvas *c, const tui_block *block, tui_color background, tui_rect area,
36                       tui_buffer *buf);
37/* Canvas::render when the area isn't known before painting: paint(ctx, arg) is called on a
38 * context sized to the area's inside (ratatui calls the paint closure the same way). */
39void tui_canvas_widget(tui_arena *a, const tui_block *block, tui_color background, const double x_bounds[2],
40                       const double y_bounds[2], tui_marker marker, void (*paint)(tui_canvas *c, void *arg), void *arg,
41                       tui_rect area, tui_buffer *buf);
42
43#endif