Header Script: Difference between revisions

From HLKitWiki
Jump to navigationJump to search
New page: {{context|Kit Reference|Script Types}} ==Technical Details== :{| class="scripttable" |class="leftnormal"|Initial Context: |Template |- |Alternate Context: |None |- |...
 
No edit summary
Line 25: Line 25:
==Description==
==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.
The Header script behaves very similarly to the [[Position Script|Position script]]. This script's purpose is to handle the sizing and positioning of visual elements in one specific situation. When the same template is used within a table for positioning both items '''and''' a header, the Header script serves to position the header portals. If two separate templates are used for items versus header, the Position script for each is used and the Header script is not employed.


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.
Although the behaviors are similar, the Header script is distinct from the Position script in a variety of ways. First of all, portals within the template that are designated as "isheader" are only accessible via the Header script, hence the name. Second, the Header script is invoked '''after''' the normal Position script. This allows the header contents to be sized and positioned relative to the final locations for non-header portals. To make this easy, the Header script '''can''' access '''both''' header and non-header portals, although any positioning changes to non-header portals is ignored.


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.
For more details, please see the section on [[[[Dual-purpose Headers on Tables|dual-purpose headers]].
 
{{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==


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.
We'll assume that there are two fields within each item of the table that we want to put a simple header above. Let's call them "damage" and "range", and each is shown within its own portal. These two portals are positioned via the Position script, so the Header script will position the header labels directly above those portals.


<pre>
<pre>
~center both portals vertically
~our header height is the height of our labels
perform portal[label].centervert
height = portal[hdrdamage].height
perform portal[edit].centervert
 
~if this is a "sizing" calculation, we're done
if (issizing <> 0) then
  done
  endif
 
~each of our header labels has the same width as the corresponding data beneath
portal[hdrdamage].width = portal[damage].width
portal[hdrrange].width = portal[range].width


~pick a width for the edit portal
~center each header label on the corresponding data beneath
portal[edit].width = 150
perform portal[hdrdamage].centeron[horz,damage]
perform portal[hdrrange].centeron[horz,range]


~put the label on the left and the edit portal on its right
~align all header labels at the bottom of the header region
portal[label].left = 0
perform portal[hdrdamage].alignedge[bottom,0]
perform portal[edit].alignrel[ltor,label,10]
perform portal[hdrrange].alignedge[bottom,0]
</pre>
</pre>

Revision as of 09:52, 12 December 2008

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

Technical Details

Initial Context: Template
Alternate Context: None
Fields Finalized? Yes

The Header script utilizes the following special symbols:

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

Description

The Header script behaves very similarly to the Position script. This script's purpose is to handle the sizing and positioning of visual elements in one specific situation. When the same template is used within a table for positioning both items and a header, the Header script serves to position the header portals. If two separate templates are used for items versus header, the Position script for each is used and the Header script is not employed.

Although the behaviors are similar, the Header script is distinct from the Position script in a variety of ways. First of all, portals within the template that are designated as "isheader" are only accessible via the Header script, hence the name. Second, the Header script is invoked after the normal Position script. This allows the header contents to be sized and positioned relative to the final locations for non-header portals. To make this easy, the Header script can access both header and non-header portals, although any positioning changes to non-header portals is ignored.

For more details, please see the section on [[dual-purpose headers.

Example

We'll assume that there are two fields within each item of the table that we want to put a simple header above. Let's call them "damage" and "range", and each is shown within its own portal. These two portals are positioned via the Position script, so the Header script will position the header labels directly above those portals.

~our header height is the height of our labels
height = portal[hdrdamage].height

~if this is a "sizing" calculation, we're done
if (issizing <> 0) then
  done
  endif

~each of our header labels has the same width as the corresponding data beneath
portal[hdrdamage].width = portal[damage].width
portal[hdrrange].width = portal[range].width

~center each header label on the corresponding data beneath
perform portal[hdrdamage].centeron[horz,damage]
perform portal[hdrrange].centeron[horz,range]

~align all header labels at the bottom of the header region
perform portal[hdrdamage].alignedge[bottom,0]
perform portal[hdrrange].alignedge[bottom,0]