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/

  • 相关阅读:
    阿里IM技术分享(六):闲鱼亿级IM消息系统的离线推送到达率优化
    IM开发基础知识补课(十):大型IM系统有多难?万字长文,搞懂异地多活!
    长连接网关技术专题(六):石墨文档单机50万WebSocket长连接架构实践
    手把手教你实现网页端社交应用中的@人功能:技术原理、代码示例等
    跟着源码学IM(九):基于Netty实现一套分布式IM系统
    网络编程懒人入门(十三):一泡尿的时间,快速搞懂TCP和UDP的区别
    探探的IM长连接技术实践:技术选型、架构设计、性能优化
    直播系统聊天技术(六):百万人在线的直播间实时聊天消息分发技术实践
    基于实践:一套百万消息量小规模IM系统技术要点总结
    Datafram 实现作为正文发送邮件
  • 原文地址:https://www.cnblogs.com/sevenyuan/p/2871492.html
Copyright © 2011-2022 走看看