<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>muhuk.com &#187; javascript</title>
	<atom:link href="http://www.muhuk.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.muhuk.com</link>
	<description>know thyself</description>
	<lastBuildDate>Wed, 07 Jul 2010 10:26:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Nominate Qooxdoo for SourceForge Community Choice Awards</title>
		<link>http://www.muhuk.com/2009/05/nominate-qooxdoo-for-sourceforge-community-choice-awards/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=nominate-qooxdoo-for-sourceforge-community-choice-awards</link>
		<comments>http://www.muhuk.com/2009/05/nominate-qooxdoo-for-sourceforge-community-choice-awards/#comments</comments>
		<pubDate>Sat, 16 May 2009 08:00:34 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[free software]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[qooxdoo]]></category>
		<category><![CDATA[ria]]></category>
		<category><![CDATA[share]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=215</guid>
		<description><![CDATA[I&#8217;ve just voted Qooxdoo for Most Likely to Change the Way You Do Everything category. You can use the link below to vote yourself: Related posts:Why Not To Localize Community Support Using Layouts In Qooxdoo &#8211; Part 1 Using Layouts In Qooxdoo &#8211; Index]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just voted <a href="http://qooxdoo.org/">Qooxdoo</a> for <strong>Most Likely to Change the Way You Do Everything</strong> category.</p>

<p>You can use the link below to vote yourself:</p>

<p><a href="http://sourceforge.net/community/cca09/nominate/?project_name=qooxdoo&#038;project_url=http://qooxdoo.org/"><img src="http://sourceforge.net/images/cca/cca_nominate.png" border="0"/></a></p>


<p>Related posts:<ol><li><a href='http://www.muhuk.com/2010/04/why-not-to-localize-community-support/' rel='bookmark' title='Permanent Link: Why Not To Localize Community Support'>Why Not To Localize Community Support</a></li>
<li><a href='http://www.muhuk.com/2009/01/using-layouts-in-qooxdoo-part-1/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 1'>Using Layouts In Qooxdoo &#8211; Part 1</a></li>
<li><a href='http://www.muhuk.com/2009/04/using-layouts-in-qooxdoo-index/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Index'>Using Layouts In Qooxdoo &#8211; Index</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2009/05/nominate-qooxdoo-for-sourceforge-community-choice-awards/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Layouts In Qooxdoo &#8211; Index</title>
		<link>http://www.muhuk.com/2009/04/using-layouts-in-qooxdoo-index/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=using-layouts-in-qooxdoo-index</link>
		<comments>http://www.muhuk.com/2009/04/using-layouts-in-qooxdoo-index/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 15:25:01 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[qooxdoo]]></category>
		<category><![CDATA[ria]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=192</guid>
		<description><![CDATA[Using Layouts In Qooxdoo tutorial series is finished. I tried my best to explain how layout managers work and how they differ from each other. This tutorial is for those who have little or no object oriented GUI programming experience. Especially JavaScript/DOM programmers learning Qooxdoo. I hope it is helpful. Complete list of parts: Introduction [...]]]></description>
			<content:encoded><![CDATA[<p>Using Layouts In Qooxdoo tutorial series is finished. I tried my best to explain how layout managers work and how they differ from each other. This tutorial is for those who have little or no object oriented GUI programming experience. Especially JavaScript/DOM programmers learning <a href="http://qooxdoo.org/">Qooxdoo</a>. I hope it is helpful.</p>

<p>Complete list of parts:</p>

<ol>
<li><a href="http://www.muhuk.com/2009/01/using-layouts-in-qooxdoo-part-1/">Introduction</a></li>
<li><a href="http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-2-vbox-layout/">VBox Layout</a></li>
<li><a href="http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-3-hbox-layout/">HBox Layout</a></li>
<li><a href="http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-4-grid-layout/">Grid Layout</a></li>
<li><a href="http://www.muhuk.com/2009/04/using-layouts-in-qooxdoo-part-5-basic-canvas/">Basic &amp; Canvas Layouts</a></li>
</ol>


<p>Related posts:<ol><li><a href='http://www.muhuk.com/2009/01/using-layouts-in-qooxdoo-part-1/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 1'>Using Layouts In Qooxdoo &#8211; Part 1</a></li>
<li><a href='http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-2-vbox-layout/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 2: VBox Layout'>Using Layouts In Qooxdoo &#8211; Part 2: VBox Layout</a></li>
<li><a href='http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-3-hbox-layout/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 3: HBox Layout'>Using Layouts In Qooxdoo &#8211; Part 3: HBox Layout</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2009/04/using-layouts-in-qooxdoo-index/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Layouts In Qooxdoo &#8211; Part 5: Basic &amp; Canvas</title>
		<link>http://www.muhuk.com/2009/04/using-layouts-in-qooxdoo-part-5-basic-canvas/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=using-layouts-in-qooxdoo-part-5-basic-canvas</link>
		<comments>http://www.muhuk.com/2009/04/using-layouts-in-qooxdoo-part-5-basic-canvas/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 07:57:40 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[qooxdoo]]></category>
		<category><![CDATA[ria]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=183</guid>
		<description><![CDATA[This is the fifth part of a tutorial series about layout managers, container objects and object hierarchies in Qooxdoo. Read the first part here. Basic Layout Manager qx.ui.layout.Basic layout manager positions your widgets with absolute coordinates. It doesn&#8217;t have much to offer except the freedom of manual positioning. We supply a left and top property [...]]]></description>
			<content:encoded><![CDATA[<p><small>This is the fifth part of a tutorial series about layout managers, container objects and object hierarchies in Qooxdoo. Read the first part <a href="/2009/01/using-layouts-in-qooxdoo-part-1/">here</a>.</small></p>

<h3>Basic Layout Manager</h3>

<p><code>qx.ui.layout.Basic</code> layout manager positions your widgets with absolute coordinates. It doesn&#8217;t have much to offer except the freedom of manual positioning.</p>

<p>We supply a <code>left</code> and <code>top</code> property when we add our widgets. Following example places buttons in a circular path, like a clock.</p>

<pre><code><span style="color:#9a9a9a">   1 </span><span style="color:#38ad24">/*</span>
<span style="color:#9a9a9a">   2 </span><span style="color:#38ad24">#asset(qooxdoolayouts/*)</span>
<span style="color:#9a9a9a">   3 </span><span style="color:#38ad24">*/</span>
<span style="color:#9a9a9a">   4 </span>qx<span style="color:#555555">.</span>Class<span style="color:#555555">.</span><span style="color:#d11ced">define</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;qooxdoolayouts.Application&quot;</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">   5 </span><span style="color:#555555">{</span>
<span style="color:#9a9a9a">   6 </span>    extend<span style="color:#555555">:</span> qx<span style="color:#555555">.</span>application<span style="color:#555555">.</span>Standalone<span style="color:#555555">,</span>
<span style="color:#9a9a9a">   7 </span>    members<span style="color:#555555">: {</span>
<span style="color:#9a9a9a">   8 </span>        main<span style="color:#555555">:</span> <span style="color:#ff3030; font-weight:bold">function</span><span style="color:#555555">(){</span>
<span style="color:#9a9a9a">   9 </span>            <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">base</span><span style="color:#555555">(</span>arguments<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  10 </span>
<span style="color:#9a9a9a">  11 </span>            <span style="color:#ff3030; font-weight:bold">var</span> main_container <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>container<span style="color:#555555">.</span><span style="color:#d11ced">Composite</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  12 </span>
<span style="color:#9a9a9a">  13 </span>            <span style="color:#ff3030; font-weight:bold">var</span> layout_manager <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>layout<span style="color:#555555">.</span><span style="color:#d11ced">Basic</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  14 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">setLayout</span><span style="color:#555555">(</span>layout_manager<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  15 </span>
<span style="color:#9a9a9a">  16 </span>            <span style="color:#ff3030; font-weight:bold">var</span> btn_size <span style="color:#555555">=</span> <span style="color:#32ba06">50</span><span style="color:#555555">;</span>
<span style="color:#9a9a9a">  17 </span>            <span style="color:#ff3030; font-weight:bold">var</span> distance <span style="color:#555555">=</span> <span style="color:#32ba06">175</span><span style="color:#555555">;</span>
<span style="color:#9a9a9a">  18 </span>            <span style="color:#ff3030; font-weight:bold">var</span> pi2 <span style="color:#555555">=</span> <span style="color:#32ba06">2</span> <span style="color:#555555">*</span> <span style="color:#32ba06">3.141592</span><span style="color:#555555">;</span>
<span style="color:#9a9a9a">  19 </span>            center <span style="color:#555555">= {</span>
<span style="color:#9a9a9a">  20 </span>                x<span style="color:#555555">:</span> <span style="color:#0000ff">Math</span><span style="color:#555555">.</span><span style="color:#0000ff">round</span><span style="color:#555555">(</span>qx<span style="color:#555555">.</span>bom<span style="color:#555555">.</span>Viewport<span style="color:#555555">.</span><span style="color:#d11ced">getWidth</span><span style="color:#555555">()/</span><span style="color:#32ba06">2</span><span style="color:#555555">)-</span>btn_size<span style="color:#555555">/</span><span style="color:#32ba06">2</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  21 </span>                y<span style="color:#555555">:</span> <span style="color:#0000ff">Math</span><span style="color:#555555">.</span><span style="color:#0000ff">round</span><span style="color:#555555">(</span>qx<span style="color:#555555">.</span>bom<span style="color:#555555">.</span>Viewport<span style="color:#555555">.</span><span style="color:#d11ced">getHeight</span><span style="color:#555555">()/</span><span style="color:#32ba06">2</span><span style="color:#555555">)-</span>btn_size<span style="color:#555555">/</span><span style="color:#32ba06">2</span>
<span style="color:#9a9a9a">  22 </span>            <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  23 </span>
<span style="color:#9a9a9a">  24 </span>            <span style="color:#ff3030; font-weight:bold">for</span> <span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">var</span> i<span style="color:#555555">=</span><span style="color:#32ba06">0</span><span style="color:#555555">;</span> i<span style="color:#555555">&lt;</span><span style="color:#32ba06">12</span><span style="color:#555555">;</span> i<span style="color:#555555">++) {</span>
<span style="color:#9a9a9a">  25 </span>                <span style="color:#ff3030; font-weight:bold">var</span> button <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;CW&quot;</span><span style="color:#555555">+(</span>i<span style="color:#555555">+</span><span style="color:#32ba06">1</span><span style="color:#555555">).</span><span style="color:#0000ff">toString</span><span style="color:#555555">());</span>
<span style="color:#9a9a9a">  26 </span>                button<span style="color:#555555">.</span><span style="color:#d11ced">setWidth</span><span style="color:#555555">(</span>btn_size<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  27 </span>                button<span style="color:#555555">.</span><span style="color:#d11ced">setHeight</span><span style="color:#555555">(</span>btn_size<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  28 </span>                <span style="color:#ff3030; font-weight:bold">var</span> dist_x <span style="color:#555555">=</span> <span style="color:#0000ff">Math</span><span style="color:#555555">.</span><span style="color:#0000ff">round</span><span style="color:#555555">(</span>distance <span style="color:#555555">*</span> <span style="color:#0000ff">Math</span><span style="color:#555555">.</span><span style="color:#0000ff">sin</span><span style="color:#555555">(-(</span>i<span style="color:#555555">/</span><span style="color:#32ba06">12</span><span style="color:#555555">+</span><span style="color:#32ba06">0.5</span><span style="color:#555555">)*</span>pi2<span style="color:#555555">));</span>
<span style="color:#9a9a9a">  29 </span>                <span style="color:#ff3030; font-weight:bold">var</span> dist_y <span style="color:#555555">=</span> <span style="color:#0000ff">Math</span><span style="color:#555555">.</span><span style="color:#0000ff">round</span><span style="color:#555555">(</span>distance <span style="color:#555555">*</span> <span style="color:#0000ff">Math</span><span style="color:#555555">.</span><span style="color:#0000ff">cos</span><span style="color:#555555">(-(</span>i<span style="color:#555555">/</span><span style="color:#32ba06">12</span><span style="color:#555555">+</span><span style="color:#32ba06">0.5</span><span style="color:#555555">)*</span>pi2<span style="color:#555555">));</span>
<span style="color:#9a9a9a">  30 </span>                main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span>button<span style="color:#555555">, {</span>
<span style="color:#9a9a9a">  31 </span>                    left<span style="color:#555555">:</span> center<span style="color:#555555">.</span>x <span style="color:#555555">+</span> dist_x<span style="color:#555555">,</span>
<span style="color:#9a9a9a">  32 </span>                    <span style="color:#0000ff">top</span><span style="color:#555555">:</span> center<span style="color:#555555">.</span>y <span style="color:#555555">+</span> dist_y
<span style="color:#9a9a9a">  33 </span>                <span style="color:#555555">});</span>
<span style="color:#9a9a9a">  34 </span>            <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  35 </span>
<span style="color:#9a9a9a">  36 </span>            <span style="color:#ff3030; font-weight:bold">var</span> application_root <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">getRoot</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  37 </span>            application_root<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span>main_container<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  38 </span>        <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  39 </span>    <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  40 </span><span style="color:#555555">});</span></code></pre>

<div id="attachment_186" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.muhuk.com/wp-content/uploads/2009/04/basic1.png"><img src="http://www.muhuk.com/wp-content/uploads/2009/04/basic1-300x187.png" alt="Basic Example" title="Basic Example" width="300" height="187" class="size-medium wp-image-186" /></a><p class="wp-caption-text">Basic Example</p></div>

<p>Nevermind the math. What is important is; this would be much harder to achieve with other, more advanced managers such as <code>Grid</code>.</p>

<h3>Canvas Layout Manager</h3>

<p><code>qx.ui.layout.Canvas</code> is a slightly advanced version of <code>Basic</code>. <code>Canvas</code> lets you define margins (of all four directions) and dimensions in percentage as well as in pixels.</p>

<p><code>Canvas</code> allows you to define all four margins. You don&#8217;t have to define all of them of course. For example if you define a <code>top</code> and <code>bottom</code> margin remaining space will be your widget&#8217;s <code>height</code><sup>1</sup>. Alternatively you can specify a <code>bottom</code> margin and a <code>height</code> for you widget. This way it will keep its position relative to container&#8217;s bottom edge.</p>

<p>One thing to keep in mind is <strong>margins are defined against container</strong>, not against a bounding box like <a href="http://en.wikipedia.org/wiki/Document_Object_Model">DOM</a>. Say, if you set the same <code>left</code> on two widgets, they&#8217;ll be stacked on top of each other if they happen to have the same vertical coordinates. The following example mimics a <code>Grid</code> layout using <code>Canvas</code>:</p>

<pre><span style="color:#9a9a9a">   1 </span><span style="color:#38ad24">/*</span>
<span style="color:#9a9a9a">   2 </span><span style="color:#38ad24">#asset(qooxdoolayouts/*)</span>
<span style="color:#9a9a9a">   3 </span><span style="color:#38ad24">*/</span>
<span style="color:#9a9a9a">   4 </span>qx<span style="color:#555555">.</span>Class<span style="color:#555555">.</span><span style="color:#d11ced">define</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;qooxdoolayouts.Application&quot;</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">   5 </span><span style="color:#555555">{</span>
<span style="color:#9a9a9a">   6 </span>    extend<span style="color:#555555">:</span> qx<span style="color:#555555">.</span>application<span style="color:#555555">.</span>Standalone<span style="color:#555555">,</span>
<span style="color:#9a9a9a">   7 </span>    members<span style="color:#555555">: {</span>
<span style="color:#9a9a9a">   8 </span>        main<span style="color:#555555">:</span> <span style="color:#ff3030; font-weight:bold">function</span><span style="color:#555555">(){</span>
<span style="color:#9a9a9a">   9 </span>            <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">base</span><span style="color:#555555">(</span>arguments<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  10 </span>
<span style="color:#9a9a9a">  11 </span>            <span style="color:#ff3030; font-weight:bold">var</span> main_container <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>container<span style="color:#555555">.</span><span style="color:#d11ced">Composite</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  12 </span>
<span style="color:#9a9a9a">  13 </span>            <span style="color:#ff3030; font-weight:bold">var</span> layout_manager <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>layout<span style="color:#555555">.</span><span style="color:#d11ced">Canvas</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  14 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">setLayout</span><span style="color:#555555">(</span>layout_manager<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  15 </span>
<span style="color:#9a9a9a">  16 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 1&quot;</span><span style="color:#555555">), {</span>
<span style="color:#9a9a9a">  17 </span>                left<span style="color:#555555">:</span> <span style="color:#32ba06">20</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  18 </span>                <span style="color:#0000ff">top</span><span style="color:#555555">:</span> <span style="color:#32ba06">10</span>
<span style="color:#9a9a9a">  19 </span>            <span style="color:#555555">});</span>
<span style="color:#9a9a9a">  20 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 2&quot;</span><span style="color:#555555">), {</span>
<span style="color:#9a9a9a">  21 </span>                left<span style="color:#555555">:</span> <span style="color:#32ba06">140</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  22 </span>                right<span style="color:#555555">:</span> <span style="color:#32ba06">20</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  23 </span>                <span style="color:#0000ff">top</span><span style="color:#555555">:</span> <span style="color:#32ba06">10</span>
<span style="color:#9a9a9a">  24 </span>            <span style="color:#555555">});</span>
<span style="color:#9a9a9a">  25 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 3&quot;</span><span style="color:#555555">), {</span>
<span style="color:#9a9a9a">  26 </span>                left<span style="color:#555555">:</span> <span style="color:#32ba06">20</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  27 </span>                <span style="color:#0000ff">top</span><span style="color:#555555">:</span> <span style="color:#32ba06">50</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  28 </span>                bottom<span style="color:#555555">:</span> <span style="color:#32ba06">10</span>
<span style="color:#9a9a9a">  29 </span>            <span style="color:#555555">});</span>
<span style="color:#9a9a9a">  30 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 4&quot;</span><span style="color:#555555">), {</span>
<span style="color:#9a9a9a">  31 </span>                left<span style="color:#555555">:</span> <span style="color:#32ba06">140</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  32 </span>                right<span style="color:#555555">:</span> <span style="color:#32ba06">20</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  33 </span>                <span style="color:#0000ff">top</span><span style="color:#555555">:</span> <span style="color:#32ba06">50</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  34 </span>                bottom<span style="color:#555555">:</span> <span style="color:#32ba06">10</span>
<span style="color:#9a9a9a">  35 </span>            <span style="color:#555555">});</span>
<span style="color:#9a9a9a">  36 </span>
<span style="color:#9a9a9a">  37 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">getChildren</span><span style="color:#555555">()[</span><span style="color:#32ba06">0</span><span style="color:#555555">].</span><span style="color:#d11ced">setWidth</span><span style="color:#555555">(</span><span style="color:#32ba06">100</span><span style="color:#555555">);</span>
<span style="color:#9a9a9a">  38 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">getChildren</span><span style="color:#555555">()[</span><span style="color:#32ba06">2</span><span style="color:#555555">].</span><span style="color:#d11ced">setWidth</span><span style="color:#555555">(</span><span style="color:#32ba06">100</span><span style="color:#555555">);</span>
<span style="color:#9a9a9a">  39 </span>
<span style="color:#9a9a9a">  40 </span>            <span style="color:#ff3030; font-weight:bold">var</span> application_root <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">getRoot</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  41 </span>            application_root<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span>main_container<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  42 </span>
<span style="color:#9a9a9a">  43 </span>            application_root<span style="color:#555555">.</span><span style="color:#d11ced">addListener</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;resize&quot;</span><span style="color:#555555">,</span> <span style="color:#ff3030; font-weight:bold">function</span><span style="color:#555555">(</span>e<span style="color:#555555">) {</span>
<span style="color:#9a9a9a">  44 </span>                main_container<span style="color:#555555">.</span><span style="color:#d11ced">set</span><span style="color:#555555">({</span>
<span style="color:#9a9a9a">  45 </span>                    <span style="color:#1861a7">&quot;width&quot;</span><span style="color:#555555">:</span> qx<span style="color:#555555">.</span>bom<span style="color:#555555">.</span>Viewport<span style="color:#555555">.</span><span style="color:#d11ced">getWidth</span><span style="color:#555555">(),</span>
<span style="color:#9a9a9a">  46 </span>                    <span style="color:#1861a7">&quot;height&quot;</span><span style="color:#555555">:</span> qx<span style="color:#555555">.</span>bom<span style="color:#555555">.</span>Viewport<span style="color:#555555">.</span><span style="color:#d11ced">getHeight</span><span style="color:#555555">(),</span>
<span style="color:#9a9a9a">  47 </span>                <span style="color:#555555">});</span>
<span style="color:#9a9a9a">  48 </span>            <span style="color:#555555">},</span> <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">);</span>
<span style="color:#9a9a9a">  49 </span>        <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  50 </span>    <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  51 </span><span style="color:#555555">});</span>
</pre>

<div id="attachment_188" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.muhuk.com/wp-content/uploads/2009/04/canvas1.png"><img src="http://www.muhuk.com/wp-content/uploads/2009/04/canvas1-300x187.png" alt="Canvas Example 1" title="Canvas Example 1" width="300" height="187" class="size-medium wp-image-188" /></a><p class="wp-caption-text">Canvas Example 1</p></div>

<p>We set two widgets&#8217; widths manually (see lines 37 &amp; 38) to get all the margins (almost) equal. The first row only has <code>top</code> margin set, but the second row has both <code>top</code> and <code>bottom</code> margins. We have given widgets in the second row <code>top</code> margins taking:</p>

<ul>
<li>Top margin of first row</li>
<li>Height of the widgets in the first row</li>
</ul>

<p>and</p>

<ul>
<li>Margin between first and second rows</li>
</ul>

<p>into account. The same thing is true for the <code>left</code> margin of second column. This is because, as I mentioned, margins are calculated relative to container edges.</p>

<p>If you need to position your controls relative to one another, like DOM positioning, you should probably look into other layout managers like <code>Grid</code>. A good example of a use case for <code>Canvas</code> can be a mapping application such as <a href="http://maps.google.com/">Google Maps</a>.</p>

<p>As I mentioned earlier <code>Canvas</code> layout accepts parameters in percentages. Following example sets vertical margins in pixels but horizontal margins in percentages:</p>

<pre><span style="color:#9a9a9a">   1 </span><span style="color:#555555">/*</span>
<span style="color:#9a9a9a">   2 </span><span style="color:#38ad24">#asset(qooxdoolayouts/*)</span>
<span style="color:#9a9a9a">   3 </span><span style="color:#555555">*/</span>
<span style="color:#9a9a9a">   4 </span>qx<span style="color:#555555">.</span>Class<span style="color:#555555">.</span><span style="color:#d11ced">define</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;qooxdoolayouts.Application&quot;</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">   5 </span><span style="color:#555555">{</span>
<span style="color:#9a9a9a">   6 </span>    extend<span style="color:#555555">:</span> qx<span style="color:#555555">.</span>application<span style="color:#555555">.</span>Standalone<span style="color:#555555">,</span>
<span style="color:#9a9a9a">   7 </span>    members<span style="color:#555555">: {</span>
<span style="color:#9a9a9a">   8 </span>        main<span style="color:#555555">:</span> <span style="color:#d11ced">function</span><span style="color:#555555">(){</span>
<span style="color:#9a9a9a">   9 </span>            this<span style="color:#555555">.</span><span style="color:#d11ced">base</span><span style="color:#555555">(</span>arguments<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  10 </span>
<span style="color:#9a9a9a">  11 </span>            var main_container <span style="color:#555555">=</span> new qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>container<span style="color:#555555">.</span><span style="color:#d11ced">Composite</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  12 </span>
<span style="color:#9a9a9a">  13 </span>            var layout_manager <span style="color:#555555">=</span> new qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>layout<span style="color:#555555">.</span><span style="color:#d11ced">Canvas</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  14 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">setLayout</span><span style="color:#555555">(</span>layout_manager<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  15 </span>
<span style="color:#9a9a9a">  16 </span>            var button <span style="color:#555555">=</span> new qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 1&quot;</span><span style="color:#555555">);</span>
<span style="color:#9a9a9a">  17 </span>            button<span style="color:#555555">.</span><span style="color:#d11ced">setMinWidth</span><span style="color:#555555">(</span><span style="color:#32ba06">250</span><span style="color:#555555">);</span>
<span style="color:#9a9a9a">  18 </span>            button<span style="color:#555555">.</span><span style="color:#d11ced">setMaxWidth</span><span style="color:#555555">(</span><span style="color:#32ba06">400</span><span style="color:#555555">);</span>
<span style="color:#9a9a9a">  19 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span>button<span style="color:#555555">, {</span>
<span style="color:#9a9a9a">  20 </span>                left<span style="color:#555555">:</span> <span style="color:#1861a7">&quot;30%&quot;</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  21 </span>                right<span style="color:#555555">:</span> <span style="color:#1861a7">&quot;30%&quot;</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  22 </span>                top<span style="color:#555555">:</span> <span style="color:#32ba06">40</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  23 </span>                bottom<span style="color:#555555">:</span> <span style="color:#32ba06">40</span>
<span style="color:#9a9a9a">  24 </span>            <span style="color:#555555">});</span>
<span style="color:#9a9a9a">  25 </span>
<span style="color:#9a9a9a">  26 </span>            var application_root <span style="color:#555555">=</span> this<span style="color:#555555">.</span><span style="color:#d11ced">getRoot</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  27 </span>            application_root<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span>main_container<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  28 </span>
<span style="color:#9a9a9a">  29 </span>            application_root<span style="color:#555555">.</span><span style="color:#d11ced">addListener</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;resize&quot;</span><span style="color:#555555">,</span> <span style="color:#d11ced">function</span><span style="color:#555555">(</span>e<span style="color:#555555">) {</span>
<span style="color:#9a9a9a">  30 </span>                main_container<span style="color:#555555">.</span><span style="color:#f48c23">set</span><span style="color:#555555">({</span>
<span style="color:#9a9a9a">  31 </span>                    <span style="color:#1861a7">&quot;width&quot;</span><span style="color:#555555">:</span> qx<span style="color:#555555">.</span>bom<span style="color:#555555">.</span>Viewport<span style="color:#555555">.</span><span style="color:#d11ced">getWidth</span><span style="color:#555555">(),</span>
<span style="color:#9a9a9a">  32 </span>                    <span style="color:#1861a7">&quot;height&quot;</span><span style="color:#555555">:</span> qx<span style="color:#555555">.</span>bom<span style="color:#555555">.</span>Viewport<span style="color:#555555">.</span><span style="color:#d11ced">getHeight</span><span style="color:#555555">(),</span>
<span style="color:#9a9a9a">  33 </span>                <span style="color:#555555">});</span>
<span style="color:#9a9a9a">  34 </span>            <span style="color:#555555">},</span> this<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  35 </span>        <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  36 </span>    <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  37 </span><span style="color:#555555">});</span>
</pre>

<hr />

<p><strong>1</strong>: Whether your widget grows this high depends. Let&#8217;s say that height is reserved for your widget.</p>


<p>Related posts:<ol><li><a href='http://www.muhuk.com/2009/01/using-layouts-in-qooxdoo-part-1/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 1'>Using Layouts In Qooxdoo &#8211; Part 1</a></li>
<li><a href='http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-2-vbox-layout/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 2: VBox Layout'>Using Layouts In Qooxdoo &#8211; Part 2: VBox Layout</a></li>
<li><a href='http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-3-hbox-layout/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 3: HBox Layout'>Using Layouts In Qooxdoo &#8211; Part 3: HBox Layout</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2009/04/using-layouts-in-qooxdoo-part-5-basic-canvas/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Layouts In Qooxdoo &#8211; Part 4: Grid Layout</title>
		<link>http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-4-grid-layout/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=using-layouts-in-qooxdoo-part-4-grid-layout</link>
		<comments>http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-4-grid-layout/#comments</comments>
		<pubDate>Sat, 21 Feb 2009 13:00:03 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[qooxdoo]]></category>
		<category><![CDATA[ria]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=134</guid>
		<description><![CDATA[This is the fourth part of a tutorial series about layout managers, container objects and object hierarchies in Qooxdoo. Read the first part here. qx.ui.layout.Grid is like a combined VBox &#38; Hbox. Grid supports: Variable width/height columns/rows. Cells spanning multiple columns/rows. Empty cells. Here is a simple application using a Grid layout: 1 /* 2 [...]]]></description>
			<content:encoded><![CDATA[<p><small>This is the fourth part of a tutorial series about layout managers, container objects and object hierarchies in Qooxdoo. Read the first part <a href="/2009/01/using-layouts-in-qooxdoo-part-1/">here</a>.</small></p>

<p><code>qx.ui.layout.Grid</code> is like a combined <code>VBox</code> &amp; <code>Hbox</code>. <code>Grid</code> supports:</p>

<ul>
<li>Variable width/height columns/rows.</li>
<li>Cells spanning multiple columns/rows.</li>
<li>Empty cells.</li>
</ul>

<div id="attachment_136" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.muhuk.com/wp-content/uploads/2009/02/grid.png"><img src="http://www.muhuk.com/wp-content/uploads/2009/02/grid-300x300.png" alt="Grid Layout" title="Grid Layout" width="300" height="300" class="size-medium wp-image-136" /></a><p class="wp-caption-text">Grid Layout</p></div>

<p>Here is a simple application using a <code>Grid</code> layout:</p>

<pre><span style="color:#9a9a9a">   1 </span><span style="color:#38ad24">/*</span>
<span style="color:#9a9a9a">   2 </span><span style="color:#38ad24">#asset(grid/*)</span>
<span style="color:#9a9a9a">   3 </span><span style="color:#38ad24">*/</span>
<span style="color:#9a9a9a">   4 </span>qx<span style="color:#555555">.</span>Class<span style="color:#555555">.</span><span style="color:#d11ced">define</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;grid.Application&quot;</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">   5 </span><span style="color:#555555">{</span>
<span style="color:#9a9a9a">   6 </span>    extend<span style="color:#555555">:</span> qx<span style="color:#555555">.</span>application<span style="color:#555555">.</span>Standalone<span style="color:#555555">,</span>
<span style="color:#9a9a9a">   7 </span>    members<span style="color:#555555">: {</span>
<span style="color:#9a9a9a">   8 </span>        main<span style="color:#555555">:</span> <span style="color:#ff3030; font-weight:bold">function</span><span style="color:#555555">(){</span>
<span style="color:#9a9a9a">   9 </span>            <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">base</span><span style="color:#555555">(</span>arguments<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  10 </span>
<span style="color:#9a9a9a">  11 </span>            <span style="color:#ff3030; font-weight:bold">var</span> main_container <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>container<span style="color:#555555">.</span><span style="color:#d11ced">Composite</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  12 </span>
<span style="color:#9a9a9a">  13 </span>            <span style="color:#ff3030; font-weight:bold">var</span> layout_manager <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>layout<span style="color:#555555">.</span><span style="color:#d11ced">Grid</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  14 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">setLayout</span><span style="color:#555555">(</span>layout_manager<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  15 </span>
<span style="color:#9a9a9a">  16 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 1&quot;</span><span style="color:#555555">), {</span>row<span style="color:#555555">:</span> <span style="color:#32ba06">0</span><span style="color:#555555">,</span> column<span style="color:#555555">:</span> <span style="color:#32ba06">0</span><span style="color:#555555">});</span>
<span style="color:#9a9a9a">  17 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 2&quot;</span><span style="color:#555555">), {</span>row<span style="color:#555555">:</span> <span style="color:#32ba06">0</span><span style="color:#555555">,</span> column<span style="color:#555555">:</span> <span style="color:#32ba06">1</span><span style="color:#555555">});</span>
<span style="color:#9a9a9a">  18 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 3&quot;</span><span style="color:#555555">), {</span>row<span style="color:#555555">:</span> <span style="color:#32ba06">0</span><span style="color:#555555">,</span> column<span style="color:#555555">:</span> <span style="color:#32ba06">2</span><span style="color:#555555">});</span>
<span style="color:#9a9a9a">  19 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 4&quot;</span><span style="color:#555555">), {</span>row<span style="color:#555555">:</span> <span style="color:#32ba06">1</span><span style="color:#555555">,</span> column<span style="color:#555555">:</span> <span style="color:#32ba06">0</span><span style="color:#555555">});</span>
<span style="color:#9a9a9a">  20 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 5&quot;</span><span style="color:#555555">), {</span>row<span style="color:#555555">:</span> <span style="color:#32ba06">1</span><span style="color:#555555">,</span> column<span style="color:#555555">:</span> <span style="color:#32ba06">1</span><span style="color:#555555">});</span>
<span style="color:#9a9a9a">  21 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 6&quot;</span><span style="color:#555555">), {</span>row<span style="color:#555555">:</span> <span style="color:#32ba06">1</span><span style="color:#555555">,</span> column<span style="color:#555555">:</span> <span style="color:#32ba06">2</span><span style="color:#555555">});</span>
<span style="color:#9a9a9a">  22 </span>
<span style="color:#9a9a9a">  23 </span>            <span style="color:#ff3030; font-weight:bold">var</span> application_root <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">getRoot</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  24 </span>            application_root<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span>main_container<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  25 </span>        <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  26 </span>    <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  27 </span><span style="color:#555555">});</span>
</pre>

<div id="attachment_137" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.muhuk.com/wp-content/uploads/2009/02/grid1.png"><img src="http://www.muhuk.com/wp-content/uploads/2009/02/grid1-300x226.png" alt="Grid Example 1" title="Grid Example 1" width="300" height="226" class="size-medium wp-image-137" /></a><p class="wp-caption-text">Grid Example 1</p></div>

<p>We have created an 3&#215;2 table layout without explicitly stating row/column count. Just set your <code>row</code> and <code>column</code> layout preferences when you add your child widgets.</p>

<p>Try commenting out some cells to see what happens. If you, for example, comment out second (<code>0,1</code>) and fifth (<code>1,1</code>) cells the second column disappears. But missing cells are OK otherwise. You can see below the layout when third and fifth cells are commented:</p>

<div id="attachment_138" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.muhuk.com/wp-content/uploads/2009/02/grid1a.png"><img src="http://www.muhuk.com/wp-content/uploads/2009/02/grid1a-300x226.png" alt="Grid Example 1 - Missing Cells" title="Grid Example 1 - Missing Cells" width="300" height="226" class="size-medium wp-image-138" /></a><p class="wp-caption-text">Grid Example 1 - Missing Cells</p></div>

<p>Following example illustrates row/column spanning:</p>

<pre><span style="color:#9a9a9a">   1 </span><span style="color:#38ad24">/*</span>
<span style="color:#9a9a9a">   2 </span><span style="color:#38ad24">#asset(grid/ *)</span>
<span style="color:#9a9a9a">   3 </span><span style="color:#38ad24">*/</span>
<span style="color:#9a9a9a">   4 </span>qx<span style="color:#555555">.</span>Class<span style="color:#555555">.</span><span style="color:#d11ced">define</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;grid.Application&quot;</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">   5 </span><span style="color:#555555">{</span>
<span style="color:#9a9a9a">   6 </span>    extend<span style="color:#555555">:</span> qx<span style="color:#555555">.</span>application<span style="color:#555555">.</span>Standalone<span style="color:#555555">,</span>
<span style="color:#9a9a9a">   7 </span>    members<span style="color:#555555">: {</span>
<span style="color:#9a9a9a">   8 </span>        main<span style="color:#555555">:</span> <span style="color:#ff3030; font-weight:bold">function</span><span style="color:#555555">(){</span>
<span style="color:#9a9a9a">   9 </span>            <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">base</span><span style="color:#555555">(</span>arguments<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  10 </span>
<span style="color:#9a9a9a">  11 </span>            <span style="color:#ff3030; font-weight:bold">var</span> main_container <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>container<span style="color:#555555">.</span><span style="color:#d11ced">Composite</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  12 </span>
<span style="color:#9a9a9a">  13 </span>            <span style="color:#ff3030; font-weight:bold">var</span> layout_manager <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>layout<span style="color:#555555">.</span><span style="color:#d11ced">Grid</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  14 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">setLayout</span><span style="color:#555555">(</span>layout_manager<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  15 </span>
<span style="color:#ff0000">  <b>16</b> </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 1&quot;</span><span style="color:#555555">), {</span>
<span style="color:#ff0000">  <b>17</b> </span>                row<span style="color:#555555">:</span> <span style="color:#32ba06">0</span><span style="color:#555555">,</span>
<span style="color:#ff0000">  <b>18</b> </span>                column<span style="color:#555555">:</span> <span style="color:#32ba06">0</span><span style="color:#555555">,</span>
<span style="color:#ff0000">  <b>19</b> </span>                rowSpan<span style="color:#555555">:</span> <span style="color:#32ba06">2</span>
<span style="color:#ff0000">  <b>20</b> </span>            <span style="color:#555555">});</span>
<span style="color:#ff0000">  <b>21</b> </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 2&quot;</span><span style="color:#555555">), {</span>
<span style="color:#ff0000">  <b>22</b> </span>                row<span style="color:#555555">:</span> <span style="color:#32ba06">0</span><span style="color:#555555">,</span>
<span style="color:#ff0000">  <b>23</b> </span>                column<span style="color:#555555">:</span> <span style="color:#32ba06">1</span><span style="color:#555555">,</span>
<span style="color:#ff0000">  <b>24</b> </span>                colSpan<span style="color:#555555">:</span> <span style="color:#32ba06">2</span>
<span style="color:#ff0000">  <b>25</b> </span>            <span style="color:#555555">});</span>
<span style="color:#ff0000">  <b>26</b> </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 3&quot;</span><span style="color:#555555">), {</span>
<span style="color:#ff0000">  <b>27</b> </span>                row<span style="color:#555555">:</span> <span style="color:#32ba06">1</span><span style="color:#555555">,</span>
<span style="color:#ff0000">  <b>28</b> </span>                column<span style="color:#555555">:</span> <span style="color:#32ba06">1</span>
<span style="color:#ff0000">  <b>29</b> </span>            <span style="color:#555555">});</span>
<span style="color:#ff0000">  <b>30</b> </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 4&quot;</span><span style="color:#555555">), {</span>
<span style="color:#ff0000">  <b>31</b> </span>                row<span style="color:#555555">:</span> <span style="color:#32ba06">1</span><span style="color:#555555">,</span>
<span style="color:#ff0000">  <b>32</b> </span>                column<span style="color:#555555">:</span> <span style="color:#32ba06">2</span>
<span style="color:#ff0000">  <b>33</b> </span>            <span style="color:#555555">});</span>
<span style="color:#9a9a9a">  34 </span>
<span style="color:#9a9a9a">  35 </span>            <span style="color:#ff3030; font-weight:bold">var</span> application_root <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">getRoot</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  36 </span>            application_root<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span>main_container<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  37 </span>        <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  38 </span>    <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  39 </span><span style="color:#555555">});</span></pre>

