class

Lipgloss::Canvas

Inherits Ultraviolet::Screen < Ultraviolet::Drawable < Reference < Object

Canvas is a cell-buffer that can be used to compose and draw Ultraviolet::Drawable objects like Layers.

Composed drawables are drawn onto the canvas in the order they were composed, meaning later drawables will appear "on top" of earlier ones.

A canvas can read, modify, and render its cell contents.

It implements Ultraviolet::Screen and Ultraviolet::Drawable.

Constructors

new(width : Int32, height : Int32)

Creates a new Canvas with the given size.

Instance methods

bounds

Returns the bounding rectangle of the canvas.

cell_at(x : Int32, y : Int32) : Ultraviolet::Cell | Nil

Returns the cell at position (x, y), or nil if out of bounds. Note: Unlike Go's *uv.Cell pointer, this returns a value type. Mutating the returned cell does not update the buffer. Use set_cell to modify the buffer. This is a known API difference from Go lipgloss.

clear

Clear clears the canvas.

compose(drawable : Ultraviolet::Drawable) : Canvas

Composes a drawable onto the canvas.

draw(screen : Ultraviolet::Screen, area : Ultraviolet::Rectangle) : Nil

Draws the canvas onto the given screen within the specified area.

draw_string(str : String, x : Int32, y : Int32) : Nil

Draws a string at position (x, y). This method is not part of the Go API but is used by Layer. It converts the string to Ultraviolet::Cell objects and sets them.

height

Returns the height of the canvas.

render

Renders the canvas into a styled string.

resize(width : Int32, height : Int32) : Nil

Resize resizes the canvas to the given width and height.

set_cell(x : Int32, y : Int32, cell : Ultraviolet::Cell | Nil) : Nil

Sets the cell at position (x, y).

width

Returns the width of the canvas.

width_method

Returns the width calculation method used by the canvas.