简体   繁体   English

火花皮肤按钮大小设置在哪里?

[英]Where is Spark Skin Button Size Set?

I've skinned an hSlider's thumb with an image. 我给hSlider的拇指贴上了图像。 But the image is pixelated, as though it's been forced to resize. 但是图像被像素化,就好像它被迫调整大小一样。 It's just a pretty circle with a radius of 30 px. 这只是一个半径为30像素的漂亮圆圈。

The other thing that happens is that instead of the new button being cleanly bisected by the track, it is just below the track, tangential to it. 发生的另一件事是,新的按钮不会正好被轨道一分为二,而是位于轨道的正下方,与之相切。 So now I have to reposition it by modifying its y value in SliderThumbSkin.mxml? 所以现在我必须通过修改SliderThumbSkin.mxml中的y值来重新定位它? And (presumably because its registration point is at upper left) when I slide it all the way to the right, it goes right off the end of the track until its left edge is at the track's right edge. 并且(大概是因为它的注册点在左上角)当我将它一直滑到最右边时,它从轨道的尽头一直走到它的左边缘在轨道的右边缘为止。 This might also mess up calculations for the hSlider.value property. 这也可能使hSlider.value属性的计算混乱。

You'd think you could just apply the skin and it would replace the button, but seems that both its position and size are being wrongly manipulated.Is the thumb's size automatically reset or resized somewhere? 您可能会认为只需涂一下皮肤就可以代替按钮,但似乎位置和大小都被错误地操纵了,拇指的大小会自动重置还是在某个地方调整大小? Is there a way to do this correctly and cleanly? 有没有办法正确,干净地做到这一点?

EDIT: Here's code for the entire test project: 编辑:这是整个测试项目的代码:

//HSliderTest.mxml:
<?xml version="1.0" encoding="utf-8"?>
<s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
firstView="views.HSliderTestHomeView" applicationDPI="160">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</s:ViewNavigatorApplication>

//SliderSkin.mxml. Only modified the <s:Button tag at the end:
<?xml version="1.0" encoding="utf-8"?>
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fb="http://ns.adobe.com/flashbuilder/2009" minHeight="11"
alpha.disabled="0.5">

<fx:Metadata>
<![CDATA[
/**
* @copy spark.skins.spark.ApplicationSkin#hostComponent
*/
[HostComponent("spark.components.HSlider")]

]]>
</fx:Metadata>

<fx:Script fb:purpose="styling">
/* Define the skin elements that should not be colorized.
For slider, the skin itself is colorized but the individual parts are
not. */

static private const exclusions:Array = ["track", "thumb"];

/**
* @private
*/
override public function get colorizeExclusions():Array {return
exclusions;}

/**
* @private
*/
override protected function initializationComplete():void
{
useChromeColor = true;
super.initializationComplete();
}
</fx:Script>

<fx:Script>
/**
* @private
*/
override protected function measure() : void
{
// Temporarily move the thumb to the left of the Slider so
measurement
// doesn't factor in its x position. This allows resizing the
// HSlider to less than 100px in width.
var thumbPos:Number = thumb.getLayoutBoundsX();
thumb.setLayoutBoundsPosition(0, thumb.getLayoutBoundsY());
super.measure();
thumb.setLayoutBoundsPosition(thumbPos, thumb.getLayoutBoundsY());
}
</fx:Script>

<s:states>
<s:State name="normal" />
<s:State name="disabled" />
</s:states>

<fx:Declarations>
<!--- The tooltip used in the mx.controls.Slider control.
To customize the DataTip's appearance, create a custom
HSliderSkin class.-->
<fx:Component id="dataTip">
<s:DataRenderer minHeight="24" minWidth="40" y="-34">
<s:Rect top="0" left="0" right="0" bottom="0">
<s:fill>
<s:SolidColor color="0x000000" alpha=".9"/>
</s:fill>
<s:filters>
<s:DropShadowFilter angle="90" color="0x999999"
distance="3"/>
</s:filters>
</s:Rect>
<s:Label id="labelDisplay" text="{data}"
horizontalCenter="0" verticalCenter="1"
left="5" right="5" top="5" bottom="5"
textAlign="center" verticalAlign="middle"
fontWeight="normal" color="white" fontSize="11">
</s:Label>
</s:DataRenderer>
</fx:Component>
</fx:Declarations>

<!--- The default skin class is HSliderTrackSkin.
@copy spark.components.supportClasses.TrackBase#track
@see spark.skins.spark.HSliderTrackSkin -->
<s:Button id="track" left="0" right="0" width="11" height="11"
tabEnabled="false"
skinClass="spark.skins.spark.HSliderTrackSkin" />

<!--- The default skin class is HSliderThumbSkin.
@copy spark.components.supportClasses.TrackBase#thumb
@see spark.skins.spark.HSliderThumbSkin -->
<s:Button id="thumb" top="0" bottom="0" height="11" width="11"
tabEnabled="false" skinClass="skins.SliderThumbSkin" />
</s:SparkSkin>

//SliderThumbSkin.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:SparkButtonSkin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
minWidth="21"
minHeight="21"
alpha.disabled="0.5">

<fx:Metadata>
<![CDATA[
/**
* @copy spark.skins.spark.ApplicationSkin#hostComponent
*/
[HostComponent("spark.components.Button")]
]]>
</fx:Metadata>

