2.2.8. Add Margins to an Element (layout.managers.margins
)¶
-
class
layout.managers.margins.
MarginsLM
(top=0, right=0, bottom=0, left=0, element=None)¶ Bases:
layout.managers.root.LayoutManager
A layout manager that has only one element, surrounded by the given absolute margins.
-
get_minimum_size
(data)¶ How small can the element be? Should return a Point.
-
render
(rect, data)¶ Asks the element to render itself.
-
-
class
layout.managers.margins.
PaddedMarginsLM
(top=0.5, right=0.5, bottom=0.5, left=0.5, element=None)¶ Bases:
layout.managers.root.LayoutManager
A layout manager that surrounds its single element by margins that grow with the available space. The margins grow with the available space in the given proportions. If the proportions for a pair of margins don’t add up to 1.0, then any additional proportion will be given to the element to make it grow.
Using this layout manager with the correct proportions, you can duplicate the behavior of the
layout.managers.align.AlignLM
. This class provides more flexibility, however.-
get_minimum_size
(data)¶ Our minimum size is simply our element’s minimum size.
-
render
(rect, data)¶ Asks the element to render itself.
-
-
class
layout.managers.margins.
ProportionalMarginsLM
(top=0, right=0, bottom=0, left=0, element=None)¶ Bases:
layout.managers.root.LayoutManager
A layout manager that has only one element, surrounded by the given margins that are proportional to total size of this manager.
For example, if we specify that the left margin is at 0.2 and the right margin is at 0.4, then the child element will be 0.4 times the width of this manager.
Pairs of margins (left & right or top & bottom) must sum to at least zero, and strictly less than 1.
-
get_minimum_size
(data)¶ How small can the element be? Should return a Point.
-
render
(rect, data)¶ Asks the element to render itself.
-
-
class
layout.managers.margins.
VanDeGraafCanonLM
(recto=True, element=None)¶ Bases:
layout.managers.margins.ProportionalMarginsLM
Wraps its child element in margins calculated according to the Van de Graaf page construction canon.
Using this canon the proportions of the child element are the same as the proportions of this manager. The standard de Graaf proportions are based on geometrical construction, here we perform the calculation, by dividing the page into ninths (the original canon would also do this, if drawn precisely, obviously we don’t allow for the innacuracies in drawing which would have been common in medieval manuscripts).
Using this approach the child element gets two thirds of both the height and the width of the parent element.