Module Brr_canvas.Canvas

Canvas element.

type t

The type for HTMLCanvasElement objects.

val create : ?d:Brr.Document.t -> ?at:Brr.At.t list -> ?w:int -> ?h:int -> Brr.El.t list -> t

create ~w ~h [] is a canvas element with a render buffer of wxh pixels (they default to 0).

val of_el : Brr.El.t -> t

of_el e is a canvas from element e. This throws a JavaScript error if e is not a canvas element.

val to_el : t -> Brr.El.t

to_el c is c as an an element.

Render buffer dimensions

val w : t -> int

w c is the render buffer width of c in pixels.

val h : t -> int

h c is the render buffer height of c in pixels.

val set_w : t -> int -> unit

set_w c w sets the render buffer width of c to w pixels.

val set_h : t -> int -> unit

set_h c h sets the render buffer height of c to h pixels.

val set_size_to_layout_size : ?hidpi:bool -> t -> unit

set_size_to_layout_size t sets the render buffer size to the canvas' element Brr.El.inner_w Brr.El.inner_h and values. If hidpi is true (defaults), these values are multiplied by Brr.Window.device_pixel_ratio.


Context are obtained by the modules that handle them.


type image_encode

The type for image encode parameters.

val image_encode : ?type':Jstr.t -> ?quality:float -> unit -> image_encode

image_encode ~type' ~quality () are image encoding parameters type' is the mime type of the image, it defaults to "image/png". quality a number from 0. to 1. if it makes sense for the data format (e.g. JPEG), default is implementation dependent.

val to_data_url : ?encode:image_encode -> t -> (Jstr.t, Jv.Error.t) Stdlib.result

to_data_url ~encode t is the canvas's image as a data url.

val to_blob : ?encode:image_encode -> t -> Brr.Blob.t option Fut.or_error

to_blob ~encode t is the canvas's image a blob object. None is returned either if the canvas has no pixels or if an error occurs during image serialisation.

val capture_stream : hz:int option -> t -> Brr_io.Media.Stream.t

capture_stream ~hz is a capture media stream for the canvas at the frequency of hz or manually if unspecified.