Copyright © 2008, 2009 Arndt Roger Schneider
The procedure template creates a Runtime Library based template.
Example 9.1. rtl::template public Interface
namespace eval sample {
# Template Interface definition
variable var
array set var {
original toplevel
attributes { background foreground }
background {
{0 background}
}
foreground {{3 foreground}}
}
# to be continued with window structure…
Example 9.2. …continued rtl::template Structure
# Template window Structure (used by
# the interface):
variable w
array set w {
0 {}
1 .first
2 .second
3. first.third
...
}
# to be continued with implementation…
The windowing hierarchy ... notice there is no main window $base or $base$w(0). The base window was created by »rtl::template«!
Example 9.3. …continued rtl::template Implementation
rtl::template sample {
frame $base$w(1) -borderwidth 0
frame $base$w(2) -background red
button $base$w(3) -text Sample
pack $base$w(3)
pack $base$w(2) -side bottom
pack $base$w(1) -side top
}
} ;# end of namespace sample
The above Example 9.2, “…continued rtl::template Structure” to Example 9.3, “…continued rtl::template Implementation” shows a complete template definition. »template« creates a procedure named »sample« inside the namespace »sample« , which contains the structure of the new template.
The created template is then used in the usual way.
Example 9.4. Using a Runtime Library based Template
sample::sample .mysample \
-foreground black \
-background white