Migration: Layouting issues with TitleWindow in Flex 3
I have been working on a migration project offlate and I encountered this very pressing issue. Any component that extended from TitleWindow had its layout screwed up. If you add any components to the content area of the extended TitleWindow, it would the child would find its place underneath the header of the TitleWindow !!! That was a very awkward behaviour and here’s a rather simple solution. Just add the following function to your component..and Swosh!! the layouting behaves just the way you want.
private var panelViewMetrics:EdgeMetrics;
override public function get viewMetrics():EdgeMetrics
{
var vm:EdgeMetrics = super.viewMetrics;
// The getViewMetrics function needs to return its own object.
// Rather than allocating a new one each time, we’ll allocate
// one once and then hold a pointer to it.
if ((FlexVersion.compatibilityVersion < FlexVersion.VERSION_3_0) ||
(getQualifiedClassName(border) != “mx.skins.halo::PanelSkin”) ||
(getStyle(”borderStyle”) != “default”) )
{
if (!panelViewMetrics)
panelViewMetrics = new EdgeMetrics(0, 0, 0, 0);
vm = panelViewMetrics;
var o:EdgeMetrics = super.viewMetrics;
var bt:Number = getStyle(”borderThickness”);
var btl:Number = getStyle(”borderThicknessLeft”);
var btt:Number = getStyle(”borderThicknessTop”);
var btr:Number = getStyle(”borderThicknessRight”);
var btb:Number = getStyle(”borderThicknessBottom”);
// Add extra space to edges (was margins).
vm.left = o.left + (isNaN(btl) ? bt : btl);
vm.top = o.top + (isNaN(btt) ? bt : btt);
vm.right = o.right + (isNaN(btr) ? bt : btr);
// Bottom is a special case. If borderThicknessBottom is NaN,
// use btl if we don’t have a control bar or btt if we do.
vm.bottom = o.bottom + (isNaN(btb) ?
(controlBar && !isNaN(btt) ? btt : isNaN(btl) ? bt : btl) :
btb);
// Since the header covers the solid portion of the border,
// we need to use the larger of borderThickness or headerHeight
var hHeight:Number = getHeaderHeight();
if (!isNaN(hHeight))
vm.top += hHeight;
if (controlBar && controlBar.includeInLayout)
vm.bottom += controlBar.getExplicitOrMeasuredHeight();
}
return vm;
}
So why does it work now and not earlier…the reason is that in Flex 3, Panel now uses the PanelSkin unlike earlier wherein it used HaloBorder or Border. Also, it doesn’t support any borderStyle but default. So the change here is an additional condition in the if loop
if ((FlexVersion.compatibilityVersion < FlexVersion.VERSION_3_0) ||
(getQualifiedClassName(border) != “mx.skins.halo::PanelSkin”) ||
(getStyle(”borderStyle”) != “default”) )
So now you have the perfect layouting in flex 3 as well when using older classes ![]()
Comments(0)