Module Mlpost.Box
A Box is a rectangle with some content and a (not necessarily rectangular) frame. Boxes can be placed, aligned and modified.
Creating boxes
type style=|Rect|Circle|RoundRect|Patatoid|Patatoid2|Ellipse|RoundBox|Custom of Num.t -> Num.t -> Num.t * Num.t * Path.ttype 'a box_creator= ?dx:Num.t -> ?dy:Num.t -> ?name:string -> ?brush:Brush.t -> ?stroke:Color.t option -> ?pen:Pen.t -> ?dash:Dash.t -> ?fill:Color.t -> 'a -> tAll functions used to create boxes take the following optional parameters :
dx(resp.dy) is the horizontal (resp. vertical) padding between the box border and its contents ;name, if present, is associated with the box and can be used to retrieve it usingget;strokeis the color used to draw the outline of the box ; when equal toNone, the outline will not be drawn ;penis the pen used to draw the box's outline, if absentBrush.Pen.defaultis used ;fill, if present, is the color used to fill the box.
val empty : ?width:Num.t -> ?height:Num.t -> ?style:style -> ?name:string -> ?brush:Brush.t -> ?stroke:Color.t option -> ?pen:Pen.t -> ?dash:Dash.t -> ?fill:Color.t -> unit -> tthe empty box
val empty_from_box : ?style:style -> ?name:string -> ?brush:Brush.t -> ?stroke:Color.t option -> ?pen:Pen.t -> ?dash:Dash.t -> ?fill:Color.t -> t -> tthe empty box with the same position and dimension as the box. The special points are kept
val pic : ?style:style -> Picture.t box_creatorpic pcreates a new box containing the picturep
val path : ?style:style -> Path.t box_creatorpath pcreates a new box containing the pathp
val tex : ?style:style -> string box_creatortex screates a new box containing the LaTeX strings
val box : ?style:style -> t box_creatorbox bcreates a new box containing the boxb
val circle : t box_creatorcircle piccreates a circle box containing the picturepic. Optional padding is given by argumentsdxanddy; default is 2bp.
val ellipse : t box_creatorellipse piccreates a elliptic box containing the picturepic. Optional padding is given by argumentsdxanddy; default is 2bp
val rect : t box_creatorrect piccreates a rectangular box containing the picturepic. Optional padding is given by argumentsdxanddy; default is 2bp.
val round_rect : t box_creatorround_rect piccreates a rectangular box containing the picturepic, with rounded corners. Optional padding is given bydxanddy; default is 2bp_rect.png
val patatoid : t box_creatorpatatoid piccreates an undefined, vaguely rectangular box containing the picturepic. It may happen that the content overlaps with the box.
val patatoid2 : t box_creatorpatatoid2 piccreates an undefined, vaguely rectangular box containing the picturepic, which is guaranteed to be fully contained in the patatoid.
val round_box : t box_creatorval bpath : t -> Path.tGet the bounding path of a box
Set the bounding path of a box
Special points on a box
type vposition=[|Command.vposition|`Custom of t -> Num.t]type hposition=[|Command.hposition|`Custom of t -> Num.t]type position=[|Command.position|`Custom of t -> Point.t]
Operators
val shift : Point.t -> t -> treturn the width of the box

shift pt xshifts the boxxabout the pointpt
val center : Point.t -> t -> tshift pt xshifts the boxxabout the pointpt
center pt xcenters the boxxat the pointpt
val draw : ?debug:bool -> t -> Command.tDraws a box
- parameter debug
if set to to true, the bounding path and the center of the box are drawn as well, default is false
val group : ?style:style -> t list box_creatorgroup blgroups a list of boxesblinto a single box
Boxes alignment
val halign : ?pos:vposition -> Num.t -> t list -> t listhalign ~pos y lvertically moves the boxes inlsuch that the vertical position given byposis equal toy. The default value ofposis `Center, so by default this function moves each box such that the y coordinate of its center isy. The horizontal position of each box is unchanged. @img halign.png
val hplace : ?padding:Num.t -> ?pos:position -> ?min_width:Num.t -> ?same_width:bool -> t list -> t listhplace lplaces the boxes oflhorizontally, from left to right following the order of list elements, without changing their vertical position.- parameter min_width
minimum width of all boxes; default is zero
- parameter same_width
if
true, all boxes are of same width, and at least ofmin_width; default is false
val vplace : ?padding:Num.t -> ?pos:position -> ?min_height:Num.t -> ?same_height:bool -> t list -> t listhplace lplaces the boxes oflhorizontally, from left to right following the order of list elements, without changing their vertical position.- parameter min_width
minimum width of all boxes; default is zero
- parameter same_width
if
true, all boxes are of same width, and at least ofmin_width; default is false
the vertical counterpart of
hplace
val hbox : ?padding:Num.t -> ?pos:position -> ?style:style -> ?min_width:Num.t -> ?same_width:bool -> t list box_creatorplaces the given boxes horizontally, aligning them horizontally, and returns a box containing these boxes as sub-components. Leave the first box at its place.
hbox lactually gives the same result asgroup (hplace (halign l)).- parameter padding
horizontal padding used to separate the boxes; defaults to 0
- parameter pos
used to determine the way boxes are aligned; defaults to
`Center
val hbox_list : ?padding:Num.t -> ?pos:position -> ?min_width:Num.t -> ?same_width:bool -> t list -> t listas
hbox, but does not group the resulting boxes into a surrounding box; it returns the list of placed boxes instead.hbox_list lis equal tohplace (halign l).
val vbox : ?padding:Num.t -> ?pos:position -> ?style:style -> ?min_height:Num.t -> ?same_height:bool -> t list box_creatoraligns the given boxes vertically and returns a box containing these boxes as sub-components. Leave the first box at its place.
- parameter padding
vertical padding used to separate the boxes
- parameter pos
used to determine the way boxes are aligned
val vbox_list : ?padding:Num.t -> ?pos:position -> ?min_height:Num.t -> ?same_height:bool -> t list -> t listval tabular : ?hpadding:Num.t -> ?vpadding:Num.t -> ?pos:Command.position -> ?style:style -> ?name:string -> ?stroke:Color.t option -> ?pen:Pen.t -> ?dash:Dash.t -> ?fill:Color.t -> t array array -> taligns the given boxes both vertically and horizontally and returns a box containing all these boxes (with rows as first sub-components, and then individual boxes as sub-components of each row). Columns (resp. rows) are separated by
hpadding(resp.vpadding); both default to 0. Alignment within columns and rows is controlled usingpos. The arrays for rows must have the same lengths; otherwiseInvalid_argumentis raised.
val tabularl : ?hpadding:Num.t -> ?vpadding:Num.t -> ?pos:Command.position -> ?style:style -> ?name:string -> ?stroke:Color.t option -> ?pen:Pen.t -> ?dash:Dash.t -> ?fill:Color.t -> t list list -> tsimilar to
tabular, but using lists instead of arrays
val tabulari : ?hpadding:Num.t -> ?vpadding:Num.t -> ?pos:Command.position -> ?style:style -> ?name:string -> ?stroke:Color.t option -> ?pen:Pen.t -> ?dash:Dash.t -> ?fill:Color.t -> int -> int -> (int -> int -> t) -> tsimilar to
tabular, but using a matrix defined with a function
val hblock : ?padding:Num.t -> ?pos:Command.position -> ?name:string -> ?stroke:Color.t option -> ?pen:Pen.t -> ?dash:Dash.t -> ?min_width:Num.t -> ?same_width:bool -> t list -> thblock blaligns the boxes ofblhorizontally and surround them with new rectangular boxes of the same height; all these new boxes are packed together into the returned box.- parameter min_width
minimum width of all boxes; default is zero
- parameter same_width
if
true, all boxes are of same width, and at least ofmin_width; default is false
val vblock : ?padding:Num.t -> ?pos:Command.position -> ?name:string -> ?stroke:Color.t option -> ?pen:Pen.t -> ?dash:Dash.t -> ?min_height:Num.t -> ?same_height:bool -> t list -> tsimilar to
hblock, with vertical alignment.- parameter min_height
minimum height of all boxes; default is zero
- parameter same_height
if
true, all boxes are of same height, and at least ofmin_height; default is false
val grid : ?hpadding:Num.t -> ?vpadding:Num.t -> ?pos:Command.position -> ?stroke:Color.t option -> ?pen:Pen.t -> ?dash:Dash.t -> t array array -> tAligns the given boxes in a way that is similar to
hblockandvblock: boxes are aligned in a grid where all cells have the same size. Each one of these cells is a box containing the original corresponding box.
val gridl : ?hpadding:Num.t -> ?vpadding:Num.t -> ?pos:Command.position -> ?stroke:Color.t option -> ?pen:Pen.t -> ?dash:Dash.t -> t list list -> tsimilar to
grid, but using lists instead of arrays
val gridi : ?hpadding:Num.t -> ?vpadding:Num.t -> ?pos:Command.position -> ?stroke:Color.t option -> ?pen:Pen.t -> ?dash:Dash.t -> int -> int -> (int -> int -> t) -> tsimilar to
gridi, but using a matrix defined with a function
val place : position -> ?pos:position -> ?padding:Num.t -> t -> t -> tPlace a box relatively to another box.
place `East ais a function which places a box at the east ofa. Thus,place `East a breturns a copy ofbplaced at the east ofa.place posa ~pos: posb ~padding a breturns a new boxcwhich is obtained by movingbto place theposapoint ofaon top of theposbpoint ofb, and then padding the result bypaddingin directionposa.Default value of
posbis the opposite direction ofposawrt. the center (seeopposite_position). Default value ofpaddingis zero.The padding argument multiplies a unit vector which goes from the center of
ato the corner ofaindicated byposa. This effectively places pointposaofaat exactlypaddingunits of pointposbofb, in directionposa. This also means that for diagonal directions, the actual direction will change according to the width / height ratio ofa.
val relative : t -> t -> tAfter using one of the previous function which give you a group
gof box from multiple box (one of them must beb), you can userelative b gto translategso thatbinsidegis at the same place than before. Indeed it's justsuband a translation.relativeis really useful when someone make a slideshow from a succession of figures.
Sub-boxes accessors
val nth : int -> t -> tnth i breturns thei-th sub-box ofb. The first sub-box has index 0. RaisesInvalid_argumentif there is no such sub-box.
val get : string -> t -> tget n breturns the sub-box ofbof namen, if any, and raisesInvalid_argumentotherwise. The behavior is not specified ifbcontains several sub-boxes with namen.
Specials Points
Box properties
val get_fill : t -> Color.t optionval set_fill : Color.t -> t -> tval get_stroke : t -> Color.t optionval set_stroke : Color.t -> t -> tval clear_stroke : t -> tval get_name : t -> string optionval set_name : string -> t -> tval get_pen : t -> Pen.t optionval set_pen : Pen.t -> t -> tval set_height : Command.vposition -> Num.t -> t -> tval set_width : Command.hposition -> Num.t -> t -> tval get_dash : t -> Dash.t optionval set_dash : Dash.t -> t -> tval clear_dash : t -> tval set_height2 : vposition -> Num.t -> vposition -> Num.t -> t -> tset_height2 `North y1 `South y2 b return the box b with its height and center chosen such as the ordinate of the top (because of `North) of the box is at y1 and the ordinate of its south is at y2
val set_width2 : hposition -> Num.t -> hposition -> Num.t -> t -> tval set_size : Command.position -> width:Num.t -> height:Num.t -> t -> tval same_height : ?pos:vposition -> t list -> t listval same_width : ?pos:hposition -> t list -> t listval same_size : ?pos:position -> t list -> t listval henlarge : t list -> t listhenlarge lset the west boundaries of the box inlto the westest boundaries of the box inl. same for the east boundaries
Misc.
val shadow : t -> tval cpath : ?style:Path.joint -> ?outd:Path.direction -> ?ind:Path.direction -> ?sep:Num.t -> t -> t -> Path.tthe path that connects 2 boxes and stops at the box boundaries
val cpath_left : ?style:Path.joint -> ?outd:Path.direction -> ?ind:Path.direction -> ?sep:Num.t -> t -> Point.t -> Path.tthe path that connects a box and a point and stops at the box boundaries
val cpath_right : ?style:Path.joint -> ?outd:Path.direction -> ?ind:Path.direction -> ?sep:Num.t -> Point.t -> t -> Path.tthe path that connects a box and a point and stops at the box boundaries





