How to align elements in a toolbar to left, middle, right
Asked Answered
V

5

14

How can I have the three regions left, middle, right within a toolbar? I know that I can use -> to trigger the right aligned container for all following items but what about center?

Vibrations answered 19/12, 2012 at 9:11 Comment(0)
Y
26

You can archive this with a trick:

Ext.create('Ext.panel.Panel', {
     title: 'Toolbar Fill Example',
     width: 300,
     height: 200,
     tbar : [
         'Item 1',
         { xtype: 'tbfill' },
         'Item 4',
         { xtype: 'tbfill' },
         'Item 2'
     ],
     renderTo: Ext.getBody()
 });

JSFiddle

Note that:

[
    'Item 1',
    '->',
    'Item 4',
    '->',
    'Item 2'
]

is working all the same.

How it work

-> or it's xtype tbfill is nothing more than a empty Component with a flex: 1 configuration.

York answered 19/12, 2012 at 9:16 Comment(2)
This will only keep the middle item centered assuming they all have the same width. You can make the last item, "Item 10102598" and you will see that the middle item is not centered anymore.Dasilva
+ for explaining xtype of ->Unpretentious
M
5
Ext.create('Ext.panel.Panel', {
     title: 'Toolbar Fill Example',
     width: 300,
     height: 200,
     tbarCfg:{
          buttonAlign:'center'  //for center align
         // buttonAlign:'left' //for left align
         // buttonAlign:'right' //for right align
     },
     tbar : [
         'Item 1',
         { xtype: 'tbfill' },
         'Item 4',
         { xtype: 'tbfill' },
         'Item 2'
     ],
     renderTo: Ext.getBody()
 });
Monarchism answered 19/12, 2012 at 13:26 Comment(0)
H
4
For Right:    
bbar: ['->',{
                    xtype: 'button',
                    text: 'xyz',

                }]

For Left:    
bbar: ['<-',{
                    xtype: 'button',
                    text: 'xyz',

                }]
Haematocele answered 20/7, 2016 at 11:32 Comment(0)
E
2

dockedItems: [{ xtype: 'toolbar', buttonAlign:'center', dock: 'top', items: [{ text: 'Docked to the top' }] }]

Ethnomusicology answered 19/12, 2012 at 9:26 Comment(0)
C
0

The easiest answer might be:

layout: {
    type: 'hbox',
    align: 'center',
    pack: 'space-between'
}

Using space-between will setup items evenly upon the width.

Contact answered 27/5 at 11:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.