<div id="attachment_139" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.muhuk.com/wp-content/uploads/2009/02/grid2.png"><img src="http://www.muhuk.com/wp-content/uploads/2009/02/grid2-300x226.png" alt="Grid Example 2" title="Grid Example 2" width="300" height="226" class="size-medium wp-image-139" /></a><p class="wp-caption-text">Grid Example 2</p></div>

<p>Spanning is easy, just like HTML tables. But we set placement (<code>row</code> and <code>column</code> parameters) explicitly. We can add our widgets in any order and still get the same layout if we use the same preferences.</p>

<p>As I said in the beginning of this part <code>Grid</code> is like a combination of <code>VBox</code> and <code>HBox</code>. Therefore <code>flex</code>ing is two dimensional:</p>

<pre><span style="color:#9a9a9a">   1 </span><span style="color:#38ad24">/*</span>
<span style="color:#9a9a9a">   2 </span><span style="color:#38ad24">#asset(grid/ *)</span>
<span style="color:#9a9a9a">   3 </span><span style="color:#38ad24">*/</span>
<span style="color:#9a9a9a">   4 </span>qx<span style="color:#555555">.</span>Class<span style="color:#555555">.</span><span style="color:#d11ced">define</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;grid.Application&quot;</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">   5 </span><span style="color:#555555">{</span>
<span style="color:#9a9a9a">   6 </span>    extend<span style="color:#555555">:</span> qx<span style="color:#555555">.</span>application<span style="color:#555555">.</span>Standalone<span style="color:#555555">,</span>
<span style="color:#9a9a9a">   7 </span>    members<span style="color:#555555">: {</span>
<span style="color:#9a9a9a">   8 </span>        main<span style="color:#555555">:</span> <span style="color:#ff3030; font-weight:bold">function</span><span style="color:#555555">(){</span>
<span style="color:#9a9a9a">   9 </span>            <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">base</span><span style="color:#555555">(</span>arguments<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  10 </span>
<span style="color:#9a9a9a">  11 </span>            <span style="color:#ff3030; font-weight:bold">var</span> main_container <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>container<span style="color:#555555">.</span><span style="color:#d11ced">Composite</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  12 </span>
<span style="color:#9a9a9a">  13 </span>            <span style="color:#ff3030; font-weight:bold">var</span> layout_manager <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>layout<span style="color:#555555">.</span><span style="color:#d11ced">Grid</span><span style="color:#555555">();</span>
<span style="color:#ff0000">  <b>14</b> </span>            layout_manager<span style="color:#555555">.</span><span style="color:#d11ced">setRowFlex</span><span style="color:#555555">(</span><span style="color:#32ba06">0</span><span style="color:#555555">,</span> <span style="color:#32ba06">1</span><span style="color:#555555">);</span>
<span style="color:#ff0000">  <b>15</b> </span>            layout_manager<span style="color:#555555">.</span><span style="color:#d11ced">setRowFlex</span><span style="color:#555555">(</span><span style="color:#32ba06">1</span><span style="color:#555555">,</span> <span style="color:#32ba06">1</span><span style="color:#555555">);</span>
<span style="color:#ff0000">  <b>16</b> </span>            layout_manager<span style="color:#555555">.</span><span style="color:#d11ced">setColumnFlex</span><span style="color:#555555">(</span><span style="color:#32ba06">0</span><span style="color:#555555">,</span> <span style="color:#32ba06">1</span><span style="color:#555555">);</span>
<span style="color:#ff0000">  <b>17</b> </span>            layout_manager<span style="color:#555555">.</span><span style="color:#d11ced">setColumnFlex</span><span style="color:#555555">(</span><span style="color:#32ba06">2</span><span style="color:#555555">,</span> <span style="color:#32ba06">1</span><span style="color:#555555">);</span>
<span style="color:#9a9a9a">  18 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">setLayout</span><span style="color:#555555">(</span>layout_manager<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  19 </span>
<span style="color:#9a9a9a">  20 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 1&quot;</span><span style="color:#555555">), {</span>
<span style="color:#9a9a9a">  21 </span>                row<span style="color:#555555">:</span> <span style="color:#32ba06">0</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  22 </span>                column<span style="color:#555555">:</span> <span style="color:#32ba06">0</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  23 </span>                rowSpan<span style="color:#555555">:</span> <span style="color:#32ba06">2</span>
<span style="color:#9a9a9a">  24 </span>            <span style="color:#555555">});</span>
<span style="color:#9a9a9a">  25 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 2&quot;</span><span style="color:#555555">), {</span>
<span style="color:#9a9a9a">  26 </span>                row<span style="color:#555555">:</span> <span style="color:#32ba06">0</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  27 </span>                column<span style="color:#555555">:</span> <span style="color:#32ba06">1</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  28 </span>                colSpan<span style="color:#555555">:</span> <span style="color:#32ba06">2</span>
<span style="color:#9a9a9a">  29 </span>            <span style="color:#555555">});</span>
<span style="color:#9a9a9a">  30 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 3&quot;</span><span style="color:#555555">), {</span>
<span style="color:#9a9a9a">  31 </span>                row<span style="color:#555555">:</span> <span style="color:#32ba06">1</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  32 </span>                column<span style="color:#555555">:</span> <span style="color:#32ba06">1</span>
<span style="color:#9a9a9a">  33 </span>            <span style="color:#555555">});</span>
<span style="color:#9a9a9a">  34 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 4&quot;</span><span style="color:#555555">), {</span>
<span style="color:#9a9a9a">  35 </span>                row<span style="color:#555555">:</span> <span style="color:#32ba06">1</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  36 </span>                column<span style="color:#555555">:</span> <span style="color:#32ba06">2</span>
<span style="color:#9a9a9a">  37 </span>            <span style="color:#555555">});</span>
<span style="color:#9a9a9a">  38 </span>
<span style="color:#9a9a9a">  39 </span>            <span style="color:#ff3030; font-weight:bold">var</span> application_root <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">getRoot</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  40 </span>            application_root<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span>main_container<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  41 </span>
<span style="color:#ff0000">  <b>42</b> </span>            application_root<span style="color:#555555">.</span><span style="color:#d11ced">addListener</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;resize&quot;</span><span style="color:#555555">,</span> <span style="color:#ff3030; font-weight:bold">function</span><span style="color:#555555">(</span>e<span style="color:#555555">) {</span>
<span style="color:#ff0000">  <b>43</b> </span>                main_container<span style="color:#555555">.</span><span style="color:#d11ced">set</span><span style="color:#555555">({</span>
<span style="color:#ff0000">  <b>44</b> </span>                    <span style="color:#1861a7">&quot;width&quot;</span><span style="color:#555555">:</span> qx<span style="color:#555555">.</span>bom<span style="color:#555555">.</span>Viewport<span style="color:#555555">.</span><span style="color:#d11ced">getWidth</span><span style="color:#555555">(),</span>
<span style="color:#ff0000">  <b>45</b> </span>                    <span style="color:#1861a7">&quot;height&quot;</span><span style="color:#555555">:</span> qx<span style="color:#555555">.</span>bom<span style="color:#555555">.</span>Viewport<span style="color:#555555">.</span><span style="color:#d11ced">getHeight</span><span style="color:#555555">(),</span>
<span style="color:#ff0000">  <b>46</b> </span>                <span style="color:#555555">});</span>
<span style="color:#ff0000">  <b>47</b> </span>            <span style="color:#555555">},</span> <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">);</span>
<span style="color:#9a9a9a">  48 </span>        <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  49 </span>    <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  50 </span><span style="color:#555555">});</span>
</pre>

