How to write your own layout in ExtJs 4 or 3

I want to write your own layout .. (eg vbox, borderetc.) ... I want to create a layout that places it in the middle (verticall - middle, horizontal - Intermediate).

Is there anyone who could show me how this control will look in extJs or can provide some links that might be useful?


I have this example from

http://dev.sencha.com/deploy/dev/examples/layout-browser/layout-browser.html

Ext.ux.layout.CenterLayout = Ext.extend(Ext.layout.FitLayout, {
// private
setItemSize : function(item, size){
    this.container.addClass('ux-layout-center');
    item.addClass('ux-layout-center-item');
    if(item && size.height > 0){
        if(item.width){
            size.width = item.width;
        }
        item.setSize(size);
    }
}
});

Ext.Container.LAYOUTS['ux.center'] = Ext.ux.layout.CenterLayout;

But that gives me more questions than answers. What is setItemSizeHow does it work? When? What for? Ect. What is required item.setSize? How it works? When? What for? Ect.

+3
source share
3 answers

ExtJS 3, Ext.ux.Layout.CenterLayout , , ?

http://dev.sencha.com/deploy/dev/examples/layout-browser/layout-browser.html


: , .

Ext.ns('Ext.ux.layout');

Ext.ux.layout.CenterLayout = Ext.extend(Ext.layout.ContainerLayout, {
    monitorResize:true,
    type: 'ux.center',
    getLayoutTargetSize : function() {
        var target = this.container.getLayoutTarget();
        if (!target) {
            return {};
        }
        return target.getStyleSize();
    },
    onLayout : function(ct, target){
        Ext.ux.layout.CenterLayout.superclass.onLayout.call(this, ct, target);
        if(!ct.collapsed){
            this.setItemSize(this.activeItem || ct.items.itemAt(0), this.getLayoutTargetSize());
        }
    },
    setItemSize : function(item, size){
        var left = (size.width - item.getWidth()) / 2;
        var top  = (size.height - item.getHeight()) / 2;

        var pos = Ext.apply(item.getEl().getPositioning(), {
            position : 'absolute',
            left     : left,
            top      : top
        });
        item.getEl().setPositioning(pos);
    }
});
Ext.Container.LAYOUTS['ux.center'] = Ext.ux.layout.CenterLayout;
+4
+2
Ext.create('Ext.container.Viewport', {
        layout: {
            type: 'hbox',
            pack: 'center',
            align: 'middle'
        },
        items: [
            {
                html: 'Hello World'
            }
        ]
    });
+2

All Articles