package mosaic
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/mosaic.mlx/Mosaic_mlx/Canvas/index.html
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.
type t = Mosaic_ui.Canvas.tThe type for canvases.
Dimensions
val width : t -> intwidth t is the grid width of t in cells.
val height : t -> intheight 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 ->
unitdraw_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 ->
unitfill_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 ->
unitdraw_box t ~x ~y ~width ~height () draws a Unicode box at column x, row y.
borderdefaults toBorder.rounded.sidesdefaults to all four sides.styledefaults toAnsi.Style.default.filldefaults to no fill.titledefaults to no title.title_alignmentdefaults to`Left.title_styledefaults toAnsi.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 ->
unitdraw_line t ~x1 ~y1 ~x2 ~y2 () draws a line from (x1, y1) to (x2, y2).
styledefaults toAnsi.Style.default.glyphsdefaults to standard box-drawing characters.kinddefaults to`Line. Use`Braillefor 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 ->
unitset_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 -> unitclear 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.tgrid t is the underlying grid for t. Use this for operations not covered by the canvas drawing functions.
Callbacks
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.
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 -> unitrequest_render t schedules a re-render of t. Call this after drawing outside of a draw callback.
Properties
val set_respect_alpha : t -> bool -> unitset_respect_alpha t v enables or disables alpha blending within the canvas grid.
val respect_alpha : t -> boolrespect_alpha t is true iff alpha blending is enabled.