Navigation
Synopsis A rectangular box.
Function
  1. Figure box(FProperty props...)
  2. Figure box(Figure inner, FProperty props...)
Description Draw a rectangular box using the properties props. An optional nested figure inner may be placed inside the box.
Examples Lets start with a box b0 of given (minimal) dimensions:
b0 = box(size(150,50), fillColor("lightGray"));
render(b0);
that will display as: box0

We can nest a new box b1 in box b0 as follows:
b1 = box(shrink(0.8), fillColor("green"));
b0 = box(b1, size(150,50), fillColor("lightGray"));
render(b0);
The result is: box1

Note that:
  • Box b0 contains box b1.
  • The dimensions of b1 are determined by shrinking to 80% of the dimensions of b0.
The placement of an inner figure is determined by alignment, see align. We can, for instance, place b1 in the top left corner of b0:
b1 = box(shrink(0.8), align(0, 0), fillColor("green"));
b0 = box(b1, size(150,50), fillColor("lightGray"));
render(b0);
The result is: box2

Placing b1 in the bottom right corner of b0:
b1 = box(shrink(0.8), align(1, 1), fillColor("green"));
b0 = box(b1, size(150,50), fillColor("lightGray"));
render(b0);
gives: box3

We can also nest box b0 in another box b2 and make b2 20% larger than b0:
b0 = box(size(150,50), fillColor("lightGray"));
b2 = box(b0, grow(1.2), fillColor("blue"));
render(b2);
The result is: box4

If no sizes are given at all then the box will expand to fill the available size:

render(box(box(box(box(shrink(0.5)),shrink(0.5)),shrink(0.5))));
The result is: box5
Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.