<!-- states -->
<s:states>
<s:State name="up" />
<s:State name="over" />
<s:State name="down" />
<s:State name="disabled" />
</s:states>
<s:Image source.up="assets/PurpleOnlyCircle60x60.png"
source.over="assets/PurpleOnlyCircle60x60.png"
source.down="assets/PurpleOnlyCircle60x60.png"
source.disabled="assets/PurpleOnlyCircle60x60.png"
width="60"
height="60"/>
</s:SparkButtonSkin>

Can anyone see why this doesn't display correctly? 谁能看到为什么无法正确显示? Thanks! 谢谢!

Here's the answer. 这就是答案。

SliderSkin.mxml -- SliderSkin.mxml-

 //change this line
 thumb.setLayoutBoundsPosition(thumbPos, (thumb.getLayoutBoundsY() **- 25**));
 //and change this line too
 <s:Button id="thumb" **top="-25"** bottom="0" height="11" width="11"

So the whole class looks like this: 所以整个类看起来像这样:

   @see spark.components.HSlider
   @see spark.skins.spark.HSliderThumbSkin
   @see spark.skins.spark.HSliderTrackSkin

  @langversion 3.0
  @playerversion Flash 10
  @playerversion AIR 1.5
  @productversion Flex 4
 -->
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fb="http://ns.adobe.com/flashbuilder/2009" minHeight="11" alpha.disabled="0.5">

<fx:Metadata>
<![CDATA[ 
    /** 
     * @copy spark.skins.spark.ApplicationSkin#hostComponent
     */
    [HostComponent("spark.components.HSlider")]

]]>
</fx:Metadata> 

<fx:Script fb:purpose="styling">
    /* Define the skin elements that should not be colorized. 
       For slider, the skin itself is colorized but the individual parts are not. */

    static private const exclusions:Array = ["track", "thumb"];

    /**
     * @private
     */  
    override public function get colorizeExclusions():Array {return exclusions;}

    /**
     * @private
     */
    override protected function initializationComplete():void
    {
        useChromeColor = true;
        super.initializationComplete();
    }
</fx:Script>

<fx:Script>
    /**
     *  @private
     */  
    override protected function measure() : void
    {
        // Temporarily move the thumb to the left of the Slider so measurement
        // doesn't factor in its x position. This allows resizing the
        // HSlider to less than 100px in width. 
        var thumbPos:Number = thumb.getLayoutBoundsX();
        thumb.setLayoutBoundsPosition(0, thumb.getLayoutBoundsY());
        super.measure();
        thumb.setLayoutBoundsPosition(thumbPos, (thumb.getLayoutBoundsY() - 25));
    }
</fx:Script>

<s:states>
    <s:State name="normal" />
    <s:State name="disabled" />
</s:states>

<fx:Declarations>
    <!--- The tooltip used in the mx.controls.Slider control. 
           To customize the DataTip's appearance, create a custom HSliderSkin class.-->
    <fx:Component id="dataTip">     
       <s:DataRenderer minHeight="24" minWidth="40" y="-34">  
          <s:Rect top="0" left="0" right="0" bottom="0">
                <s:fill>
                    <s:SolidColor color="0x000000" alpha=".9"/>
                </s:fill>
                <s:filters>
                    <s:DropShadowFilter angle="90" color="0x999999" distance="3"/>
                </s:filters>
            </s:Rect>
            <s:Label id="labelDisplay" text="{data}"
                     horizontalCenter="0" verticalCenter="1"
                     left="5" right="5" top="5" bottom="5"
                     textAlign="center" verticalAlign="middle"
                     fontWeight="normal" color="white" fontSize="11">
            </s:Label>
        </s:DataRenderer>
   </fx:Component>
</fx:Declarations>

<!--- The default skin class is HSliderTrackSkin. 
        @copy spark.components.supportClasses.TrackBase#track
        @see spark.skins.spark.HSliderTrackSkin -->
<s:Button id="track" left="0" right="0" width="11" height="11"
          tabEnabled="false"
          skinClass="spark.skins.spark.HSliderTrackSkin" />

<!--- The default skin class is HSliderThumbSkin.
        @copy spark.components.supportClasses.TrackBase#thumb 
        @see spark.skins.spark.HSliderThumbSkin -->
<s:Button id="thumb" top="-25" bottom="0" height="11" width="11"
          tabEnabled="false"                                                                                                                                                                                                                                                                                                                                                                                                                    
          skinClass="skins.SliderThumbSkin" />

SliderThumbSkin -- change s:Image x="-25": SliderThumbSkin-更改s:Image x =“-25”:

<fx:Metadata>
    <![CDATA[ 
    /** 
    * @copy spark.skins.spark.ApplicationSkin#hostComponent
    */
    [HostComponent("spark.components.Button")]
    ]]>
</fx:Metadata>

<!-- states -->
<s:states>
    <s:State name="up" />
    <s:State name="over" />
    <s:State name="down" />
    <s:State name="disabled" />
</s:states>

<s:Image  x="-25" source.up="@Embed('assets/buttons/PurpleOnlyCircle60x60.png')"
                         source.over="@Embed('assets/buttons/PurpleOnlyCircle60x60.png')"
                         source.down="@Embed('assets/buttons/PurpleOnlyCircle60x60.png')"
                         source.disabled="@Embed('assets/buttons/PurpleOnlyCircle60x60.png')"
         />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM