Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   Flex (http://www.flasher.ru/forum/forumdisplay.php?f=84)
-   -   Неверно высчитывается measuredWidth (http://www.flasher.ru/forum/showthread.php?t=208006)

djyamato 27.05.2014 12:50

Неверно высчитывается measuredWidth
 
Здравствуйте
Я написал скин для поля ввода (для мобильников)
Но когда я TextInput со своим скином пытаюсь позиционировать в скине родительского компонента, свойство measuredWidth у скина textInput-а высчитывается неверно
Где я ошибся ?
Вот скин
Код AS3:

package swiz.views.components.skins
{
        import flash.events.Event;
        import flash.geom.Rectangle;
 
        import mx.core.DPIClassification;
 
        import spark.skins.mobile.TextInputSkin;
 
        public class TextInputSkin extends spark.skins.mobile.TextInputSkin
        {
                protected var _width:int;
                protected var _height:int;
 
                protected var paddingLR:int = 12;
                protected var paddingTB:int = 1;
 
                protected var guiSize:Rectangle = new Rectangle(0,0, 640,960);
                protected var appSize:Rectangle;
                protected var appScale:Number = 1;
                protected var deviceSize:Rectangle;       
 
                public function TextInputSkin()
                {
                        super();
 
                        setStyle("minWidth",0);
 
                        setStyle("borderVisible",false);
                        setStyle("paddingTop",1);
                        setStyle("paddingButtom",1);
                        setStyle("paddingLeft",0);
                        setStyle("paddingRight",0);
 
                        setStyle("contentBackgroundColor",0xffffff);
                        setStyle("contentBackgroundAlpha",0);
 
                        addEventListener(Event.ADDED_TO_STAGE,addedToStageHandler);
                }
 
                protected function addedToStageHandler(event:Event):void
                {
                        _width = stage.stageWidth / 4;
                        _height = _width / 5.11;
 
                        // trace("addedToStage _width="+_width+"  stage.stageWidth="+stage.stageWidth);
 
                        deviceSize = new Rectangle(0, 0, stage.fullScreenWidth, stage.fullScreenHeight);
                        appSize = guiSize.clone();
                        appScale = deviceSize.width / guiSize.width;
 
                        switch (applicationDPI)
                        {
                                case DPIClassification.DPI_640:
                                case DPIClassification.DPI_480:
                                {
                                        // here can be small displays
                                        if(appScale < .6)
                                        {
                                                // 240
                                                textDisplay.setStyle("fontSize", 21);
                                                promptDisplay.setStyle("fontSize", 21);
                                                setStyle("paddingTop",2);
                                                setStyle("paddingButtom",2);
                                        }
                                        else if(appScale>.5 && appScale<1.2)
                                        {
                                                //320
                                                textDisplay.setStyle("fontSize", 32);
                                                promptDisplay.setStyle("fontSize", 32);
                                                setStyle("paddingTop",3);
                                                setStyle("paddingButtom",3);
                                        }
                                        else
                                        {
                                                //480
                                                //trace("480");
                                                textDisplay.setStyle("fontSize", 47);
                                                promptDisplay.setStyle("fontSize", 47);
                                                setStyle("paddingTop",4);
                                                setStyle("paddingButtom",4);
                                        }
 
                                        break;
                                }
                                case DPIClassification.DPI_320:
                                {
                                        //trace("320");
                                        textDisplay.setStyle("fontSize", 32);
                                        promptDisplay.setStyle("fontSize", 32);
                                        setStyle("paddingTop",3);
                                        setStyle("paddingButtom",3);
                                        break;
                                }
                                case DPIClassification.DPI_240:
                                {
                                        //trace("240");
                                        textDisplay.setStyle("fontSize", 21);
                                        promptDisplay.setStyle("fontSize", 21);
                                        setStyle("paddingTop",2);
                                        setStyle("paddingButtom",2);
                                        break;
                                }
 
                                default:
                                {
                                        // default DPI_160
                                        // here can be big displays
                                        if(appScale < .6)
                                        {
                                                // LOW
                                                textDisplay.setStyle("fontSize", 14);
                                                promptDisplay.setStyle("fontSize", 14);
                                        }
                                        else if(appScale>.5 && appScale<1.2)
                                        {
                                                // MED
                                                textDisplay.setStyle("fontSize", 21);
                                                promptDisplay.setStyle("fontSize", 21);
                                                setStyle("paddingTop",2);
                                                setStyle("paddingButtom",2);
                                        }
                                        else
                                        {
                                                // HIGH
                                                textDisplay.setStyle("fontSize", 32);
                                                promptDisplay.setStyle("fontSize", 32);
                                                setStyle("paddingTop",3);
                                                setStyle("paddingButtom",3);
                                        }
                                        break;
                                }
                        }
                        textDisplay.commitStyles();
                        promptDisplay.commitStyles();
 
                        invalidateSize();
                        invalidateDisplayList();
                }
 
 
                override protected function measure():void
                {
                        trace("text input measure _width="+_width+" paddingLeft="+getStyle("paddingLeft")+" diff="+(_width + getStyle("paddingLeft")*2));
                        measuredWidth = _width + getStyle("paddingLeft")*2;
                        measuredHeight = _height+ getStyle("paddingTop")*2;
                        trace("text input measuredWidth="+measuredWidth);
                }
 
                override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
                {
                        trace("TI UDL");
                        super.updateDisplayList(unscaledWidth, unscaledHeight);
 
                        setElementSize(textDisplay,_width + getStyle("paddingLeft")*2, _height + getStyle("paddingTop")*2);
                        setElementPosition(textDisplay,getStyle("paddingLeft"),getStyle("paddingTop"));
 
                        if(promptDisplay)
                        {
                                setElementSize(promptDisplay,_width + getStyle("paddingLeft")*2, _height + getStyle("paddingTop")*2);
                                setElementPosition(promptDisplay,getStyle("paddingLeft"),getStyle("paddingTop"));
                        }
 
                        graphics.clear();
                        graphics.lineStyle(1,0xb8c7c6);
                        graphics.beginFill(0xffffff);
                        graphics.drawRect(0,0,_width+getStyle("paddingLeft")*2,_height+getStyle("paddingTop")*4);
                        graphics.endFill();
                }
        }
}

Вот позиционирование textInput-а внутри скина родительского компонента
Код AS3:

...
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
                {
                        super.updateDisplayList(unscaledWidth, unscaledHeight);
 
                        // place skin parts...
                        cityDropDownLabelTextWidth = getElementPreferredWidth(cityDropDownLabel);
                        cityDropDownLabelTextHeight = getElementPreferredHeight(cityDropDownLabel);
 
                        typeDropDownLabelTextWidth = getElementPreferredWidth(typeDropDownLabel);
                        typeDropDownLabelTextHeight = getElementPreferredHeight(typeDropDownLabel);
 
                        setElementSize(cityDropDownLabel, cityDropDownLabelTextWidth, cityDropDownLabelTextHeight);
                        setElementPosition(cityDropDownLabel,(_width - cityDropDown.measuredWidth)/2,0);
                        setElementPosition(cityDropDown,(_width - cityDropDown.measuredWidth)/2,gap + cityDropDownLabelTextHeight);
 
                        setElementSize(typeDropDownLabel, typeDropDownLabelTextWidth, typeDropDownLabelTextHeight);
                        setElementPosition(typeDropDownLabel,(_width - typeDropDown.measuredWidth)/2,gap*2 + cityDropDown.measuredHeight+cityDropDownLabelTextHeight);
                        setElementPosition(typeDropDown, (_width - typeDropDown.measuredWidth)/2, gap*3 + cityDropDown.measuredHeight+cityDropDownLabelTextHeight+typeDropDownLabelTextHeight);
 
                        trace("cityTextInput.measuredWidth="+cityTextInput.measuredWidth+"  _width="+_width);
                        setElementPosition(cityTextInput,(_width - cityTextInput.measuredWidth)/2, gap*4 + cityDropDown.measuredHeight+cityDropDownLabelTextHeight+typeDropDownLabelTextHeight + typeDropDown.measuredHeight);
 // позиционирование поля ввода
                        setElementPosition(searchButton, (_width - searchButton.measuredWidth)/2, gap*6 + cityDropDown.measuredHeight+cityDropDownLabelTextHeight+typeDropDownLabelTextHeight + typeDropDown.measuredHeight+cityTextInput.measuredHeight);
                }

В трэйсе в функции measure у скина textInput-а
Код:

text input measure _width=80 paddingLeft=0 diff=80
text input measuredWidth=300

Как видно из расчетов - 300 там никак не должно быть

alatar 27.05.2014 20:06

Цитата:

Как видно из расчетов - 300 там никак не должно быть
Откройте исходники MobileSkin и посмотрите на код геттера measuredWidth

Код AS3:

override public function get measuredWidth():Number
{
    return Math.max(super.measuredWidth, measuredDefaultWidth);
}

Откройте исходник TextInputSkin и посмотрите на код контруктора

Код AS3:

...
switch (applicationDPI)
{
    ...
    default:
    {
        borderClass = spark.skins.mobile160.assets.TextInput_border;
        layoutCornerEllipseSize = 12;
        measuredDefaultWidth = 300;
        measuredDefaultHeight = 33;
        layoutBorderSize = 1;
 
        break;
    }
}


djyamato 27.05.2014 21:49

да, точно. Спасибо.
Только Math.max я нашел в ActionScriptSkinBase


Часовой пояс GMT +4, время: 07:18.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.