Code Monkey home page Code Monkey logo

Comments (2)

joshtynjala avatar joshtynjala commented on July 19, 2024

You can provide a custom item renderer by setting the itemRendererRecycler property.

list.itemRendererRecycler = DisplayObjectRecycler.withClass(CustomItemRenderer);

If your custom item renderer implements the IDataRenderer interface, the data property will be set to an item from the ListView's data provider. You can interpret that item in any way that you'd like, inside an override of update().

However, DisplayObjectRecycler makes it possible to skip implementing IDataRenderer, if you'd prefer. You can optionally provide update and reset methods to that interpret the data.

Here's an example that creates a LayoutGroup with a Label and an AssetLoader:

var recycler = DisplayObjectRecycler.withFunction(() ->
{
	var itemRenderer = new LayoutGroup();
	var label = new Label();
	label.name = "label";
	itemRenderer.addChild(label);
	var loader = new AssetLoader();
	loader.name = "loader";
	itemRenderer.addChild(loader);
	return itemRenderer;
});

recycler.update = (itemRenderer, state) ->
{
	var label = cast(itemRenderer.getChildByName("label"), Label);
	var loader = cast(itemRenderer.getChildByName("loader"), AssetLoader);

	label.text = state.text;
	loader.source = state.data.url;
});

recycler.reset = (itemRenderer, state) ->
{
	var label = cast(itemRenderer.getChildByName("label"), Label);
	var loader = cast(itemRenderer.getChildByName("loader"), AssetLoader);

	label.text = "";
	loader.source = null;
});

list.itemRendererRecycler = recycler;

(Note: I haven't tried running that code, so it may need some minor tweaks to work properly)

I'm working on the documentation this month, and I'll try to go into more detail on item renderers. In the meantime, feel free to ask if anything is confusing.

from feathersui-openfl.

varadig avatar varadig commented on July 19, 2024

Thank You @joshtynjala!

from feathersui-openfl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.