How to use the Feathers List component
http://wiki.starling-framework.org/feathers/list
The List
class renders a series of items from a flat data source such as an Array
or Vector
. It includes support for selection, scrolling, custom layouts, layout virtualization, and custom item renderers.
The Basics
Let's start by creating our List
control:
var list:List = new List(); list.width = 250; list.height = 300; this.addChild( list );
Next, we want the list to display some items, so let's create a ListCollection
as its data provider. In the example below, an Array
of objects is passed to the ListCollection
.
var groceryList:ListCollection = new ListCollection( [ { text: "Milk", thumbnail: textureAtlas.getTexture( "milk" ) }, { text: "Eggs", thumbnail: textureAtlas.getTexture( "eggs" ) }, { text: "Bread", thumbnail: textureAtlas.getTexture( "bread" ) }, { text: "Chicken", thumbnail: textureAtlas.getTexture( "chicken" ) }, ]); list.dataProvider = groceryList;
ListCollection
wraps any type of data to provide a common API that the List
component can understand. Out of the box, ListCollection
automatically supports Vector
, Array
, and XMLList
, but you can create _data descriptors_ to use other types of data, if needed.
Now, we need to tell the list how to display the data. Well, actually, we need to tell the item renderer how to display the data. The default item renderer has many options for displaying text, images, and other display objects. Here, we'll tell it to use the text
property and the thumbnail
property from the items.
list.itemRendererProperties.labelField = "text"; list.itemRendererProperties.iconTextureField = "thumbnail";
When using the labelField
, the default item renderer will automatically create an appropriate text renderer to display the label. Similarly, when you use the iconTextureField
, the item renderer will automatically create and manage an Image
to display the texture. Read the documentation for the DefaultListItemRenderer
class to see all of the various fields that are available. We'll look at a couple more in more detail in a moment.
Working with the Default Item Renderer
The default item renderer of a list is a subclass of Button
, so all of the skinning and layout options available to buttons can be used by item renderers too. For example, you might want to center your content vertically and horizontally, place the icon on top, and add a gap between them:
list.itemRendererProperties.horizontalAlign = Button.HORIZONTAL_ALIGN_CENTER; list.itemRendererProperties.verticalAlign = Button.VERTICAL_ALIGN_MIDDLE; list.itemRendererProperties.iconPosition = Button.ICON_POSITION_TOP; list.itemRendererProperties.gap = 10;
Also just like buttons, the default item renderer has different touch states like down and hover. You can see how the skins for different states may be customized in the Getting Started with Feathers tutorial.
Accessories
In addition to the label and the icon, the default item renderer can display an accessory view. This is an extra display object that is often interactive in some way. For instance, you might create a list of settings with labels on the left and some user interface controls like sliders and toggle switches on the right.
An accessory may be a label, an image, or any Starling display object, including Feathers components. Similar to how you use labelField
to access text from the item, you can use accessoryLabelField
to display a second label. The default item renderer also has an accessoryTextureField
which is similar to iconTextureField
. Those two will give you the best performance when you want the accessory to display text or an image. If you need to display a UI control or any other type of display object, use the accessoryField
property.
The Components Explorer example uses accessories in the settings screens for several of the Feathers components.
Custom Item Renderers
If the default item renderer doesn't have the features that you need, the List
component offers the ability to use custom item renderers instead. Custom item renderers must implement the IListItemRenderer
interface. They should also subclass FeathersControl
.
The easiest way to pass in a custom item renderer is to set the itemRendererType
property:
list.itemRendererType = ExampleCustomItemRenderer;
Sometimes, you might want to change some properties on each item renderer as it is created. For example, if you're not using a theme, you will need to pass the skins to the item renderer when you create it. In this case, you can use the itemRendererFactory
property instead of itemRendererType
:
list.itemRendererFactory = function():IListItemRenderer { var renderer:DefaultListItemRenderer = new DefaultListItemRenderer(); renderer.defaultSkin = new Image( texture ); renderer.defaultLabelProperties.textFormat = new BitmapFontTextFormat( font ); return renderer; }
In the example above, we create the default item renderer for a List
component, but we pass in a skin and a text format.
Layout
The default layout for a list is to display the items vertically one after the other. We can change that to a horizontal layout, a tiled layout, or even a completely custom algorithm that implements the ILayout
interface. Let's switch to a HorizontalLayout
and customize it a bit:
var layout:HorizontalLayout = new HorizontalLayout(); layout.verticalAlign = HorizontalLayout.VERTICAL_ALIGN_JUSTIFY; layout.gap = 10; layout.paddingTop = layout.paddingRight = layout.paddingBottom = layout.paddingLeft = 15; list.layout = layout;
When the list automatically defaults to a VerticalLayout
, it also disables the horizontal scroll policy of its Scroller
subcomponent so that the “elastic” edges of the Scroller
only apply to the vertical direction. If we're switching to a horizontal layout, we should also adjust the scroll policies appropriately.
list.scrollerProperties.horizontalScrollPolicy = Scroller.SCROLL_POLICY_AUTO; list.scrollerProperties.verticalScrollPolicy = Scroller.SCROLL_POLICY_OFF;
Selection
The List
component may have one selected item. You can access information about selection through the selectedIndex
and selectedItem
properties. If there is no selection, the value of selectedIndex
will be -1
and the value of selectedItem
will be null
.
To listen for when the selection changes, listen to the Event.CHANGE
event:
list.addEventListener( Event.CHANGE, list_changeHandler );
The listener might look something like this:
private function list_changeHandler( event:Event ):void { var list:List = List( event.currentTarget ); trace( "selectedIndex:", list.selectedIndex ); }
To disable selection, set isSelected
to false
.
Related Links
For more tutorials, return to the Feathers Documentation.
相关推荐
Strling和FeathersUI是两个在游戏开发和用户界面设计中常用的库,特别是在Adobe AIR和Flash平台上。这两个库结合使用可以创建高性能、丰富的图形和交互式应用。 **Strling** Strling是一个基于ActionScript 3的2D...
Starling-feathers API的文档,下载及可打开浏览。很实用
The intimate relationship between energy levels, orbital states, and electromagnetic waves helps to explain why diamonds shimmer, rubies are red, and the feathers of the Blue Jay are blue. Then, ...
Feathers 2.0.0 是一款专为Starling框架设计的UI组件库,它旨在为Flash开发者提供一套高效、高性能的用户界面解决方案。利用Starling的硬件加速特性,Feathers能够帮助开发者创建出流畅、丰富的2D图形界面,尤其适用...
**As3 Feathers** 是一个专门针对移动端UI设计的组件库,它在Adobe生态系统中扮演着重要的角色。这个库提供了一系列美观且功能丰富的用户界面元素,适用于开发Android和iOS等移动平台的应用程序。由于其出色的性能和...
feathers-2.0.1 This is the newest stable version of the open source Feathers user interface components for Starling Framework. Most people will want to download this version of Feathers.
feathers是一个JavaScript框架, 用于构建Web应用。。
feathers, Starling框架的用户界面组件 羽毛 3.4.0 -prerelease警告: 这是羽毛UI的预发布版本。 它可能包含 Bug 或者未完成的功能。 它不推荐用于生产应用,因为它被认为是潜在的不稳定的产品。 使用自己的风险。 ...
aor-feathers-client, rest的rest客户端管理 Admin-on-rest的 REST客户端基于REST服务构建后台和前端管理的完美匹配。 用于使用 和 admin-on-rest 。特性GET_MANY_REFERENCEGET_MANYGET_LISTGET_ONE创
Starling Feathers是一款专为Adobe Starling框架设计的UI库,它允许开发者创建美观、高性能的2D用户界面。Starling本身是一个跨平台的游戏开发框架,基于ActionScript 3.0,利用硬件加速来实现高效的2D图形渲染,...
### 孔雀羽毛色彩策略研究 #### 摘要与背景 本文主要探讨了孔雀羽毛中的色彩形成机制,尤其关注其独特的结构色彩表现形式。研究人员发现,孔雀羽毛中色彩的表现并非仅通过色素来实现,而更多的是依赖于一种二维...
feathers-hooks, 用于轻松授权和处理的服务方法钩子 羽毛钩重要: feathers-hooks 包含在羽毛( @feathersjs/feathers ) v3,而且不需要单独装载和配置。 面向羽毛服务方法的中间件文档有关更多详细信息,请参阅羽毛...
羽毛mongodb 用于数据库适配器,使用用于。 $ npm install --save mongodb feathers-mongodb 重要提示: feathers-mongodb实现了和。 该适配器还需要一个数据库服务器。... use ( '/messages' ,
Feathers:下一代应用的实时JavaScript框架.zip,A framework for real-time applications and REST APIs with JavaScript and TypeScript
此版本配置为与Swagger UI 3.x一起使用安装npm install feathers-swagger --save原料药swagger(options) 初始化模块。 服务注册之前应提供给app.configure。 const feathers = require ( '@feathersjs/feathers' ) ...
copy template to feathers folder -您可以自定义自己的模板,并将其用于创建新服务。 它将放置在./src/store/feathers/templates/${templateName} ,并将按以下方式调用: add service from custom templ
羽毛同步 在应用程序实例之间同步服务事件编写自定义适配器执照 关于当运行Feathers应用程序的多个实例(例如,在多个Heroku Dynos上)时,服务事件( created , updated , patched , removed和任何自定义事件)...
将请求者的IP地址公开给您的Feathers服务 使用feathers-express-ip,您可以针对以下情况制定自己的解决方案: 每个IP地址的速率限制 通过IP跟踪请求 安装 npm install feathers-express-ip --save yarn add ...
Feathers-Vuex Feathers-Vuex是FeathersJS和Vuex的一流集成。 它在引擎盖下实现了许多Redux最佳实践,消除了Feathers-Vuex Feathers-Vuex是FeathersJS和Vuex的一流集成。 它在后台实现了许多Redux最佳实践,通过灵活...
vue-feathers-chat使用Vue和Feathers进行实时聊天的示例关于此项目是示例公共聊天,在视觉上几乎类似于WhatsApp克隆,vue-feathers-chat用Vue和Feathers进行实时聊天的示例关于本项目是一个示例公开聊天,在视觉上...