<div id="attachment_140" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.muhuk.com/wp-content/uploads/2009/02/grid3.png"><img src="http://www.muhuk.com/wp-content/uploads/2009/02/grid3-300x226.png" alt="Grid Example 3" title="Grid Example 3" width="300" height="226" class="size-medium wp-image-140" /></a><p class="wp-caption-text">Grid Example 3</p></div>

<p>We have set <code>rowFlex</code> (vertical) and <code>columnFlex</code> (horizontal) <em>for specific rows/columns</em> on the layout manager itself. Try resizing the window to see how cells react. Note that second column (column index 1) doesn&#8217;t <code>flex</code> horizontally.</p>

<p><small>NEXT PART: Back To Basics</small></p>


<p>Related posts:<ol><li><a href='http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-2-vbox-layout/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 2: VBox Layout'>Using Layouts In Qooxdoo &#8211; Part 2: VBox Layout</a></li>
<li><a href='http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-3-hbox-layout/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 3: HBox Layout'>Using Layouts In Qooxdoo &#8211; Part 3: HBox Layout</a></li>
<li><a href='http://www.muhuk.com/2009/01/using-layouts-in-qooxdoo-part-1/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 1'>Using Layouts In Qooxdoo &#8211; Part 1</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-4-grid-layout/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Layouts In Qooxdoo &#8211; Part 3: HBox Layout</title>
		<link>http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-3-hbox-layout/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=using-layouts-in-qooxdoo-part-3-hbox-layout</link>
		<comments>http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-3-hbox-layout/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 11:00:11 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[hbox]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[qooxdoo]]></category>
		<category><![CDATA[ria]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=124</guid>
		<description><![CDATA[This is the third part of a tutorial series about layout managers, container objects and object hierarchies in Qooxdoo. Read the first part here. qx.ui.layout.HBox layout manager is similar to VBox but it places its children side by side. Let us begin with a simple application: 1 /* 2 #asset(hbox/*) 3 */ 4 qx.Class.define(&#34;hbox.Application&#34;, 5 [...]]]></description>
			<content:encoded><![CDATA[<p><small>This is the third part of a tutorial series about layout managers, container objects and object hierarchies in Qooxdoo. Read the first part <a href="/2009/01/using-layouts-in-qooxdoo-part-1/">here</a>.</small></p>

<p><code>qx.ui.layout.HBox</code> layout manager is similar to <code>VBox</code> but it places its children side by side.</p>

<div id="attachment_128" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.muhuk.com/wp-content/uploads/2009/02/hbox.png"><img src="http://www.muhuk.com/wp-content/uploads/2009/02/hbox-300x150.png" alt="HBox Layout" title="HBox Layout" width="300" height="150" class="size-medium wp-image-128" /></a><p class="wp-caption-text">HBox Layout</p></div>

<p>Let us begin with a simple application:</p>

<pre><span style="color:#9a9a9a">   1 </span><span style="color:#38ad24">/*</span>
<span style="color:#9a9a9a">   2 </span><span style="color:#38ad24">#asset(hbox/*)</span>
<span style="color:#9a9a9a">   3 </span><span style="color:#38ad24">*/</span>
<span style="color:#9a9a9a">   4 </span>qx<span style="color:#555555">.</span>Class<span style="color:#555555">.</span><span style="color:#d11ced">define</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;hbox.Application&quot;</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">   5 </span><span style="color:#555555">{</span>
<span style="color:#9a9a9a">   6 </span>    extend<span style="color:#555555">:</span> qx<span style="color:#555555">.</span>application<span style="color:#555555">.</span>Standalone<span style="color:#555555">,</span>
<span style="color:#9a9a9a">   7 </span>    members<span style="color:#555555">: {</span>
<span style="color:#9a9a9a">   8 </span>        main<span style="color:#555555">:</span> <span style="color:#ff3030; font-weight:bold">function</span><span style="color:#555555">(){</span>
<span style="color:#9a9a9a">   9 </span>            <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">base</span><span style="color:#555555">(</span>arguments<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  10 </span>
<span style="color:#9a9a9a">  11 </span>            <span style="color:#ff3030; font-weight:bold">var</span> main_container <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>container<span style="color:#555555">.</span><span style="color:#d11ced">Composite</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  12 </span>
<span style="color:#9a9a9a">  13 </span>            <span style="color:#ff3030; font-weight:bold">var</span> layout_manager <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>layout<span style="color:#555555">.</span><span style="color:#d11ced">HBox</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  14 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">setLayout</span><span style="color:#555555">(</span>layout_manager<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  15 </span>
<span style="color:#9a9a9a">  16 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 1&quot;</span><span style="color:#555555">));</span>
<span style="color:#9a9a9a">  17 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 2&quot;</span><span style="color:#555555">));</span>
<span style="color:#9a9a9a">  18 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 3&quot;</span><span style="color:#555555">));</span>
<span style="color:#9a9a9a">  19 </span>
<span style="color:#9a9a9a">  20 </span>            <span style="color:#ff3030; font-weight:bold">var</span> application_root <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">getRoot</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  21 </span>            application_root<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span>main_container<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  22 </span>        <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  23 </span>    <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  24 </span><span style="color:#555555">});</span></pre>

<div id="attachment_129" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.muhuk.com/wp-content/uploads/2009/02/hbox1.png"><img src="http://www.muhuk.com/wp-content/uploads/2009/02/hbox1-300x226.png" alt="HBox Example 1" title="HBox Example 1" width="300" height="226" class="size-medium wp-image-129" /></a><p class="wp-caption-text">HBox Example 1</p></div>

<p>Ok, nothing special here. In the next example we will see how we can apply different constraints to individual child elements:</p>

<pre><span style="color:#9a9a9a">   1 </span><span style="color:#38ad24">/*</span>
<span style="color:#9a9a9a">   2 </span><span style="color:#38ad24">#asset(hbox/*)</span>
<span style="color:#9a9a9a">   3 </span><span style="color:#38ad24">*/</span>
<span style="color:#9a9a9a">   4 </span>qx<span style="color:#555555">.</span>Class<span style="color:#555555">.</span><span style="color:#d11ced">define</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;hbox.Application&quot;</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">   5 </span><span style="color:#555555">{</span>
<span style="color:#9a9a9a">   6 </span>    extend<span style="color:#555555">:</span> qx<span style="color:#555555">.</span>application<span style="color:#555555">.</span>Standalone<span style="color:#555555">,</span>
<span style="color:#9a9a9a">   7 </span>    members<span style="color:#555555">: {</span>
<span style="color:#9a9a9a">   8 </span>        main<span style="color:#555555">:</span> <span style="color:#ff3030; font-weight:bold">function</span><span style="color:#555555">(){</span>
<span style="color:#9a9a9a">   9 </span>            <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">base</span><span style="color:#555555">(</span>arguments<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  10 </span>
<span style="color:#9a9a9a">  11 </span>            <span style="color:#ff3030; font-weight:bold">var</span> main_container <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>container<span style="color:#555555">.</span><span style="color:#d11ced">Composite</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  12 </span>
<span style="color:#9a9a9a">  13 </span>            <span style="color:#ff3030; font-weight:bold">var</span> layout_manager <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>layout<span style="color:#555555">.</span><span style="color:#d11ced">HBox</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  14 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">setLayout</span><span style="color:#555555">(</span>layout_manager<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  15 </span>
<span style="color:#ff0000">  <b>16</b> </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span>
<span style="color:#ff0000">  <b>17</b> </span>                                           <span style="color:#1861a7">&quot;Child Widget 1&quot;</span><span style="color:#555555">).</span><span style="color:#d11ced">set</span><span style="color:#555555">({</span><span style="color:#0000ff">width</span><span style="color:#555555">:</span><span style="color:#32ba06">300</span><span style="color:#555555">}));</span>
<span style="color:#ff0000">  <b>18</b> </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 2&quot;</span><span style="color:#555555">));</span>
<span style="color:#ff0000">  <b>19</b> </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span>
<span style="color:#ff0000">  <b>20</b> </span>                                            <span style="color:#1861a7">&quot;Child Widget 3&quot;</span><span style="color:#555555">).</span><span style="color:#d11ced">set</span><span style="color:#555555">({</span><span style="color:#0000ff">width</span><span style="color:#555555">:</span><span style="color:#32ba06">75</span><span style="color:#555555">}));</span>
<span style="color:#ff0000">  <b>21</b> </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span>
<span style="color:#ff0000">  <b>22</b> </span>                                <span style="color:#1861a7">&quot;Child Widget 4 has a slightly longer title&quot;</span><span style="color:#555555">));</span>
<span style="color:#9a9a9a">  23 </span>
<span style="color:#9a9a9a">  24 </span>            <span style="color:#ff3030; font-weight:bold">var</span> application_root <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">getRoot</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  25 </span>            application_root<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span>main_container<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  26 </span>        <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  27 </span>    <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  28 </span><span style="color:#555555">});</span></pre>

<div id="attachment_130" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.muhuk.com/wp-content/uploads/2009/02/hbox2.png"><img src="http://www.muhuk.com/wp-content/uploads/2009/02/hbox2-300x226.png" alt="HBox Example 2" title="HBox Example 2" width="300" height="226" class="size-medium wp-image-130" /></a><p class="wp-caption-text">HBox Example 2</p></div>

<p>We have set some properties on child widgets here. I know, it&#8217;s a bit ugly doing it on the same line with the <code>add</code>ition. But screen space is more expensive now on the intertubes since the economic crisis<sup>1</sup>. The important point here is <em>we have set width of first and third widgets explicitly</em>. Second and fourth will be automatically sized. Also notice that the fourth widget is wider. Buttons consider length of their labels when calculating their sizes.</p>

<p>The container will also be auto-sized on creation. But it won&#8217;t fill the viewport since we haven&#8217;t coded this behaviour (see <a href="/2009/02/using-layouts-in-qooxdoo-part-2-vbox-layout/">previous part</a>&#41;. Next example will include this behaviour:</p>

