13693261870
2022-09-16 354b3dbfbffb3df45212a2a44dbbf48b4acc2594
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='Ext-ux-layout-Center'>/**
</span> * This layout manager is used to center contents within a container. As a subclass of
 * {@link Ext.layout.container.Fit fit layout}, CenterLayout expects to have one child
 * item; multiple items will be placed overlapping. The layout does not require any config
 * options. Items in the container can use percentage width or height rather than be fit
 * to the full size of the container.
 *
 * Example usage:
 *
 *      // The content panel is centered in the container
 *
 *      var p = Ext.create('Ext.Panel', {
 *          title: 'Center Layout',
 *          layout: 'ux.center',
 *          items: [{
 *              title: 'Centered Content',
 *              width: '75%',  // assign 75% of the container width to the item
 *              html: 'Some content'
 *          }]
 *      });
 *
 * If you leave the title blank and specify no border you can create a non-visual, structural
 * container just for centering the contents.
 *
 *      var p = Ext.create('Ext.Container', {
 *          layout: 'ux.center',
 *          items: [{
 *              title: 'Centered Content',
 *              width: 300,
 *              height: '90%', // assign 90% of the container height to the item
 *              html: 'Some content'
 *          }]
 *      });
 */
Ext.define('Ext.ux.layout.Center', {
    extend: 'Ext.layout.container.Fit',
    alias: 'layout.ux.center',
 
<span id='Ext-ux-layout-Center-property-percentRe'>    percentRe: /^\d+(?:\.\d+)?\%$/,
</span>
<span id='Ext-ux-layout-Center-cfg-itemCls'>    itemCls: 'ux-layout-center-item',
</span>
<span id='Ext-ux-layout-Center-method-initLayout'>    initLayout: function () {
</span>        this.callParent(arguments);
 
        this.owner.addCls('ux-layout-center');
    },
 
<span id='Ext-ux-layout-Center-method-getItemSizePolicy'>    getItemSizePolicy: function (item) {
</span>        var policy = this.callParent(arguments);
        if (typeof item.width == 'number') {
            policy = this.sizePolicies[policy.setsHeight ? 2 : 0];
        }
        return policy;
    },
 
<span id='Ext-ux-layout-Center-method-getPos'>    getPos: function (itemContext, info, dimension) {
</span>        var size = itemContext.props[dimension] + info.margins[dimension],
            pos = Math.round((info.targetSize[dimension] - size) / 2);
 
        return Math.max(pos, 0);
    },
 
<span id='Ext-ux-layout-Center-method-getSize'>    getSize: function (item, info, dimension) {
</span>        var ratio = item[dimension];
 
        if (typeof ratio == 'string' &amp;&amp; this.percentRe.test(ratio)) {
            ratio = parseFloat(ratio) / 100;
        } else {
            ratio = item[dimension + 'Ratio']; // backwards compat
        }
 
        return info.targetSize[dimension] * (ratio || 1) - info.margins[dimension];
    },
 
<span id='Ext-ux-layout-Center-method-positionItemX'>    positionItemX: function (itemContext, info) {
</span>        var left = this.getPos(itemContext, info, 'width');
 
        itemContext.setProp('x', left);
    },
 
<span id='Ext-ux-layout-Center-method-positionItemY'>    positionItemY: function (itemContext, info) {
</span>        var top = this.getPos(itemContext, info, 'height');
 
        itemContext.setProp('y', top);
    },
 
<span id='Ext-ux-layout-Center-method-setItemHeight'>    setItemHeight: function (itemContext, info) {
</span>        var height = this.getSize(itemContext.target, info, 'height');
 
        itemContext.setHeight(height);
    },
 
<span id='Ext-ux-layout-Center-method-setItemWidth'>    setItemWidth: function (itemContext, info) {
</span>        var width = this.getSize(itemContext.target, info, 'width');
 
        itemContext.setWidth(width);
    }
});
</pre>
</body>
</html>