Feathers UI 扩展实例 For Starling Framework
Posted on 2013-01-22 15:37 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/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 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的设计模式综述