package mosaic

  1. Overview
  2. Docs

Module Mosaic_mlx.CanvasSource

Mutable cell-level drawing surface.

A canvas is passed to the ~on_draw callback of the canvas element. Use the drawing functions to render content into the canvas grid.

The type for canvases.

Dimensions

val width : t -> int

width t is the grid width of t in cells.

val height : t -> int

height t is the grid height of t in cells.

Drawing

val draw_text : ?style:Ansi.Style.t -> ?tab_width:int -> t -> x:int -> y:int -> text:string -> unit

draw_text t ~x ~y ~text draws text as a single line at column x, row y.

style defaults to Ansi.Style.default. tab_width defaults to 8.

val fill_rect : t -> x:int -> y:int -> width:int -> height:int -> color:Ansi.Color.t -> unit

fill_rect t ~x ~y ~width ~height ~color fills the rectangle with the given background color.

val draw_box : t -> x:int -> y:int -> width:int -> height:int -> ?border:Border.t -> ?sides:Border.side list -> ?style:Ansi.Style.t -> ?fill:Ansi.Color.t -> ?title:string -> ?title_alignment:[ `Left | `Center | `Right ] -> ?title_style:Ansi.Style.t -> unit -> unit

draw_box t ~x ~y ~width ~height () draws a Unicode box at column x, row y.

  • border defaults to Border.rounded.
  • sides defaults to all four sides.
  • style defaults to Ansi.Style.default.
  • fill defaults to no fill.
  • title defaults to no title.
  • title_alignment defaults to `Left.
  • title_style defaults to Ansi.Style.default.
val draw_line : t -> x1:int -> y1:int -> x2:int -> y2:int -> ?style:Ansi.Style.t -> ?glyphs:Matrix.Grid.line_glyphs -> ?kind:[ `Line | `Braille ] -> unit -> unit

draw_line t ~x1 ~y1 ~x2 ~y2 () draws a line from (x1, y1) to (x2, y2).

  • style defaults to Ansi.Style.default.
  • glyphs defaults to standard box-drawing characters.
  • kind defaults to `Line. Use `Braille for Braille dot patterns.
val set_cell : t -> x:int -> y:int -> glyph:Matrix.Glyph.t -> fg:Ansi.Color.t -> bg:Ansi.Color.t -> attrs:Ansi.Attr.t -> ?link:string -> ?blend:bool -> unit -> unit

set_cell t ~x ~y ~glyph ~fg ~bg ~attrs () writes a single cell.

link defaults to no hyperlink. blend defaults to the canvas respect_alpha setting.

val clear : ?color:Ansi.Color.t -> t -> unit

clear t clears the canvas grid and schedules a re-render.

color defaults to the terminal default background.

Low-level grid access

val grid : t -> Matrix.Grid.t

grid t is the underlying grid for t. Use this for operations not covered by the canvas drawing functions.

Callbacks

val set_on_draw : t -> (t -> delta:float -> unit) option -> unit

set_on_draw t cb registers cb as the render-time drawing callback for t. cb fires each render pass after the grid has been auto-resized; ~delta is the elapsed time in seconds since the last frame. Pass None to clear the callback.

val set_on_resize : t -> (t -> unit) option -> unit

set_on_resize t cb registers cb as the resize callback for t. cb fires when the canvas grid dimensions change. Pass None to clear the callback.

Render control

val request_render : t -> unit

request_render t schedules a re-render of t. Call this after drawing outside of a draw callback.

Properties

val set_respect_alpha : t -> bool -> unit

set_respect_alpha t v enables or disables alpha blending within the canvas grid.

val respect_alpha : t -> bool

respect_alpha t is true iff alpha blending is enabled.