You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

305 lines
14 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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-VBoxLayout'>/**
  19. </span> * @class Ext.layout.VBoxLayout
  20. * @extends Ext.layout.BoxLayout
  21. * &lt;p&gt;A layout that arranges items vertically down a Container. This layout optionally divides available vertical
  22. * space between child items containing a numeric &lt;code&gt;flex&lt;/code&gt; configuration.&lt;/p&gt;
  23. * This layout may also be used to set the widths of child items by configuring it with the {@link #align} option.
  24. */
  25. Ext.layout.VBoxLayout = Ext.extend(Ext.layout.BoxLayout, {
  26. <span id='Ext-layout-VBoxLayout-cfg-align'> /**
  27. </span> * @cfg {String} align
  28. * Controls how the child items of the container are aligned. Acceptable configuration values for this
  29. * property are:
  30. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  31. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;left&lt;/tt&gt;&lt;/b&gt; : &lt;b&gt;Default&lt;/b&gt;&lt;div class=&quot;sub-desc&quot;&gt;child items are aligned horizontally
  32. * at the &lt;b&gt;left&lt;/b&gt; side of the container&lt;/div&gt;&lt;/li&gt;
  33. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;center&lt;/tt&gt;&lt;/b&gt; : &lt;div class=&quot;sub-desc&quot;&gt;child items are aligned horizontally at the
  34. * &lt;b&gt;mid-width&lt;/b&gt; of the container&lt;/div&gt;&lt;/li&gt;
  35. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;stretch&lt;/tt&gt;&lt;/b&gt; : &lt;div class=&quot;sub-desc&quot;&gt;child items are stretched horizontally to fill
  36. * the width of the container&lt;/div&gt;&lt;/li&gt;
  37. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;stretchmax&lt;/tt&gt;&lt;/b&gt; : &lt;div class=&quot;sub-desc&quot;&gt;child items are stretched horizontally to
  38. * the size of the largest item.&lt;/div&gt;&lt;/li&gt;
  39. * &lt;/ul&gt;&lt;/div&gt;
  40. */
  41. <span id='Ext-layout-VBoxLayout-property-type'> align : 'left', // left, center, stretch, strechmax
  42. </span> type: 'vbox',
  43. <span id='Ext-layout-VBoxLayout-cfg-pack'> /**
  44. </span> * @cfg {String} pack
  45. * Controls how the child items of the container are packed together. Acceptable configuration values
  46. * for this property are:
  47. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  48. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;start&lt;/tt&gt;&lt;/b&gt; : &lt;b&gt;Default&lt;/b&gt;&lt;div class=&quot;sub-desc&quot;&gt;child items are packed together at
  49. * &lt;b&gt;top&lt;/b&gt; side of container&lt;/div&gt;&lt;/li&gt;
  50. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;center&lt;/tt&gt;&lt;/b&gt; : &lt;div class=&quot;sub-desc&quot;&gt;child items are packed together at
  51. * &lt;b&gt;mid-height&lt;/b&gt; of container&lt;/div&gt;&lt;/li&gt;
  52. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;end&lt;/tt&gt;&lt;/b&gt; : &lt;div class=&quot;sub-desc&quot;&gt;child items are packed together at &lt;b&gt;bottom&lt;/b&gt;
  53. * side of container&lt;/div&gt;&lt;/li&gt;
  54. * &lt;/ul&gt;&lt;/div&gt;
  55. */
  56. <span id='Ext-layout-VBoxLayout-cfg-flex'> /**
  57. </span> * @cfg {Number} flex
  58. * This configuation option is to be applied to &lt;b&gt;child &lt;tt&gt;items&lt;/tt&gt;&lt;/b&gt; of the container managed
  59. * by this layout. Each child item with a &lt;tt&gt;flex&lt;/tt&gt; property will be flexed &lt;b&gt;vertically&lt;/b&gt;
  60. * according to each item's &lt;b&gt;relative&lt;/b&gt; &lt;tt&gt;flex&lt;/tt&gt; value compared to the sum of all items with
  61. * a &lt;tt&gt;flex&lt;/tt&gt; value specified. Any child items that have either a &lt;tt&gt;flex = 0&lt;/tt&gt; or
  62. * &lt;tt&gt;flex = undefined&lt;/tt&gt; will not be 'flexed' (the initial size will not be changed).
  63. */
  64. <span id='Ext-layout-VBoxLayout-method-calculateChildBoxes'> /**
  65. </span> * @private
  66. * Calculates the size and positioning of each item in the VBox. This iterates over all of the rendered,
  67. * visible items and returns a height, width, top and left for each, as well as a reference to each. Also
  68. * returns meta data such as maxHeight which are useful when resizing layout wrappers such as this.innerCt.
  69. * @param {Array} visibleItems The array of all rendered, visible items to be calculated for
  70. * @param {Object} targetSize Object containing target size and height
  71. * @return {Object} Object containing box measurements for each child, plus meta data
  72. */
  73. calculateChildBoxes: function(visibleItems, targetSize) {
  74. var visibleCount = visibleItems.length,
  75. padding = this.padding,
  76. topOffset = padding.top,
  77. leftOffset = padding.left,
  78. paddingVert = topOffset + padding.bottom,
  79. paddingHoriz = leftOffset + padding.right,
  80. width = targetSize.width - this.scrollOffset,
  81. height = targetSize.height,
  82. availWidth = Math.max(0, width - paddingHoriz),
  83. isStart = this.pack == 'start',
  84. isCenter = this.pack == 'center',
  85. isEnd = this.pack == 'end',
  86. nonFlexHeight= 0,
  87. maxWidth = 0,
  88. totalFlex = 0,
  89. desiredHeight= 0,
  90. minimumHeight= 0,
  91. //used to cache the calculated size and position values for each child item
  92. boxes = [],
  93. //used in the for loops below, just declared here for brevity
  94. child, childWidth, childHeight, childSize, childMargins, canLayout, i, calcs, flexedHeight,
  95. horizMargins, vertMargins, stretchWidth, length;
  96. //gather the total flex of all flexed items and the width taken up by fixed width items
  97. for (i = 0; i &lt; visibleCount; i++) {
  98. child = visibleItems[i];
  99. childHeight = child.height;
  100. childWidth = child.width;
  101. canLayout = !child.hasLayout &amp;&amp; typeof child.doLayout == 'function';
  102. // Static height (numeric) requires no calcs
  103. if (typeof childHeight != 'number') {
  104. // flex and not 'auto' height
  105. if (child.flex &amp;&amp; !childHeight) {
  106. totalFlex += child.flex;
  107. // Not flexed or 'auto' height or undefined height
  108. } else {
  109. //Render and layout sub-containers without a flex or width defined, as otherwise we
  110. //don't know how wide the sub-container should be and cannot calculate flexed widths
  111. if (!childHeight &amp;&amp; canLayout) {
  112. child.doLayout();
  113. }
  114. childSize = child.getSize();
  115. childWidth = childSize.width;
  116. childHeight = childSize.height;
  117. }
  118. }
  119. childMargins = child.margins;
  120. vertMargins = childMargins.top + childMargins.bottom;
  121. nonFlexHeight += vertMargins + (childHeight || 0);
  122. desiredHeight += vertMargins + (child.flex ? child.minHeight || 0 : childHeight);
  123. minimumHeight += vertMargins + (child.minHeight || childHeight || 0);
  124. // Max width for align - force layout of non-layed out subcontainers without a numeric width
  125. if (typeof childWidth != 'number') {
  126. if (canLayout) {
  127. child.doLayout();
  128. }
  129. childWidth = child.getWidth();
  130. }
  131. maxWidth = Math.max(maxWidth, childWidth + childMargins.left + childMargins.right);
  132. //cache the size of each child component
  133. boxes.push({
  134. component: child,
  135. height : childHeight || undefined,
  136. width : childWidth || undefined
  137. });
  138. }
  139. var shortfall = desiredHeight - height,
  140. tooNarrow = minimumHeight &gt; height;
  141. //the height available to the flexed items
  142. var availableHeight = Math.max(0, (height - nonFlexHeight - paddingVert));
  143. if (tooNarrow) {
  144. for (i = 0, length = visibleCount; i &lt; length; i++) {
  145. boxes[i].height = visibleItems[i].minHeight || visibleItems[i].height || boxes[i].height;
  146. }
  147. } else {
  148. //all flexed items should be sized to their minimum width, other items should be shrunk down until
  149. //the shortfall has been accounted for
  150. if (shortfall &gt; 0) {
  151. var minHeights = [];
  152. // When we have a shortfall but are not tooNarrow, we need to shrink the height of each non-flexed item.
  153. // Flexed items are immediately reduced to their minHeight and anything already at minHeight is ignored.
  154. // The remaining items are collected into the minHeights array, which is later used to distribute the shortfall.
  155. for (var index = 0, length = visibleCount; index &lt; length; index++) {
  156. var item = visibleItems[index],
  157. minHeight = item.minHeight || 0;
  158. //shrink each non-flex tab by an equal amount to make them all fit. Flexed items are all
  159. //shrunk to their minHeight because they're flexible and should be the first to lose height
  160. if (item.flex) {
  161. boxes[index].height = minHeight;
  162. } else {
  163. minHeights.push({
  164. minHeight: minHeight,
  165. available: boxes[index].height - minHeight,
  166. index : index
  167. });
  168. }
  169. }
  170. //sort by descending minHeight value
  171. minHeights.sort(function(a, b) {
  172. return a.available &gt; b.available ? 1 : -1;
  173. });
  174. /*
  175. * Distribute the shortfall (difference between total desired with of all items and actual height available)
  176. * between the non-flexed items. We try to distribute the shortfall evenly, but apply it to items with the
  177. * smallest difference between their height and minHeight first, so that if reducing the height by the average
  178. * amount would make that item less than its minHeight, we carry the remainder over to the next item.
  179. */
  180. for (var i = 0, length = minHeights.length; i &lt; length; i++) {
  181. var itemIndex = minHeights[i].index;
  182. if (itemIndex == undefined) {
  183. continue;
  184. }
  185. var item = visibleItems[itemIndex],
  186. box = boxes[itemIndex],
  187. oldHeight = box.height,
  188. minHeight = item.minHeight,
  189. newHeight = Math.max(minHeight, oldHeight - Math.ceil(shortfall / (length - i))),
  190. reduction = oldHeight - newHeight;
  191. boxes[itemIndex].height = newHeight;
  192. shortfall -= reduction;
  193. }
  194. } else {
  195. //temporary variables used in the flex height calculations below
  196. var remainingHeight = availableHeight,
  197. remainingFlex = totalFlex;
  198. //calculate the height of each flexed item
  199. for (i = 0; i &lt; visibleCount; i++) {
  200. child = visibleItems[i];
  201. calcs = boxes[i];
  202. childMargins = child.margins;
  203. horizMargins = childMargins.left + childMargins.right;
  204. if (isStart &amp;&amp; child.flex &amp;&amp; !child.height) {
  205. flexedHeight = Math.ceil((child.flex / remainingFlex) * remainingHeight);
  206. remainingHeight -= flexedHeight;
  207. remainingFlex -= child.flex;
  208. calcs.height = flexedHeight;
  209. calcs.dirtySize = true;
  210. }
  211. }
  212. }
  213. }
  214. if (isCenter) {
  215. topOffset += availableHeight / 2;
  216. } else if (isEnd) {
  217. topOffset += availableHeight;
  218. }
  219. //finally, calculate the left and top position of each item
  220. for (i = 0; i &lt; visibleCount; i++) {
  221. child = visibleItems[i];
  222. calcs = boxes[i];
  223. childMargins = child.margins;
  224. topOffset += childMargins.top;
  225. horizMargins = childMargins.left + childMargins.right;
  226. calcs.left = leftOffset + childMargins.left;
  227. calcs.top = topOffset;
  228. switch (this.align) {
  229. case 'stretch':
  230. stretchWidth = availWidth - horizMargins;
  231. calcs.width = stretchWidth.constrain(child.minWidth || 0, child.maxWidth || 1000000);
  232. calcs.dirtySize = true;
  233. break;
  234. case 'stretchmax':
  235. stretchWidth = maxWidth - horizMargins;
  236. calcs.width = stretchWidth.constrain(child.minWidth || 0, child.maxWidth || 1000000);
  237. calcs.dirtySize = true;
  238. break;
  239. case 'center':
  240. var diff = availWidth - calcs.width - horizMargins;
  241. if (diff &gt; 0) {
  242. calcs.left = leftOffset + horizMargins + (diff / 2);
  243. }
  244. }
  245. topOffset += calcs.height + childMargins.bottom;
  246. }
  247. return {
  248. boxes: boxes,
  249. meta : {
  250. maxWidth : maxWidth,
  251. nonFlexHeight: nonFlexHeight,
  252. desiredHeight: desiredHeight,
  253. minimumHeight: minimumHeight,
  254. shortfall : desiredHeight - height,
  255. tooNarrow : tooNarrow
  256. }
  257. };
  258. }
  259. });
  260. Ext.Container.LAYOUTS.vbox = Ext.layout.VBoxLayout;
  261. </pre>
  262. </body>
  263. </html>