Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
portals::Canvas Class Reference

Synchronous clipped cell drawing inside a retained widget's paint hook. The context and optional brush are borrowed through the enclosing frame. Commands use widget-local coordinates; the frame sink applies surface translation and ancestor clipping. No I/O, allocation, model access or invalidation. Discard the frame's commands on error. More...

#include <canvas.hpp>

Public Member Functions

 Canvas (PaintContext &context, CellRect clip, const GraphemeText *brush=nullptr) noexcept
 Borrow a sink and optional one-cell glyph for this frame.
std::expected< void, TreeError > point (CellPoint position, CellStyle style={})
 Draw a cell if it is inside the clip.
std::expected< void, TreeError > line (CellPoint first, CellPoint last, CellStyle style={})
 Rasterize an inclusive DDA line, rounding ties away from zero, then clip. Only the clip's dominant-axis coordinates are visited, even for INT32_MIN/MAX endpoints.

Detailed Description

Synchronous clipped cell drawing inside a retained widget's paint hook. The context and optional brush are borrowed through the enclosing frame. Commands use widget-local coordinates; the frame sink applies surface translation and ancestor clipping. No I/O, allocation, model access or invalidation. Discard the frame's commands on error.

Constructor & Destructor Documentation

◆ Canvas()

portals::Canvas::Canvas ( PaintContext & context,
CellRect clip,
const GraphemeText * brush = nullptr )
noexcept

Borrow a sink and optional one-cell glyph for this frame.

Parameters
contextUI-owned command sink, alive through all drawing calls.
clipHalf-open local cell clip, intersected with every emitted command.
brushOptional one-cell, one-grapheme brush alive and unchanged through frame rendering; null draws styled spaces, useful with a background color. Invalid brushes fail on drawing.

Member Function Documentation

◆ line()

std::expected< void, TreeError > portals::Canvas::line ( CellPoint first,
CellPoint last,
CellStyle style = {} )

Rasterize an inclusive DDA line, rounding ties away from zero, then clip. Only the clip's dominant-axis coordinates are visited, even for INT32_MIN/MAX endpoints.

Parameters
firstStarting cell coordinate; negative and offscreen values are allowed.
lastEnding cell coordinate, included when visible.
styleOwning paint value shared by all rasterized cells.
Returns
Success, invalid brush, or the first sink error; earlier commands may already be submitted.

◆ point()

std::expected< void, TreeError > portals::Canvas::point ( CellPoint position,
CellStyle style = {} )

Draw a cell if it is inside the clip.

Parameters
positionWidget-local cell coordinate.
styleOwning cell paint value.
Returns
Success for a clipped-out point, INVALID_ARGUMENT for an invalid brush, or the sink error.

The documentation for this class was generated from the following file: