Last active
December 28, 2015 08:59
-
-
Save joshtynjala/7475943 to your computer and use it in GitHub Desktop.
Feathers: This subclass of LayoutGroupItemRenderer demonstrates how to create a simple custom item renderer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import feathers.controls.Label; | |
import feathers.controls.renderers.LayoutGroupListItemRenderer; | |
import feathers.layout.AnchorLayout; | |
import feathers.layout.AnchorLayoutData; | |
public class CustomLayoutGroupItemRenderer extends LayoutGroupListItemRenderer | |
{ | |
public function CustomLayoutGroupItemRenderer() | |
{ | |
} | |
protected var _label:Label; | |
protected var _padding:Number = 0; | |
public function get padding():Number | |
{ | |
return this._padding; | |
} | |
public function set padding(value:Number):void | |
{ | |
if(this._padding == value) | |
{ | |
return; | |
} | |
this._padding = value; | |
this.invalidate(INVALIDATION_FLAG_LAYOUT); | |
} | |
override protected function initialize():void | |
{ | |
this.layout = new AnchorLayout(); | |
var labelLayoutData:AnchorLayoutData = new AnchorLayoutData(); | |
labelLayoutData.top = 0; | |
labelLayoutData.right = 0; | |
labelLayoutData.bottom = 0; | |
labelLayoutData.left = 0; | |
this._label = new Label(); | |
this._label.layoutData = labelLayoutData; | |
this.addChild(this._label); | |
} | |
override protected function commitData():void | |
{ | |
if(this._data && this._owner) | |
{ | |
this._label.text = this._data.label; | |
} | |
else | |
{ | |
this._label.text = null; | |
} | |
} | |
override protected function commitLayout():void | |
{ | |
var labelLayoutData:AnchorLayoutData = AnchorLayoutData(this._label.layoutData); | |
labelLayoutData.top = this._padding; | |
labelLayoutData.right = this._padding; | |
labelLayoutData.bottom = this._padding; | |
labelLayoutData.left = this._padding; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment