<!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' && 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>
|