<?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>Saturnboy &#187; design</title>
	<atom:link href="http://saturnboy.com/tag/design/feed/" rel="self" type="application/rss+xml" />
	<link>http://saturnboy.com</link>
	<description>Code, Work, and Life</description>
	<lastBuildDate>Thu, 01 Mar 2012 22:35:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Spark TreeList</title>
		<link>http://saturnboy.com/2011/09/spark-treelist/</link>
		<comments>http://saturnboy.com/2011/09/spark-treelist/#comments</comments>
		<pubDate>Sat, 10 Sep 2011 04:36:57 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[custom component]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[flex45]]></category>

		<guid isPermaLink="false">http://saturnboy.com/?p=1883</guid>
		<description><![CDATA[Did a little bit of vanilla Flex work recently, and I needed a Tree component to display an object hierarchy. Everyone, by now, hopefully knows that mx:DataGrid and mx:Tree are two of the crappiest, bug ridden, worst performing components from Flex 3. And, everyone by now, has left the buggy world of Flex 3 behind [...]]]></description>
			<content:encoded><![CDATA[<p>Did a little bit of vanilla Flex work recently, and I needed a Tree component to display an object hierarchy. Everyone, by now, hopefully knows that <code>mx:DataGrid</code> and <code>mx:Tree</code> are two of the crappiest, bug ridden, worst performing components from Flex 3. And, everyone by now, has left the buggy world of Flex 3 behind and entered the world Flex 4 and the vastly improved Spark components.  With the arrival of Flex 4.5 this summer, Adobe finally gave us a rewritten Spark-based <code>DataGrid</code>. Alas, no updated <code>Tree</code> yet, so I had to write my own.  So once again, I turned to the trusty combo of <code>List</code> plus custom <code>ItemRenderer</code> to make pure-Spark custom <code>TreeList</code> component that doesn&#8217;t suck.</p>
<p>Alex Harui is the guru of turning a Flex 4 Spark <code>List</code> into a look-alike for the old Flex 3 component using skins and a custom <code>ItemRenderer</code>. Alex has used <code>List</code> + <code>ItemRenderer</code> to make a <a href="http://blogs.adobe.com/aharui/2009/12/spark_list_spark_list_spark_da.html">DataGrid</a>, <a href="http://blogs.adobe.com/aharui/2010/01/spark_datefield_and_colorpicke.html">DateField</a>, <a href="http://blogs.adobe.com/aharui/2010/01/spark_datefield_and_colorpicke.html">ColorPicker</a>, <a href="http://blogs.adobe.com/aharui/2010/02/spark_menu_and_menubar.html">Menu + MenuBar</a>, and even an <a href="http://blogs.adobe.com/aharui/2009/12/displaying_tree-like_hierarchi.html">XML-based TreeList</a>. Unfortunately, Alex&#8217;s <code>TreeList</code> assumes incoming XML, and I needed a <code>TreeList</code> that could display a simple object hierarchy (root node with children, and those children have children, etc.). Since I couldn&#8217;t find exactly what I wanted, I decided to build it myself.</p>
<h3>Flattener</h3>
<p>The key step to getting a hierarchy of objects to display as a list is: flatten the list, duh!  Or at least flatten the part of the tree you wish to display. So, I built a simple adapter class that turns an object hierarchy into an <code>ArrayList</code> that can be given directly to a <code>List</code>&#8216;s <code>dataProvider</code>.</p>
<p class="bottom">Here&#8217;s the actual flattener, but with just the comments not the code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyObjFlattenedList <span style="color: #0066CC;">extends</span> ArrayList <span style="color: #66cc66;">&#123;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">//the root object</span>
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">_root</span>:MyObj;
&nbsp;
    <span style="color: #808080; font-style: italic;">//list of open nodes</span>
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _openList:<span style="color: #0066CC;">Array</span>;
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyObjFlattenedList<span style="color: #66cc66;">&#40;</span>root:MyObj<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">_root</span> = root;
        _openList = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;
        reset<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        ...
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> reset<span style="color: #66cc66;">&#40;</span>openList:<span style="color: #0066CC;">Array</span> = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #808080; font-style: italic;">//init the flattened list, starting at root</span>
        _openList = <span style="color: #66cc66;">&#40;</span>openList == <span style="color: #000000; font-weight: bold;">null</span> ? <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> : openList<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #000000; font-weight: bold;">var</span> a:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;
        addItemToList<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">_root</span>, a<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0066CC;">this</span>.<span style="color: #006600;">source</span> = a;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> addItemToList<span style="color: #66cc66;">&#40;</span>obj:MyObj, a:<span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #808080; font-style: italic;">//recursively walk obj and all of its &quot;open&quot; children to build</span>
        <span style="color: #808080; font-style: italic;">//a flattened list that is returned in array a</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> isItemOpen<span style="color: #66cc66;">&#40;</span>obj:MyObj<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #808080; font-style: italic;">//true if obj has children and is &quot;open&quot;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> openItem<span style="color: #66cc66;">&#40;</span>obj:MyObj<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #808080; font-style: italic;">//add all of obj's children (if any) to the list</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> closeItem<span style="color: #66cc66;">&#40;</span>obj:MyObj<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #808080; font-style: italic;">//remove all of obj's children (if any) from the list</span>
    <span style="color: #66cc66;">&#125;</span>
    ...
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>There&#8217;s really not much to it.  When instantiated with a root object, the object hierarchy is walked recursively to build a flattened list of all the <i>open</i> nodes.  Once the initial list is built, <code>openItem()</code> can be called to open a node, and add all its children to the list.  Alternately, <code>closeItem()</code> can be called to close a node, and remove all its children from the list.</p>
<h3>Design</h3>
<p class="bottom">I used some basic styling and skinning, but the <code>ItemRenderer</code> does the majority of the work. Here&#8217;s the abbreviated version of <code>MyObjRenderer.mxml</code> with all the boring stuff edited out:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:ItemRenderer</span></span>
<span style="color: #000000;">    xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> </span>
<span style="color: #000000;">    xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span></span>
<span style="color: #000000;">    width=<span style="color: #ff0000;">&quot;100%&quot;</span></span>
<span style="color: #000000;">    autoDrawBackground=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">            <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> private var _obj:MyObj;</span>
<span style="color: #000000;">            <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> private var _hasChildren:Boolean = false;</span>
&nbsp;
<span style="color: #000000;">            private var _list:MyObjFlattenedList;</span>
&nbsp;
<span style="color: #000000;">            override public function set data<span style="color: #66cc66;">&#40;</span>val:Object<span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">                super.data = val;</span>
&nbsp;
<span style="color: #000000;">                if <span style="color: #66cc66;">&#40;</span>val != null<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">                    _obj = val as MyObj;</span>
&nbsp;
<span style="color: #000000;">                    var ownerList:List = owner as List;</span>
<span style="color: #000000;">                    _list = ownerList.dataProvider as MyObjFlattenedList;</span>
&nbsp;
<span style="color: #000000;">                    btn.selected = _list.isItemOpen<span style="color: #66cc66;">&#40;</span>_obj<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">                    _hasChildren = <span style="color: #66cc66;">&#40;</span>_obj.children != null &amp;&amp; _obj.children.length <span style="color: #7400FF;">&gt;</span></span> 0);
                }
            }
