zoukankan      html  css  js  c++  java
  • Feathers UI 扩展实例 For Starling Framework

    package com.renaun.controls
    {
    import feathers.controls.Label;
    import feathers.core.FeathersControl;
    import starling.display.DisplayObject;
    
    public class Group extends FeathersControl
    {
        public function Group()
        {
            super();
        
        }
        
        protected var children:Vector.<FeathersControl> = new Vector.<FeathersControl>();
        protected var childrenPercentValues:Vector.<int> = new Vector.<int>();
    
        protected var explicitTotal:Number;
    
        protected var percentTotalValue:Number;
        
        protected var isValid:Boolean = false;
    
        protected var isFirstTime:Boolean = false;
    
        /**
         *  Currently you have to add items in order, there is not addLayoutItemAt.
         * 
         *  @param item The target item you want to add to this group, add in order
         *      @param percentHeight The percent value of the VGroup's height. 100 = 100%, and if the total percent is> 100 it will be scaled by the value/totalPrecents.
         */
        public function addLayoutItem(item:FeathersControl, percentValue:int = -1):void
        {
            addChild(item);
            children.push(item);
            item.onResize.add(resizeHandler);
            childrenPercentValues.push(percentValue);
            measure();
            invalidate();
        }
        
        override protected function initialize():void
        {
            //trace("init");
            super.initialize();
            isFirstTime = true;
        }
        
        protected function measure():void
        {
        }
        
        protected function resizeHandler(target:FeathersControl, oldWidth:Number, oldHeight:Number):void
        {
            /*
            if (target is Label)
                trace("resizeHandler2["+(target as Label).text+"]: " + oldWidth + " - " + width);
            else
            trace("resizeHandler2["+target+"]: " + oldWidth + " - " + width);
            */
            isValid = false;
            invalidate();
        }
        
    }
    }
    package com.renaun.controls
    {
    import feathers.core.FeathersControl;
    import starling.display.DisplayObject;
    
    public class VGroup extends Group
    {
        public function VGroup()
        {
            super();
        
        }
    
        public var gap:int = 8;
        public var paddingLeft:int = 8;
        public var paddingRight:int = 8;
        public var paddingTop:int = 8;
        public var paddingBottom:int = 8;
        
        override protected function measure():void
        {
            var item:DisplayObject;
            explicitTotal = -gap;
            percentTotalValue = 0;
            var i:int;
            for (i = 0; i <children.length; i++)
            {
                item = children[i];
                if (childrenPercentValues[i]> 0)
                    percentTotalValue += childrenPercentValues[i];
                else
                {
                
                    if (item is FeathersControl)
                    {
                        //item.height = (item as BitmapFontTextRenderer).measureText().y;
                        (item as FeathersControl).validate();
                    }
                    explicitTotal = explicitTotal + item.height;
                }      
                explicitTotal += gap;
            }
            isValid = true;
        }
        
        override protected function draw():void
        {
            // Delay items width/height are still not valid inside initalize method so have to wait for draw
            if (isFirstTime)
            {
                measure();
                isFirstTime = false;
            }
            var availableHeightForPercents:Number = explicitHeight - explicitTotal - paddingTop - paddingBottom;
            //trace("availableHeightForPercents: " + availableHeightForPercents + " - " + explicitTotal + " - " + explicitHeight);
            // Make smaller if the percents add up more then 100
            if (percentTotalValue> 100)
                availableHeightForPercents = availableHeightForPercents / (percentTotalValue / 100);
            
            //trace("percentTotalValue: " + percentTotalValue + " aHFP: " + availableHeightForPercents + " - " + explicitTotal + " - " + explicitHeight);
            var percentHeightValue:int = 0;
            var lastHeight:int = 0;
            var i:int;
            var item:DisplayObject;
            for (i = 0; i <children.length; i++)
            {
                item = children[i];
                // Set Y
                item.y = lastHeight + paddingTop;
                if (childrenPercentValues[i]> 0)
                {
                    percentHeightValue = childrenPercentValues[i];
                    // Set HEIGHT
                    item.height = int(availableHeightForPercents * percentHeightValue / 100);
                }
                lastHeight += item.height + gap;
                
                // Set X
                item.x = paddingLeft;
                // Set WIDTH
                item.width = explicitWidth - paddingLeft - paddingRight;
                //trace("lastHeight : " + lastHeight);
            }
        }
    }
    }
    var vgroup:VGroup = new VGroup();
    vgroup.addLayoutItem(renderer);
    vgroup.addLayoutItem(list, 100);
    vgroup.addLayoutItem(appCountLabel);
    
    addChild(vgroup);

    转自:http://renaun.com/blog/2012/10/playing-with-feathers-ui-components-for-starling-framework/

  • 相关阅读:
    [kuangbin带你飞]专题十六 KMP & 扩展KMP & ManacherK
    [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher J
    [kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher I
    pat 1065 A+B and C (64bit)(20 分)(大数, Java)
    pat 1069 The Black Hole of Numbers(20 分)
    pat 1077 Kuchiguse(20 分) (字典树)
    pat 1084 Broken Keyboard(20 分)
    pat 1092 To Buy or Not to Buy(20 分)
    pat 1046 Shortest Distance(20 分) (线段树)
    pat 1042 Shuffling Machine(20 分)
  • 原文地址:https://www.cnblogs.com/sevenyuan/p/2871492.html
Copyright © 2011-2022 走看看