PDA

View Full Version : [CLOSED] Column Layout should allow for full height or relative heights



jay@moduscreate.com
6 Jan 2009, 1:39 PM
http://tdg-i.com/img/screencasts/2009-01-06_1641.png


Ext.override(Ext.layout.ColumnLayout, {
onLayout : function(ct, target){
var cs = ct.items.items, len = cs.length, c, i;

if(!this.innerCt){
target.addClass('x-column-layout-ct');

// the innerCt prevents wrapping and shuffling while
// the container is resizing
this.innerCt = target.createChild({cls:'x-column-inner'});
this.innerCt.createChild({cls:'x-clear'});
}
this.renderAll(ct, this.innerCt);

var size = Ext.isIE && target.dom != Ext.getBody().dom ? target.getStyleSize() : target.getViewSize();

if(size.width < 1 && size.height < 1){ // display none?
return;
}

var w = size.width - target.getPadding('lr') - this.scrollOffset,
h = size.height - target.getPadding('tb'),
pw = w;

this.innerCt.setWidth(w);

// some columns can be percentages while others are fixed
// so we need to make 2 passes

for(i = 0; i < len; i++){
c = cs[i];
if(!c.columnWidth){
pw -= (c.getSize().width + c.getEl().getMargins('lr'));

}
}

pw = pw < 0 ? 0 : pw;
for(i = 0; i < len; i++){
c = cs[i];
if(c.columnWidth){
c.setSize(Math.floor(c.columnWidth*pw) - c.getEl().getMargins('lr'));
}
if (c.columnHeight) {//New code here
c.setHeight(size.height * c.columnHeight);
}
}
}
});
test usage:


new Ext.Window({
height : 200,
width : 400,
border : false,
autoScroll : true,
id : 'myWin',
title : 'A Window with a Card layout',
layout : 'column',
defaults : {
frame : true
},
items : [
{
title : 'Col 1',
id : 'col1',
columnWidth : .3,
columnHeight : 1,
layout : 'fit',
items : {
xtype : 'panel',
title : 'blah',
html : 'blah',
frame : true
}


},
{
title : 'Col 2',
html : "20% relative width",
columnWidth : .2

},
{
title : 'Col 3',
html : "100px fixed width",
width : 100,
columnHeight : 1

},
{
title : 'Col 4',
frame : true,
html : "50% relative width",
columnWidth : .5,
columnHeight : 1
}
]

});


untested with anything but fx3 on the mac

Condor
6 Jan 2009, 11:33 PM
You should probably merge your code with Animal's ColumnLayout (http://extjs.com/forum/showthread.php?t=45143) (it supports margins, splitters and fitHeight, but no relative heights).

jay@moduscreate.com
7 Jan 2009, 2:14 AM
Good idea. :)

too bad this stuff didn't make it into core yet :(

Condor
7 Jan 2009, 2:32 AM
Not completely, but Ext 3.0 does have HBox and VBox layouts with some very nice features (e.g. alignment).

jay@moduscreate.com
9 Jan 2009, 6:34 AM
Hell, why even keep Column Layout, other than compatability.... :-\

hbox seems to be column Layout and then some!

emredagli
8 Mar 2010, 11:52 PM
Dear Garcia,
In Ext3.1.1, is your suggestion become:


Ext.override(Ext.layout.ColumnLayout, {

onLayout : function(ct, target){
var cs = ct.items.items, len = cs.length, c, i;

this.renderAll(ct, target);

var size = this.getLayoutTargetSize();

if(size.width < 1 && size.height < 1){ // display none?
return;
}

var w = size.width - this.scrollOffset,
h = size.height,
pw = w;

this.innerCt.setWidth(w);

// some columns can be percentages while others are fixed
// so we need to make 2 passes

for(i = 0; i < len; i++){
c = cs[i];
if(!c.columnWidth){
pw -= (c.getWidth() + c.getPositionEl().getMargins('lr'));
}
}

pw = pw < 0 ? 0 : pw;

for(i = 0; i < len; i++){
c = cs[i];
if(c.columnWidth){
c.setSize(Math.floor(c.columnWidth * pw) - c.getPositionEl().getMargins('lr'));
}
if (c.columnHeight) {//New code here
c.setHeight(size.height * c.columnHeight);
}
}

// Browsers differ as to when they account for scrollbars. We need to re-measure to see if the scrollbar
// spaces were accounted for properly. If not, re-layout.
if (Ext.isIE) {
if (i = target.getStyle('overflow') && i != 'hidden' && !this.adjustmentPass) {
var ts = this.getLayoutTargetSize();
if (ts.width != size.width){
this.adjustmentPass = true;
this.onLayout(ct, target);
}
}
}
delete this.adjustmentPass;
}
});

emredagli
9 Mar 2010, 12:35 AM
Dear Garcia I like your solution and I use many place,
But we need some thing like, I want all columns have same height with the maximum one.
I try following code but it doesnt work:


...
var maxheight = 0;
for(i = 0; i < len; i++){
c = cs[i];
if(c.columnWidth){
c.setSize(Math.floor(c.columnWidth * pw) - c.getPositionEl().getMargins('lr'));
}
var panelHeight = c.getHeight();
maxheight = maxheight < panelHeight ? panelHeight : maxheight;
//if (c.columnHeight) {//New code here
// c.setHeight(size.height * c.columnHeight);
//}
}
for(i = 0; i < len; i++){
c = cs[i];
c.setHeight(maxheight);
}
Actually I could not find the computed height of the panel items in "c" object.
It will be something combination of autoHeight and columnHeight... But how... :)
I need this feature because I want to put seperator between column panels by setting border-left style.

Thanks for your advance.

Animal
9 Mar 2010, 3:33 AM
What you are describing is an hbox layout configured with



align: 'stretchmax'


That stretches the height of all the columns to match the height of the highest one.

jay@moduscreate.com
9 Mar 2010, 3:55 AM
yes, this thread should be closed.