Column.html 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-layout-container-Column'>/**
  19. </span> * This is the layout style of choice for creating structural layouts in a multi-column format where the width of each
  20. * column can be specified as a percentage or fixed width, but the height is allowed to vary based on the content. This
  21. * class is intended to be extended or created via the layout:'column' {@link Ext.container.Container#layout} config,
  22. * and should generally not need to be created directly via the new keyword.
  23. *
  24. * ColumnLayout does not have any direct config options (other than inherited ones), but it does support a specific
  25. * config property of `columnWidth` that can be included in the config of any panel added to it. The layout will use
  26. * the columnWidth (if present) or width of each panel during layout to determine how to size each panel. If width or
  27. * columnWidth is not specified for a given panel, its width will default to the panel's width (or auto).
  28. *
  29. * The width property is always evaluated as pixels, and must be a number greater than or equal to 1. The columnWidth
  30. * property is always evaluated as a percentage, and must be a decimal value greater than 0 and less than 1 (e.g., .25).
  31. *
  32. * The basic rules for specifying column widths are pretty simple. The logic makes two passes through the set of
  33. * contained panels. During the first layout pass, all panels that either have a fixed width or none specified (auto)
  34. * are skipped, but their widths are subtracted from the overall container width.
  35. *
  36. * During the second pass, all panels with columnWidths are assigned pixel widths in proportion to their percentages
  37. * based on the total **remaining** container width. In other words, percentage width panels are designed to fill
  38. * the space left over by all the fixed-width and/or auto-width panels. Because of this, while you can specify any
  39. * number of columns with different percentages, the columnWidths must always add up to 1 (or 100%) when added
  40. * together, otherwise your layout may not render as expected.
  41. *
  42. * @example
  43. * // All columns are percentages -- they must add up to 1
  44. * Ext.create('Ext.panel.Panel', {
  45. * title: 'Column Layout - Percentage Only',
  46. * width: 350,
  47. * height: 250,
  48. * layout:'column',
  49. * items: [{
  50. * title: 'Column 1',
  51. * columnWidth: 0.25
  52. * },{
  53. * title: 'Column 2',
  54. * columnWidth: 0.55
  55. * },{
  56. * title: 'Column 3',
  57. * columnWidth: 0.20
  58. * }],
  59. * renderTo: Ext.getBody()
  60. * });
  61. *
  62. * // Mix of width and columnWidth -- all columnWidth values must add up
  63. * // to 1. The first column will take up exactly 120px, and the last two
  64. * // columns will fill the remaining container width.
  65. *
  66. * Ext.create('Ext.Panel', {
  67. * title: 'Column Layout - Mixed',
  68. * width: 350,
  69. * height: 250,
  70. * layout:'column',
  71. * items: [{
  72. * title: 'Column 1',
  73. * width: 120
  74. * },{
  75. * title: 'Column 2',
  76. * columnWidth: 0.7
  77. * },{
  78. * title: 'Column 3',
  79. * columnWidth: 0.3
  80. * }],
  81. * renderTo: Ext.getBody()
  82. * });
  83. */
  84. Ext.define('Ext.layout.container.Column', {
  85. extend: 'Ext.layout.container.Container',
  86. alias: ['layout.column'],
  87. alternateClassName: 'Ext.layout.ColumnLayout',
  88. type: 'column',
  89. itemCls: Ext.baseCSSPrefix + 'column',
  90. targetCls: Ext.baseCSSPrefix + 'column-layout-ct',
  91. // Columns with a columnWidth have their width managed.
  92. columnWidthSizePolicy: {
  93. setsWidth: 1,
  94. setsHeight: 0
  95. },
  96. childEls: [
  97. 'innerCt'
  98. ],
  99. manageOverflow: 2,
  100. renderTpl: [
  101. '&lt;div id=&quot;{ownerId}-innerCt&quot; class=&quot;',Ext.baseCSSPrefix,'column-inner&quot;&gt;',
  102. '{%this.renderBody(out,values)%}',
  103. '&lt;div class=&quot;',Ext.baseCSSPrefix,'clear&quot;&gt;&lt;/div&gt;',
  104. '&lt;/div&gt;',
  105. '{%this.renderPadder(out,values)%}'
  106. ],
  107. getItemSizePolicy: function (item) {
  108. if (item.columnWidth) {
  109. return this.columnWidthSizePolicy;
  110. }
  111. return this.autoSizePolicy;
  112. },
  113. beginLayout: function() {
  114. this.callParent(arguments);
  115. this.innerCt.dom.style.width = '';
  116. },
  117. calculate: function (ownerContext) {
  118. var me = this,
  119. containerSize = me.getContainerSize(ownerContext),
  120. state = ownerContext.state;
  121. if (state.calculatedColumns || (state.calculatedColumns = me.calculateColumns(ownerContext))) {
  122. if (me.calculateHeights(ownerContext)) {
  123. me.calculateOverflow(ownerContext, containerSize);
  124. return;
  125. }
  126. }
  127. me.done = false;
  128. },
  129. calculateColumns: function (ownerContext) {
  130. var me = this,
  131. containerSize = me.getContainerSize(ownerContext),
  132. innerCtContext = ownerContext.getEl('innerCt', me),
  133. items = ownerContext.childItems,
  134. len = items.length,
  135. contentWidth = 0,
  136. blocked, availableWidth, i, itemContext, itemMarginWidth, itemWidth;
  137. // Can never decide upon necessity of vertical scrollbar (and therefore, narrower
  138. // content width) until the component layout has published a height for the target
  139. // element.
  140. if (!ownerContext.heightModel.shrinkWrap &amp;&amp; !ownerContext.targetContext.hasProp('height')) {
  141. return false;
  142. }
  143. // No parallel measurement, cannot lay out boxes.
  144. if (!containerSize.gotWidth) { //\\ TODO: Deal with target padding width
  145. ownerContext.targetContext.block(me, 'width');
  146. blocked = true;
  147. } else {
  148. availableWidth = containerSize.width;
  149. innerCtContext.setWidth(availableWidth);
  150. }
  151. // we need the widths of the columns we don't manage to proceed so we block on them
  152. // if they are not ready...
  153. for (i = 0; i &lt; len; ++i) {
  154. itemContext = items[i];
  155. // this is needed below for non-calculated columns, but is also needed in the
  156. // next loop for calculated columns... this way we only call getMarginInfo in
  157. // this loop and use the marginInfo property in the next...
  158. itemMarginWidth = itemContext.getMarginInfo().width;
  159. if (!itemContext.widthModel.calculated) {
  160. itemWidth = itemContext.getProp('width');
  161. if (typeof itemWidth != 'number') {
  162. itemContext.block(me, 'width');
  163. blocked = true;
  164. }
  165. contentWidth += itemWidth + itemMarginWidth;
  166. }
  167. }
  168. if (!blocked) {
  169. availableWidth = (availableWidth &lt; contentWidth) ? 0 : availableWidth - contentWidth;
  170. for (i = 0; i &lt; len; ++i) {
  171. itemContext = items[i];
  172. if (itemContext.widthModel.calculated) {
  173. itemMarginWidth = itemContext.marginInfo.width; // always set by above loop
  174. itemWidth = itemContext.target.columnWidth;
  175. itemWidth = Math.floor(itemWidth * availableWidth) - itemMarginWidth;
  176. itemWidth = itemContext.setWidth(itemWidth); // constrains to min/maxWidth
  177. contentWidth += itemWidth + itemMarginWidth;
  178. }
  179. }
  180. ownerContext.setContentWidth(contentWidth);
  181. }
  182. // we registered all the values that block this calculation, so abort now if blocked...
  183. return !blocked;
  184. },
  185. calculateHeights: function (ownerContext) {
  186. var me = this,
  187. items = ownerContext.childItems,
  188. len = items.length,
  189. blocked, i, itemContext;
  190. // in order for innerCt to have the proper height, all the items must have height
  191. // correct in the DOM...
  192. blocked = false;
  193. for (i = 0; i &lt; len; ++i) {
  194. itemContext = items[i];
  195. if (!itemContext.hasDomProp('height')) {
  196. itemContext.domBlock(me, 'height');
  197. blocked = true;
  198. }
  199. }
  200. if (!blocked) {
  201. ownerContext.setContentHeight(me.innerCt.getHeight() + ownerContext.targetContext.getPaddingInfo().height);
  202. }
  203. return !blocked;
  204. },
  205. finishedLayout: function (ownerContext) {
  206. var bc = ownerContext.bodyContext;
  207. // Owner may not have a body - this seems to only be needed for Panels.
  208. if (bc &amp;&amp; (Ext.isIE6 || Ext.isIE7 || Ext.isIEQuirks)) {
  209. // Fix for https://sencha.jira.com/browse/EXTJSIV-4979
  210. bc.el.repaint();
  211. }
  212. this.callParent(arguments);
  213. },
  214. getRenderTarget : function() {
  215. return this.innerCt;
  216. }
  217. });
  218. </pre>
  219. </body>
  220. </html>