feathersui / feathersui-starling

User interface components for Starling Framework and Adobe AIR
https://feathersui.com/learn/as3-starling/
Other
914 stars 386 forks source link

Use same label TextFormat for selected state of list item rendered #1687

Closed CrazyFlasher closed 6 years ago

CrazyFlasher commented 6 years ago

... In below case itemRenderer.iconLabelFontStyles is null. What is the best way to solve current problem?

private function tileListItemRendererFactory():IListItemRenderer
        {
            var bgSkin:Quad = new Quad(1, 1, 0);
            bgSkin.alpha = 0;

            var itemRenderer:DefaultListItemRenderer = new DefaultListItemRenderer();

            itemRenderer.touchable = false;
            itemRenderer.defaultSkin = bgSkin;
            itemRenderer.labelField = "ammo";
            itemRenderer.iconSourceField = "texture";
            itemRenderer.iconLabelSelectedFontStyles = itemRenderer.iconLabelFontStyles;
            itemRenderer.iconPosition = RelativePosition.TOP;
            itemRenderer.horizontalAlign = HorizontalAlign.CENTER;
            itemRenderer.verticalAlign = VerticalAlign.BOTTOM;

            return itemRenderer;
        }
joshtynjala commented 6 years ago

The quick and dirty way to do it is to use an AddOnFunctionStyleProvider:

itemRenderer.styleProvider = new AddOnFunctionStyleProvider(itemRenderer.styleProvider, function(itemRenderer:DefaultListItemRenderer):void
{
    itemRenderer.iconLabelSelectedFontStyles = itemRenderer.iconLabelFontStyles;
});

If you want to follow best practices, it would be better to add a new style name to the theme.