<pre><span style="color:#9a9a9a">   1 </span><span style="color:#38ad24">/*</span>
<span style="color:#9a9a9a">   2 </span><span style="color:#38ad24">#asset(hbox/*)</span>
<span style="color:#9a9a9a">   3 </span><span style="color:#38ad24">*/</span>
<span style="color:#9a9a9a">   4 </span>qx<span style="color:#555555">.</span>Class<span style="color:#555555">.</span><span style="color:#d11ced">define</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;hbox.Application&quot;</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">   5 </span><span style="color:#555555">{</span>
<span style="color:#9a9a9a">   6 </span>    extend<span style="color:#555555">:</span> qx<span style="color:#555555">.</span>application<span style="color:#555555">.</span>Standalone<span style="color:#555555">,</span>
<span style="color:#9a9a9a">   7 </span>    members<span style="color:#555555">: {</span>
<span style="color:#9a9a9a">   8 </span>        main<span style="color:#555555">:</span> <span style="color:#ff3030; font-weight:bold">function</span><span style="color:#555555">(){</span>
<span style="color:#9a9a9a">   9 </span>            <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">base</span><span style="color:#555555">(</span>arguments<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  10 </span>
<span style="color:#9a9a9a">  11 </span>            <span style="color:#ff3030; font-weight:bold">var</span> main_container <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>container<span style="color:#555555">.</span><span style="color:#d11ced">Composite</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  12 </span>
<span style="color:#9a9a9a">  13 </span>            <span style="color:#ff3030; font-weight:bold">var</span> layout_manager <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>layout<span style="color:#555555">.</span><span style="color:#d11ced">HBox</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  14 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">setLayout</span><span style="color:#555555">(</span>layout_manager<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  15 </span>
<span style="color:#ff0000">  <b>16</b> </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 1&quot;</span><span style="color:#555555">).</span><span style="color:#d11ced">set</span><span style="color:#555555">({</span>
<span style="color:#ff0000">  <b>17</b> </span>                <span style="color:#0000ff">width</span><span style="color:#555555">:</span> <span style="color:#32ba06">300</span><span style="color:#555555">,</span>
<span style="color:#ff0000">  <b>18</b> </span>                allowGrowX<span style="color:#555555">:</span> <span style="color:#ff3030; font-weight:bold">true</span><span style="color:#555555">,</span>
<span style="color:#ff0000">  <b>19</b> </span>            <span style="color:#555555">}), {</span>flex<span style="color:#555555">:</span> <span style="color:#32ba06">1</span><span style="color:#555555">});</span>
<span style="color:#ff0000">  <b>20</b> </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 2&quot;</span><span style="color:#555555">).</span><span style="color:#d11ced">set</span><span style="color:#555555">({</span>
<span style="color:#ff0000">  <b>21</b> </span>                minWidth<span style="color:#555555">:</span> <span style="color:#32ba06">75</span><span style="color:#555555">,</span>
<span style="color:#ff0000">  <b>22</b> </span>                maxWidth<span style="color:#555555">:</span> <span style="color:#32ba06">200</span><span style="color:#555555">,</span>
<span style="color:#ff0000">  <b>23</b> </span>            <span style="color:#555555">}), {</span>flex<span style="color:#555555">:</span> <span style="color:#32ba06">1</span><span style="color:#555555">});</span>
<span style="color:#ff0000">  <b>24</b> </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 3&quot;</span><span style="color:#555555">).</span><span style="color:#d11ced">set</span><span style="color:#555555">({</span>
<span style="color:#ff0000">  <b>25</b> </span>                <span style="color:#0000ff">width</span><span style="color:#555555">:</span> <span style="color:#32ba06">75</span><span style="color:#555555">,</span>
<span style="color:#ff0000">  <b>26</b> </span>                allowGrowX<span style="color:#555555">:</span> <span style="color:#ff3030; font-weight:bold">false</span><span style="color:#555555">,</span>
<span style="color:#ff0000">  <b>27</b> </span>            <span style="color:#555555">}), {</span>flex<span style="color:#555555">:</span> <span style="color:#32ba06">1</span><span style="color:#555555">});</span>
<span style="color:#9a9a9a">  28 </span>
<span style="color:#9a9a9a">  29 </span>            <span style="color:#ff3030; font-weight:bold">var</span> application_root <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">getRoot</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  30 </span>            application_root<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span>main_container<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  31 </span>
<span style="color:#ff0000">  <b>32</b> </span>            application_root<span style="color:#555555">.</span><span style="color:#d11ced">addListener</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;resize&quot;</span><span style="color:#555555">,</span> <span style="color:#ff3030; font-weight:bold">function</span><span style="color:#555555">(</span>e<span style="color:#555555">) {</span>
<span style="color:#ff0000">  <b>33</b> </span>                main_container<span style="color:#555555">.</span><span style="color:#d11ced">set</span><span style="color:#555555">({</span>
<span style="color:#ff0000">  <b>34</b> </span>                    <span style="color:#1861a7">&quot;width&quot;</span><span style="color:#555555">:</span> qx<span style="color:#555555">.</span>bom<span style="color:#555555">.</span>Viewport<span style="color:#555555">.</span><span style="color:#d11ced">getWidth</span><span style="color:#555555">(),</span>
<span style="color:#ff0000">  <b>35</b> </span>                <span style="color:#555555">});</span>
<span style="color:#ff0000">  <b>36</b> </span>            <span style="color:#555555">},</span> <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">);</span>
<span style="color:#9a9a9a">  37 </span>        <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  38 </span>    <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  39 </span><span style="color:#555555">});</span>
</pre>

<div id="attachment_131" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.muhuk.com/wp-content/uploads/2009/02/hbox3.png"><img src="http://www.muhuk.com/wp-content/uploads/2009/02/hbox3-300x226.png" alt="HBox Example 3" title="HBox Example 3" width="300" height="226" class="size-medium wp-image-131" /></a><p class="wp-caption-text">HBox Example 3</p></div>

<p>We have quite a few changes this time. First of all each widget is set to <code>flex</code>. First and third widgets have their (different) <code>width</code>s explicitly set. <code>Grow</code>ing is enabled for the first<sup>2</sup> and disabled for the third. For the second widget we have created different constraints; we have set the maximum and minimum values for <code>width</code>.</p>

<p>Try resizing the window to see how each widget reacts. We should note that the second widget never goes beyond its limits. While the other two conform to fit the containers space. <code>MinWidth</code> and <code>MaxWidth</code> are stronger constraints than <code>width</code>.</p>

<p>Let&#8217;s try constraining the container&#8217;s size:</p>

<pre><span style="color:#9a9a9a">   1 </span><span style="color:#38ad24">/*</span>
<span style="color:#9a9a9a">   2 </span><span style="color:#38ad24">#asset(hbox/ *)</span>
<span style="color:#9a9a9a">   3 </span><span style="color:#38ad24">*/</span>
<span style="color:#9a9a9a">   4 </span>qx<span style="color:#555555">.</span>Class<span style="color:#555555">.</span><span style="color:#d11ced">define</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;hbox.Application&quot;</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">   5 </span><span style="color:#555555">{</span>
<span style="color:#9a9a9a">   6 </span>    extend<span style="color:#555555">:</span> qx<span style="color:#555555">.</span>application<span style="color:#555555">.</span>Standalone<span style="color:#555555">,</span>
<span style="color:#9a9a9a">   7 </span>    members<span style="color:#555555">: {</span>
<span style="color:#9a9a9a">   8 </span>        main<span style="color:#555555">:</span> <span style="color:#ff3030; font-weight:bold">function</span><span style="color:#555555">(){</span>
<span style="color:#9a9a9a">   9 </span>            <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">base</span><span style="color:#555555">(</span>arguments<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  10 </span>
<span style="color:#9a9a9a">  11 </span>            <span style="color:#ff3030; font-weight:bold">var</span> main_container <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>container<span style="color:#555555">.</span><span style="color:#d11ced">Composite</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  12 </span>
<span style="color:#9a9a9a">  13 </span>            <span style="color:#ff3030; font-weight:bold">var</span> layout_manager <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>layout<span style="color:#555555">.</span><span style="color:#d11ced">HBox</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  14 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">setLayout</span><span style="color:#555555">(</span>layout_manager<span style="color:#555555">);</span>
<span style="color:#ff0000">  <b>15</b> </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">set</span><span style="color:#555555">({</span>
<span style="color:#ff0000">  <b>16</b> </span>                maxWidth<span style="color:#555555">:</span> <span style="color:#32ba06">900</span><span style="color:#555555">,</span>
<span style="color:#ff0000">  <b>17</b> </span>                minWidth<span style="color:#555555">:</span> <span style="color:#32ba06">400</span><span style="color:#555555">,</span>
<span style="color:#ff0000">  <b>18</b> </span>            <span style="color:#555555">});</span>
<span style="color:#9a9a9a">  19 </span>
<span style="color:#9a9a9a">  20 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 1&quot;</span><span style="color:#555555">).</span><span style="color:#d11ced">set</span><span style="color:#555555">({</span>
<span style="color:#9a9a9a">  21 </span>                <span style="color:#0000ff">width</span><span style="color:#555555">:</span> <span style="color:#32ba06">300</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  22 </span>                allowGrowX<span style="color:#555555">:</span> <span style="color:#ff3030; font-weight:bold">true</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  23 </span>            <span style="color:#555555">}), {</span>flex<span style="color:#555555">:</span> <span style="color:#32ba06">1</span><span style="color:#555555">});</span>
<span style="color:#9a9a9a">  24 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 2&quot;</span><span style="color:#555555">).</span><span style="color:#d11ced">set</span><span style="color:#555555">({</span>
<span style="color:#9a9a9a">  25 </span>                minWidth<span style="color:#555555">:</span> <span style="color:#32ba06">75</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  26 </span>                maxWidth<span style="color:#555555">:</span> <span style="color:#32ba06">200</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  27 </span>            <span style="color:#555555">}), {</span>flex<span style="color:#555555">:</span> <span style="color:#32ba06">1</span><span style="color:#555555">});</span>
<span style="color:#9a9a9a">  28 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 3&quot;</span><span style="color:#555555">).</span><span style="color:#d11ced">set</span><span style="color:#555555">({</span>
<span style="color:#9a9a9a">  29 </span>                <span style="color:#0000ff">width</span><span style="color:#555555">:</span> <span style="color:#32ba06">75</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  30 </span>                allowGrowX<span style="color:#555555">:</span> <span style="color:#ff3030; font-weight:bold">false</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">  31 </span>            <span style="color:#555555">}), {</span>flex<span style="color:#555555">:</span> <span style="color:#32ba06">1</span><span style="color:#555555">});</span>
<span style="color:#9a9a9a">  32 </span>
<span style="color:#9a9a9a">  33 </span>            <span style="color:#ff3030; font-weight:bold">var</span> application_root <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">getRoot</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  34 </span>            application_root<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span>main_container<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  35 </span>
<span style="color:#9a9a9a">  36 </span>            application_root<span style="color:#555555">.</span><span style="color:#d11ced">addListener</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;resize&quot;</span><span style="color:#555555">,</span> <span style="color:#ff3030; font-weight:bold">function</span><span style="color:#555555">(</span>e<span style="color:#555555">) {</span>
<span style="color:#9a9a9a">  37 </span>                main_container<span style="color:#555555">.</span><span style="color:#d11ced">set</span><span style="color:#555555">({</span>
<span style="color:#9a9a9a">  38 </span>                    <span style="color:#1861a7">&quot;width&quot;</span><span style="color:#555555">:</span> qx<span style="color:#555555">.</span>bom<span style="color:#555555">.</span>Viewport<span style="color:#555555">.</span><span style="color:#d11ced">getWidth</span><span style="color:#555555">(),</span>
<span style="color:#9a9a9a">  39 </span>                <span style="color:#555555">});</span>
<span style="color:#9a9a9a">  40 </span>            <span style="color:#555555">},</span> <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">);</span>
<span style="color:#9a9a9a">  41 </span>        <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  42 </span>    <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  43 </span><span style="color:#555555">});</span>
</pre>

<p>We have set the maximum and minimum <code>width</code> for the container widget. If you resize the window you should notice the container obeying these constraints.</p>

<h3>VBox &amp; HBox Wrap-up</h3>

<p><code>VBox</code> and <code>HBox</code> are simple layout managers. I have mostly tried to illustrate how container preferences, layout preferences and child widget preferences work together with examples. In the next chapters we&#8217;ll work on more advanced layout managers and then composite layouts with multiple containers.</p>

<p><small>NEXT PART: <a href="/2009/02/using-layouts-in-qooxdoo-part-4-grid-layout/">Grid Layout</a></small></p>

<hr />

<p><strong>1:</strong> This is a lame joke, I&#8217;ve just done that for the sake of brevity.</p>

<p><strong>2:</strong> This is redundant. <code>Grow</code> and <code>Shrink</code> properties are <code>true</code> by default.</p>


