Position Script: Difference between revisions

From HLKitWiki
Jump to navigationJump to search
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{context|Kit Reference|Script Types}}
{{context|Kit Reference|Script Types}}
==Description==
The location of visual elements on the display is controlled via a number of different scripts. The location of templates is controlled via the Position script. Since templates are displayed within layouts that contain multiple visual elements, the actual position and dimensions of a template are usually controlled by its container. However, within the Position script, the location and dimensions of the portals within the template are also controlled. These portals are always positioned relative to the upper left corner of the template itself, so keep this in mind when performing any calculations.
{{note}}The Position script is read-only with respect to the contents of the portfolio, although visual elements may be modified. Within this script, all aspects of the hierarchy can be accessed, but nothing can be changed.


==Technical Details==
==Technical Details==
Line 18: Line 12:
|Fields Finalized?
|Fields Finalized?
|Yes
|Yes
|-
|Where Used:
|[[Template Element (Data)|Templates]], [[Layout Element (Data)|Layouts]], [[Panel Element (Data)|Panels]], [[Form Element (Data)|Forms]], [[Sheet Element (Data)|Sheets]]
|-
|Procedure Use:
|None
|-
|-
|}
|}


==Special Symbols==
The Position script utilizes the following special symbols:


:{| class="infotable"
:{| class="infotable"
Line 28: Line 28:
|-
|-
|}
|}
==Description==
The location of visual elements on the display is controlled via the Position script. This script is used the same way within scenes, layouts, and templates. Through this script, the visual elements contained within are sized and positioned. For example, a Position script for a template will coordinate the sizing and positioning of the various portals that are defined within the template.
Most visual elements are sized and positioned by their containing element. For example, a layout is often told by the containing scene how much space it gets to utilize and then it sizes it contents to fit within that space. However, there are times when visual elements must size themselves, so it is also possible for a visual element to size itself within its Position script. An example of this is where you have a template within a table that needs to determine its own height based on the information being shown within.
Within a visual container, the position of elements is always relative to the upper left corner of the container. If the container has a margin assigned, then upper left corner is adjusted accordingly. This ensures that the visual container can be positioned anywhere within its container, and the visual elements within don't need any knowledge of the container's position.
{{important}}The Position script for a template within a table is invoked separately for each item shown within the table. If the template is within a table containing items of non-varying height (the norm), the Position script is also invoked one '''additional''' time. The occurs '''before''' each item is processed and serves the purposes of calculating the of each item. When invoked for sizing, all text-based fields are empty and all value-based fields have a value of zero. The "issizing" target reference allows detection of this special use.
{{note}}The Position script is read-only with respect to the contents of the portfolio, although visual elements may be modified. Within this script, all aspects of the hierarchy can be accessed, but nothing can be changed.


==Example==
==Example==


For an example, we'll assume that we have a template that contains two portals: a label portal and a edit portal. The label portal is simply a literal string that is used to indicate the contents of the edit portal. The edit portal allows the user to modify the contents of a field within the pick, just like the hero's name is presented atop the display when using the d20 System data files. We assume that the location of the template itself is controlled by its container, with the template controlling its width and its contents. The Position script for a simple template like this might look like below:
Assume we have a template that contains two portals: a label portal and an edit portal. The template is used to let the user edit the name of something, so the label portal displays "Name:" and the edit portal allows the user to edit the name. The label portal will be automatically sized to the width of its text, so all we need to do is size the edit portal and position both portals. The Position script for a simple template like this might look like the following.


<pre>
<pre>
portal[stLblName].width = portal[stLblName].textwidth
~center both portals vertically
portal[stEdtName].left = portal[stLblName].right + 15
perform portal[label].centervert
portal[stEdtName].height = portal[stEdtName].fontheight + 2
perform portal[edit].centervert
width = portal[stEdtName].right
 
~pick a width for the edit portal
portal[edit].width = 150
 
~put the label on the left and the edit portal on its right
portal[label].left = 0
perform portal[edit].alignrel[ltor,label,10]
</pre>
</pre>

Latest revision as of 08:47, 20 February 2009

Context: HL Kit &#133; Kit Reference &#133; Script Types 

Technical Details

Initial Context: Scene or Layout or Template
Alternate Context: None
Fields Finalized? Yes
Where Used: Templates, Layouts, Panels, Forms, Sheets
Procedure Use: None

The Position script utilizes the following special symbols:

-None- There are no special symbols for a Position script

Description

The location of visual elements on the display is controlled via the Position script. This script is used the same way within scenes, layouts, and templates. Through this script, the visual elements contained within are sized and positioned. For example, a Position script for a template will coordinate the sizing and positioning of the various portals that are defined within the template.

Most visual elements are sized and positioned by their containing element. For example, a layout is often told by the containing scene how much space it gets to utilize and then it sizes it contents to fit within that space. However, there are times when visual elements must size themselves, so it is also possible for a visual element to size itself within its Position script. An example of this is where you have a template within a table that needs to determine its own height based on the information being shown within.

Within a visual container, the position of elements is always relative to the upper left corner of the container. If the container has a margin assigned, then upper left corner is adjusted accordingly. This ensures that the visual container can be positioned anywhere within its container, and the visual elements within don't need any knowledge of the container's position.

IMPORTANT! The Position script for a template within a table is invoked separately for each item shown within the table. If the template is within a table containing items of non-varying height (the norm), the Position script is also invoked one additional time. The occurs before each item is processed and serves the purposes of calculating the of each item. When invoked for sizing, all text-based fields are empty and all value-based fields have a value of zero. The "issizing" target reference allows detection of this special use.

NOTE! The Position script is read-only with respect to the contents of the portfolio, although visual elements may be modified. Within this script, all aspects of the hierarchy can be accessed, but nothing can be changed.

Example

Assume we have a template that contains two portals: a label portal and an edit portal. The template is used to let the user edit the name of something, so the label portal displays "Name:" and the edit portal allows the user to edit the name. The label portal will be automatically sized to the width of its text, so all we need to do is size the edit portal and position both portals. The Position script for a simple template like this might look like the following.

~center both portals vertically
perform portal[label].centervert
perform portal[edit].centervert

~pick a width for the edit portal
portal[edit].width = 150

~put the label on the left and the edit portal on its right
portal[label].left = 0
perform portal[edit].alignrel[ltor,label,10]