&nbsp;
            private function toggleHandler():void {
                if (btn.selected) {
                    _list.openItem(_obj);
                } else {
                    _list.closeItem(_obj);
                }
            }
        ]]&gt;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:states</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;normal&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;hovered&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;selected&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:states</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Rect</span> ...<span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:HGroup</span> ...<span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:ToggleButton</span> id=<span style="color: #ff0000;">&quot;btn&quot;</span> click=<span style="color: #ff0000;">&quot;toggleHandler()&quot;</span> visible=<span style="color: #ff0000;">&quot;{_hasChildren}&quot;</span> ... <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Group</span> id=<span style="color: #ff0000;">&quot;dot&quot;</span> visible=<span style="color: #ff0000;">&quot;{!_hasChildren}&quot;</span> ... <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> ... <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:HGroup</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:ItemRenderer</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>Each rendered item has a background <code>Rect</code> and a <code>Label</code>.  But most importantly, each row has either a ToggleButton (if the object has children) or some non-interactive visuals (if the object doesn&#8217;t have children it just gets a dot).  The toggle button is the key interactive element used to open or close the node, everything else is part of the visual gravy added to make the list look good.</p>
<p>Focusing on the functional stuff, if you look in the script block, you&#8217;ll see two functions: a <code>data()</code> setter and a <code>toggleHandler()</code> to handle toggle button clicks.  As expected, clicking the toggle button calls <code>openItem()</code> or <code>closeItem()</code> on the flattener adapter which adds or removes children from the flattened list, respectively.  The setter mostly sets up the local variables, but it notably computes if the object has children or not, and also sets the initial state of the toggle button.</p>
<h3>Conclusion</h3>
<p>With just a little effort, we can have a nice usable Spark TreeList component that looks decent.  More importantly, we have total control and can make the TreeList look like anything our designer can throw at us.  As is always the case, the combo of <code>List</code> + <code>ItemRenderer</code> proves to be awesome.  I tried to cover all the interesting pieces, but for the details, you&#8217;ll need to check out the source code.</p>
<p class="bottom">Here&#8217;s the finished product (view source enabled):</p>
<div id="flashcontent-objtreelist">
Flash is required.  <a href="http://www.adobe.com/go/getflashplayer">Get it here!</a>
</div>
<p>Use it and enjoy.</p>
<h5>Files</h5>
<ul>
<li><a href="http://saturnboy.com/proj/flex45/obj_treelist/ObjTreeList.html">ObjTreeList</a> (<a href="http://saturnboy.com/proj/flex45/obj_treelist/ObjTreeList.fxp">fxp download</a>)</li>
</ul>
<div>
<script type="text/javascript">
swfobject.embedSWF('http://saturnboy.com/proj/flex45/obj_treelist/ObjTreeList.swf', 'flashcontent-objtreelist', '240', '360', '10.3.0', 'playerProductInstall.swf', false, { bgColor:'#eeeeee', base:'.' });
</script>
</div>
]]></content:encoded>
			<wfw:commentRss>http://saturnboy.com/2011/09/spark-treelist/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Programmatic Skinning in Flex 4 &#8212; an FXG Clock</title>
		<link>http://saturnboy.com/2010/11/programmatic-skinning-in-flex-4-an-fxg-clock/</link>
		<comments>http://saturnboy.com/2010/11/programmatic-skinning-in-flex-4-an-fxg-clock/#comments</comments>
		<pubDate>Thu, 04 Nov 2010 06:22:27 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[custom component]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[flex4]]></category>
		<category><![CDATA[skinning]]></category>

		<guid isPermaLink="false">http://saturnboy.com/?p=1576</guid>
		<description><![CDATA[I tried to push my Flex 4 skinning skills to the limit, and the result is a fancy clock skin. (click to see it in action) The fancy clock skin overlays a very simple clock component. The Clock component is quite underwhelming, but here it is in all of its abbreviated glory: public class Clock [...]]]></description>
			<content:encoded><![CDATA[<p>I tried to push my Flex 4 skinning skills to the limit, and the result is a fancy clock skin.</p>
<div class="span-14 top" style="min-height:510px; text-align:center;">
<a href="http://saturnboy.com/proj/flex4/clock/AnalogClock.html"><img src="http://saturnboy.com/proj/flex4/clock/clock.png" width="500" height="500" alt="clock" title="clock" /></a>
</div>
<div style="text-align:center; padding-bottom:10px;">(click to see it in action)</div>
<p class="bottom">The fancy clock skin overlays a very simple clock component.  The Clock component is quite underwhelming, but here it is in all of its abbreviated glory:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Clock <span style="color: #0066CC;">extends</span> SkinnableComponent <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> secAngle:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0.0</span>;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> minAngle:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0.0</span>;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> hourAngle:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">0.0</span>;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _timer:Timer;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _tween:GTween;
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Clock<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        ...
        _tween = <span style="color: #000000; font-weight: bold;">new</span> GTween<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #cc66cc;">2</span>, ...<span style="color: #66cc66;">&#41;</span>;
        _timer = <span style="color: #000000; font-weight: bold;">new</span> Timer<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2000</span>,<span style="color: #cc66cc;">30</span><span style="color: #66cc66;">&#41;</span>;
        _timer.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER</span>, tickHandler<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> tickHandler<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:TimerEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">var</span> t:<span style="color: #0066CC;">Date</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Date</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
        <span style="color: #000000; font-weight: bold;">var</span> h:<span style="color: #0066CC;">Number</span> = t.<span style="color: #0066CC;">getHours</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #000000; font-weight: bold;">var</span> m:<span style="color: #0066CC;">Number</span> = t.<span style="color: #0066CC;">getMinutes</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> + h <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">60</span>;
        <span style="color: #000000; font-weight: bold;">var</span> s:<span style="color: #0066CC;">Number</span> = t.<span style="color: #0066CC;">getSeconds</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> + m <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">60</span>;
        <span style="color: #000000; font-weight: bold;">var</span> ms:<span style="color: #0066CC;">Number</span> = t.<span style="color: #0066CC;">getMilliseconds</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
        _tween.<span style="color: #006600;">proxy</span>.<span style="color: #006600;">secAngle</span> = -<span style="color: #cc66cc;">90</span> + s <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">6</span> + ms <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">0.006</span>;
        _tween.<span style="color: #006600;">proxy</span>.<span style="color: #006600;">minAngle</span> = -<span style="color: #cc66cc;">90</span> + s <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">0.1</span>;
        _tween.<span style="color: #006600;">proxy</span>.<span style="color: #006600;">hourAngle</span> = -<span style="color: #cc66cc;">90</span> + <span style="color: #66cc66;">&#40;</span>s <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">120</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
    ...
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>At the core of the Clock component is a single timer.  When the timer fires, it uses the current date to compute the angle of the hour hand, minute hand, and second hand.  The actual motion of the hands is managed via the awesome proxy functionality in Grant Skinner&#8217;s <a href="http://www.gskinner.com/libraries/gtween/">GTween</a> library.</p>
<p class="bottom">All the interesting FXG action takes place in the skin, so let&#8217;s check it out:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Skin</span></span>
<span style="color: #000000;">        xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span></span>
<span style="color: #000000;">        xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span></span>
<span style="color: #000000;">        creationComplete=<span style="color: #ff0000;">&quot;complete()&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Metadata</span><span style="color: #7400FF;">&gt;</span></span>
        [HostComponent(&quot;components.Clock&quot;)]
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Metadata</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">            private function complete<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:void <span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">                ...lots of programmatic FXG here...</span>
<span style="color: #000000;">            <span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">        <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    ...lots of vanilla FXG here...
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Path</span> rotation=<span style="color: #ff0000;">&quot;{hostComponent.minAngle}&quot;</span> ...</span>
<span style="color: #000000;">    <span style="color: #7400FF;">&lt;s:Path</span> rotation=<span style="color: #ff0000;">&quot;{hostComponent.hourAngle}&quot;</span> ...</span>
<span style="color: #000000;">    <span style="color: #7400FF;">&lt;s:Path</span> rotation=<span style="color: #ff0000;">&quot;{hostComponent.secAngle}&quot;</span> ...</span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Skin</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>Getting data to the skin is done via the standard binding to <code>hostComponent</code>.  There is no need for the more complicated <code>partAdded()</code> and <code>partRemoved()</code> mechanism, because the Clock component is <i>not</i> intended for general use, unlike my previous components: <a href="http://saturnboy.com/2010/08/terrifictabbar-custom-component/">Terrific TabBar</a>, <a href="http://saturnboy.com/2010/07/supertextinput-building-a-custom-component/">SuperTextInput</a>, and <a href="http://saturnboy.com/2010/06/drawer-component-flex-4/">Drawer</a>.</p>
<p>The skin has a big block of programmatic FXG skinning, done in actionscript code inside the <code>complete()</code> handler which is fired by the <code>creationComplete</code> event.  It also has a big block of vanilla MXML declarative FXG skinning, which, most importantly, includes the clock hands and the previously mentioned binding to <code>hostComponent</code>.</p>
<p class="bottom">By its nature, a clock has a lot of identical elements that are positioned in a circle.  The obvious attack is to put the repeated elements in a loop, or set of loops, and go the programmatic route to construct the skin.  For example, the long thin ticks along the outer ring are constructed with a double loop.  Here&#8217;s the relevant snippet of code from inside the <code>complete()</code> handler:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #b1b100;">for</span> <span style="color: #b1b100;">each</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> <span style="color: #b1b100;">in</span> <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">30</span>,<span style="color: #cc66cc;">60</span>,<span style="color: #cc66cc;">90</span>,<span style="color: #cc66cc;">120</span>,<span style="color: #cc66cc;">150</span>,<span style="color: #cc66cc;">180</span>,<span style="color: #cc66cc;">210</span>,<span style="color: #cc66cc;">240</span>,<span style="color: #cc66cc;">270</span>,<span style="color: #cc66cc;">300</span>,<span style="color: #cc66cc;">330</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #b1b100;">each</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> j:<span style="color: #0066CC;">int</span> <span style="color: #b1b100;">in</span> <span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">6</span>,<span style="color: #cc66cc;">12</span>,<span style="color: #cc66cc;">18</span>,<span style="color: #cc66cc;">24</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">var</span> p:Path = <span style="color: #000000; font-weight: bold;">new</span> Path<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        p.<span style="color: #0066CC;">data</span> = <span style="color: #ff0000;">&quot;M 174,-0.5 L 184,-0.5 184,0.5 174,0.5 Z&quot;</span>;
        p.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">250</span>;
        p.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">250</span>;
        p.<span style="color: #006600;">rotation</span> = i + j;
        p.<span style="color: #006600;">fill</span> = gray;
        <span style="color: #0066CC;">this</span>.<span style="color: #006600;">addElementAt</span><span style="color: #66cc66;">&#40;</span>p, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>A new <code>Path</code> element is created and its <code>data</code> property is set.  Our tick mark is 10px long, but only 1px wide.  With each iteration, a tick mark is created and rotated into place.  There are two important tricks in this code that are worth pointing out.  First, the rotation origin is at (0,0) for each element, so we must construct our path from -0.5 to 0.5 for it to rotate correctly.  Second, we must use <code>addElementAt()</code> to place each element into the proper layer of the drawing because the programmatic FXG code runs after all the vanilla (aka non-programmatic) FXG has been drawn.</p>
<h3>Conclusion</h3>
<p>No one in their right mind would ever build a clock skin like this.  To do this the right way, you&#8217;d definitely want to use an image or two to construct the skin.  The only reason I went the programmatic FXG skinning route was to verify to myself that it could be done.  So, yes it can be done, and I enjoyed the trip.</p>
<h5>Files</h5>
<ul>
<li><a href="http://saturnboy.com/proj/flex4/clock/AnalogClock.html">AnalogClock</a> (<a href="http://saturnboy.com/proj/flex4/clock/srcview/AnalogClock.zip">download</a>)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://saturnboy.com/2010/11/programmatic-skinning-in-flex-4-an-fxg-clock/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Building Flex 4 Containers with Multiple Content Areas</title>
		<link>http://saturnboy.com/2010/07/multiple-content-area-containers/</link>
		<comments>http://saturnboy.com/2010/07/multiple-content-area-containers/#comments</comments>
		<pubDate>Thu, 15 Jul 2010 22:48:18 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[custom component]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[flex4]]></category>
		<category><![CDATA[skinning]]></category>

		<guid isPermaLink="false">http://saturnboy.com/?p=1454</guid>
		<description><![CDATA[Back in the days of Flex 3, if you wanted multiple content areas in your main application, you&#8217;d need to arrange some set of containers (Canvas, HBox, VBox) in the app and fill them with content. It was just your basic Flex 3 development process. The danger, of course, is that you are mixing content [...]]]></description>
			<content:encoded><![CDATA[<p>Back in the days of Flex 3, if you wanted multiple content areas in your main application, you&#8217;d need to arrange some set of containers (<code>Canvas</code>, <code>HBox</code>, <code>VBox</code>) in the app and fill them with content.  It was just your basic Flex 3 development process.  The danger, of course, is that you are mixing content with presentation, aka bad separation of concerns.  Today, with the power of Flex 4 skins, we can avoid this issue by moving the presentation layer into a skin (or set of skins).  And thus, we can do a much better job achieving a happy level of separation of concerns.</p>
<h3>The Flex 3 Way</h3>
<p class="bottom">To give a concrete example, I&#8217;ll build a blog layout (yes, another blog layout) with a header, footer, sidebar, and main content areas.  But before we get started, let&#8217;s review the old Flex 3 way:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:HBox</span> id=<span style="color: #ff0000;">&quot;header&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Image</span> source=<span style="color: #ff0000;">&quot;@Embed('assets/logo.png')&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:HBox</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Canvas</span> id=<span style="color: #ff0000;">&quot;body&quot;</span> width=<span style="color: #ff0000;">&quot;800&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Text</span> text=<span style="color: #ff0000;">&quot;main content&quot;</span> width=<span style="color: #ff0000;">&quot;600&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span> id=<span style="color: #ff0000;">&quot;sidebar&quot;</span> x=<span style="color: #ff0000;">&quot;600&quot;</span> width=<span style="color: #ff0000;">&quot;200&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Text</span> text=<span style="color: #ff0000;">&quot;Sidebar&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Text</span> text=<span style="color: #ff0000;">&quot;sidebar content&quot;</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Canvas</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span> id=<span style="color: #ff0000;">&quot;footer&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Text</span> text=<span style="color: #ff0000;">&quot;2010 saturnboy&quot;</span> styleName=<span style="color: #ff0000;">&quot;footer&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>The above code comes from a previous post, <a href="http://saturnboy.com/2009/02/designing-in-flex/">Designing in Flex 3</a>, but has been modified to make sense here.  You&#8217;ve got you basic blog design: a box for the header, footer, and body, where body is subsequently is divided into a main content area and a sidebar.</p>
<h3>The 3-in-4 Way, aka The Wrong Way</h3>
<p>The unfortunate next step in a Flex developer&#8217;s evolution is what I like to call the Flex 3-in-4 way.  This is a the way of neanderthals,  which is to say, it is an evolutionary dead end.  If you ever have the bad luck to see 3-in-4 code, you can be sure you are dealing with a novice Flex 4 developer.  In general, the 3-in-4 way consists of making the simple transcription: <code>Canvas</code> &rarr; <code>Group</code>, <code>HBox</code> &rarr; <code>HGroup</code>, <code>VBox</code> &rarr; <code>VGroup</code>.  But the most damning tipoff of a 3-in-4 developer is the assertion that one is now a Flex 4 developer and the learning curve wasn&#8217;t all that bad.  While I do think Flex 4 is more of an evolutionary release than a revolutionary release, it&#8217;s different enough.  And it is particularly different on the design side of the framework, how it handles skins, layout, etc.</p>
<p class="bottom">If we just transcribe the above example, we get some classic 3-in-4 code:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:HGroup</span> id=<span style="color: #ff0000;">&quot;header&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;Multi Content Area Example&quot;</span> styleName=<span style="color: #ff0000;">&quot;header&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:HGroup</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Group</span> id=<span style="color: #ff0000;">&quot;body&quot;</span> width=<span style="color: #ff0000;">&quot;800&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;main content&quot;</span> width=<span style="color: #ff0000;">&quot;600&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VGroup</span> x=<span style="color: #ff0000;">&quot;600&quot;</span> width=<span style="color: #ff0000;">&quot;200&quot;</span> styleName=<span style="color: #ff0000;">&quot;sidebarBox&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;Sidebar&quot;</span> styleName=<span style="color: #ff0000;">&quot;title&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;sidebar content&quot;</span> styleName=<span style="color: #ff0000;">&quot;sidebar&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:VGroup</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Group</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VGroup</span> id=<span style="color: #ff0000;">&quot;footer&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;2010 saturnboy&quot;</span> styleName=<span style="color: #ff0000;">&quot;footer&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:VGroup</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>*Barf*, please <b>not</b> do this.  This code has all the same issues as the Flex 3 code in the first example, and moreover it is a slap in the face of <i>The Flex 4 Way</i> and all of its improvements.</p>
<h3>The Flex 4 Way</h3>
<p>Yes, there is a Flex 4 Way and it looks like this.</p>
<p class="bottom">First, we rewrite the main app using a custom container.  Ignoring the specifics of the custom container for a moment, here is the re-written main app (minus some clutter):</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;containers:headerContent</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;Multi Content Area Example&quot;</span> styleName=<span style="color: #ff0000;">&quot;header&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/containers:headerContent</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;containers:sidebarContent</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:RichText</span> left=<span style="color: #ff0000;">&quot;0&quot;</span> right=<span style="color: #ff0000;">&quot;0&quot;</span> styleName=<span style="color: #ff0000;">&quot;sidebar&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:content</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:p</span> fontSize=<span style="color: #ff0000;">&quot;20&quot;</span><span style="color: #7400FF;">&gt;</span></span>Sidebar<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:p</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:p</span><span style="color: #7400FF;">&gt;</span></span>sidebar content<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:p</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:content</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:RichText</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/containers:sidebarContent</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;containers:footerContent</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Label</span> text=<span style="color: #ff0000;">&quot;2010 saturnboy&quot;</span> styleName=<span style="color: #ff0000;">&quot;footer&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/containers:footerContent</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:RichText</span> left=<span style="color: #ff0000;">&quot;0&quot;</span> right=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:content</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:p</span> fontSize=<span style="color: #ff0000;">&quot;30&quot;</span><span style="color: #7400FF;">&gt;</span></span>Content<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:p</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:p</span><span style="color: #7400FF;">&gt;</span></span>main content<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:p</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:content</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:RichText</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>As you can see, the main app is now a nice set of semantic buckets, one for each of the content areas.  Header stuff goes in the <code>headerContent</code> bucket, footer stuff goes in the <code>footerContent</code> bucket, etc.</p>
<h3>Building a Multi Content Area Container</h3>
<p>Second, we need to create a custom container with the nice set of semantic buckets used in the above code.  This is achieved by following a straightforward formula:</p>
<ol>
<li><b>Extend SkinnableContainer</b> &ndash; Extend <code>SkinnableContainer</code> or some child class.  In our sample app, our custom container extends <code>Application</code> (which extends <code>SkinnableContainer</code>).</li>
<li><b>Add Buckets</b> &ndash; add some content buckets (in the form of <i>xxx</i><code>Content</code>) as <code>Array</code>s.  These become the MXML tags used to bucket components together.  Each content bucket has a public getter, but most importantly a public setter that accepts an incoming <code>Array</code> of <code>IVisualElement</code>s and uses the magical <code>mxmlContent</code> property to assign it to the associated <code>SkinPart</code>.</li>
<li><b>Add SkinParts</b> &ndash; add some matching SkinParts (in the form of <i>xxx</i><code>Group</code>) as spark <code>Group</code>s.  There are used in the custom skin to display the content.  Also, I usually set <code>required=&quot;false&quot;</code> to make everything optional.</li>
<li><b>Add partAdded() &amp; partRemoved()</b> &ndash; override the new Flex 4 skinning lifecycle methods to wire the incoming content to the outgoing <code>SkinPart</code>.</li>
</ol>
<p class="bottom">The custom component code is actually easier to follow then the description.  Here is a custom container with only one additional content bucket, <code>sidebarContent</code>, and its matching <code>SkinPart</code>, <code>sidebarGroup</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package containers <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">import</span> spark.<span style="color: #006600;">components</span>.<span style="color: #006600;">Group</span>;
    <span style="color: #0066CC;">import</span> spark.<span style="color: #006600;">components</span>.<span style="color: #006600;">Application</span>;
&nbsp;
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MainApp <span style="color: #0066CC;">extends</span> Application <span style="color: #66cc66;">&#123;</span>
        <span style="color: #66cc66;">&#91;</span>SkinPart<span style="color: #66cc66;">&#40;</span>required=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> sidebarGroup:Group;
&nbsp;
        <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _sidebarContent:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;
&nbsp;
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MainApp<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #66cc66;">&#91;</span>ArrayElementType<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;mx.core.IVisualElement&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> sidebarContent<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Array</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #b1b100;">return</span> _sidebarContent;
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> sidebarContent<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
            _sidebarContent = value;
            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>sidebarGroup<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                sidebarGroup.<span style="color: #006600;">mxmlContent</span> = value;
            <span style="color: #66cc66;">&#125;</span>
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        override protected <span style="color: #000000; font-weight: bold;">function</span> partAdded<span style="color: #66cc66;">&#40;</span>partName:<span style="color: #0066CC;">String</span>, instance:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #0066CC;">super</span>.<span style="color: #006600;">partAdded</span><span style="color: #66cc66;">&#40;</span>partName, instance<span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>instance == sidebarGroup<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                sidebarGroup.<span style="color: #006600;">mxmlContent</span> = _sidebarContent;
            <span style="color: #66cc66;">&#125;</span>
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        override protected <span style="color: #000000; font-weight: bold;">function</span> partRemoved<span style="color: #66cc66;">&#40;</span>partName:<span style="color: #0066CC;">String</span>, instance:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #0066CC;">super</span>.<span style="color: #006600;">partRemoved</span><span style="color: #66cc66;">&#40;</span>partName, instance<span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>instance == sidebarGroup<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                sidebarGroup.<span style="color: #006600;">mxmlContent</span> = <span style="color: #000000; font-weight: bold;">null</span>;
            <span style="color: #66cc66;">&#125;</span>
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Following the four steps: we extend <code>Application</code>, have a <code>sidebarContent</code> bucket and its associated <code>sidebarGroup</code> <code>SkinPart</code>, and override <code>partAdded()</code> and <code>partRemoved()</code> to wire everything together.</p>
<h3>Skinning a Multi Content Area Container</h3>
<p>Skinning in Flex 4 is awesome, and like everyone says, it&#8217;s easily one of the best new features in the framework.  While I find the skinning process fairly straightforward, I would never call it trivial, mostly due to the depth and flexibility of the skinning system.</p>
<p>We need a custom skin for our custom multi content area component.  This is probably the 10% case for skinning, but it&#8217;s also the coolest.  In my experience, an average Flex 4 app has many <code>Button</code> skins (like 10 or even 20), a few default component skins (skins for <code>List</code>, <code>DropDownList</code>, <code>TextInput</code>, etc.), and maybe only two or three skins for custom components.</p>
<p>The skin itself is nothing special.  To display our custom component&#8217;s <code>SkinPart</code>s, we simply include a <code>Group</code> with the matching <code>id</code> attribute.  For example, our skin will include a <code>&lt;s:Group id="sidebarGroup" /&gt;</code> to display the <code>sidebarGroup</code> <code>SkinPart</code>.  Just rinse, wash, repeat, to add all of our custom content areas in the container to the skin.</p>
<p class="bottom">Here is a trivial skin:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Skin</span> ... <span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Metadata</span><span style="color: #7400FF;">&gt;</span></span>
        [HostComponent(&quot;containers.MainApp&quot;)]
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Metadata</span><span style="color: #7400FF;">&gt;</span></span> 
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:states</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;normal&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:State</span> name=<span style="color: #ff0000;">&quot;disabled&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:states</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:VGroup</span> left=<span style="color: #ff0000;">&quot;40&quot;</span> right=<span style="color: #ff0000;">&quot;40&quot;</span> top=<span style="color: #ff0000;">&quot;40&quot;</span> bottom=<span style="color: #ff0000;">&quot;40&quot;</span> gap=<span style="color: #ff0000;">&quot;20&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Group</span> id=<span style="color: #ff0000;">&quot;headerGroup&quot;</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Group</span> id=<span style="color: #ff0000;">&quot;contentGroup&quot;</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Group</span> id=<span style="color: #ff0000;">&quot;sidebarGroup&quot;</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;s:Group</span> id=<span style="color: #ff0000;">&quot;footerGroup&quot;</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:VGroup</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:Skin</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>In this trivial skin, we just shove all the content groups (including <code>SkinnableContainer</code>&#8216;s default <code>Group</code>, <code>contentGroup</code>) into a <code>VGroup</code>.  Also note, we correctly set <code>HostComponent</code> to our custom container.  If you are thinking, &quot;Hey, this skin looks similar to the Flex 3 and 3-in-4 example code, just minus the content&quot; that&#8217;s exactly the point.</p>
<p class="bottom">Lastly, we wire out skin to our custom component via CSS:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">containers|MainApp <span style="color: #00AA00;">&#123;</span>
    skinClass<span style="color: #00AA00;">:</span>ClassReference<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'skins.TrivialAppSkin'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Using <code>skinClass</code> to wire a skin to a component is <b>so</b> 2009.  The sample app has its CSS inline, but in any real app I&#8217;ll always put this in an external file.</p>
<h3>Conclusion</h3>
<p>After this, there&#8217;s really not much more to say.  You can certainly create a more complicated arrangement of the multiple content areas by making a more complicated skin.  I&#8217;ve done exactly this in the final sample, which includes three different skins and a skin switcher (click 1, 2, or 3 to switch skins).</p>
<p>&raquo; <a href="http://saturnboy.com/proj/flex4/multi_content_area/MultiContentArea.html">view MultiConentArea sample</a> (view source enabled)</p>
<h5>Files</h5>
<ul>
<li><a href="http://saturnboy.com/proj/flex4/multi_content_area/MultiContentArea.html">MultiContentArea</a> (<a href="http://saturnboy.com/proj/flex4/multi_content_area/srcview/MultiContentArea.zip">download</a>)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://saturnboy.com/2010/07/multiple-content-area-containers/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Perfect Gradients for Perfect Buttons</title>
		<link>http://saturnboy.com/2010/05/perfect-gradients-perfect-buttons/</link>
		<comments>http://saturnboy.com/2010/05/perfect-gradients-perfect-buttons/#comments</comments>
		<pubDate>Tue, 11 May 2010 03:21:02 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://saturnboy.com/?p=1334</guid>
		<description><![CDATA[Photoshop does this annoying thing where purely vertical gradients have some horizontal variation. Yes, it&#8217;s usually only plus or minus one bit of color, but it offends! I&#8217;ve battled Photoshop for a while on this, but I just can&#8217;t seem to get exactly what I want out of it. So to make a perfect gradient, [...]]]></description>
			<content:encoded><![CDATA[<p>Photoshop does this annoying thing where purely vertical gradients have some horizontal variation.  Yes, it&#8217;s usually only plus or minus one bit of color, but it offends!  I&#8217;ve battled Photoshop for a while on this, but I just can&#8217;t seem to get <b>exactly</b> what I want out of it.  So to make a perfect gradient, I decided to write some code.  The requirements are simple: given a starting color and a set of deltas, output a perfect gradient.</p>
<p class="bottom">Here are some quick examples:</p>
<div class="span-14 last">
<div class="span-1 comm-idx">1</div>
<div class="span-3">
<img src="http://saturnboy.com/proj/php/perfect_gradient/gradient1.png" alt="gradient1" title="gradient1" width="60" height="100" />
</div>
<div class="prepend-1 span-1 comm-idx">2</div>
<div class="span-3">
<img src="http://saturnboy.com/proj/php/perfect_gradient/gradient2.png" alt="gradient2" title="gradient2" width="60" height="100" />
</div>
<div class="prepend-1 span-1 comm-idx">3</div>
<div class="span-3 last">
<img src="http://saturnboy.com/proj/php/perfect_gradient/gradient3.png" alt="gradient3" title="gradient3" width="60" height="100" />
</div>
</div>
<div class="span-14 last">
<div class="prepend-1 span-3"><b>#000000</b><br />4, 1, 0.25</div>
<div class="prepend-2 span-3"><b>#eeeeff</b><br />-2.2, -1, -0.3</div>
<div class="prepend-2 span-3 last"><b>#ff0099</b><br />-1, 0, 1</div>
</div>
<div class="span-14 last">&nbsp;</div>
<p class="bottom">If we zoom in on example #1, which starts with black (#000000) and has deltas of 4, 1, 0.25, we see the following:</p>
<div class="prepend-1 span-13 last">
<img src="http://saturnboy.com/proj/php/perfect_gradient/gradient-diagram.png" alt="zoomed gradient" title="zoomed gradient" width="252" height="200" />
</div>
<div class="span-14 last">&nbsp;</div>
<p>The diagram shows the first ten rows of the gradient.  The delta values are accumulated with each row, and only the whole part of the resulting color value is used (aka I take the <b>floor</b> of each color bit).  So in this example, using the fractional delta of 0.25 results in exactly one additional blue bit every four rows.  Ahhh, perfect!</p>
<h3>The Code</h3>
<p class="bottom">No need to <a href="http://saturnboy.com/2010/04/the-schizophrenic-programmer/">use some fancy new language</a>, I wrote a simple PHP program to handle commandline input and output a perfect PNG gradient.  The interesting part is the function that generates and saves the gradient:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> build_image<span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #000088;">$w</span><span style="color: #339933;">,</span> <span style="color: #000088;">$h</span><span style="color: #339933;">,</span> <span style="color: #000088;">$color</span><span style="color: #339933;">,</span> <span style="color: #000088;">$delta</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$img</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span><span style="color: #339933;">,</span> <span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #000088;">$color</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$color</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$color</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$d</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$delta</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$y</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$y</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$h</span><span style="color: #339933;">;</span> <span style="color: #000088;">$y</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">imagefilledrectangle</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #000088;">$w</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span>
      clamp<span style="color: #009900;">&#40;</span><span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$color</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$d</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      clamp<span style="color: #009900;">&#40;</span><span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$color</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$d</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      clamp<span style="color: #009900;">&#40;</span><span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$color</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$d</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$d</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$d</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$delta</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$d</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$delta</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$d</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$delta</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The code is straight forward.  First, create the image via <code>imagecreatetruecolor()</code>.  Then, starting with the starting color, draw a one pixel tall rectangle for each row of the image.  The next row&#8217;s color is computed in each iteration by adding the accumulated delta to the starting color.  Finally, output the image as a PNG via <code>imagepng()</code> and free the memory.  The complete php source can be downloaded <a href="http://saturnboy.com/proj/php/perfect_gradient/gradient.php.gz">here</a>.</p>
<h3>Button Time </h3>
<p>Once we have our perfect gradient engine in place, it&#8217;s time to make some perfect buttons.  To achieve the standard <i>glass button</i> look-and-feel, I typically fuse two gradients together: light on the top, dark on the bottom.</p>
<p class="bottom">Here are the two halves of a pretty red button, along with their starting color and deltas:</p>
<div class="span-14 last">
<div class="prepend-1 span-3 quiet">TOP</div>
<div class="prepend-2 span-3 last quiet">BOTTOM</div>
</div>
<div class="span-14 last">
<div class="prepend-1 span-3">
<img src="http://saturnboy.com/proj/php/perfect_gradient/red-top.png" alt="top" title="top" width="100" height="16" />
</div>
<div class="prepend-2 span-3 last">
<img src="http://saturnboy.com/proj/php/perfect_gradient/red-bottom.png" alt="bottom" title="bottom" width="100" height="16" />
</div>
</div>
<div class="span-14 last">
<div class="prepend-1 span-3"><b>#ff8080</b><br />-3,-3,-3</div>
<div class="prepend-2 span-3 last"><b>#d23c3c</b><br />-3,-3,-3</div>
</div>
<div class="span-14 last">&nbsp;</div>
<p class="bottom">And the two commandline invocations of <code>gradient.php</code> to create the gradients:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">php gradient.php 100x16 ff8080 -<span style="color: #000000;">3</span>,-<span style="color: #000000;">3</span>,-<span style="color: #000000;">3</span> top.png
php gradient.php 100x16 d23c3c -<span style="color: #000000;">3</span>,-<span style="color: #000000;">3</span>,-<span style="color: #000000;">3</span> bottom.png</pre></div></div>

<p>If I want my buttons to be sexy, rounded corners are a must.  My favorite photoshop trick to create multiple rounded buttons is to use a rounded alpha-transparent button with each gradient as a clipping mask.  Using a clipping mask is a simple way to guarantee button geometry remains fixed while colors are changed.</p>
<p class="bottom">Here is the layers pane showing the two gradients fused together and used as a clipping mask for the rounded alpha-transparent button:</p>
<div class="prepend-1 span-13 last">
<img src="http://saturnboy.com/proj/php/perfect_gradient/layers-dialog.png" alt="clip mask" title="clip mask" width="220" height="177" />
</div>
<div class="span-14 last">&nbsp;</div>
<p class="bottom">The result is a horizontally stretchable gradient button, that doesn&#8217;t look half bad.  See for yourself:</p>
<div class="prepend-1 span-13 last">
<img src="http://saturnboy.com/proj/php/perfect_gradient/btn-red.png" alt="button" title="button" width="26" height="32" />
</div>
<div class="span-14 last">&nbsp;</div>
<h3>Custom UIButton</h3>
<p class="bottom">The final button asset can be used as desired, but here is a simple Objective-C example since I&#8217;ve been in iPhone world lately:</p>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">UIButton <span style="color: #002200;">*</span>btn <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIButton buttonWithType<span style="color: #002200;">:</span>UIButtonTypeCustom<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>btn setFrame<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">&#40;</span><span style="color: #2400d9;">20</span>, <span style="color: #2400d9;">20</span>, <span style="color: #2400d9;">140</span>, <span style="color: #2400d9;">32</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>btn setBackgroundImage<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;btn-red.png&quot;</span><span style="color: #002200;">&#93;</span>
      stretchableImageWithLeftCapWidth<span style="color: #002200;">:</span><span style="color: #2400d9;">10.0</span>
      topCapHeight<span style="color: #002200;">:</span><span style="color: #2400d9;">0.0</span><span style="color: #002200;">&#93;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>btn setTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;BUTTON&quot;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>btn setTitleColor<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIColor whiteColor<span style="color: #002200;">&#93;</span> forState<span style="color: #002200;">:</span>UIControlStateNormal<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>btn.titleLabel setFont<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>UIFont boldSystemFontOfSize<span style="color: #002200;">:</span><span style="color: #2400d9;">14</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</pre></div></div>

<p>Create a new <code>UIButton</code> of type <code>UIButtonTypeCustom</code> and then set the button skin as the <code>backgroundImage</code>.  The horizontal stretchability is due to the <code>stretchableImageWithLeftCapWidth</code> and <code>topCapHeight</code>.</p>
<p class="bottom">Here is a screenshot from the iPhone simulator showing the button in action:</p>
<div class="prepend-1 span-13 last">
<img src="http://saturnboy.com/proj/php/perfect_gradient/screenshot.png" alt="screenshot" title="screenshot" width="326" height="486" />
</div>
<div class="span-14 last">&nbsp;</div>
<h5>Files</h5>
<ul>
<li><a href="http://saturnboy.com/proj/php/perfect_gradient/gradient.php.gz">gradient.php</a> &ndash; the perfect gradient engine</li>
<li><a href="http://saturnboy.com/proj/php/perfect_gradient/gradient-button.psd">gradient-button.psd</a> &ndash; the photoshop source for the red button image, including the rounded alpha-transparent button and fused red gradients</li>
<li><a href="http://saturnboy.com/proj/php/perfect_gradient/btn-red.png">btn-red.png</a> &ndash; the red button image</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://saturnboy.com/2010/05/perfect-gradients-perfect-buttons/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Inkscape SVG to Degrafa Path</title>
		<link>http://saturnboy.com/2009/06/inkscape-svg-degrafa-path/</link>
		<comments>http://saturnboy.com/2009/06/inkscape-svg-degrafa-path/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 03:44:44 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[degrafa]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[inkscape]]></category>
		<category><![CDATA[svg]]></category>

		<guid isPermaLink="false">http://saturnboy.com/?p=528</guid>
		<description><![CDATA[Going from SVG data to a Degrafa Path couldn&#8217;t be easier: just copy &#38; paste. You can watch this video tutorial or you can check out this demo. But there is one trick for Inkscape: even though the coordinate origin on the Inkscape document is the normal cartesian origin in the bottom left and the [...]]]></description>
			<content:encoded><![CDATA[<p>Going from <a href="http://www.w3.org/TR/SVG/">SVG</a> data to a <a href="http://www.degrafa.org/">Degrafa</a> <code>Path</code> couldn&#8217;t be easier: just copy &amp; paste.  You can watch <a href="http://www.vimeo.com/1223682">this video tutorial</a> or you can check out <a href="http://www.degrafa.org/source/Car/Car.html">this demo</a>.</p>
<p><b>But there is one trick for <a href="http://www.inkscape.org/">Inkscape</a></b>: even though the coordinate origin on the Inkscape document is the normal cartesian origin in the bottom left and the y-axis points up, the SVG output always uses the upper left corner of the document as the origin and the y-axis points down (per the <a href="http://www.w3.org/TR/SVG/coords.html#InitialCoordinateSystem">SVG Spec, &sect; 7.3</a>).</p>
<p class="bottom">To demonstrate, I created a new document in Inkscape, set my dimensions to 500 x 500, and placed a simple path (which happens to be a square) in the upper left corner:</p>
<div class="span-14 top bottom last" style="min-height:453px;">
<img src="http://saturnboy.com/wp-content/uploads/2009/06/square.png" alt="square" title="square" width="459" height="443" />
</div>
<p>You can see by the rulers in Inkscape that the square&#8217;s origin is at (0,500).</p>
<p class="bottom">If we save our square and examine the SVG output, we see:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;svg</span> ...<span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;g</span> ...<span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;path</span> <span style="color: #000066;">d</span>=<span style="color: #ff0000;">&quot;M 0,0 L 100,0 L 100,100 L 0,100 L 0,0 z&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/g<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/svg<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>If we ignore everything in the file except the relevant path data, we can see the very first path command is <code>M 0,0</code> which is path-speak for move to (0,0).  This is exactly as expected from the SVG spec: upper left <b>is</b> the coordinate origin.  <b>The cartesian origin in Inkscape is bogus!</b></p>
<p class="bottom">Next, we can just copy the path data from the SVG file and paste it into the <code>data</code> attribute of a Degrafa <code>Path</code> component.</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;Degrafa:Path</span> data=<span style="color: #ff0000;">&quot;M 0,0 L 100,0 L 100,100 L 0,100 L 0,0 z&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;Degrafa:fill</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;Degrafa:SolidFill</span> color=<span style="color: #ff0000;">&quot;#EECCEE&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/Degrafa:fill</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;Degrafa:stroke</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;Degrafa:SolidStroke</span> color=<span style="color: #ff0000;">&quot;#FF00FF&quot;</span> weight=<span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/Degrafa:stroke</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/Degrafa:Path</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>Give it a fill color and a stroke color, and we get a <a href="http://saturnboy.com/proj/degrafa_svg/degrafa_square/degrafa_square.html">pretty purple square</a>.  Now I know my Degrafa <code>Path</code> component will have a square in the upper left, because I know my square was in the upper left in Inkscape.  Nice and easy.</p>
<h5>Files</h5>
<ul>
<li><a href="http://saturnboy.com/wp-content/uploads/2009/06/square.svg">square.svg</a></li>
<li><a href="http://saturnboy.com/proj/degrafa_svg/degrafa_square/degrafa_square.html">Square</a> (<a href="http://saturnboy.com/proj/degrafa_svg/degrafa_square/srcview/degrafa_square.zip">download</a>)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://saturnboy.com/2009/06/inkscape-svg-degrafa-path/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Styling Flexlib&#8217;s WindowShade</title>
		<link>http://saturnboy.com/2009/03/styling-flexlib-windowshade/</link>
		<comments>http://saturnboy.com/2009/03/styling-flexlib-windowshade/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 05:45:03 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[flexlib]]></category>
		<category><![CDATA[skinning]]></category>

		<guid isPermaLink="false">http://saturnboy.com/?p=246</guid>
		<description><![CDATA[A while back I started digging into the WindowShade component in Flexlib. I really needed a set of cool collapsable buckets for a project at work, and WindowShade was perfect for the task. Alas, I couldn&#8217;t find too much info on styling a WindowShade other than Doug McCune&#8217;s awesome example of WindowShade and Degrafa. So, [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I started digging into the <a href="http://flexlib.googlecode.com/svn/trunk/docs/flexlib/containers/WindowShade.html">WindowShade</a> component in <a href="http://code.google.com/p/flexlib/">Flexlib</a>. I really needed a set of cool collapsable buckets for a project at <a href="http://www.gorillalogic.com/">work</a>, and WindowShade was perfect for the task.  Alas, I couldn&#8217;t find too much info on styling a WindowShade other than Doug McCune&#8217;s <a href="http://dougmccune.com/blog/2008/02/26/examples-from-my-360flex-session-using-open-source-community-projects/">awesome example of WindowShade and Degrafa</a>.  So, here is how I went about achieving the look and feel I needed with WindowShade.</p>
<h5>Plain Vanilla</h5>
<p>I started with an unstyled, super vanilla WindowShade wrapping a List.  And of course, I get this super-vanilla output:</p>
<p><a href="http://saturnboy.com/proj/shade/shade1/shade1.html">shade 1</a> (view source enabled)</p>
<p>The only styling magic was to add <code>padding="0"</code> to the WindowShade to get the child List component to suck up to the bottom of the WindowShade button.</p>
<h5>My First Attempt</h5>
<p class="bottom">In the next pass, I ditched the lame WindowShade button, and went with Flexlib&#8217;s <a href="http://flexlib.googlecode.com/svn/trunk/docs/flexlib/controls/CanvasButton.html">CanvasButton</a>, which contains a simple Label plus a CheckBox skinned with a plus or minus graphic. The code:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span></span>
<span style="color: #000000;">        xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #000000;">        xmlns:flexlibContainer=<span style="color: #ff0000;">&quot;flexlib.containers.*&quot;</span></span>
<span style="color: #000000;">        xmlns:flexlibControl=<span style="color: #ff0000;">&quot;flexlib.controls.*&quot;</span></span>
<span style="color: #000000;">        viewSourceURL=<span style="color: #ff0000;">&quot;srcview/index.html&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">    &lt;![CDATA[</span>
<span style="color: #339933;">        [Bindable]</span>
<span style="color: #339933;">        private var goodies:Array = [</span>
<span style="color: #339933;">            { header:'Ice Cream', items:['Vanilla', 'Chocolate', 'Strawberry', 'Cookies &amp; Cream'] },</span>
<span style="color: #339933;">            { header:'Candy', items:['Twix', 'Snickers', 'Fire Balls', 'Hot Tamales', 'Mike &amp; Ikes', 'Pez'] },</span>
<span style="color: #339933;">            { header:'Cookies', items:['Chewy Chips Ahoy', 'Mint Milano', 'Oreo', 'Nutter Butter', 'Fig Newtons'] }];</span>
<span style="color: #339933;">    ]]&gt;</span>
<span style="color: #339933;">    &lt;/mx:Script&gt;</span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Style</span> source=<span style="color: #ff0000;">&quot;style.css&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span> width=<span style="color: #ff0000;">&quot;140&quot;</span> styleName=<span style="color: #ff0000;">&quot;container&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Repeater</span> id=<span style="color: #ff0000;">&quot;r&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{goodies}&quot;</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;flexlibContainer:WindowShade</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> styleName=<span style="color: #ff0000;">&quot;shade&quot;</span></span>
<span style="color: #000000;">                    data=<span style="color: #ff0000;">&quot;{r.currentItem.header}&quot;</span></span>
<span style="color: #000000;">                    opened=<span style="color: #ff0000;">&quot;{r.currentIndex == 0}&quot;</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;flexlibContainer:headerRenderer</span><span style="color: #7400FF;">&gt;</span></span>
                    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Component</span><span style="color: #7400FF;">&gt;</span></span>
                        <span style="color: #000000;"><span style="color: #7400FF;">&lt;flexlibControl:CanvasButton</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;30&quot;</span> styleName=<span style="color: #ff0000;">&quot;shadeBtn&quot;</span><span style="color: #7400FF;">&gt;</span></span>
                            <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">                            &lt;![CDATA[</span>
<span style="color: #339933;">                                import flexlib.containers.WindowShade;</span>
<span style="color: #339933;">                            ]]&gt;</span>
<span style="color: #339933;">                            &lt;/mx:Script&gt;</span>
&nbsp;
                            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> id=<span style="color: #ff0000;">&quot;header&quot;</span> top=<span style="color: #ff0000;">&quot;3&quot;</span> left=<span style="color: #ff0000;">&quot;4&quot;</span> text=<span style="color: #ff0000;">&quot;{WindowShade(parent).data}&quot;</span> styleName=<span style="color: #ff0000;">&quot;shadeHead&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
                            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:CheckBox</span> id=<span style="color: #ff0000;">&quot;chk&quot;</span> top=<span style="color: #ff0000;">&quot;9&quot;</span> right=<span style="color: #ff0000;">&quot;6&quot;</span> selected=<span style="color: #ff0000;">&quot;{WindowShade(parent).opened}&quot;</span> styleName=<span style="color: #ff0000;">&quot;shadeChk&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
                        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/flexlibControl:CanvasButton</span><span style="color: #7400FF;">&gt;</span></span>
                    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Component</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;/flexlibContainer:headerRenderer</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:List</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{r.currentItem.items}&quot;</span> rowCount=<span style="color: #ff0000;">&quot;{r.currentItem.items.length}&quot;</span> styleName=<span style="color: #ff0000;">&quot;shadeList&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/flexlibContainer:WindowShade</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Repeater</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>After throwing in some colors from a sweet <a href="http://kuler.adobe.com/#themeID/356863">Kuler theme</a> and embedding Helvetica, we get this:</p>
<p><a href="http://saturnboy.com/proj/shade/shade2/shade2.html">shade 2</a> (view source enabled)</p>
<p>At this point, I was really happy with look and feel, but there we still a few minor issues with the CanvasButton header that needed to be fixed before declaring victory.</p>
<h5>Fixups</h5>
<p>First, I needed the rollover event to flow down to the checkbox, so it would correctly show the overSkin on mouse over.  Second, I wanted a color change on the Label on rollover to provide better visual feedback to the user.  And lastly, I wanted the entire CanvasButton header to be clickable, not just the label text or the checkbox graphic.</p>
<p class="bottom">Focusing just on the modified CanvasButton code, used in the <code>headerRendered</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;flexlibControl:CanvasButton</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;30&quot;</span> styleName=<span style="color: #ff0000;">&quot;shadeBtn&quot;</span></span>
<span style="color: #000000;">        rollOver=<span style="color: #ff0000;">&quot;header.setStyle('color', 0xffffff); chk.dispatchEvent(event);&quot;</span></span>
<span style="color: #000000;">        rollOut=<span style="color: #ff0000;">&quot;header.setStyle('color', 0xcccccc); chk.dispatchEvent(event);&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">    &lt;![CDATA[</span>
<span style="color: #339933;">        import flexlib.containers.WindowShade;</span>
<span style="color: #339933;">    ]]&gt;</span>
<span style="color: #339933;">    &lt;/mx:Script&gt;</span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Label</span> id=<span style="color: #ff0000;">&quot;header&quot;</span> top=<span style="color: #ff0000;">&quot;3&quot;</span> left=<span style="color: #ff0000;">&quot;4&quot;</span> text=<span style="color: #ff0000;">&quot;{WindowShade(parent).data}&quot;</span> styleName=<span style="color: #ff0000;">&quot;shadeHead&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:CheckBox</span> id=<span style="color: #ff0000;">&quot;chk&quot;</span> top=<span style="color: #ff0000;">&quot;9&quot;</span> right=<span style="color: #ff0000;">&quot;6&quot;</span> selected=<span style="color: #ff0000;">&quot;{WindowShade(parent).opened}&quot;</span> styleName=<span style="color: #ff0000;">&quot;shadeChk&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Canvas</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> height=<span style="color: #ff0000;">&quot;100%&quot;</span> backgroundColor=<span style="color: #ff0000;">&quot;#000000&quot;</span> backgroundAlpha=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/flexlibControl:CanvasButton</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>The final result, a nice styled WindowShade:</p>
<p><a href="http://saturnboy.com/proj/shade/shade3/shade3.html">shade 3</a> (view source enabled)</p>
<p>I used the parent CanvasButton&#8217;s rollover event to set the child Label color and forward the event to the child CheckBox.  To make the entire button clickable, I used one of my favorite Flex UI hacks: I added a space-filling transparent Canvas.</p>
<h5>Comparison Shopping</h5>
<p class="bottom">And finally, a side-by-side comparison of all three WindowShade skins:</p>
<div id="flashcontent-windowshade">
Flash is required.  <a href="http://www.adobe.com/go/getflashplayer">Get it here!</a>
</div>
<p><b>Update:</b> See my <a href="http://saturnboy.com/2010/06/drawer-component-flex-4/">Drawer Component in Flex 4</a> post for a custom collapsible drawer component written from scratch in Flex 4.</p>
<div>
<script type="text/javascript">
swfobject.embedSWF('http://saturnboy.com/proj/shade/shade/shade.swf', 'flashcontent-windowshade', '530', '400', '9.0.28', 'expressInstall.swf', false, { bgColor:'#ffffff', base:'.' });
</script>
</div>
]]></content:encoded>
			<wfw:commentRss>http://saturnboy.com/2009/03/styling-flexlib-windowshade/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Designing in Flex</title>
		<link>http://saturnboy.com/2009/02/designing-in-flex/</link>
		<comments>http://saturnboy.com/2009/02/designing-in-flex/#comments</comments>
		<pubDate>Sun, 08 Feb 2009 06:04:02 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://saturnboy.com/?p=188</guid>
		<description><![CDATA[Flex is awesome. In many ways, it&#8217;s the right tool for the job of bringing beautiful design to the web. I use flex every day at work, and also at home on my own fun projects. Today&#8217;s challenge is to take a very simple blog design and re-implement it in flex. In The Red Corner [...]]]></description>
			<content:encoded><![CDATA[<p>Flex is awesome.  In many ways, it&#8217;s the right tool for the job of bringing beautiful design to the web.  I use flex every day <a href="http://www.gorillalogic.com/">at work</a>, and also at home on my own <a href="http://saturnboy.com/projects/">fun projects</a>.  Today&#8217;s challenge is to take a very simple blog design and re-implement it in flex.</p>
<h5>In The Red Corner</h5>
<p>I&#8217;ll start with my simple two-column blog design that I like to call <b>Circles of Doom</b>.  The original design was done in <a href="http://www.inkscape.org/">Inkscape</a>, and assembled for the web using <a href="http://www.blueprintcss.org/">Blueprint CSS</a>.  You can read all the gory details of the design and assembly in a series of earlier posts: <a href="http://saturnboy.com/2008/11/blueprint-css-magic/">part 1</a>, <a href="http://saturnboy.com/2008/11/designing-with-inkscape-and-blueprint-css/">part 2</a>, <a href="http://saturnboy.com/2008/12/slice-and-dice/">part 3</a>, <a href="http://saturnboy.com/2009/02/optimizing-web-design/">part 4</a>.</p>
<p>Skipping right to the end result, you can view the final results here:</p>
<div class="span-11 prepend-3">
<div class="span-4" style="text-align:center; border: 4px solid #999; background-color: #eef;">
<h3 class="top bottom" style="padding:10px 0;"><a href="http://saturnboy.com/proj/circles_of_doom/v2/" target="_blank">html + css</a></h3>
</div>
<div class="span-4 last" style="text-align:center; border: 4px solid #999; background-color: #fee;">
<h3 class="top bottom" style="padding:10px 0;"><a href="http://saturnboy.com/proj/circles_of_doom/flex/" target="_blank">flex</a></h3>
</div>
</div>
<p class="top bottom">&nbsp;</p>
<h5>In The Blue Corner</h5>
<p>Flex provides a lot of design leverage with its support for fills &#038; strokes, gradients, rounded corners, and filters like drop shadow and glow.  The original html design required the use of images to handle these features, but Flex&#8217;s CSS is powerful enough to handle everything with the exception of the <a href="http://saturnboy.com/proj/circles_of_doom/flex/srcview/source/assets/circ.png">blood red background circles</a>.</p>
<p>The design architecture can be thought of as a simple three layer structure show here:</p>
<div class="span-14 top bottom" style="min-height:254px; text-align:center;">
<img src="http://saturnboy.com/wp-content/uploads/2009/02/flex-layers-diagram.png" alt="flex layers diagram" title="flex layers diagram" width="521" height="244" />
</div>
<p>The bottom layer has the blood red background circle image.  It is absolutely positioned vertically (<code>y="-65"</code>) and horizontally centered (<code>x="{(this.width - 950)/2}"</code>).  Like this:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Image</span> source=<span style="color: #ff0000;">&quot;@Embed(source='assets/circ.png')&quot;</span></span>
<span style="color: #000000;">        x=<span style="color: #ff0000;">&quot;{(this.width - 950)/2}&quot;</span> y=<span style="color: #ff0000;">&quot;-65&quot;</span> <span style="color: #7400FF;">/&gt;</span></span></pre></div></div>

<p>The middle layer has the main box with rounded corners and a black glow.  Like this:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span> width=<span style="color: #ff0000;">&quot;870&quot;</span> x=<span style="color: #ff0000;">&quot;{(this.width - 870)/2}&quot;</span> y=<span style="color: #ff0000;">&quot;130&quot;</span> styleName=<span style="color: #ff0000;">&quot;body&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:filters</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:GlowFilter</span> blurX=<span style="color: #ff0000;">&quot;22&quot;</span> blurY=<span style="color: #ff0000;">&quot;22&quot;</span> color=<span style="color: #ff0000;">&quot;#111111&quot;</span> alpha=<span style="color: #ff0000;">&quot;0.6&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:filters</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>And the Flex CSS:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">VBox<span style="color: #6666ff;">.body</span> <span style="color: #00AA00;">&#123;</span>
	horizontalAlign<span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
	backgroundColor<span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ffffff</span><span style="color: #00AA00;">;</span>
	borderStyle<span style="color: #00AA00;">:</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
	borderThickness<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">10</span><span style="color: #00AA00;">;</span>
	borderColor<span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#886655</span><span style="color: #00AA00;">;</span>
	cornerRadius<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">28</span><span style="color: #00AA00;">;</span>
	verticalGap<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">10</span><span style="color: #00AA00;">;</span>
	paddingTop<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">20</span><span style="color: #00AA00;">;</span> paddingBottom<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">4</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>And the top layer has the main content, sidebar &#038; sidebar content, and footer. Like this:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Canvas</span> width=<span style="color: #ff0000;">&quot;790&quot;</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Text</span> text=<span style="color: #ff0000;">&quot;main&quot;</span> width=<span style="color: #ff0000;">&quot;590&quot;</span> styleName=<span style="color: #ff0000;">&quot;contentTxt&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span> width=<span style="color: #ff0000;">&quot;190&quot;</span> x=<span style="color: #ff0000;">&quot;600&quot;</span> styleName=<span style="color: #ff0000;">&quot;sidebar&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Text</span> text=<span style="color: #ff0000;">&quot;sidebar&quot;</span> width=<span style="color: #ff0000;">&quot;100%&quot;</span> styleName=<span style="color: #ff0000;">&quot;sidebarTxt&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Canvas</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Text</span> textg=<span style="color: #ff0000;">&quot;footer&quot;</span> styleName=<span style="color: #ff0000;">&quot;footerTxt&quot;</span> <span style="color: #7400FF;">/&gt;</span></span></pre></div></div>

<p>And the associated Flex CSS:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">Text<span style="color: #6666ff;">.contentTxt</span> <span style="color: #00AA00;">&#123;</span>
	fontFamily<span style="color: #00AA00;">:</span> Arial<span style="color: #00AA00;">;</span>
	fontSize<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">12</span><span style="color: #00AA00;">;</span>
	fontWeight<span style="color: #00AA00;">:</span> <span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000000</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
VBox<span style="color: #6666ff;">.sidebar</span> <span style="color: #00AA00;">&#123;</span>
	backgroundColor<span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#aa1100</span><span style="color: #00AA00;">;</span>
	borderStyle<span style="color: #00AA00;">:</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
	borderThickness<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">2</span><span style="color: #00AA00;">;</span>
	borderColor<span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ff2200</span><span style="color: #00AA00;">;</span>
	cornerRadius<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">12</span><span style="color: #00AA00;">;</span>
	paddingLeft<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">10</span><span style="color: #00AA00;">;</span> paddingRight<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">10</span><span style="color: #00AA00;">;</span>
	paddingTop<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">10</span><span style="color: #00AA00;">;</span> paddingBottom<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">10</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
Text<span style="color: #6666ff;">.sidebarTxt</span> <span style="color: #00AA00;">&#123;</span>
	fontFamily<span style="color: #00AA00;">:</span> Arial<span style="color: #00AA00;">;</span>
	fontSize<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">12</span><span style="color: #00AA00;">;</span>
	fontWeight<span style="color: #00AA00;">:</span> <span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ffffff</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
Text<span style="color: #6666ff;">.footerTxt</span> <span style="color: #00AA00;">&#123;</span>
	fontFamily<span style="color: #00AA00;">:</span> Arial<span style="color: #00AA00;">;</span>
	fontSize<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">10</span><span style="color: #00AA00;">;</span>
	fontWeight<span style="color: #00AA00;">:</span> <span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#886655</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<h5>The Result</h5>
<p>Put it all together with some dummy <a href="http://en.wikipedia.org/wiki/Lorem_ipsum">Lorem ipsum</a> text and you get a decent looking <a href="http://saturnboy.com/proj/circles_of_doom/flex/" target="_blank">Flex blog design</a> (just right-click, and select &#8220;view source&#8221; to see the code).  It compares favorably to the <a href="http://saturnboy.com/proj/circles_of_doom/v2/" target="_blank">original html design</a>.  The only obvious difference is the browser font rendering versus Flex&#8217;s font rendering.</p>
<h5>The Files</h5>
<ul>
<li><a href="http://saturnboy.com/proj/circles_of_doom/flex/circles_of_doom_flex.tgz">circles_of_doom_flex.tgz</a> (<a href="http://saturnboy.com/proj/circles_of_doom/flex/">view</a>)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://saturnboy.com/2009/02/designing-in-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimizing Web Design</title>
		<link>http://saturnboy.com/2009/02/optimizing-web-design/</link>
		<comments>http://saturnboy.com/2009/02/optimizing-web-design/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 19:49:24 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[blueprint css]]></category>
		<category><![CDATA[design]]></category>

		<guid isPermaLink="false">http://saturnboy.com/?p=132</guid>
		<description><![CDATA[Once everything is done (meaning I have a layout, I have a design, and I have it sliced and assembled), I like to make another pass to optimize both the size of the image files, and the number of files. My two favorite techniques are using Sprites to reduce the total number of images, and [...]]]></description>
			<content:encoded><![CDATA[<p>Once everything is done (meaning I have a <a href="http://saturnboy.com/2008/11/blueprint-css-magic/">layout</a>, I have a <a href="http://saturnboy.com/2008/11/designing-with-inkscape-and-blueprint-css/">design</a>, and I have it <a href="http://saturnboy.com/2008/12/slice-and-dice/">sliced and assembled</a>), I like to make another pass to optimize both the size of the image files, and the number of files.  My two favorite techniques are using <a href="http://www.alistapart.com/articles/sprites/">Sprites</a> to reduce the total number of images, and using <a href="http://optipng.sourceforge.net/">OptiPNG</a> to compress the images.</p>
<h5>Sprites</h5>
<p>It is fairly common to see sprites used in high performance web design.  The Gmail team has a great <a href="http://gmailblog.blogspot.com/2008/05/need-for-speed-path-to-faster-loading.html">blog post</a> discussing various performance enhancements currently in use, including sprites.  But for some reason, almost everyone thinks of sprites for icons and buttons.  In my opinion, any time you can fuse two images into one, you&#8217;re making a &#8220;sprite&#8221; and you&#8217;re improving performance.  Using a grid-based framework like <a href="http://blueprintcss.org/">Blueprint CSS</a> tends create a lot of rectangular layout imagery, which are often ideally suited for fusing into a larger sprite.</p>
<p>The current <a href="http://saturnboy.com/2008/12/slice-and-dice/">web page</a> has two candidates for spriting: the main header image can be fused to the footer, and the sidebar header to the sidebar footer.  Just like this:</p>
<div class="span-14 top bottom" style="min-height:108px; text-align:center;">
<img src="http://saturnboy.com/wp-content/uploads/2009/01/fuse-diagram.png" alt="fuse diagram" title="fuse diagram" width="340" height="98" />
</div>
<p>So the original <a href="http://saturnboy.com/proj/circles_of_doom/v1/img/circ-head.png"><code>circ-head.png</code></a> and <a href="http://saturnboy.com/proj/circles_of_doom/v1/img/circ-foot.png"><code>circ-foot.png</code></a> are fused to create <a href="http://saturnboy.com/proj/circles_of_doom/v2/img/circ.png"><code>circ.png</code></a>.  Similarly, the sidebar header and footer are fused to create <a href="http://saturnboy.com/proj/circles_of_doom/v2/img/sidebar.png"><code>sidebar.png</code></a>.</p>
<p>The original <a href="http://saturnboy.com/proj/circles_of_doom/v1/circ.css"><code>circ.css</code></a> is simply modified with the new image filenames and a negative vertical offsets on the footer backgrounds.  Here are the relevant parts of the new <a href="http://saturnboy.com/proj/circles_of_doom/v2/circ.css"><code>circ.css</code></a>:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#header</span> <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#111</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">img/circ.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">160px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">min-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">160px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#footer</span> <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#111</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">img/circ.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">-160px</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">min-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#sidehead</span> <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">transparent</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">img/sidebar.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">14px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">min-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">14px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#sidefoot</span> <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">transparent</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">img/sidebar.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">-14px</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">14px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">min-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">14px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<h5>Compression</h5>
<p>Using OptiPNG is really easy.  Just run it over a folder of PNGs, and it losslessly compresses what it can, and leaves the rest untouched.  When I&#8217;m not using source control on a design, I&#8217;ll often perform the compression step exclusively on the server to keep things simple.</p>
<p>Here is a simple command to perform maximum compression of all the PNGs in a folder:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">optipng <span style="color: #660033;">-o7</span> <span style="color: #000000; font-weight: bold;">*</span>.png</pre></div></div>

<blockquote class="deeper"><p><b>Digging Deeper:</b> I have noticed that OptiPNG, in it&#8217;s quest for maximum optimization, will sometimes alter the image type (either by reducing the bit depth or switching from full color to indexed color) in such a way as to make Photoshop very unhappy with the resulting image.  In these cases, the <a href="http://gimp.org/">GIMP</a> is your friend.</p></blockquote>
<h5>The Results</h5>
<p>We fused four images totaling 52552 bytes into two images totaling 52356 bytes.  So we saved two whole HTTP requests and a meager 200 bytes.  Not much to write home about (or even blog about), but hopefully it serves as a useful demonstration that design optimization is fairly simple.  Next up, we&#8217;ll take our <a href="http://saturnboy.com/2009/02/designing-in-flex/">design and layout into Flex</a>.  What fun!</p>
<h5>The Files</h5>
<ul>
<li><a href="http://saturnboy.com/proj/circles_of_doom/circles_of_doom_v2.tgz">circles_of_doom_v2.tgz</a> (<a href="http://saturnboy.com/proj/circles_of_doom/v2/">view</a>)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://saturnboy.com/2009/02/optimizing-web-design/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Slice and Dice</title>
		<link>http://saturnboy.com/2008/12/slice-and-dice/</link>
		<comments>http://saturnboy.com/2008/12/slice-and-dice/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 05:19:17 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[blueprint css]]></category>
		<category><![CDATA[design]]></category>

		<guid isPermaLink="false">http://saturnboy.com/?p=101</guid>
		<description><![CDATA[The design from the last post is finished, and it follows a very simple blog layout. In this post, I&#8217;ll slice the design and turn it into a pretty html page with the magic of Blueprint CSS. Slice It Before we get slice happy, we need to think. First, Blueprint is grid-based, so that means [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://saturnboy.com/wp-content/uploads/2008/11/circles-of-doom.png">design</a> from the <a href="http://saturnboy.com/2008/11/designing-with-inkscape-and-blueprint-css/">last post</a> is finished, and it follows a very <a href="http://saturnboy.com/2008/11/blueprint-css-magic/">simple blog layout</a>.  In this post, I&#8217;ll slice the design and turn it into a pretty html page with the magic of <a href="http://www.blueprintcss.org/">Blueprint CSS</a>.</p>
<h5>Slice It</h5>
<p>Before we get slice happy, we need to think.  First, Blueprint is grid-based, so that means rectangles are good.  And second, the default Blueprint container width is 950px.  The defaults are intelligently chosen and have always worked great for me.  By sticking with the defaults, we will get a 950px wide, centered, fixed-width site, which is exactly what we want.</p>
<p class="bottom">We could get all clever and try to slice out just the circles as a background image, but that would force the top border to be a transparent PNG because of the shadow.  Similarly, we could cut out all four rounded corners and all four edges of the sidebar, but that would force us to reassemble humpty dumpty with some fancy css and markup.  In both cases, just say No!  The simplest possible choice is to slice the entire header, the entire footer, and then a thin slice for the body that can be vertically tiled.  Exactly like this:</p>
<div class="span-14 top bottom" style="min-height:310px; text-align:center;">
<img src="http://saturnboy.com/wp-content/uploads/2008/11/slice_diagram.png" alt="slice diagram" title="slice diagram" width="360" height="300" />
</div>
<p>And we get: <a href="http://saturnboy.com/wp-content/uploads/2008/12/circ-head.png">the header</a>, <a href="http://saturnboy.com/wp-content/uploads/2008/12/circ-bg.png">the background tile</a>, and <a href="http://saturnboy.com/wp-content/uploads/2008/12/circ-foot.png">the footer</a>.  Slicing the sidebar in the exact same manner gives: <a href="http://saturnboy.com/wp-content/uploads/2008/12/sidebar-head.png">sidebar header</a>, <a href="http://saturnboy.com/wp-content/uploads/2008/12/sidebar-bg.png">sidebar background tile</a>, and <a href="http://saturnboy.com/wp-content/uploads/2008/12/sidebar-foot.png">sidebar footer</a>.</p>
<h5>Code It</h5>
<p class="bottom">The original <a href="http://saturnboy.com/2008/11/blueprint-css-magic/">simple blog layout</a> had four divs: header, content, sidebar, and footer.  This is exactly want we want, but the original markup won&#8217;t exactly work, because the current design has a vertically-tiled background.  The solution is simple &ndash; just wrap the content and sidebar inside a div with a bit of padding (via a <code>prepend-2</code> and <code>append-2</code>).  If we ignore the sidebar design for a moment, and just insert a placeholder, the markup is:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;container&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;header&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;span-24&quot;</span>&gt;</span>header<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;bg&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;prepend-2 span-20 append-2&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;span-15&quot;</span>&gt;</span>content<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sidebar&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;span-5 last&quot;</span>&gt;</span>sidebar<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;footer&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;span-24&quot;</span>&gt;</span>footer<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p class="bottom">That&#8217;s just beautiful Blueprint markup!  Adding some simple css:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">body <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#111</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#header</span> <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#111</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">img/circ-head.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">160px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">min-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">160px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#footer</span> <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#111</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">img/circ-foot.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">min-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#bg</span> <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">img/circ-bg.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">repeat-y</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>And that gives us Circles of Doom, version 0!  <a href="http://saturnboy.com/proj/circles_of_doom/v0/">View it</a>, or <a href="http://saturnboy.com/proj/circles_of_doom/circles_of_doom_v0.tgz">download it</a>.  I&#8217;ve included the latest-and-greatest <a href="http://www.blueprintcss.org/">Blueprint CSS</a>, which is <a href="http://www.christianmontoya.com/2008/11/11/blueprint-version-08/">v0.8</a> at the time of writing.  I&#8217;ve chosen to enforce the vertical height of the header and footer via <code>height</code> and <code>min-height</code> which seems to work fine in Firefox, Safari, and IE7.</p>
<h5>Sidebar Me</h5>
<p class="bottom">Since the sidebar graphic was sliced in the exact same manner as the body graphic, we just add the exact same markup to the sidebar div &ndash; header, bg, and footer.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sidebar&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;span-5 last&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sidehead&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;span-5&quot;</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!-- sidebar header --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sidebg&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;span-5&quot;</span>&gt;</span>sidebar content<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sidefoot&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;span-5&quot;</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!-- sidebar footer --&gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p class="bottom">Style it like this:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#sidehead</span> <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">transparent</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">img/sidebar-head.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">14px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">min-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">14px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#sidefoot</span> <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">transparent</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">img/sidebar-foot.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">14px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">min-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">14px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#sidebg</span> <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">transparent</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">img/sidebar-bg.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">repeat-y</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Putting everything together with some dummy <a href="http://en.wikipedia.org/wiki/Lorem_ipsum">Lorem Ipsum</a> text gives us Circles of Doom, version 1!  <a href="http://saturnboy.com/proj/circles_of_doom/v1/">View it</a>, or <a href="http://saturnboy.com/proj/circles_of_doom/circles_of_doom_v1.tgz">download it</a>.</p>
<h5>Debug It</h5>
<p class="bottom">Lorem Ipsum text is the basic unit testing for HTML+CSS.  I always fill out every content div with some dummy text, just to see what breaks.  This time around, I noticed the sidebar content was touching the edges.   I decided against adding a <code>prepend-1</code> and <code>append-1</code> because that&#8217;s too much padding.  Instead, I thought I might just add some padding to <code>sidebg</code>, but this is bad, bad, bad!  <strong>You can not add padding or margins to a Blueprint node</strong>, which <code>sidebg</code> clearly is because of the <code>class="span-5"</code>.  I could add another div inside <code>sidebg</code>, but that seemed like too much markup.  So, I took the easy way out and just padded the known sidebar content markup (in this case, just <code>p</code> and <code>h3</code>).</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#sidebar</span> h3<span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#sidebar</span> p <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<blockquote class="deeper"><p><b>Digging Deeper:</b> Blueprint CSS uses <code>margin</code> and <code>padding</code> to create the grid.  Thus it should have been obvious to me that you can NOT add margins or padding to a Blueprint element (any markup element with a Blueprint grid class).  Alas, it was not immediately obvious, but I was able to catch my mistake during debugging.</p></blockquote>
<p>And that&#8217;s it for the visual aspect of Circles of Doom.  Next, I&#8217;ll cover <a href="http://saturnboy.com/2009/02/optimizing-web-design/">web design optimization</a>.</p>
<h5>The Files</h5>
<ul>
<li><a href="http://saturnboy.com/proj/circles_of_doom/circles_of_doom_v0.tgz">circles_of_doom_v0.tgz</a> (<a href="http://saturnboy.com/proj/circles_of_doom/v0/">view</a>)</li>
<li><a href="http://saturnboy.com/proj/circles_of_doom/circles_of_doom_v1.tgz">circles_of_doom_v1.tgz</a> (<a href="http://saturnboy.com/proj/circles_of_doom/v1/">view</a>)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://saturnboy.com/2008/12/slice-and-dice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Designing with Inkscape and Blueprint CSS</title>
		<link>http://saturnboy.com/2008/11/designing-with-inkscape-and-blueprint-css/</link>
		<comments>http://saturnboy.com/2008/11/designing-with-inkscape-and-blueprint-css/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 05:15:42 +0000</pubDate>
		<dc:creator>justin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[blueprint css]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[inkscape]]></category>

		<guid isPermaLink="false">http://saturnboy.com/?p=69</guid>
		<description><![CDATA[I don&#8217;t know how a real designer does it, but when I attempt a design, particularly a blog design, I always start with a simple theme. If the ideas begin to flow, I&#8217;ll know I chose well. If not, and I still think it&#8217;s a good theme, I&#8217;ll visit the usual suspects for some inspiration. [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know how a real designer does it, but when I attempt a design, particularly a blog design, I always start with a simple theme.  If the ideas begin to flow, I&#8217;ll know I chose well.  If not, and I still think it&#8217;s a good theme, I&#8217;ll visit the <a href="http://www.deviantart.com/">usual</a> <a href="http://images.google.com/">suspects</a> for some inspiration.</p>
<p>On this blog, I started with robots, which quickly lead to gears and mechanics.  For this post, I started with circles.  Actually, I started with Ironman&#8217;s HUD.  The whole movie was super cool, but the HUD was the best.  And the HUD had all this motion and targeting, and that&#8217;s what got me to circles.  So that&#8217;s the theme.  I already know I&#8217;m going to apply this theme to a simple grid-based blog layer that I <a href="http://saturnboy.com/2008/11/blueprint-css-magic/">discussed earlier</a>.</p>
<h5>Palette</h5>
<p class="bottom">After the theme, I worked on the color palette.  I&#8217;ve used <a href="http://kuler.adobe.com/">Kuler</a> in the past to build out a couple of palettes, but this time I just jumped into <a href="http://inkscape.org/">Inkscape</a> and started messing around.  I came up with a nice blood red and black palette.</p>
<div class="span-14 top bottom" style="min-height:58px; text-align:center;">
<img src="http://saturnboy.com/wp-content/uploads/2008/11/palette.png" alt="palette" title="palette" width="250" height="48" />
</div>
<h5>Circles</h5>
<p class="bottom">Now that I have a palette, I shift my design focus back to circles.  It&#8217;s not just gonna be &#8220;Dot, dot, dot&#8221; as my daughter likes to say, so it&#8217;s back to Inkscape.  Here&#8217;s the result:</p>
<div class="span-14 top bottom" style="min-height:148px; text-align:center;">
<img src="http://saturnboy.com/wp-content/uploads/2008/11/circles.png" alt="circles" title="circles" width="325" height="138" />
</div>
<h5>Layout</h5>
<p>Not much left but the real work &ndash; make a cool blog design with circles plus some pretty colors.  I know my <a href="http://saturnboy.com/2008/11/blueprint-css-magic/">layout</a>, so once again it&#8217;s back to Inkscape.  There is a nice <a href="http://www.vunzzz.net/blueprint-inkscape/">Inkscape template generator</a> for Blueprint CSS grid layouts.  Choosing which colors go where isn&#8217;t too bad, because I love dark text on white for blogs.  Following that decision, I go with lots of circles in the header in blood red, over a black background.  We know the main content will be white with black text, so I decide to make the sidebar really stand out with a bold blood red.</p>
<p class="bottom">The circles in the header are really easy, I just pick random sizes and put them in random locations.  Darker usually means further away, so I just reduce the opacity to let more black through.  I use a rounded rectangle with a thick stroke for the main content area.  I also add a black shadow around the entire content area to highlight the content.  The finished design is <a href="http://saturnboy.com/wp-content/uploads/2008/11/circles-of-doom.png" target="_blank">here</a>, and I&#8217;m calling it <strong>Circles Of Doom</strong>.  Here is a closeup of the header:</p>
<div class="span-14 top bottom" style="min-height:135px; text-align:center;">
<a href="http://saturnboy.com/wp-content/uploads/2008/11/circles-of-doom.png"><img src="http://saturnboy.com/wp-content/uploads/2008/11/circles-of-doom-closeup.png" alt="" title="circles-of-doom-closeup" width="300" height="125" /></a>
</div>
<p>Next, we <a href="http://saturnboy.com/2008/12/slice-and-dice/">slice and dice</a>&#8230;</p>
<h5>Files</h5>
<ul>
<li><a href="http://saturnboy.com/proj/circles_of_doom/palette.svg">palette.svg</a></li>
<li><a href="http://saturnboy.com/proj/circles_of_doom/circles.svg">circles.svg</a></li>
<li><a href="http://saturnboy.com/proj/circles_of_doom/circles-of-doom.svg">circles-of-doom.svg</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://saturnboy.com/2008/11/designing-with-inkscape-and-blueprint-css/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

