智慧 + 毅力 = 无所不能

正确性、健壮性、可靠性、效率、易用性、可读性、可复用性、兼容性、可移植性...
随笔 - 991, 文章 - 0, 评论 - 27, 阅读 - 341万

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

Feathers UI 扩展实例 For Starling Framework

Posted on   Bill Yuan  阅读(1407)  评论(0编辑  收藏  举报
复制代码
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/

(评论功能已被禁用)
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· [AI/GPT/综述] AI Agent的设计模式综述
点击右上角即可分享
微信分享提示