@qooxdoo/framework
Version:
The JS Framework for Coders
152 lines (127 loc) • 4.02 kB
JavaScript
/* ************************************************************************
qooxdoo - the new era of web development
http://qooxdoo.org
Copyright:
2004-2008 1&1 Internet AG, Germany, http://www.1und1.de
License:
MIT: https://opensource.org/licenses/MIT
See the LICENSE file in the project's top-level directory for details.
Authors:
* Sebastian Werner (wpbasti)
************************************************************************ */
/**
* The grow layout stretches all children to the full available size
* but still respects limits configured by min/max values.
*
* It will place all children over each other with the top and left coordinates
* set to <code>0</code>. The {@link qx.ui.container.Stack} and the
* {@link qx.ui.core.scroll.ScrollPane} are using this layout.
*
* *Features*
*
* * Auto-sizing
* * Respects minimum and maximum child dimensions
*
* *Item Properties*
*
* None
*
* *Example*
*
* <pre class="javascript">
* var layout = new qx.ui.layout.Grow();
*
* var w1 = new qx.ui.core.Widget();
* var w2 = new qx.ui.core.Widget();
* var w3 = new qx.ui.core.Widget();
*
* var container = new qx.ui.container.Composite(layout);
* container.add(w1);
* container.add(w2);
* container.add(w3);
* </pre>
*
* *External Documentation*
*
* <a href='https://qooxdoo.org/documentation/#/desktop/layout/grow.md'>
* Extended documentation</a> and links to demos of this layout in the qooxdoo manual.
*/
qx.Class.define("qx.ui.layout.Grow", {
extend: qx.ui.layout.Abstract,
/*
*****************************************************************************
MEMBERS
*****************************************************************************
*/
members: {
/*
---------------------------------------------------------------------------
LAYOUT INTERFACE
---------------------------------------------------------------------------
*/
// overridden
verifyLayoutProperty: qx.core.Environment.select("qx.debug", {
true(item, name, value) {
this.assert(
false,
"The property '" + name + "' is not supported by the Grow layout!"
);
},
false: null
}),
// overridden
renderLayout(availWidth, availHeight, padding) {
var children = this._getLayoutChildren();
var child, size, width, height;
// Render children
for (var i = 0, l = children.length; i < l; i++) {
child = children[i];
size = child.getSizeHint();
width = availWidth;
if (width < size.minWidth) {
width = size.minWidth;
} else if (width > size.maxWidth) {
width = size.maxWidth;
}
height = availHeight;
if (height < size.minHeight) {
height = size.minHeight;
} else if (height > size.maxHeight) {
height = size.maxHeight;
}
child.renderLayout(padding.left, padding.top, width, height);
}
},
// overridden
_computeSizeHint() {
var children = this._getLayoutChildren();
var child, size;
var neededWidth = 0,
neededHeight = 0;
var minWidth = 0,
minHeight = 0;
var maxWidth = Infinity,
maxHeight = Infinity;
// Iterate over children
for (var i = 0, l = children.length; i < l; i++) {
child = children[i];
size = child.getSizeHint();
neededWidth = Math.max(neededWidth, size.width);
neededHeight = Math.max(neededHeight, size.height);
minWidth = Math.max(minWidth, size.minWidth);
minHeight = Math.max(minHeight, size.minHeight);
maxWidth = Math.min(maxWidth, size.maxWidth);
maxHeight = Math.min(maxHeight, size.maxHeight);
}
// Return hint
return {
width: neededWidth,
height: neededHeight,
minWidth: minWidth,
minHeight: minHeight,
maxWidth: maxWidth,
maxHeight: maxHeight
};
}
}
});