<p>Related posts:<ol><li><a href='http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-2-vbox-layout/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 2: VBox Layout'>Using Layouts In Qooxdoo &#8211; Part 2: VBox Layout</a></li>
<li><a href='http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-4-grid-layout/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 4: Grid Layout'>Using Layouts In Qooxdoo &#8211; Part 4: Grid Layout</a></li>
<li><a href='http://www.muhuk.com/2009/01/using-layouts-in-qooxdoo-part-1/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 1'>Using Layouts In Qooxdoo &#8211; Part 1</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-3-hbox-layout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Layouts In Qooxdoo &#8211; Part 2: VBox Layout</title>
		<link>http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-2-vbox-layout/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=using-layouts-in-qooxdoo-part-2-vbox-layout</link>
		<comments>http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-2-vbox-layout/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 11:00:59 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[qooxdoo]]></category>
		<category><![CDATA[ria]]></category>
		<category><![CDATA[vbox]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=102</guid>
		<description><![CDATA[This is the second part of a tutorial series about layout managers, container objects and object hierarchies in Qooxdoo. Read the first part here. qx.ui.layout.VBox is a basic layout manager that places child widgets on top of each other. Let&#8217;s see how VBox lays out components on a simple application1. All the necessary code is [...]]]></description>
			<content:encoded><![CDATA[<p><small>This is the second part of a tutorial series about layout managers, container objects and object hierarchies in Qooxdoo. Read the first part <a href="/2009/01/using-layouts-in-qooxdoo-part-1/">here</a>.</small></p>

<p><code>qx.ui.layout.VBox</code> is a basic layout manager that places child widgets on top of each other.</p>

<div id="attachment_105" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.muhuk.com/wp-content/uploads/2009/01/vbox.png"><img src="http://www.muhuk.com/wp-content/uploads/2009/01/vbox.png" alt="VBox Layout" title="VBox Layout" width="300" height="400" class="size-full wp-image-105" /></a><p class="wp-caption-text">VBox Layout</p></div>

<p>Let&#8217;s see how <code>VBox</code> lays out components on a simple application<sup>1</sup>. All the necessary code is below:</p>

<pre><span style="color:#9a9a9a">   1 </span><span style="color:#38ad24">/*</span>
<span style="color:#9a9a9a">   2 </span><span style="color:#38ad24">#asset(vbox/*)</span>
<span style="color:#9a9a9a">   3 </span><span style="color:#38ad24">*/</span>
<span style="color:#9a9a9a">   4 </span>qx<span style="color:#555555">.</span>Class<span style="color:#555555">.</span><span style="color:#d11ced">define</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;vbox.Application&quot;</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">   5 </span><span style="color:#555555">{</span>
<span style="color:#9a9a9a">   6 </span>    extend<span style="color:#555555">:</span> qx<span style="color:#555555">.</span>application<span style="color:#555555">.</span>Standalone<span style="color:#555555">,</span>
<span style="color:#9a9a9a">   7 </span>    members<span style="color:#555555">: {</span>
<span style="color:#9a9a9a">   8 </span>        main<span style="color:#555555">:</span> <span style="color:#ff3030; font-weight:bold">function</span><span style="color:#555555">(){</span>
<span style="color:#9a9a9a">   9 </span>            <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">base</span><span style="color:#555555">(</span>arguments<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  10 </span>
<span style="color:#9a9a9a">  11 </span>            <span style="color:#ff3030; font-weight:bold">var</span> main_container <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>container<span style="color:#555555">.</span><span style="color:#d11ced">Composite</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  12 </span>
<span style="color:#9a9a9a">  13 </span>            <span style="color:#ff3030; font-weight:bold">var</span> layout_manager <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>layout<span style="color:#555555">.</span><span style="color:#d11ced">VBox</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  14 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">setLayout</span><span style="color:#555555">(</span>layout_manager<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  15 </span>
<span style="color:#9a9a9a">  16 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 1&quot;</span><span style="color:#555555">));</span>
<span style="color:#9a9a9a">  17 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 2&quot;</span><span style="color:#555555">));</span>
<span style="color:#9a9a9a">  18 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 3&quot;</span><span style="color:#555555">));</span>
<span style="color:#9a9a9a">  19 </span>
<span style="color:#9a9a9a">  20 </span>            <span style="color:#ff3030; font-weight:bold">var</span> application_root <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">getRoot</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  21 </span>            application_root<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span>main_container<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  22 </span>        <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  23 </span>    <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  24 </span><span style="color:#555555">});</span></pre>

<div id="attachment_109" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.muhuk.com/wp-content/uploads/2009/01/vbox1.png"><img src="http://www.muhuk.com/wp-content/uploads/2009/01/vbox1-300x226.png" alt="VBox Example 1" title="VBox Example 1" width="300" height="226" class="size-medium wp-image-109" /></a><p class="wp-caption-text">VBox Example 1</p></div>

<p>I told you VBox is basic; child widgets are stacked vertically in order they have added. We haven&#8217;t set any preferences (constraints), so it&#8217;s all defaults. <code>Button</code>s get an optimal width depending on the length of their label. The container <code>main_container</code> applies this width to itself, it conforms its children&#8217;s dimensions.</p>

<p>Try giving one of the buttons a longer label. Now the modified button is wider, that was expected. But the others are widened as well. That is because they have conformed (flexed) their container&#8217;s width. We will see how this works in detail.</p>

<p>Let&#8217;s set the container&#8217;s size same as the viewport&#8217;s:</p>

<pre><span style="color:#9a9a9a">   1 </span><span style="color:#38ad24">/*</span>
<span style="color:#9a9a9a">   2 </span><span style="color:#38ad24">#asset(vbox/*)</span>
<span style="color:#9a9a9a">   3 </span><span style="color:#38ad24">*/</span>
<span style="color:#9a9a9a">   4 </span>qx<span style="color:#555555">.</span>Class<span style="color:#555555">.</span><span style="color:#d11ced">define</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;vbox.Application&quot;</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">   5 </span><span style="color:#555555">{</span>
<span style="color:#9a9a9a">   6 </span>    extend<span style="color:#555555">:</span> qx<span style="color:#555555">.</span>application<span style="color:#555555">.</span>Standalone<span style="color:#555555">,</span>
<span style="color:#9a9a9a">   7 </span>    members<span style="color:#555555">: {</span>
<span style="color:#9a9a9a">   8 </span>        main<span style="color:#555555">:</span> <span style="color:#ff3030; font-weight:bold">function</span><span style="color:#555555">(){</span>
<span style="color:#9a9a9a">   9 </span>            <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">base</span><span style="color:#555555">(</span>arguments<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  10 </span>
<span style="color:#9a9a9a">  11 </span>            <span style="color:#ff3030; font-weight:bold">var</span> main_container <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>container<span style="color:#555555">.</span><span style="color:#d11ced">Composite</span><span style="color:#555555">();</span>
<span style="color:#ff0000">  <b>12</b> </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">setWidth</span><span style="color:#555555">(</span>qx<span style="color:#555555">.</span>bom<span style="color:#555555">.</span>Viewport<span style="color:#555555">.</span><span style="color:#d11ced">getWidth</span><span style="color:#555555">());</span>
<span style="color:#ff0000">  <b>13</b> </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">setHeight</span><span style="color:#555555">(</span>qx<span style="color:#555555">.</span>bom<span style="color:#555555">.</span>Viewport<span style="color:#555555">.</span><span style="color:#d11ced">getHeight</span><span style="color:#555555">());</span>
<span style="color:#9a9a9a">  14 </span>
<span style="color:#9a9a9a">  15 </span>
<span style="color:#9a9a9a">  16 </span>            <span style="color:#ff3030; font-weight:bold">var</span> layout_manager <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>layout<span style="color:#555555">.</span><span style="color:#d11ced">VBox</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  17 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">setLayout</span><span style="color:#555555">(</span>layout_manager<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  18 </span>
<span style="color:#9a9a9a">  19 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 1&quot;</span><span style="color:#555555">));</span>
<span style="color:#9a9a9a">  20 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 2&quot;</span><span style="color:#555555">));</span>
<span style="color:#9a9a9a">  21 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 3&quot;</span><span style="color:#555555">));</span>
<span style="color:#9a9a9a">  22 </span>
<span style="color:#9a9a9a">  23 </span>            <span style="color:#ff3030; font-weight:bold">var</span> application_root <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">getRoot</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  24 </span>            application_root<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span>main_container<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  25 </span>        <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  26 </span>    <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  27 </span><span style="color:#555555">});</span></pre>

<div id="attachment_110" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.muhuk.com/wp-content/uploads/2009/01/vbox2.png"><img src="http://www.muhuk.com/wp-content/uploads/2009/01/vbox2-300x226.png" alt="VBox Example 2" title="VBox Example 2" width="300" height="226" class="size-medium wp-image-110" /></a><p class="wp-caption-text">VBox Example 2</p></div>

<p>Notice that only width seems to be adjusted, even though we have set both dimensions. Actually, it worked as we intended to; <code>main_container</code> now fills the entire viewport. But by default <code>VBox</code> won&#8217;t flex child widgets vertically. We will start overriding this behaviour in a minute.</p>

<p>Try setting <code>alignY</code> property to &#8220;<code>center</code>&#8221; or &#8220;<code>bottom</code>&#8221; on the layout manager:</p>

<pre>layout_manager<span style="color:#555555">.</span><span style="color:#d11ced">setAlignY</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;bottom&quot;</span><span style="color:#555555">);</span></pre>

<p>So far we have set properties (constraints) on containers (<code>main_container.width</code> &amp; <code>main_container.height</code>) and on layout managers (<code>layout_manager.alignY</code>). In the next example we will set properties on child widgets:</p>

<pre><span style="color:#9a9a9a">   1 </span><span style="color:#38ad24">/*</span>
<span style="color:#9a9a9a">   2 </span><span style="color:#38ad24">#asset(vbox/*)</span>
<span style="color:#9a9a9a">   3 </span><span style="color:#38ad24">*/</span>
<span style="color:#9a9a9a">   4 </span>qx<span style="color:#555555">.</span>Class<span style="color:#555555">.</span><span style="color:#d11ced">define</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;vbox.Application&quot;</span><span style="color:#555555">,</span>
<span style="color:#9a9a9a">   5 </span><span style="color:#555555">{</span>
<span style="color:#9a9a9a">   6 </span>    extend<span style="color:#555555">:</span> qx<span style="color:#555555">.</span>application<span style="color:#555555">.</span>Standalone<span style="color:#555555">,</span>
<span style="color:#9a9a9a">   7 </span>    members<span style="color:#555555">: {</span>
<span style="color:#9a9a9a">   8 </span>        main<span style="color:#555555">:</span> <span style="color:#ff3030; font-weight:bold">function</span><span style="color:#555555">(){</span>
<span style="color:#9a9a9a">   9 </span>            <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">base</span><span style="color:#555555">(</span>arguments<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  10 </span>
<span style="color:#9a9a9a">  11 </span>            <span style="color:#ff3030; font-weight:bold">var</span> main_container <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>container<span style="color:#555555">.</span><span style="color:#d11ced">Composite</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  12 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">setWidth</span><span style="color:#555555">(</span>qx<span style="color:#555555">.</span>bom<span style="color:#555555">.</span>Viewport<span style="color:#555555">.</span><span style="color:#d11ced">getWidth</span><span style="color:#555555">());</span>
<span style="color:#9a9a9a">  13 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">setHeight</span><span style="color:#555555">(</span>qx<span style="color:#555555">.</span>bom<span style="color:#555555">.</span>Viewport<span style="color:#555555">.</span><span style="color:#d11ced">getHeight</span><span style="color:#555555">());</span>
<span style="color:#9a9a9a">  14 </span>
<span style="color:#9a9a9a">  15 </span>            <span style="color:#ff3030; font-weight:bold">var</span> layout_manager <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>layout<span style="color:#555555">.</span><span style="color:#d11ced">VBox</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  16 </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">setLayout</span><span style="color:#555555">(</span>layout_manager<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  17 </span>
<span style="color:#ff0000">  <b>18</b> </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 1&quot;</span><span style="color:#555555">), {</span>flex<span style="color:#555555">:</span> <span style="color:#32ba06">1</span><span style="color:#555555">});</span>
<span style="color:#ff0000">  <b>19</b> </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 2&quot;</span><span style="color:#555555">), {</span>flex<span style="color:#555555">:</span> <span style="color:#32ba06">1</span><span style="color:#555555">});</span>
<span style="color:#ff0000">  <b>20</b> </span>            main_container<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span><span style="color:#ff3030; font-weight:bold">new</span> qx<span style="color:#555555">.</span>ui<span style="color:#555555">.</span>form<span style="color:#555555">.</span><span style="color:#d11ced">Button</span><span style="color:#555555">(</span><span style="color:#1861a7">&quot;Child Widget 3&quot;</span><span style="color:#555555">), {</span>flex<span style="color:#555555">:</span> <span style="color:#32ba06">1</span><span style="color:#555555">});</span>
<span style="color:#9a9a9a">  21 </span>
<span style="color:#9a9a9a">  22 </span>            <span style="color:#ff3030; font-weight:bold">var</span> application_root <span style="color:#555555">=</span> <span style="color:#ff3030; font-weight:bold">this</span><span style="color:#555555">.</span><span style="color:#d11ced">getRoot</span><span style="color:#555555">();</span>
<span style="color:#9a9a9a">  23 </span>            application_root<span style="color:#555555">.</span><span style="color:#d11ced">add</span><span style="color:#555555">(</span>main_container<span style="color:#555555">);</span>
<span style="color:#9a9a9a">  24 </span>        <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  25 </span>    <span style="color:#555555">}</span>
<span style="color:#9a9a9a">  26 </span><span style="color:#555555">});</span></pre>

<div id="attachment_111" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.muhuk.com/wp-content/uploads/2009/01/vbox3.png"><img src="http://www.muhuk.com/wp-content/uploads/2009/01/vbox3-300x226.png" alt="VBox Example 3" title="VBox Example 3" width="300" height="226" class="size-medium wp-image-111" /></a><p class="wp-caption-text">VBox Example 3</p></div>

<p>We have added a second parameter to the <code>add</code> method of layout manager. This JavaScript object literal is used to set widget specific properties on the layout manager.</p>

<p><code>Flex</code> property determines how the extra space<sup>2</sup> is distributed between children. By default it is set to <code>0</code>, which means that the widget will not grow vertically. Any other (integer) value for <code>flex</code> will cause growing to occupy the extra space. Growing is proportional to <code>flex</code> value. Try different <code>flex</code> values for different widgets and see the changes.</p>

<p><small>NEXT PART: HBox Layout</small></p>

<hr />

<p><strong>1</strong>: If you haven&#8217;t created a qx application before, it is explained in detail in <a href="/2008/10/getting-a-little-further-than-hello-world-with-qooxdoo/">the tutorial</a>.</p>

<p><strong>2</strong>: Remaining space after initial dimensions of children are computed.</p>


