Web Interface For Lite Argus Control modules
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.

300 lines
14 KiB

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