prefab

Creates a DIY component based on a common layout with a minimum of coding effort.
Configuring Prefab Components
pfDIY
pfSettings
pfTitleBox
pfContentBox

Creates a DIY component based on a common layout with a minimum of coding effort.

The prefab library includes all the script code needed to create a basic DIY component that includes a title text area, a body text area, and optionally a portrait. All you need to supply is the name of a base setting key, and the library will do the rest, reading everything necessary for the component from settings.

Although no coding is required, the prefab library provides hooks for all of the standard DIY functions that allow you to customize behaviour or to extend the libary to create new prefab layouts. For each standard DIY function, you can define a "before" and/or "after" hook which will be called at the start and end of the prefab library's implementation of that function. For example, to customize the basic DIY configuration, which would normally happen in the create function, you would define the function afterCreate( diy ), which would be called after the prefab library finished its configuration. You can also replace the default implementation completely by assigning a replacement function: create = function myCreate( diy ) { ... }.

Configuring Prefab Components

To create a prefab component, a diy script must use the prefab library, then set the value of the variable pfBaseKey to a base name for a family of keys that will be used to configure the component. Note that every key has a default value; it is only necessary to define keys that differ from the default.

Key Suffix Effect or Purpose Default
The following keys describe the front face of the component. They are all optional except for -front-template.
-front-template Background image of front face. null, but templates/diy-default.png if default pfBaseKey is used
-front-template-hires Optional double resolution version of the background image for print/export. null
-front-ppi Background image resolution in pixels per inch. 150
-front-expsym-region Location of expansion symbol(s) on front face. null
-front-expsym-invert Index of the expansion symbol logical variant to use. 0
The following keys describe the back face of the component. If the template key is defined, the component will use the PLAIN_BACK face style; otherwise it will be SHARED_FACE. All of the keys are optional.
-back-template Background image of back face; makes component. PLAIN_BACK type. null
-back-template-hires Optional double resolution version of the background image for print/export. null
-back-ppi Background image resolution in pixels per inch. 150
-back-expsym-region Location of expansion symbol(s) on back face. null
-back-expsym-invert Index of the expansion symbol variant to use. 0
The following keys control whether, and where, a portrait image is drawn on the component.
-portrait-template Image to use as the default portrait image; if null, no portrait appears. null
-portrait-clip-region The region that the portrait image is drawn within. null
-portrait-scale The scale to use for the default portrait. fit automatically
-portrait-panx The x-offset to use for the default portrait. 0
-portrait-pany The y-offset to use for the default portrait. 0
-portrait-overlay Image to draw over the portrait. If not present, the portrait is drawn first, then the template. Otherwise, the template is drawn, followed by the portrait, and finally the overlay image. null
-portrait-overlay-regionRegion covered by the overlay image. cover the entire card
-portrait-on-back Boolean setting; if true, the portrait appears on the back face. false
The following keys control the initial content and labels for the component's text fields. They are all optional.
-name The initial name used for new components. empty string
-content The initial body content used for new components. empty string
-name-label The label used for the name text field. @prefab-l-name
-content-label The label used for the body content text field. @prefab-l-content
-tab-label The label used for the tab added to the editor. @prefab-l-tab
-panel-title The title applied to the layout panel containing the controls. null
The following keys control the location and style of the title text.
-name-region Region where the title is drawn; if null, there will be no title field. null
-name-oneliner Boolean setting; if true, the title is drawn as a single line. null (false)
-name-alignment Text alignment of the title text. centre, middle
-name-style Text style of the title text. null (uses default style for new markup boxes)
The following keys control the location and style of the content text.
-content-region Region where the content is drawn; if null, there will be no content field. null
-content-alignment Text alignment of the content text. centre, top
-content-style Text style of the content text. null (uses default style for new markup boxes)

pfDIY

This variable holds the DIY component.

pfSettings

This variable holds the component's private settings.

pfTitleBox

This variable holds the markup box used to lay out the card title, or null if there is no title. It is set during createFrontPainter.

pfContentBox

This variable holds the markup box used to lay out the content text, or null if there is no content text. It is set during createFrontPainter.

Contents