tabs.lzx
<library>
<include href="base/basetabs.lzx"/>
<include href="base/basecomponent.lzx"/>
<include href="base/swatchview.lzx"/>
<include href="utils/layouts/stableborderlayout.lzx"/>
<include href="utils/layouts/simplelayout.lzx"/>
<resource name="tab_L_rsc">
<frame src="resources/tab/tab_disable_lft.swf"/>
<frame src="resources/tab/tab_dslct_lft.swf"/>
<frame src="resources/tab/tab_mo_lft.swf"/>
<frame src="resources/tab/tab_slct_lft.swf"/>
</resource>
<resource name="tab_M_rsc">
<frame src="resources/tab/tab_disable_mid.swf"/>
<frame src="resources/tab/tab_dslct_mid.swf"/>
<frame src="resources/tab/tab_mo_mid.swf"/>
<frame src="resources/tab/tab_slct_mid.swf"/>
</resource>
<resource name="tab_R_rsc">
<frame src="resources/tab/tab_disable_rt.swf"/>
<frame src="resources/tab/tab_dslct_rt.swf"/>
<frame src="resources/tab/tab_mo_rt.swf"/>
<frame src="resources/tab/tab_slct_rt.swf"/>
</resource>
<class name="tab" extends="basetab">
<attribute name="padding" value="20
"/>
<attribute name="tabstate" value="2
" type="number"/>
<attribute name="MIN_TEXT_BORDER" value="2
" type="number"/>
<attribute name="titleshift" value="${this.tabstate == 4 ? 4 : 0}" type="number"/>
<attribute name="width" value="${tabview.labeltext.getTextWidth() + 2*padding}"/>
<view name="tabview" width="100%">
<stableborderlayout axis="x"/>
<view name="left" resource="tab_L_rsc">
<attribute name="frame" value="${classroot.tabstate}"/>
</view>
<view name="middle" resource="tab_M_rsc" stretches="width">
<attribute name="frame" value="${classroot.tabstate}"/>
</view>
<view name="right" resource="tab_R_rsc">
<attribute name="frame" value="${classroot.tabstate}"/>
</view>
<statictext name="labeltext" x="${parent.parent.width/2 - this.width/2}" y="${parent.parent.height/2-(this.height/2) - parent.parent.titleshift +4}" text="${parent.parent.text}" resize="true">
</statictext>
</view>
<method name="_applystyle" args="s">
tabview.labeltext.setAttribute('fgcolor',s.textcolor);
setTint(tabview.left, s.basecolor);
setTint(tabview.middle, s.basecolor);
setTint(tabview.right, s.basecolor);
</method>
<method name="_showEnabled">
setAttribute('tabstate', this._enabled ? 2 : 1);
</method>
<handler name="onmouseover">
setAttribute('tabstate', 3);
</handler>
<handler name="onmouseout">
if (!this["selected"]) {
setAttribute('tabstate',2);
}
</handler>
<method name="setSelected" args="s">
if (s) {
setAttribute('tabstate', 4);
setAttribute("y", 1);
} else {
setAttribute('tabstate', 2);
setAttribute("y",0);
}
super.setSelected(s);
</method>
<method name="setHilite" args="dohilite">
tabview.labeltext.setAttribute('fgcolor',
dohilite ? style.texthilitecolor : style.textcolor);
</method>
<doc>
<tag name="shortdesc"><text>
The lz tab is used by tabs.
</text></tag>
<text>
<p>
A <classname>tab</classname> is an LZ tab within <sgmltag class="element" role="lz.basetabsbar"><basetabsbar></sgmltag>
or any object that extends this (such as <sgmltag class="element" role="lz.tabsbar"><tabsbar></sgmltag>).
</p>
<example>
<canvas height="100">
<include href="lz" />
<basetabs x="10" y="10" tabclass="tab">
<basetabpane text="one">
<text>one</text>
</basetabpane>
<basetabpane text="two">
<text>two</text>
</basetabpane>
</basetabs>
</canvas>
</example>
<seealso>
<classes>tabsbar tabpane tabs basetab</classes>
</seealso>
</text>
</doc>
</class>
<class name="tabsbar" extends="basetabsbar" itemclassname="tab" x="-5" clip="true" layout="class: simplelayout; axis: x; spacing: -15">
<attribute name="spacing" value="0
" type="number" setter="_setTabSpacing(spacing)"/>
<method name="init">
super.init();
bringToFront();
</method>
<method name="_setTabSpacing" args="s">
if (! _initcomplete) return;
for (var i=0; i < subnodes.length; i++) {
var sn = subnodes[i];
if (sn instanceof lz.simplelayout) {
sn.setAttribute('spacing', s);
}
}
</method>
<doc>
<tag name="shortdesc"><text>
The lz tabsbar class for laying out tab items.
</text></tag>
<text>
<p>
A <classname>tabsbar</classname> is a container that uses
a default x-axis <xref linkend="lz.simplelayout"/> with a
spacing of -15 to lay out its tab children (which have
extra spacing on each side) so they overlap.
</p>
<p>
This it the default tab bar created by tabpane. This class
is dependent on tabs (or any subclass of basetabs) and
shouldn't be used by itself. The default layout for its
subviews is "class: simplelayout; axis: x; spacing: -15".
You can pass the name of this class in the 'barclass'
attribute of tabpane, basetabpane, basetabs, and tabs.
Tabs uses this class as its default 'barclass'.
</p>
<example>
<canvas height="100">
<include href="lz"/>
<simplelayout axis="x" spacing="10"/>
<view layout="class: simplelayout; axis: y; spacing: 5"
bgcolor="red">
<text>basetabs barclass=basetabsbar</text>
<basetabs y="10" tabclass="tab" barclass="basetabsbar">
<basetabpane text="one">
<text>one</text>
</basetabpane>
<basetabpane text="two">
<text>two</text>
</basetabpane>
<basetabpane text="three">
<text>three</text>
</basetabpane>
</basetabs>
</view>
<view layout="class: simplelayout; axis: y; spacing: 5"
bgcolor="yellow">
<text>basetabs barclass=tabsbar</text>
<basetabs y="10" tabclass="tab" barclass="tabsbar">
<basetabpane text="one">
<text>one</text>
</basetabpane>
<basetabpane text="two">
<text>two</text>
</basetabpane>
<basetabpane text="three">
<text>three</text>
</basetabpane>
</basetabs>
</view>
</canvas>
</example>
<seealso>
<classes>tab tabs basetabsbar</classes>
</seealso>
</text>
</doc>
</class>
<class name="tabpane" extends="basetabpane" bgcolor="0xd9d9d9">
<attribute name="tabwidth" value="-1
" type="number"/>
<attribute name="_keepchildren" value="1
" type="number"/>
<swatchview name="background" width="100%" height="100%" bgcolor="${parent.bgcolor}"/>
<method name="init">
super.init();
// Set width attribute of associated tab if tabwidth is defined
if (this.tabwidth > -1) {
this.tab.setAttribute('width', this.tabwidth);
}
</method>
<method name="_applystyle" args="s">
if (this.style != null) {
setTint(background, s.basecolor);
}
</method>
<doc>
<tag name="shortdesc"><text>
A tabpane houses content to be shown within a tabs component when its
correlated tab is selected.
</text></tag>
<text>
<p>
<classname>tabpane</classname> is the visual container for content in
<xref linkend="lz.basetabs"/>. The difference between this class and
<xref linkend="lz.basetabpane"/> is that <classname>tabpane</classname>
has a background <xref linkend="lz.swatchview"/> that is set by whatever
the default style is.
</p>
<p>
Note that the content of tabpane is <code>initstage="late"</code>.
You can override this by explicitly setting your <attribute>initstage</attribute>
preference on tabpane.
</p>
<programlisting>
<tabpane initstage="normal">
<!-- ...content... -->
</tabpane>
</tabpane>
</programlisting>
<p>
For every <tagname>tabpane</tagname> declared, a corresponding
<xref linkend="lz.tab"/> is created.
</p>
<example>
<canvas height="150" >
<include href="base"/>
<simplelayout axis="y" spacing="5"/>
<text x="10" multiline="true" width="200">
First two are tabpanes, the last one is a basetabpane
</text>
<basetabs x="10" tabclass="tab" bgcolor="green">
<tabpane>
<text>one</text>
</tabpane>
<tabpane>
<text>two</text>
</tabpane>
<basetabpane>
<text>three</text>
</basetabpane>
</basetabs>
</canvas>
</example>
</text>
</doc>
</class>
<class name="tabscontent" extends="basetabscontent" bgcolor="0x4c4c4c">
<attribute name="defaultplacement" value="borderedcontent
" type="string"/>
<view name="borderedcontent" x="${parent.parent.bordersize}" y="${parent.parent.bordersize}" width="${parent.width-(2*parent.parent.bordersize)}" height="${parent.height-(2*parent.parent.bordersize)}" clip="true"/>
<doc>
<tag name="shortdesc"><text>
The tabs content container for tabpanes.
</text></tag>
<text>
<p>
<classname>tabscontent</classname> houses a stack of
<xref linkend="lz.tabpane"/>s for <xref linkend="lz.tabs"/>,
which has a visual border and uses the default style's
background color. When a <classname>tabspane</classname>
is added to a <classname>tabs</classname>, its content
are actually placed in <classname>tabscontent</classname>.
</p>
<p>
Said another way, <classname>tabscontent</classname> is the
class used by tabs to place tabpanes. Visually, it contains
a border. The size of the border is constrained by its parent's
(tabs) bordersize attribute value. You can pass the name of
this class in the 'contentclass' attribute of basetabs and
tabs. Tabs uses this class as its default 'contentclass'.
</p>
<example>
<canvas height="100">
<include href="lz"/>
<simplelayout axis="x" spacing="10"/>
<view layout="class: simplelayout; axis: y; spacing: 5"
bgcolor="red">
<text>contentclass=basetabscontent</text>
<basetabs y="10" bordersize="5"
tabclass="tab" contentclass="basetabscontent">
<basetabpane text="one" bgcolor="teal">
<text>one</text>
</basetabpane>
<basetabpane text="two" bgcolor="green">
<text>two</text>
</basetabpane>
<basetabpane text="three" bgcolor="blue">
<text>three</text>
</basetabpane>
</basetabs>
</view>
<view layout="class: simplelayout; axis: y; spacing: 5"
bgcolor="yellow">
<text>contentclass=tabscontent</text>
<basetabs y="10" bordersize="5"
tabclass="tab" contentclass="tabscontent">
<basetabpane text="one" bgcolor="teal">
<text>one</text>
</basetabpane>
<basetabpane text="two" bgcolor="green">
<text>two</text>
</basetabpane>
<basetabpane text="three" bgcolor="blue">
<text>three</text>
</basetabpane>
</basetabs>
</view>
</canvas>
</example>
<seealso>
<classes>tabs tabpane basetabscontent</classes>
</seealso>
</text>
</doc>
</class>
<class name="tabs" extends="basetabs" clip="true">
<attribute name="tabalign" value="left
" type="string" setter="_setTabAlign(tabalign)"/>
<attribute name="tabspacing" value="-15
" type="number" setter="_setTabSpacing(tabspacing)"/>
<attribute name="bordersize" value="1
" type="number"/>
<attribute name="tabclass" value="tab
" type="string"/>
<attribute name="barclass" value="tabsbar
" type="string"/>
<attribute name="contentclass" value="tabscontent
" type="string"/>
<attribute name="layout" value="class: simplelayout; axis: y; spacing: -2
"/>
<method name="init">
super.init();
// This also calls _setTabAlign()
this._setTabSpacing(this.tabspacing);
</method>
<method name="_setTabAlign" args="align">
this.tabalign = align;
if (! _initcomplete) return;
if (align == "center") {
this.bar.setAttribute('x', Math.floor(this.width/2 - this.bar.width/2));
} else if (align == "right") {
this.bar.setAttribute('x', this.width - this.bar.width + 7);
} else { // left
this.bar.setAttribute('x', -5);
}
</method>
<method name="_setTabSpacing" args="s">
this.tabspacing = s;
if (! _initcomplete) return;
this.bar.setAttribute('spacing', s);
this._setTabAlign(tabalign);
</method>
<doc>
<tag name="shortdesc"><text>
The tabs class takes tabpanes, and provides a tab for each one.
</text></tag>
<text>
<p>The <classname>tabs</classname> component contains a row of
<classname>tabs</classname> that control the visibility of a stack of
<sgmltag class="element" role="lz.tabpane"><tabpane></sgmltag>s. When a <sgmltag class="element" role="lz.tabpane"><tabpane></sgmltag>
is added to a <classname>tabs</classname> component, a corresponding
tab is created for that <sgmltag class="element" role="lz.tabpane"><tabpane></sgmltag>. The text which shows up in the tab is
derived from the <attribute>text</attribute> attribute of the
<sgmltag class="element" role="lz.tabpane"><tabpane></sgmltag>.</p>
<p>The <classname>tabs</classname> component will be sized
automatically to the largest <classname>tabpane</classname>, unless an
explicit <attribute>height</attribute> or <attribute>width</attribute>
is specified within the <tagname>tabs</tagname> tag.</p>
<example>
<canvas height="100">
<tabs>
<tabpane text="one">
<button>press one</button>
</tabpane>
<tabpane text="two">
<button>press two</button>
</tabpane>
</tabs>
</canvas>
</example>
<p><b>See Also:</b></p>
<ul>
<li>
<sgmltag class="element" role="lz.tab"><tab></sgmltag>, <sgmltag class="element" role="lz.tabsbar"><tabsbar></sgmltag>,
<sgmltag class="element" role="lz.tabpane"><tabpane></sgmltag>, <sgmltag class="element" role="lz.tabscontent"><tabscontent></sgmltag>, and
<sgmltag class="element" role="lz.basetabs"><basetabs></sgmltag>
</li>
</ul>
</text>
</doc>
</class>
</library>
Cross References
Includes
Resources
Classes
- <class name="tab" extends="basetab">
- <class name="tabsbar" extends="basetabsbar">
- <class name="tabpane" extends="basetabpane">
- <class name="tabscontent" extends="basetabscontent">
- <class name="tabs" extends="basetabs">