Traduction de l'article de Peter DeHaan:
Setting the header height on a Spark Panel container in Flex 4
L'exemple suivant montre comment vous pouvez régler la hauteur de l'en-tête d'un conteneur Spark Panel dans Flex 4 en définissant la propriété height de la skin part titleDisplay de la skin du conteneur Panel.
L'exemple suivant requiert Flash Player 10 et le SDK Adobe Flex 4. Vous pouvez télécharger la version d'évaluation d'Adobe Flash Builder 4 à l'adresse http://www.adobe.com/products/flex/. Pour télécharger la dernière version du SDK Flex 4, regardez http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.
Pour plus d'informations sur le démarrage avec Flex 4 et Flash Builder 4, regardez le blog officiel de l'équipe Flex Adobe Flex Team blog.
-
</p>
-
<?xml version="1.0" encoding="utf-8"?>
-
<!-- http://blog.flexexamples.com/2010/07/25/setting-the-header-height-on-a-spark-panel-container-in-flex-4/ -->
-
<s:application name="Spark_Panel_titleDisplay_height_test"
-
xmlns:fx="http://ns.adobe.com/mxml/2009"
-
xmlns:s="library://ns.adobe.com/flex/spark"
-
xmlns:mx="library://ns.adobe.com/flex/mx">
-
<s:controlbarcontent>
-
<mx:form styleName="plain">
-
<mx:formitem label="titleDisplay height:">
-
<s:hslider id="sl"
-
minimum="20" maximum="100"
-
change="pnl.titleDisplay.height = sl.value;" />
-
</mx:formitem>
-
</mx:form>
-
</s:controlbarcontent>
-
-
<s:panel id="pnl"
-
title="Spark Panel title"
-
width="300" height="200"
-
horizontalCenter="0" verticalCenter="0">
-
<s:label text="Spark Label text"
-
x="20" y="20" />
-
</s:panel>
-
-
</s:application>
-
<p>
La vue du code source est activée dans l'exemple suivant.
Si vous voulez définir une hauteur de moins de 30 pixels pour la skin part titleDisplay, vous devez créer une skin personnalisée et supprimer la propriété minHeight de la skin part titleDisplay:
-
</p>
-
<?xml version="1.0" encoding="utf-8"?>
-
<!-- http://blog.flexexamples.com/2010/07/25/setting-the-header-height-on-a-spark-panel-container-in-flex-4/ -->
-
<s:sparkskin name="CustomSparkPanelSkin"
-
xmlns:fx="http://ns.adobe.com/mxml/2009"
-
xmlns:s="library://ns.adobe.com/flex/spark"
-
xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
-
blendMode="normal"
-
mouseEnabled="false"
-
minWidth="131" minHeight="127"
-
alpha.disabled="0.5" alpha.disabledWithControlBar="0.5">
-
<s:states>
-
<s:state name="normal" />
-
<s:state name="disabled" />
-
<s:state name="normalWithControlBar" stateGroups="withControls" />
-
<s:state name="disabledWithControlBar" stateGroups="withControls" />
-
</s:states>
-
-
<fx:metadata>
-
[HostComponent("spark.components.Panel")]
-
</fx:metadata>
-
-
<fx:script fb:purpose="styling">
-
<![CDATA[
-
/* Define the skin elements that should not be colorized.
-
For panel, border and title background are skinned, but the content area and title text are not. */
-
static private const exclusions:Array = ["background", "titleDisplay", "contentGroup", "controlBarGroup"];
-
-
override public function get colorizeExclusions():Array {
-
return exclusions;
-
}
-
-
override protected function initializationComplete():void {
-
useChromeColor = true;
-
super.initializationComplete();
-
}
-
-
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
-
if (getStyle("borderVisible") == true) {
-
border.visible = true;
-
background.left = background.top = background.right = background.bottom = 1;
-
contents.left = contents.top = contents.right = contents.bottom = 1;
-
} else {
-
border.visible = false;
-
background.left = background.top = background.right = background.bottom = 0;
-
contents.left = contents.top = contents.right = contents.bottom = 0;
-
}
-
-
dropShadow.visible = getStyle("dropShadowVisible");
-
-
var cr:Number = getStyle("cornerRadius");
-
var withControls:Boolean = (currentState == "disabledWithControlBar" || currentState == "normalWithControlBar");
-
-
if (cornerRadius != cr) {
-
cornerRadius = cr;
-
-
dropShadow.tlRadius = cornerRadius;
-
dropShadow.trRadius = cornerRadius;
-
dropShadow.blRadius = withControls ? cornerRadius : 0;
-
dropShadow.brRadius = withControls ? cornerRadius : 0;
-
-
setPartCornerRadii(topMaskRect, withControls);
-
setPartCornerRadii(border, withControls);
-
setPartCornerRadii(background, withControls);
-
}
-
-
if (bottomMaskRect) {
-
setPartCornerRadii(bottomMaskRect, withControls);
-
}
-
-
borderStroke.color = getStyle("borderColor");
-
borderStroke.alpha = getStyle("borderAlpha");
-
backgroundFill.color = getStyle("backgroundColor");
-
backgroundFill.alpha = getStyle("backgroundAlpha");
-
-
super.updateDisplayList(unscaledWidth, unscaledHeight);
-
}
-
-
private function setPartCornerRadii(target:Rect, includeBottom:Boolean):void {
-
target.topLeftRadiusX = cornerRadius;
-
target.topRightRadiusX = cornerRadius;
-
target.bottomLeftRadiusX = includeBottom ? cornerRadius : 0;
-
target.bottomRightRadiusX = includeBottom ? cornerRadius : 0;
-
}
-
-
private var cornerRadius:Number;
-
]]>
-
</fx:script>
-
-
<!-- drop shadow can't be hittable so it stays sibling of other graphics -->
-
<s:rectangulardropshadow id="dropShadow"
-
blurX="20" blurY="20"
-
alpha="0.32" distance="11"
-
angle="90" color="#000000"
-
left="0" top="0" right="0" bottom="0"/>
-
-
<!-- drop shadow can't be hittable so all other graphics go in this group -->
-
<s:group left="0" right="0" top="0" bottom="0">
-
-
<!-- top group mask -->
-
</s:group><s:group id="topGroupMask" left="1" top="1" right="1" bottom="1">
-
<s:rect id="topMaskRect" left="0" top="0" right="0" bottom="0">
-
<s:fill>
-
<s:solidcolor alpha="0"/>
-
</s:fill>
-
</s:rect>
-
</s:group>
-
-
<!-- bottom group mask -->
-
<s:group id="bottomGroupMask"
-
left="1" top="1" right="1" bottom="1"
-
includeIn="normalWithControlBar, disabledWithControlBar">
-
<s:rect id="bottomMaskRect" left="0" top="0" right="0" bottom="0">
-
<s:fill>
-
<s:solidcolor alpha="0"/>
-
</s:fill>
-
</s:rect>
-
</s:group>
-
-
<!-- layer 1: border -->
-
<s:rect id="border" left="0" right="0" top="0" bottom="0">
-
<s:stroke>
-
<s:solidcolorstroke id="borderStroke" weight="1" />
-
</s:stroke>
-
</s:rect>
-
-
<!-- layer 2: background fill -->
-
<!--- Defines the appearance of the PanelSkin class's background. -->
-
<s:rect id="background" left="1" top="1" right="1" bottom="1">
-
<s:fill>
-
<!--- Defines the PanelSkin class's background fill. The default color is 0xFFFFFF. -->
-
<s:solidcolor id="backgroundFill" color="#FFFFFF"/>
-
</s:fill>
-
</s:rect>
-
-
<!-- layer 3: contents -->
-
<!--- Contains the vertical stack of titlebar content and controlbar. -->
-
<s:group left="1" right="1" top="1" bottom="1" id="contents">
-
<s:layout>
-
<s:verticallayout gap="0" horizontalAlign="justify" />
-
</s:layout>
-
-
</s:group><s:group id="topGroup" mask="{topGroupMask}">
-
<!-- layer 0: title bar fill -->
-
<s:rect id="tbFill" left="0" right="0" top="0" bottom="1">
-
<s:fill>
-
<s:lineargradient rotation="90">
-
<s:gradiententry color="0xE2E2E2" />
-
<s:gradiententry color="0xD9D9D9" />
-
</s:lineargradient>
-
</s:fill>
-
</s:rect>
-
-
<!-- layer 1: title bar highlight -->
-
<s:rect id="tbHilite" left="0" right="0" top="0" bottom="0">
-
<s:stroke>
-
<s:lineargradientstroke rotation="90" weight="1">
-
<s:gradiententry color="0xEAEAEA" />
-
<s:gradiententry color="0xD9D9D9" />
-
</s:lineargradientstroke>
-
</s:stroke>
-
</s:rect>
-
-
<!-- layer 2: title bar divider -->
-
<s:rect id="tbDiv" left="0" right="0" height="1" bottom="0">
-
<s:fill>
-
<s:solidcolor color="0xC0C0C0" />
-
</s:fill>
-
</s:rect>
-
-
<!-- layer 3: text -->
-
<s:label id="titleDisplay" maxDisplayedLines="1"
-
left="9" right="3" top="1" bottom="0"
-
verticalAlign="middle" textAlign="start" fontWeight="bold" />
-
</s:group>
-
-
<!--
-
Note: setting the minimum size to 0 here so that changes to the host component's
-
size will not be thwarted by this skin part's minimum size. This is a compromise,
-
more about it here: http://bugs.adobe.com/jira/browse/SDK-21143
-
-->
-
<s:group id="contentGroup" width="100%" height="100%" minWidth="0" minHeight="0" />
-
-
<s:group id="bottomGroup" minWidth="0" minHeight="0"
-
includeIn="normalWithControlBar, disabledWithControlBar">
-
-
</s:group><s:group left="0" right="0" top="0" bottom="0" mask="{bottomGroupMask}">
-
-
<!-- layer 0: control bar divider line -->
-
<s:rect left="0" right="0" top="0" height="1" alpha="0.22">
-
<s:fill>
-
<s:solidcolor color="0x000000" />
-
</s:fill>
-
</s:rect>
-
-
<!-- layer 1: control bar highlight -->
-
<s:rect left="0" right="0" top="1" bottom="0">
-
<s:stroke>
-
<s:lineargradientstroke rotation="90" weight="1">
-
<s:gradiententry color="0xE5E5E5" />
-
<s:gradiententry color="0xD8D8D8" />
-
</s:lineargradientstroke>
-
</s:stroke>
-
</s:rect>
-
-
<!-- layer 2: control bar fill -->
-
<s:rect left="1" right="1" top="2" bottom="1">
-
<s:fill>
-
<s:lineargradient rotation="90">
-
<s:gradiententry color="0xDADADA" />
-
<s:gradiententry color="0xC5C5C5" />
-
</s:lineargradient>
-
</s:fill>
-
</s:rect>
-
</s:group>
-
<!-- layer 3: control bar -->
-
<s:group id="controlBarGroup" left="0" right="0" top="1" bottom="1" minWidth="0" minHeight="0">
-
<s:layout>
-
<s:horizontallayout paddingLeft="10" paddingRight="10" paddingTop="7" paddingBottom="7" gap="10" />
-
</s:layout>
-
</s:group>
-
-
-
-
</s:sparkskin>
-
<p>
Ou alors, vous pouvez étendre la skin du conteneur Spark Panel et définir la propriété height de la skin part titleDisplay sur NaN (not a number), en utilisant ActionScript, comme le montre l'exemple suivant:
-
</p>
-
/** http://blog.flexexamples.com/2010/07/25/setting-the-header-height-on-a-spark-panel-container-in-flex-4/ */
-
package skins {
-
import spark.skins.spark.PanelSkin;
-
-
public class CustomSparkPanelSkinAS extends PanelSkin {
-
override public function CustomSparkPanelSkinAS() {
-
super();
-
titleDisplay.minHeight = NaN;
-
}
-
}
-
}
-
<p>
Je suis Antony Chauviré, développeur sur la Flash Platform.