package matrix
Build not yet checkedInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=a92cbbcbe016fb19fb0a749222da0e459a9567aef3f4c7340d9bd6b71c53ed6f
sha512=6a7ab054605538bb31a2b73a1a6d093981a2704c9f0af5852221c05735290d74aca7c7282298c4d0f91e86a800e2ccd94b4918af883cd963449c758eb6b272b3
doc/matrix.grid/Matrix_grid/Lines/index.html
Module Matrix_grid.LinesSource
Lines that join where they meet.
Lines of box-drawing characters that join where they meet.
A line set (t) records horizontal and vertical lines on a rectangle of cells, width columns by height rows from column x and row y, named as a grid names them, and holds a value for each of its cells. Each line has a weight (weight) and a style. A line has an arm in each of its cells toward every neighbor it continues into, so its inner cells have two arms and its two end cells one. Lines that cross or meet add their arms to the cells they share, and a cell's arms say what it is, a straight piece, a corner, a tee or a cross. When two lines give a cell an arm in the same direction, the arm takes the heavier weight, double being the heaviest. A line one cell long has no arm and is a straight piece of its direction. A cell takes the style of the first line through it.
Matrix_grid.draw_lines draws each cell a line passes through with the glyph its arms call for in a glyph set (glyphs). A cell whose arms all point along one axis is drawn as a straight piece of that axis, so a line's end cells are drawn whole. With Unicode, each arm is drawn with its weight, as one of Unicode's box-drawing characters (U+2500 to U+257F). Unicode has a character for every mix of light and heavy arms, and for double arms with single ones when the two arms of each axis have one weight. For the other mixes, heavy arms are drawn double and the two arms of an axis take the heavier weight. A Set gives one glyph for each shape and draws every weight with it.
The life cycle of a line set:
createmakes an empty set for a rectangle of cells.hline,vlineandarmadd lines and arms.Matrix_grid.draw_linesdraws it, as often as the program draws the frame it belongs to.clearempties it for the lines of another frame.
This draws a box with a double frame and a light rule across it, whose ends join the frame as ╟ and ╢:
let l = Matrix_grid.Lines.create ~x:0 ~y:0 ~width:10 ~height:4 in
Matrix_grid.Lines.hline ~weight:`Double l ~x:0 ~y:0 ~length:10;
Matrix_grid.Lines.hline ~weight:`Double l ~x:0 ~y:3 ~length:10;
Matrix_grid.Lines.vline ~weight:`Double l ~x:0 ~y:0 ~length:4;
Matrix_grid.Lines.vline ~weight:`Double l ~x:9 ~y:0 ~length:4;
Matrix_grid.Lines.hline l ~x:0 ~y:2 ~length:10;
let g = Matrix_grid.create ~width:10 ~height:4 () in
Matrix_grid.draw_lines g lLine sets
A line or an arm that leaves the rectangle is cut to it, and a cell outside it is left out. The cells inside keep the arms toward the cells left out, so a line cut by an edge runs up to it.
val create : x:int -> y:int -> width:int -> height:int -> tcreate ~x ~y ~width ~height is an empty line set for the rectangle of width columns from column x and height rows from row y.
Raises Invalid_argument if width < 0 or height < 0.
val x : t -> intx l is the first column of l's rectangle.
val y : t -> inty l is the first row of l's rectangle.
val width : t -> intwidth l is the number of columns of l's rectangle.
val height : t -> intheight l is the number of rows of l's rectangle.
val clear : t -> unitclear l removes every line and arm from l.
val hline :
?weight:weight ->
?style:Ansi.Style.t ->
t ->
x:int ->
y:int ->
length:int ->
unithline ~weight ~style l ~x ~y ~length adds the horizontal line of the length cells of row y from column x, of weight weight (`Light by default) in style (Ansi.Style.default by default). It adds nothing if length <= 0.
val vline :
?weight:weight ->
?style:Ansi.Style.t ->
t ->
x:int ->
y:int ->
length:int ->
unitvline ~weight ~style l ~x ~y ~length adds the vertical line of the length cells of column x from row y, as hline adds a horizontal one.
val arm :
?weight:weight ->
?style:Ansi.Style.t ->
t ->
x:int ->
y:int ->
[ `Up | `Down | `Left | `Right ] ->
unitarm ~weight ~style l ~x ~y dir adds an arm toward dir to the cell of column x and row y, as a line into the neighbor in that direction would. The neighbor is left as it is, so the arm joins a line to a mark the program draws itself, such as a chart's tick mark beside its axis.
Glyph sets
type set = {horizontal : string;(*A straight piece across.
*)vertical : string;(*A straight piece down.
*)top_left : string;(*The corner of arms down and right.
*)top_right : string;(*The corner of arms down and left.
*)bottom_left : string;(*The corner of arms up and right.
*)bottom_right : string;(*The corner of arms up and left.
*)top_t : string;(*The tee of arms left, right and down.
*)bottom_t : string;(*The tee of arms left, right and up.
*)left_t : string;(*The tee of arms up, down and right.
*)right_t : string;(*The tee of arms up, down and left.
*)cross : string;(*The cross of the four arms.
*)
}The type for the glyphs of the eleven shapes a cell's arms make, whatever their weights. A glyph is drawn as Matrix_grid.draw_text draws a text, so a glyph wider than a cell covers the cells after it, and "" draws nothing.
type glyphs = | Unicode(*Unicode's box-drawing characters, each arm drawn with its weight.
*)| Rounded| Set of set(*The glyph of each shape from the set.
*)
The type for glyph sets.
val ascii : glyphsascii is the set of ASCII characters - across, | down and + for every corner, tee and cross, for terminals without box-drawing characters.
of_border b is the set of b's characters, so that lines join as the boxes of Matrix_grid.draw_box with b are drawn.