Documentation
¶
Overview ¶
Package paint implements the paint phase of the Kite rendering pipeline.
The paint engine performs a depth-first traversal of the immutable layout.Fragment tree produced by the layout phase and rasterises each fragment into a 2-D grid of terminal Cell values held by a FrameBuffer.
Per-fragment clipping (ADR-011) ¶
When a fragment's computed style declares OverflowX or OverflowY as any value other than OverflowVisible (i.e., Hidden, Clip, Scroll, or Auto), the engine creates a clipped sub-Surface whose drawable area equals the fragment's content box (origin inset by border + padding, size reduced by the same amounts). All descendant paint calls are routed through this clipped surface, so any cell written outside the content box is silently dropped.
The fragment's own background fill and border decoration are painted onto the unclipped surface before the clipped surface is created, ensuring that a node's border-box decoration is never eaten by its own overflow property.
For asymmetric overflow (e.g., OverflowX: Hidden, OverflowY: Visible), the clip rect spans the full surface extent on the visible axis and the content-box inset on the clipping axis. Composition for nested overflow containers is automatic: Surface.Clip intersects the new rect with the already-active clip.
Border resolution invariant ¶
PaintEngine.ResolveBorders is invoked exactly once, on the root Surface, after the full fragment tree has been painted. It must never be called on a clipped sub-surface because the junction resolver must inspect the complete set of border cells across the entire viewport. # Scroll Translation (ADR-012)
When a fragment's node is a scroll container (computed OverflowX or OverflowY is Scroll or Auto), the engine reads the node's raw scroll offset from the DOM. Paint "clamps on read" to the current content extent: the offset is clamped between 0 and (contentSize - viewportSize).
All descendant fragments are then painted at an origin shifted by the negative of the clamped scroll offset. This shift combined with the content-box clipping (ADR-011) enables scrolling.
Storing the scroll state in the DOM while clamping at paint time ensures that author intent (e.g., "scroll to bottom") is preserved across viewport resizes or content updates even when the required clamping value changes.
Index ¶
- Constants
- type BorderStyle
- type Cell
- type CellAttrs
- type Context
- type FrameBuffer
- func (fb *FrameBuffer) Bounds() geom.Rect
- func (fb *FrameBuffer) BumpVersion()
- func (fb *FrameBuffer) CellAt(x, y int) Cell
- func (fb *FrameBuffer) Clip(r geom.Rect) Surface
- func (fb *FrameBuffer) DirtyRect() (r geom.Rect, ok bool)
- func (fb *FrameBuffer) Reset()
- func (fb *FrameBuffer) Set(x, y int, c Cell)
- func (fb *FrameBuffer) Version() uint64
- type PaintEngine
- func (p *PaintEngine) ApplySelection(surface Surface, selection []SelectionRect)
- func (p *PaintEngine) Paint(ctx *Context, frag *layout.Fragment, surface Surface)
- func (p *PaintEngine) PaintFragment(ctx *Context, frag *layout.Fragment, origin geom.Point, surface Surface)
- func (p *PaintEngine) ResolveBorders(ctx *Context, surface Surface)
- type SelectionRect
- type Surface
Constants ¶
const ( // AttrBold makes the cell's text bold. AttrBold = backend.CellBold // AttrItalic makes the cell's text italic. AttrItalic = backend.CellItalic // AttrUnderline underlines the cell's text. AttrUnderline = backend.CellUnderline // AttrInverse swaps the foreground and background colors. AttrInverse = backend.CellReverse // AttrStrikethrough strikes through the cell's text. AttrStrikethrough = backend.CellStrikethrough )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BorderStyle ¶
type BorderStyle uint8
BorderStyle selects the pre-defined glyph set for a border.
const ( // BorderNone draws no border. BorderNone BorderStyle = 0 // BorderASCII draws an ASCII border. BorderASCII BorderStyle = 1 // BorderRounded draws a rounded border. BorderRounded BorderStyle = 2 // BorderSingle draws a single-line border. BorderSingle BorderStyle = 3 // BorderDouble draws a double-line border. BorderDouble BorderStyle = 4 // BorderThick draws a heavy-line border. BorderThick BorderStyle = 5 )
type Cell ¶
type Cell struct {
backend.Cell
// Content is the string to be rendered in this cell. It may be empty, but
// must not be nil. The string may contain multiple Unicode code points, but
// must not contain any combining characters. The width of the cell is
// determined by the number of columns needed to render Content, which may
// be zero for an empty string.
// BorderStyle indicates the type of border glyph in this cell.
BorderStyle BorderStyle
}
Cell represents the content and styling of a single terminal cell.
type Context ¶
type Context struct {
Tracer *trace.Tracer
Selection []SelectionRect
}
Context carries state and utilities through the paint tree.
type FrameBuffer ¶
type FrameBuffer struct {
// contains filtered or unexported fields
}
FrameBuffer is the concrete Surface implementation used by the paint engine. It holds a 2-D grid of Cells indexed by (x, y), a monotonically-increasing frame version counter, and a dirty rectangle that grows as cells are written.
FrameBuffer is not safe for concurrent use.
func NewFrameBuffer ¶
func NewFrameBuffer(ox, oy, width, height int) *FrameBuffer
NewFrameBuffer creates a FrameBuffer positioned at origin (ox, oy) with the given width and height. All cells are initialised to zero values.
func (*FrameBuffer) Bounds ¶
func (fb *FrameBuffer) Bounds() geom.Rect
Bounds returns the full drawable area of the buffer.
func (*FrameBuffer) BumpVersion ¶
func (fb *FrameBuffer) BumpVersion()
BumpVersion increments the frame version, signalling the start of a new frame. The dirty rect is also reset.
func (*FrameBuffer) CellAt ¶
func (fb *FrameBuffer) CellAt(x, y int) Cell
CellAt returns the cell at absolute position (x, y). If the position is out of bounds an empty Cell is returned.
func (*FrameBuffer) Clip ¶
func (fb *FrameBuffer) Clip(r geom.Rect) Surface
Clip returns a clippedSurface that restricts writes to the intersection of fb's bounds and r. The returned Surface still accepts absolute coordinates.
func (*FrameBuffer) DirtyRect ¶
func (fb *FrameBuffer) DirtyRect() (r geom.Rect, ok bool)
DirtyRect returns the bounding rectangle of all cells written since the last BumpVersion call. If no cell has been written, ok is false.
func (*FrameBuffer) Reset ¶
func (fb *FrameBuffer) Reset()
Reset clears the buffer content and resets the dirty rect.
func (*FrameBuffer) Set ¶
func (fb *FrameBuffer) Set(x, y int, c Cell)
Set writes cell c into position (x, y). The coordinates are absolute (same space as Bounds). Calls outside the buffer's bounds are silently ignored.
If c.BG is color.Transparent, the existing background color in the cell is preserved.
func (*FrameBuffer) Version ¶
func (fb *FrameBuffer) Version() uint64
Version returns the current frame version counter.
type PaintEngine ¶
type PaintEngine struct {
DebugXRay bool
// contains filtered or unexported fields
}
PaintEngine handles the paint phase of the pipeline.
func (*PaintEngine) ApplySelection ¶
func (p *PaintEngine) ApplySelection(surface Surface, selection []SelectionRect)
func (*PaintEngine) Paint ¶
func (p *PaintEngine) Paint(ctx *Context, frag *layout.Fragment, surface Surface)
Paint draws the immutable fragment tree onto the surface and resolves borders.
func (*PaintEngine) PaintFragment ¶
func (p *PaintEngine) PaintFragment(ctx *Context, frag *layout.Fragment, origin geom.Point, surface Surface)
PaintFragment draws the immutable fragment tree onto the surface at the given origin.
func (*PaintEngine) ResolveBorders ¶
func (p *PaintEngine) ResolveBorders(ctx *Context, surface Surface)
ResolveBorders resolves border junctions across the entire surface.
type SelectionRect ¶
SelectionRect represents a physical rectangle of selected content.
type Surface ¶
type Surface interface {
// Set writes cell c into position (x, y).
Set(x, y int, c Cell)
// CellAt returns the cell at absolute position (x, y).
CellAt(x, y int) Cell
// Bounds returns the total drawable area of this surface in absolute
// terminal-cell coordinates.
Bounds() geom.Rect
// Clip returns a new Surface whose drawable area is restricted to the
// intersection of this surface's bounds and r. Coordinates passed to
// Set on the returned surface are still in absolute terms so that the
// clip can be composed without coordinate translations.
Clip(r geom.Rect) Surface
}
Surface is the drawing target provided by the backend. All paint operations are expressed in absolute terminal-cell coordinates.
Implementations must be safe to call from the main goroutine only; no concurrent access is expected.