Documentation
¶
Overview ¶
Package sixelcanvas provides SixelCanvasView — a fixed-size pixel buffer the application can draw into and have rendered as SIXEL graphics (or half-block fallback). Useful for game-style rendering, charts, and any "I have pixels, please put them on screen" use case where a plain ImageView with a static *image.RGBA isn't enough.
Drawing primitives (Clear / SetPixel / FillRect / DrawLine) all operate on the canvas's pixel buffer; nothing is sent to the terminal until Draw runs. Animation: set OnTick to a callback and the view auto-registers a 50ms ticker (~20fps); each tick invokes the callback before the redraw, giving a simple "logical-frame" pattern without the caller having to wire anim.Register manually.
Index ¶
- type SixelCanvasView
- func (c *SixelCanvasView) Clear(rgb uint32)
- func (c *SixelCanvasView) Draw()
- func (c *SixelCanvasView) DrawLine(x1, y1, x2, y2 int, rgb uint32)
- func (c *SixelCanvasView) FillRect(x, y, w, h int, rgb uint32)
- func (c *SixelCanvasView) GetTypeID() string
- func (c *SixelCanvasView) Pixels() *image.RGBA
- func (c *SixelCanvasView) PreFlush(b views.RootBackend)
- func (c *SixelCanvasView) Resize(pixelW, pixelH int)
- func (c *SixelCanvasView) SetPixel(x, y int, rgb uint32)
- func (c *SixelCanvasView) Tick(now time.Time) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SixelCanvasView ¶
type SixelCanvasView struct {
views.Base
// PixelW × PixelH is the buffer's pixel resolution. Independent of
// the view's cell-bounds; the encoder/half-block path stretches
// the buffer to fit the cell rectangle.
PixelW, PixelH int
// OnTick is called once per frame just before Draw, if non-nil.
// Callers stage their drawing primitives inside this hook.
OnTick func()
// UseSixel mirrors sixel.IsSupported() at construction; set to
// false to force the half-block path.
UseSixel bool
// FrameInterval controls the animation cadence. Default 50ms when
// OnTick is non-nil. Ignored when OnTick is nil.
FrameInterval time.Duration
// BG is the background color emitted in cells that the SIXEL
// emission doesn't cover (cell-size mismatch, or padding when the
// integer-scale-up undershoots the cell rect). Default 0x000000.
BG uint32
// contains filtered or unexported fields
}
SixelCanvasView is a pixel canvas with drawing primitives.
func New ¶
func New(bounds geom.Rect, pixelW, pixelH int) *SixelCanvasView
New constructs a SixelCanvasView with a pixelW × pixelH backing buffer, fitted into the supplied cell bounds.
func (*SixelCanvasView) Clear ¶
func (c *SixelCanvasView) Clear(rgb uint32)
Clear paints the entire buffer with the given 24-bit RGB color.
func (*SixelCanvasView) Draw ¶
func (c *SixelCanvasView) Draw()
Draw routes to SIXEL or half-block.
SIXEL path: writes a sentinel cell (Ch = SixelPlaceholder) into every cell of the view's region. PreFlush — which runs after the entire tree walk — then resolves z-order against whatever covering views drew on top, emits SIXEL DCS only at uncovered cells, and forces covering cells to re-emit so they paint over the SIXEL pixels.
Half-block path: writes ordinary "▀" cells; the standard cell flush handles z-order automatically because cells overwrite cells.
func (*SixelCanvasView) DrawLine ¶
func (c *SixelCanvasView) DrawLine(x1, y1, x2, y2 int, rgb uint32)
DrawLine draws a Bresenham line from (x1,y1) to (x2,y2). Out-of- bounds pixels are clipped at SetPixel time.
func (*SixelCanvasView) FillRect ¶
func (c *SixelCanvasView) FillRect(x, y, w, h int, rgb uint32)
FillRect paints a w×h rectangle starting at (x, y), clipped to the canvas bounds.
func (*SixelCanvasView) GetTypeID ¶
func (c *SixelCanvasView) GetTypeID() string
GetTypeID for serial registry.
func (*SixelCanvasView) Pixels ¶
func (c *SixelCanvasView) Pixels() *image.RGBA
Pixels returns the underlying *image.RGBA so callers can draw into it with stdlib operations (image/draw, etc.).
func (*SixelCanvasView) PreFlush ¶
func (c *SixelCanvasView) PreFlush(b views.RootBackend)
PreFlush implements views.PreFlusher. Runs after the tree walk, before the cell-buffer flush. See ImageView.PreFlush for the full algorithm — this is the same shape, with c.BG taking the place of iv.BG for the under-the-SIXEL background fill.
func (*SixelCanvasView) Resize ¶
func (c *SixelCanvasView) Resize(pixelW, pixelH int)
Resize replaces the pixel buffer with a new size, clearing it.
func (*SixelCanvasView) SetPixel ¶
func (c *SixelCanvasView) SetPixel(x, y int, rgb uint32)
SetPixel writes one pixel, no-op if out of bounds.
func (*SixelCanvasView) Tick ¶
func (c *SixelCanvasView) Tick(now time.Time) bool
Tick fires the user's OnTick (if any) and asks for a redraw. Returns true to mark dirty whenever something might have changed visually — we err on the side of redrawing because skipping a frame in animation feels worse than the cost of an extra paint.