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.

178 lines
6.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. // We are adding these custom layouts to a namespace that does not
  8. // exist by default in Ext, so we have to add the namespace first:
  9. Ext.ns('Ext.ux.layout');
  10. /**
  11. * @class Ext.ux.layout.RowLayout
  12. * @extends Ext.layout.ContainerLayout
  13. * <p>This is the layout style of choice for creating structural layouts in a multi-row format where the height of
  14. * each row can be specified as a percentage or fixed height. Row widths can also be fixed, percentage or auto.
  15. * This class is intended to be extended or created via the layout:'ux.row' {@link Ext.Container#layout} config,
  16. * and should generally not need to be created directly via the new keyword.</p>
  17. * <p>RowLayout does not have any direct config options (other than inherited ones), but it does support a
  18. * specific config property of <b><tt>rowHeight</tt></b> that can be included in the config of any panel added to it. The
  19. * layout will use the rowHeight (if present) or height of each panel during layout to determine how to size each panel.
  20. * If height or rowHeight is not specified for a given panel, its height will default to the panel's height (or auto).</p>
  21. * <p>The height property is always evaluated as pixels, and must be a number greater than or equal to 1.
  22. * The rowHeight property is always evaluated as a percentage, and must be a decimal value greater than 0 and
  23. * less than 1 (e.g., .25).</p>
  24. * <p>The basic rules for specifying row heights are pretty simple. The logic makes two passes through the
  25. * set of contained panels. During the first layout pass, all panels that either have a fixed height or none
  26. * specified (auto) are skipped, but their heights are subtracted from the overall container height. During the second
  27. * pass, all panels with rowHeights are assigned pixel heights in proportion to their percentages based on
  28. * the total <b>remaining</b> container height. In other words, percentage height panels are designed to fill the space
  29. * left over by all the fixed-height and/or auto-height panels. Because of this, while you can specify any number of rows
  30. * with different percentages, the rowHeights must always add up to 1 (or 100%) when added together, otherwise your
  31. * layout may not render as expected. Example usage:</p>
  32. * <pre><code>
  33. // All rows are percentages -- they must add up to 1
  34. var p = new Ext.Panel({
  35. title: 'Row Layout - Percentage Only',
  36. layout:'ux.row',
  37. items: [{
  38. title: 'Row 1',
  39. rowHeight: .25
  40. },{
  41. title: 'Row 2',
  42. rowHeight: .6
  43. },{
  44. title: 'Row 3',
  45. rowHeight: .15
  46. }]
  47. });
  48. // Mix of height and rowHeight -- all rowHeight values must add
  49. // up to 1. The first row will take up exactly 120px, and the last two
  50. // rows will fill the remaining container height.
  51. var p = new Ext.Panel({
  52. title: 'Row Layout - Mixed',
  53. layout:'ux.row',
  54. items: [{
  55. title: 'Row 1',
  56. height: 120,
  57. // standard panel widths are still supported too:
  58. width: '50%' // or 200
  59. },{
  60. title: 'Row 2',
  61. rowHeight: .8,
  62. width: 300
  63. },{
  64. title: 'Row 3',
  65. rowHeight: .2
  66. }]
  67. });
  68. </code></pre>
  69. */
  70. Ext.ux.layout.RowLayout = Ext.extend(Ext.layout.ContainerLayout, {
  71. // private
  72. monitorResize:true,
  73. type: 'row',
  74. // private
  75. allowContainerRemove: false,
  76. // private
  77. isValidParent : function(c, target){
  78. return this.innerCt && c.getPositionEl().dom.parentNode == this.innerCt.dom;
  79. },
  80. getLayoutTargetSize : function() {
  81. var target = this.container.getLayoutTarget(), ret;
  82. if (target) {
  83. ret = target.getViewSize();
  84. // IE in strict mode will return a height of 0 on the 1st pass of getViewSize.
  85. // Use getStyleSize to verify the 0 height, the adjustment pass will then work properly
  86. // with getViewSize
  87. if (Ext.isIE && Ext.isStrict && ret.height == 0){
  88. ret = target.getStyleSize();
  89. }
  90. ret.width -= target.getPadding('lr');
  91. ret.height -= target.getPadding('tb');
  92. }
  93. return ret;
  94. },
  95. renderAll : function(ct, target) {
  96. if(!this.innerCt){
  97. // the innerCt prevents wrapping and shuffling while
  98. // the container is resizing
  99. this.innerCt = target.createChild({cls:'x-column-inner'});
  100. this.innerCt.createChild({cls:'x-clear'});
  101. }
  102. Ext.layout.ColumnLayout.superclass.renderAll.call(this, ct, this.innerCt);
  103. },
  104. // private
  105. onLayout : function(ct, target){
  106. var rs = ct.items.items,
  107. len = rs.length,
  108. r,
  109. m,
  110. i,
  111. margins = [];
  112. this.renderAll(ct, target);
  113. var size = this.getLayoutTargetSize();
  114. if(size.width < 1 && size.height < 1){ // display none?
  115. return;
  116. }
  117. var h = size.height,
  118. ph = h;
  119. this.innerCt.setSize({height:h});
  120. // some rows can be percentages while others are fixed
  121. // so we need to make 2 passes
  122. for(i = 0; i < len; i++){
  123. r = rs[i];
  124. m = r.getPositionEl().getMargins('tb');
  125. margins[i] = m;
  126. if(!r.rowHeight){
  127. ph -= (r.getHeight() + m);
  128. }
  129. }
  130. ph = ph < 0 ? 0 : ph;
  131. for(i = 0; i < len; i++){
  132. r = rs[i];
  133. m = margins[i];
  134. if(r.rowHeight){
  135. r.setSize({height: Math.floor(r.rowHeight*ph) - m});
  136. }
  137. }
  138. // Browsers differ as to when they account for scrollbars. We need to re-measure to see if the scrollbar
  139. // spaces were accounted for properly. If not, re-layout.
  140. if (Ext.isIE) {
  141. if (i = target.getStyle('overflow') && i != 'hidden' && !this.adjustmentPass) {
  142. var ts = this.getLayoutTargetSize();
  143. if (ts.width != size.width){
  144. this.adjustmentPass = true;
  145. this.onLayout(ct, target);
  146. }
  147. }
  148. }
  149. delete this.adjustmentPass;
  150. }
  151. /**
  152. * @property activeItem
  153. * @hide
  154. */
  155. });
  156. Ext.Container.LAYOUTS['ux.row'] = Ext.ux.layout.RowLayout;