TIM

Following on from my last post about Tesseract, here's a little more information about TIM. Along with the rest of Tesseract, TIM was rewritten recently and is much more powerful in its latest incarnation. Lets begin with a small example, in C#:

using System;
using Tesseract;

namespace TestApp
{
    public class MyWindow: Window
    {
        public static void Main(string[] args)
        {
            Core.Init();
            Core.Run(TIM.Load<MyWindow>("MyGUI.xml"));
            Core.Done();
        }
    }
}

And now MyGUI.xml:

<?xml version="1.0" encoding="utf-8"?>
<TIM xmlns:t="Tesseract, Tesseract"
xmlns:tg="Tesseract.Geometry, Tesseract"
>

<t:Window Title="Test Application">
<Path><tg:Rectangle W="400" H="300"/></Path>
</t:Window>
</TIM>

This example is just about the simplest piece of TIM markup possible. It begins with a standard xml declaration, then the TIM node begins. This has a number of attributes which have an "xmlns" prefix (in blue). These are specifying namespaces which are used to tell the TIM loader where to look for types it needs to find. Within the TIM element is a t:Window element, this tells the loader to look inside the Tesseract assembly under the Tesseract namespace for a type named Window. This is the root object, i.e the object which the application using Tesseract has the option of creating itself and passing to the TIM loader (it can also be created by the TIM loader if no object is created by the application). This functionality is useful as it will allow for content to be loaded into existing controls. The windows Path property is set to a 400x300 pixel rectangle (in green). This produces the following:

Suppose we want to add a Button control to the Window, we simply add the following inside the t:Window element, so that the element is a child of the window element as the Button will be a child of the Window control:

<t:Button Text="Hi!"/>

The window now contains a Button control, as shown below:

The Button control is at 0,0 and is 100x100 pixels in size, as this is the default path for a control. If we want to move the button to 10,10 and make it 100x25 pixels, we change the button declaration to the following:

<t:Button Text="Hi!">
<Path><tg:Rectangle L="10" T="10" W="100" H="25"/></Path>
</t:Button>

Now we get this:

Better, but wouldn't that button look much better with rounded corners? Well, we set its Path property to a regular rectangle above, but Tesseract also has a RoundedRectangle class which we can use, we just have to change tg:Rectngle to tg:RoundedRectangle and add a value for how much the corners should be rounded (Rn):

<t:Button Text="Hi!">
<Path><tg:RoundedRectangle L="10" T="10" W="100" H="25" Rn="5"/></Path>
</t:Button>

Much better! This barely scratches the surface of what TIM can do, but it shows the basic concept, I will write more about TIM soon.