Custom Layout manager measure() method


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. override public function measure():void {
  2. if (!useVirtualLayout)
  3. return;
  4. var layoutTarget:GroupBase = target;
  5. if (!layoutTarget)
  6. return;
  7. var dataGroupTarget:DataGroup = layoutTarget as DataGroup;
  8. if (dataGroupTarget.width == 0 || dataGroupTarget.height == 0) {
  9. _containerWidth = _containerHeight = -1;
  10. return;
  11. }
  12.  
  13. var totalWidth:Number = 0;
  14. var totalHeight:Number = 0;
  15. var dataProvider:IList = dataGroupTarget.dataProvider;
  16. if (!dataProvider || !dataProvider.length)
  17. return;
  18. var count:int = dataProvider.length;
  19. var rowWidth:Number = dataGroupTarget.width;
  20. var sectionHeight:Number = _sectionHeight;
  21. var tileHeight:Number = _tileHeight;
  22. var tileWidth:Number = _columnWidth;
  23.  
  24. totalWidth = rowWidth;
  25.  
  26. var elementWidth:Number, elementHeight:Number;
  27. var x:Number = 0;
  28. yToIndex = new Vector.<int>();
  29. indexToY = new Vector.<int>();
  30. var d:Object = d = dataProvider.getItemAt(0);
  31. if (_sectionLabel in d) {
  32. addToVectorY(0, 0, sectionHeight);
  33. totalHeight = sectionHeight + _verticalGap;
  34. } else {
  35. addToVectorY(0, 0, tileHeight);
  36. totalHeight = tileHeight + _verticalGap;
  37. }
  38. //loop though all the elements elements
  39. for (var i:int = 0; i < count; i++) {
  40. d = dataProvider.getItemAt(i);
  41. if (!d) {
  42. elementWidth = tileWidth;
  43. elementHeight = tileHeight;
  44. } else if (_sectionLabel in d) {
  45. elementWidth = rowWidth;
  46. elementHeight = sectionHeight;
  47. } else {
  48. elementWidth = tileWidth;
  49. elementHeight = tileHeight;
  50. }
  51. // Would this element fit on this line, or should we move it
  52. // to the next line?
  53. if (x + elementWidth > rowWidth) {
  54. x = 0;
  55. //add the index to vector
  56. addToVectorY(i, totalHeight + 1, elementHeight);
  57. totalHeight += elementHeight + _verticalGap;
  58. }
  59. addToVectorIndex(i, totalHeight - elementHeight - _verticalGap);
  60. // Update the current position, add the gap
  61. x += elementWidth + _horizontalGap;
  62. }
  63. layoutTarget.measuredWidth = totalWidth;
  64. layoutTarget.measuredHeight = totalHeight;
  65. layoutTarget.measuredMinWidth = totalWidth;
  66. layoutTarget.measuredMinHeight = totalHeight;
  67. layoutTarget.setContentSize(totalWidth, totalHeight);
  68. }

URL: http://corlan.org/?p=2987

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.