Templates Tutorial

In order to ease the development of common interface constructs like windows, buttons, scrollbars and menus, a number of templates are available as standard when DML is installed on a user's system. The availability of these templates means that you are relieved of the task of creating common controls yourself. Template files are stored in the "templates:" directory of your installation, so you can check this directory to see what's available on your own system. Each template has its own set of documentation, so if you open the DML files in a text editor, you can read up on how each template works.

Why Templates Make Life Easier

Earlier in our tutorials we showed you how to create a fully functional, interactive button. In reality however, the last thing you want to do is copy and paste the same large amount of code every time you want to create a button within an application. As luck would have it, a template to create buttons already exists. Here's a button that's based on the template:

This is the code that we used to create it:

   <button x="0" y="0" xoffset="0" yoffset="0" text="Click Me!"/>

Wow, only one line - and to think we went through all that effort earlier when a single line would have sufficed! This makes our point on the power of using templates to the fullest - they can save you a lot of time and effort. Here's a table that lists the most commonly used templates and what they are for:

TemplateDescription
ButtonThe Button template creates interactive buttons that you can program with customised responses when the user clicks on them.
FileDialogThe FileDialog template is used when you want to prompt the user to open or save a file.
IconSimilar to the Button template, the Icon template creates images that respond to user clicks. Unlike buttons, the user can drag icons around the display.
InputUse the Input template whenever you want to create an input box that the user can type text into.
InsideBorderThe InsideBorder template is used to create borders around gadgets, input boxes, output boxes and so forth. Use of this template will ensure that your DML program retains a consistent look and feel with the rest of the user's system.
MenuBarThe MenuBar template can be used when you want to create a menu at the top of an interface.
ScrollBarThe ScrollBar template provides your DML scripts with all the power of a standard scrollbar.
WindowThe Window template should be used whenever you want to create a new desktop window for your application. This template carries many options and it is highly recommended that you open the window template file to read its documentation.

Calling Templates

Calling a template is extremely simple, as the DML interpreter allows you to call them as if they are standard object-based tags. For instance, to create a new window you would use a tag similar to the following:

  <window x="10" y="30" insidewidth="200" insideheight="200">
    dml content
  </window>

It is also possible to call templates with the script tag, for example:

  <script src="templates:window" x="10" y="30" insidewidth="200" insideheight="200">
    dml content
  </script>

When using the window template with the DML Internet plugin, it is important to note that unless you have opened a DML desktop within the embedded area, the plugin will open a standard window that is independent of the user's Internet browser and the HTML page. In such a case, you should keep in mind that the window will automatically close when the user leaves the HTML page from which the window was created.

Customising Templates

One of the most useful aspects of templates is that the location of the template files can be redirected to other directories. What this essentially means is that the user can adjust the look and feel of your application by creating new template files and redirecting all DML scripts towards them. This allows the look and feel to be easily adjusted without having any adverse effects on your application. In some cases your application may take on a very different appearance to your original intentions, but the end user will be happier with a program that is tuned to their own environment, while still behaving the way you intended.

To customise your templates, you can either edit the files directly (this is not recommended) or you can copy the contents of the "templates:" directory to a new location and refer to it in your "user:config/asssignments.cfg" file by adding the suggested template line:

   [LIST]
   ...
   templates = path:your/template/directory/

Once you restart the system, the templates will be loaded from the location that you have set.

  1. Introduction
  2. Basic Graphics
  3. User Interaction
  4. Advanced Graphics
  5. Templates
  6. Advanced Topics

About Us | News | Downloads | Athene  |  SDK | DML | Forums | Site Index

Copyright Rocklyte Ltd © 2002-2007.