<p>Related posts:<ol><li><a href='http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-3-hbox-layout/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 3: HBox Layout'>Using Layouts In Qooxdoo &#8211; Part 3: HBox Layout</a></li>
<li><a href='http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-4-grid-layout/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 4: Grid Layout'>Using Layouts In Qooxdoo &#8211; Part 4: Grid Layout</a></li>
<li><a href='http://www.muhuk.com/2009/01/using-layouts-in-qooxdoo-part-1/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 1'>Using Layouts In Qooxdoo &#8211; Part 1</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-2-vbox-layout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Layouts In Qooxdoo &#8211; Part 1</title>
		<link>http://www.muhuk.com/2009/01/using-layouts-in-qooxdoo-part-1/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=using-layouts-in-qooxdoo-part-1</link>
		<comments>http://www.muhuk.com/2009/01/using-layouts-in-qooxdoo-part-1/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 08:00:21 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[qooxdoo]]></category>
		<category><![CDATA[ria]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=96</guid>
		<description><![CDATA[This is the first part of a tutorial series about layout managers, container objects and object hierarchies in Qooxdoo (qx for short from here on). Its target audience is mostly qx programmers coming from an (X)HTML/CSS/DOM background who have possibly used JavaScript libraries such as JQuery or prototype before. Qx is different, it is a [...]]]></description>
			<content:encoded><![CDATA[<p>This is the first part of a tutorial series about layout managers, container objects and object hierarchies in <a href="/2008/10/getting-a-little-further-than-hello-world-with-qooxdoo/">Qooxdoo</a> (<em>qx</em> for short from here on). Its target audience is mostly qx programmers coming from an (X)HTML/CSS/DOM background who have possibly used JavaScript libraries such as <a href="http://jquery.com/">JQuery</a> or <a href="http://www.prototypejs.org/">prototype</a> before. Qx is different, it is a <strong>JavaScript <a href="http://en.wikipedia.org/wiki/Rich_Internet_application">RIA</a> Framework</strong>. If you have used a GUI toolkit such as Swing (Java), wxWidgets or GTK+ you should have no difficulty following this tutorial. In fact you will probably find it boring<sup>1</sup>. On the other hand if you are still trying to find out how you can attach your <code>&lt;div /&gt;</code> in an existing qx layout; you are in the right place.</p>

<p>The answer is &#8220;No&#8221;, to the question above. You don&#8217;t create DOM elements with qx (unless you are doing something really exotic). Actually you don&#8217;t need to concern yourself with the DOM at all. GUI is abstracted to a set of intuitive classes that you should be familiar from today&#8217;s desktop operating systems. This abstraction brings two big advantages:</p>

<ul>
<li>Developers using qx don&#8217;t need to concern themselves with cross-browser issues.</li>
<li>Theming is easy and uniform.</li>
</ul>

<h3>Widgets Are The Building Blocks</h3>

<p>A qx user interface is constructed using <em>widget</em>s. A widget is a class that encapsulates appereance, data and behaviour. For instance a TextField would render itself as a box and a caret, make the text you enter inside accessible programmatically and allow you to be notified whenever a the text data is changed. Widgets are customizable, subclassable and of course themable.</p>

<p>But a GUI hardly ever consists of a single widget. Instead there is a hierarchy of widgets. A <em>container</em> is a special kind of widget that has child widgets. A container widget ususally doesn&#8217;t have any visual parts itself and just render its children in its screen space. How child widgets are positioned within their container is decided by the container&#8217;s <em>layout manager</em>. Having a layout manager means the abstraction of layout strategy for maximum flexibility.</p>

<p>So how do containers, child widgets and layout managers work together? First of all qx positions everything with absolute coordinates (Yes; <code>position:absolute</code>) internally. But that doesn&#8217;t mean you need to position anything absolutely on the API level. Speaking in terms of JavaScript libraries; <strong>you can take advantage of floating/auto-sizing/liquid layouts</strong>. Position and size of all widgets are <em>negotiated</em> through this hierarchy. Theoretically everyone has a say. This means that you can set some constraints on parents and then some others on child widgets and they all work together. The resulting layout is then converted to absolute coordinates for rendering. (Examples in the next part)</p>

<h3>Recap</h3>

<ol>
<li>Qx GUI&#8217;s are hierarchically constructed from widgets.</li>
<li>Each <code>application</code> has a root container.</li>
<li>Each container has a layout manager and one or more child widgets<sup>2</sup>.</li>
<li>A child of a container can be either:

<ol>
<li>Another container.</li>
<li>Or a control widget (such as a form widget).</li>
</ol></li>
</ol>

<p><small>NEXT PART: <a href="/2009/02/using-layouts-in-qooxdoo-part-2-vbox-layout/">VBox Layout</a></small></p>

<hr />

<p><strong>1</strong>: You might want to see <a href="http://demo.qooxdoo.org/current/apiviewer/">Qooxdoo &#8211; API documentation</a> instead.</p>

<p><strong>2</strong>: Although it is possible that a container may have no children, it is not sensible.</p>


<p>Related posts:<ol><li><a href='http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-2-vbox-layout/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 2: VBox Layout'>Using Layouts In Qooxdoo &#8211; Part 2: VBox Layout</a></li>
<li><a href='http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-3-hbox-layout/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 3: HBox Layout'>Using Layouts In Qooxdoo &#8211; Part 3: HBox Layout</a></li>
<li><a href='http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-4-grid-layout/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 4: Grid Layout'>Using Layouts In Qooxdoo &#8211; Part 4: Grid Layout</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2009/01/using-layouts-in-qooxdoo-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Getting A Little Further Than Hello World With Qooxdoo</title>
		<link>http://www.muhuk.com/2008/10/getting-a-little-further-than-hello-world-with-qooxdoo/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=getting-a-little-further-than-hello-world-with-qooxdoo</link>
		<comments>http://www.muhuk.com/2008/10/getting-a-little-further-than-hello-world-with-qooxdoo/#comments</comments>
		<pubDate>Fri, 17 Oct 2008 17:14:54 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[hello world]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[object oriented]]></category>
		<category><![CDATA[qooxdoo]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=39</guid>
		<description><![CDATA[I have mentioned about Rich Internet Applications in a previous post. Qooxdoo is an AJAX framework, especially strong on creating desktop-like GUI&#8217;s. It allows you to build your interface in an object oriented manner. Like tkinter or GTK, and much more than the others it is like swing. Qooxdoo is well documented and has a [...]]]></description>
			<content:encoded><![CDATA[<p>I have <a href="http://www.muhuk.com/2008/09/v-for-volatile/">mentioned</a> about <a href="http://en.wikipedia.org/wiki/Rich_internet_application">Rich Internet Applications</a> in a previous post. <a href="http://qooxdoo.org">Qooxdoo</a> is an AJAX framework, especially strong on creating desktop-like GUI&#8217;s. It allows you to build your interface in an object oriented manner. Like <a href="http://wiki.python.org/moin/TkInter">tkinter</a> or <a href="http://www.gtk.org/">GTK</a>, and much more than the others it is like <a href="http://en.wikipedia.org/wiki/Java_Swing">swing</a>.</p>

<p>Qooxdoo is <a href="http://demo.qooxdoo.org/0.8.x/apiviewer/">well</a> <a href="http://qooxdoo.org/documentation">documented</a> and has a clean API. It <a href="http://qooxdoo.org/download">comes</a> with a Python program to help with builds. Because it is such a big framework you test on a partially compiled source and when finished this build program generates a single (actually two, it also generates a loader), compact (and somewhat obfuscated) file for performance. I strongly advise you to give it a try. The following is a small introductory tutorial. It aims to go little further than Hello World. <strong>This is not a tutorial explaining object oriented programming concepts, I assume you are already fluent in <a href="http://en.wikipedia.org/wiki/Object-oriented_programming">OOP</a></strong>.</p>

<h3>Create The Skeleton</h3>

<div id="attachment_52" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.muhuk.com/wp-content/uploads/2008/10/snapshot2.jpeg"><img src="http://www.muhuk.com/wp-content/uploads/2008/10/snapshot2-300x77.jpg" alt="Screenshot of finished application" title="Screenshot of finished application" width="300" height="77" class="size-medium wp-image-52" /></a><p class="wp-caption-text">Screenshot of finished application</p></div>

<p>We&#8217;ll create a simple calculator-like application. I am assuming you have downloaded (latest version is 0.8 for today) and extracted the source into a directory. Let&#8217;s call it <code>qxtut</code>. The first thing we will do is to create a skeleton of our application with the following command;</p>

<pre><code>./qooxdoo-0.8-sdk/tool/bin/create-application.py --name basicmath
</code></pre>

<p>This command has created the following directory structure under ./basicmath;</p>

<pre><code>qxtut/
  qooxdoo-0.8-sdk/
  basicmath/
    source/
    build/
    cache/
    api/
    config.json
    Manifest.json
</code></pre>

<p>Well, some of the directories (<code>build</code> &amp; <code>cache</code>) are not there yet. But as we go on they will appear, I just wanted you to see how the application is organized. <code>config.json</code> and <code>Manifest.json</code> files are configuration files for the build tool. We don&#8217;t need to change them for this tutorial, but you are welcome to check their contents.</p>

<p>Let us build our source for the first time;</p>

<pre><code>cd basicmath
./generate.py source
</code></pre>

<p>Now if you open <code>./source/index.html</code> in your browser you can see a Hello World application in action. We&#8217;ll replace this with our own program. But before we proceed I&#8217;d like to point out a few things;</p>

<ul>
<li>When we define our classes, we call a class method <code>define</code> on <code>qx.Class</code> and pass our class&#8217; name (along with its namespace) and its contents as arguments. We don&#8217;t define our classes using prototypes, in order to take advantage of Qooxdoo&#8217;s object oriented programming features.</li>
<li>Qooxdoo supports <a href="http://qooxdoo.org/documentation/0.8/classes#inheritance">single inheritance</a> (with <a href="http://qooxdoo.org/documentation/0.8/mixins">mixins</a>). We define our base class, if we have one, using <code>extend</code> key.</li>
<li>Instance members are defined inside the <code>members</code> key and class members are defined inside the <code>statics</code> key.</li>
<li><code>construct</code> and <code>destruct</code> are two special functions for initialization and cleanup of the class.</li>
<li>Qooxdoo supports [properties](http://en.wikipedia.org/wiki/Property_(programming&#41;) as well, but it is outside of this tutorial&#8217;s scope.</li>
<li>Finally, &#8220;<code>#asset(basicmath/*)</code>&#8221; line tells the build program to include assets (images etc) in <code>qxtut/basicmath/source/resource/basicmath</code> directory.</li>
</ul>

<h3>Custom Classes</h3>

<p>Let&#8217;s start building our application now. Here is a compact version of Application.js;</p>

<pre><code>/* ************************************************************************
#asset(basicmath/*)
************************************************************************ */

qx.Class.define("basicmath.Application", {
    extend: qx.application.Standalone,
    members: {
        main: function()
        {
            this.base(arguments);
            if (qx.core.Variant.isSet("qx.debug", "on")) {
                qx.log.appender.Native;
                qx.log.appender.Console;
            }
            // Our code will come here
        }
    }
});
</code></pre>

<p>Now we will create a custom class named <code>Operation</code>. This class will take two operands and perform an operation on them, and then later we will add it the ability to report the result of the operation. Paste this as <code>Operation.js</code>;</p>

<pre><code>/* ************************************************************************
#asset(basicmath/*)
************************************************************************ */

qx.Class.define("basicmath.Operation", {
    extend: qx.ui.container.Composite,
    construct: function() {
        this.base(arguments);
        var layout = new qx.ui.layout.HBox(6);
        this.setLayout(layout);
        this.operand1 = new qx.ui.form.TextField("0");
        this.operator = new qx.ui.form.SelectBox();
        this.operator.add(new qx.ui.form.ListItem("add"));
        this.operator.add(new qx.ui.form.ListItem("subtract"));
        this.operator.add(new qx.ui.form.ListItem("multiply"));
        this.operator.add(new qx.ui.form.ListItem("divide"));
        this.operand2 = new qx.ui.form.TextField("0");
        this.result = new qx.ui.basic.Label("0");
        this.add(this.operand1);
        this.add(this.operator);
        this.add(this.operand2);
        this.add(this.result);
    },
    members: {
        operand1: null,
        operator: null,
        operand2: null,
        result: null
    }
});
</code></pre>

<p>The code should be self explanatory. Notice here, we define <code>operand1</code>, <code>operator</code>, <code>operand2</code> and <code>result</code> as members of the class. Also notice we initialize those members in the constructor and not in the class body<sup>1</sup>. This is because their respected values (classes) are derived from the non-primitive <code>Object</code> type. Therefore if we have assigned them a non-primitive type (such as the array [1, 2, 3]) in the members section; all instances would point to the same object.</p>

<p>Let us now plug this object in our application. Replace the comment line &#8220;<code>// Our code will come here</code>&#8221; with the following;</p>

<pre><code>this.getRoot().add(new basicmath.Operation);
</code></pre>

<p>Now, when we compile the source and run index.html we should see our widgets in place.</p>

<div id="attachment_51" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.muhuk.com/wp-content/uploads/2008/10/snapshot1.jpeg"><img src="http://www.muhuk.com/wp-content/uploads/2008/10/snapshot1-300x40.jpg" alt="Screenshot of an Operation widget we have just created" title="Screenshot of an Operation widget we have just created" width="300" height="40" class="size-medium wp-image-51" /></a><p class="wp-caption-text">Screenshot of an Operation widget we have just created</p></div>

<h3>Simple Behaviour</h3>

<p>We want our widget to calculate the operation and show us the result. Let&#8217;s update the members section of <code>Operation</code> with the following;</p>

<pre><code>members: {
    operand1: null,
    operator: null,
    operand2: null,
    result: null,
    updateResult: function() {
        var v1 = this.cleanField(this.operand1);
        var v2 = this.cleanField(this.operand2);
        var r;
        switch(this.operator.getValue()) {
            case "add": r = v1+v2; break;
            case "subtract": r = v1-v2; break;
            case "multiply": r = v1*v2; break;
            case "divide": r = v1/v2; break;
        }
        this.result.setContent(String(r));
        this.operand1.setValue(String(v1));
        this.operand2.setValue(String(v2));
    },
    cleanField: function(field) {
        var val = parseInt(field.getValue());
        return isNaN(val) ? 0 : val;
    }
}
</code></pre>

<p>We have added two functions here <code>updateResult</code> and <code>cleanField</code>. Now we make use of them, change the <code>construct</code> with the following;</p>

<pre><code>construct: function() {
    this.base(arguments);
    var layout = new qx.ui.layout.HBox(6);
    this.setLayout(layout);
    this.operand1 = new qx.ui.form.TextField("0");
    this.operand1.addListener("input", this.updateResult, this);
    this.operator = new qx.ui.form.SelectBox();
    this.operator.add(new qx.ui.form.ListItem("add"));
    this.operator.add(new qx.ui.form.ListItem("subtract"));
    this.operator.add(new qx.ui.form.ListItem("multiply"));
    this.operator.add(new qx.ui.form.ListItem("divide"));
    this.operator.addListener("changeValue", this.updateResult, this);
    this.operand2 = new qx.ui.form.TextField("0");
    this.operand2.addListener("input", this.updateResult, this);
    this.result = new qx.ui.basic.Label("0");
    this.add(this.operand1);
    this.add(this.operator);
    this.add(this.operand2);
    this.add(this.result);
}
</code></pre>

<p>We just added these three listeners to update the result when an operand or the operator changes;</p>

<pre><code>this.operand1.addListener("input", this.updateResult, this);
this.operator.addListener("changeValue", this.updateResult, this);
this.operand2.addListener("input", this.updateResult, this);
</code></pre>

<p>The last parameter (<code>this</code>) for <code>addListener</code> (even though it is sometimes unnecessary) set the scope within the listener code (the second parameter). Qooxdoo handles most of the binding automatically, I think this is included for flexibility.</p>

<p>Let&#8217;s compile and run again. The result of the operation should update as you change the values now.</p>

<h3>Events To Tie All Together</h3>

<p>I&#8217;ll give you the finished code first and then we can go over the details. Here is <code>Operation.js</code>;</p>

<pre><code>/* ************************************************************************
#asset(basicmath/*)
#asset(qx/icon/Oxygen/*)
************************************************************************ */

qx.Class.define("basicmath.Operation", {
    extend: qx.ui.container.Composite,
    construct: function() {
        this.base(arguments);
        var layout = new qx.ui.layout.HBox(6);
        this.setLayout(layout);
        this.operand1 = new qx.ui.form.TextField("0");
        this.operand1.addListener("input", this.updateResult, this);
        this.operator = new qx.ui.form.SelectBox();
        this.operator.add(new qx.ui.form.ListItem("add"));
        this.operator.add(new qx.ui.form.ListItem("subtract"));
        this.operator.add(new qx.ui.form.ListItem("multiply"));
        this.operator.add(new qx.ui.form.ListItem("divide"));
        this.operator.addListener("changeValue", this.updateResult, this);
        this.operand2 = new qx.ui.form.TextField("0");
        this.operand2.addListener("input", this.updateResult, this);
        this.result = new qx.ui.form.TextField("0");
        this.result.setReadOnly(true);
        var close_button = new qx.ui.form.Button(
            null,
            "qx/icon/Oxygen/16/actions/application-exit.png"
        );
        close_button.addListener("execute", function(e) {
            this.fireDataEvent(
                "changeResult",
                0,
                parseFloat(this.result.getValue()),
                false
            );
            this.destroy();
        }, this);
        this.add(this.operand1);
        this.add(this.operator);
        this.add(this.operand2);
        this.add(new qx.ui.basic.Label("="));
        this.add(this.result);
        this.add(new qx.ui.core.Spacer(8));
        this.add(close_button);
    },
    events: {
        "changeResult": "qx.event.type.Data"
    },
    members: {
        operand1: null,
        operator: null,
        operand2: null,
        result: null,
        updateResult: function() {
            var v1 = this.cleanField(this.operand1);
            var v2 = this.cleanField(this.operand2);
            var r;
            switch(this.operator.getValue()) {
                case "add": r = v1+v2; break;
                case "subtract": r = v1-v2; break;
                case "multiply": r = v1*v2; break;
                case "divide": r = v1/v2; break;
            }
            this.fireDataEvent("changeResult",
                r,
                parseFloat(this.result.getValue()),
                false
            );
            this.result.setValue(String(r));
            this.operand1.setValue(String(v1));
            this.operand2.setValue(String(v2));
        },
        cleanField: function(field) {
            var val = parseInt(field.getValue());
            return isNaN(val) ? 0 : val;
        }
    }
});
</code></pre>

<p>And <code>Application.js</code>;</p>

<pre><code>/* ************************************************************************
#asset(basicmath/*)
#asset(qx/icon/Oxygen/*)
************************************************************************ */

qx.Class.define("basicmath.Application", {
    extend : qx.application.Standalone,
    members : {
        main : function()
        {
            this.base(arguments);
            if (qx.core.Variant.isSet("qx.debug", "on")) {
                qx.log.appender.Native;
                qx.log.appender.Console;
            }
            var layout = new qx.ui.container.Composite(
                new qx.ui.layout.VBox(8)
            );
            var layout_footer = new qx.ui.container.Composite(
                new qx.ui.layout.HBox(6)
            );
            var total = new qx.ui.basic.Label("0");
            var add_button = new qx.ui.form.Button(
                "Add New",
                "qx/icon/Oxygen/16/actions/list-add.png"
            );
            add_button.addListener("execute", function(e) {
                var new_operation = new basicmath.Operation();
                layout.addBefore(new_operation, layout_footer);
                new_operation.addListener("changeResult", function(e) {
                    var old_total = parseFloat(total.getContent());
                    var new_total = old_total - e.getOldData() + e.getData();
                    total.setContent(String(new_total));
                }, this);
            }, this);
            layout_footer.add(add_button);
            layout_footer.add(total);
            layout.add(layout_footer);
            add_button.execute();
            this.getRoot().add(layout);
        }
    }
});
</code></pre>

<p>Let&#8217;s go top-down and begin with the changes in the <code>Application.js</code>;</p>

<pre><code>var layout = new qx.ui.container.Composite(new qx.ui.layout.VBox(8));
this.getRoot().add(layout);
</code></pre>

<p>We don&#8217;t necessarily need to subclass everytime we need specialized behaviour. Since I had intented to re-use <code>Operation</code> I have it as a seperate class. But for the layout of the application I just instanciated some classes and tweaked them inside <code>Application.main</code>. <code>layout</code> here is the topmost widget, we will put everything else in it. Basically one or more <code>Operation</code>&#8216;s and a footer to dispay the grand total. <code>VBox</code> layout is by the way a layout manager that stacks children vertically, and a <code>HBox</code> stacks horizontally.</p>

<pre><code>var layout = new qx.ui.container.Composite(new qx.ui.layout.VBox(8));
var layout_footer = new qx.ui.container.Composite(new qx.ui.layout.HBox(6));
var total = new qx.ui.basic.Label("0");
var add_button = new qx.ui.form.Button(
    "Add New",
    "qx/icon/Oxygen/16/actions/list-add.png"
);
add_button.addListener("execute", function(e) {
    var new_operation = new basicmath.Operation();
    layout.addBefore(new_operation, layout_footer);
    new_operation.addListener("changeResult", function(e) {
        var old_total = parseFloat(total.getContent());
        var new_total = old_total - e.getOldData() + e.getData();
        total.setContent(String(new_total));
    }, this);
}, this);
</code></pre>

<p>We define a label <code>total</code> to hold the grand total of all operations and an add button for new operations. Notice the closures work on 7th line. Although we limit ourselves a little bit to take advantage of OOP, we are still in a dynamic environment. Finally we tie all these components together and finally add the <code>layout</code> to the application root.</p>

<pre><code>add_button.execute();
</code></pre>

<p>This instantiates the first <code>Operation</code> for us. We execute the button instead of creating the widget programmatically to avoid the code duplication (see the &#8220;execute&#8221; listener on the <code>add_button</code>).</p>

<p>Now let&#8217;s take a look at the changes in <code>Operation.js</code>. I have replaced the <code>result</code> <code>Label</code> with a <code>TextField</code> (remember to run &#8220;<code>generate.py source</code>&#8221; each time dependencies change). I wanted to take advantage of the getOldData function on <code>TextField</code>&#8216;s <code>changeValue</code> event. But appereantly it doesn&#8217;t supply the old data. But I kept it as a <code>TextField</code> anyway, setting it read-only.</p>

<p>Then I decided that <code>Operation</code> should signal for a result change (maybe this is more politically correct) and added a custom event <code>changeResult</code> on it.</p>

<pre><code>events: {
    "changeResult": "qx.event.type.Data"
}
</code></pre>

<p>This event is fired inside <code>Operation.updateResult</code>;</p>

<pre><code>this.fireDataEvent(
    "changeResult",
    r,
    parseFloat(this.result.getValue()),
    false
);
</code></pre>

<p>The second parameter is returned from e.getData() and the third is from e.getOldData(). Therefore we can calculate the grand total without iterating all <code>Operation</code>s;</p>

<pre><code>var new_total = old_total - e.getOldData() + e.getData();
</code></pre>

<p>An important point here is to fire <code>changeResult</code> to correct the grand total before we destroy an <code>Operation</code>;</p>

<pre><code>close_button.addListener("execute", function(e) {
    this.fireDataEvent(
        "changeResult",
        0,
        parseFloat(this.result.getValue()),
        false
    );
    this.destroy();
}, this);
</code></pre>

<h3>Wrapping Up</h3>

<p>Now it should work correctly, if I haven&#8217;t made a typo of course. Let us build it with;</p>

<pre><code>./generate.py build
</code></pre>

<p>It generates a loader (~150kb) and an application script (~400kb). You don&#8217;t need the Qooxdoo source anymore, you can just upload the contents of the <code>build</code> directory and your application would run.</p>

<p>This concludes my <em>a little further than Hello World</em> tutorial. If you find errors or typos, or have any questions please leave a comment here or contact me at muhuk@jabber.org.</p>

<hr />

<p><strong>1</strong>: Here is an explanation in <a href="http://qooxdoo.org/documentation/0.8/classes#instance_members">Qooxdoo manual</a>.</p>


<p>Related posts:<ol><li><a href='http://www.muhuk.com/2009/04/using-layouts-in-qooxdoo-index/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Index'>Using Layouts In Qooxdoo &#8211; Index</a></li>
<li><a href='http://www.muhuk.com/2009/01/using-layouts-in-qooxdoo-part-1/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 1'>Using Layouts In Qooxdoo &#8211; Part 1</a></li>
<li><a href='http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-2-vbox-layout/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 2: VBox Layout'>Using Layouts In Qooxdoo &#8211; Part 2: VBox Layout</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2008/10/getting-a-little-further-than-hello-world-with-qooxdoo/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>V For Volatile</title>
		<link>http://www.muhuk.com/2008/09/v-for-volatile/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=v-for-volatile</link>
		<comments>http://www.muhuk.com/2008/09/v-for-volatile/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 19:42:10 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[business]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[ria]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=26</guid>
		<description><![CDATA[Let&#8217;s assume we are buying a business software that will meet some business needs for our business. It is a multi user enviroment, so we opt for a product with a Client/Server architecture. What to ask for, other than the obvious requirements for the task? I would, first of all, ask for ease of deployment. [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s assume we are buying a business software that will meet some business needs for our business. It is a multi user enviroment, so we opt for a product with a Client/Server architecture. What to ask for, other than the obvious requirements for the task?</p>

<p>I would, first of all, ask for ease of <a href="http://en.wikipedia.org/wiki/Software_deployment">deployment</a>. What good is a software if you can&#8217;t run it? Ease of deployment for both the clients and the server. But clients here are more important for two reasons; they will be many, and they will be installed on desktop computers in the wild. As opposed to one server, which is (hopefully) maintained by professionals. So I would like my new software to be easily installed, uninstalled and upgraded on any computer connected to my network.</p>

<p>I would also like to be able to access the software through any client connected. It is a bad bad <a href="http://en.wikipedia.org/wiki/Security_by_design">security model</a> to rely on authentication against a client installation. Each and every client should be identical and the authentication should be done against some form of credentials<sup>1</sup>.</p>

<p>As a user I would also like to know that the client software will not mess with the rest of my system. Software breaking<sup>2</sup> other software, or the entire operating system is useless, no matter how much utility it has otherwise.</p>

<p>I guess you have realized by now where I am going with this. The system I have described above is unlikely a big over-burdened application that radiates seriousness from your screen and clings itself into the bowels of your Operating System. I am actually talking about a <em>volatile client and server</em> architecture. Where the client almost doesn&#8217;t exist. It exists of course. It resides on the server until you connect with your browser<sup>3</sup>, then get downloaded and run. This model is called <em>Rich Internet Application</em>, <a href="http://en.wikipedia.org/wiki/Rich_internet_application">RIA</a> for short.</p>

<p>The key characteristics of RIA are;</p>

<ul>
<li>No install or uninstall<sup>4</sup>.</li>
<li>Automatic remote upgrades.</li>
<li>[Sandboxed](http://en.wikipedia.org/wiki/Sandbox<em>(computer</em>security&#41;)</li>
</ul>

<p>Rich Internet Applications are powerful and considerably easier to deploy. They do have one drawback; the platform (HTML+CSS+JavaScript) they run on is not designed for applications from the beginning. It is initially designed for documents and then extended to support for applications. The main practical problem is that the JavaScript implementations are not as fast and reliable (on high loads) as native code or other popular interpreted languages. But we have started to see a new breed of <a href="http://developer.mozilla.org/en/Prism">browsers specifically</a> <a href="http://www.google.com/chrome">built for applications</a>. I am sure JavaScript virtual machines will be improved significantly in the near future.</p>

<p>On the other hand benchmarking and measuring performance by actually using and application typically yields different results. In our example, business applications do not involve heavy operations that require a lot of processing power. Non-linear video editing does, image synthesis does, desktop publishing does, business applications doesn&#8217;t. So the RIA would still be my first choice even with the possible performance problems mentioned above.</p>

<p>More on this later.</p>


<p>Related posts:<ol><li><a href='http://www.muhuk.com/2009/01/using-layouts-in-qooxdoo-part-1/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 1'>Using Layouts In Qooxdoo &#8211; Part 1</a></li>
<li><a href='http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-2-vbox-layout/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 2: VBox Layout'>Using Layouts In Qooxdoo &#8211; Part 2: VBox Layout</a></li>
<li><a href='http://www.muhuk.com/2009/02/using-layouts-in-qooxdoo-part-3-hbox-layout/' rel='bookmark' title='Permanent Link: Using Layouts In Qooxdoo &#8211; Part 3: HBox Layout'>Using Layouts In Qooxdoo &#8211; Part 3: HBox Layout</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2008/09/v-for-volatile/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
