1. #1
    Touch Premium Member
    Join Date
    Jun 2010
    Posts
    324
    Vote Rating
    2
    profunctional is on a distinguished road

      0  

    Default docked toolbar and button positioning. align attribute is ignored.

    docked toolbar and button positioning. align attribute is ignored.


    I have the following code below. Setting aligned to both left and right does nothing. Both buttons are left aligned. I also tried setting the alignment to centered. The buttons are still left aligned. Is there any reason why these are ignored?

    dockedItems:
    [
    {
    dock: 'top',
    title: 'Dashboard',
    xtype: 'toolbar',
    items:
    [
    {
    xtype: 'button',
    ui: 'mask',
    iconCls: 'refresh',
    stretch: false,
    align: 'left',
    handler: refresh
    },
    {
    xtype: 'button',
    ui: 'mask',
    iconCls: 'add',
    stretch: false,
    align: 'right',
    handler: refresh
    }
    ]
    }

  2. #2
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Vote Rating
    9
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    There is no align property available on buttons inside a Sencha Touch toolbar.

    To align your button on the right you can put in a spacer in between the buttons. In your case:

    Code:
    items: [{
        xtype: 'button',
        ui: 'mask',
        iconCls: 'refresh',
        handler: refresh
    }, {xtype: 'spacer'}, {
        xtype: 'button',
        ui: 'mask',
        iconCls: 'add',
        handler: refresh
    }]
    Just to explain the reason behind this. In Sencha Touch, toolbars are nothing more than containers with an hbox layout and custom styling. So in order to alter the alignment, the pack and other hbox layout configuration you could do:

    Code:
    layout: {
        pack: 'justify',
        align: 'center' // align center is the default
    }
    This also means that you can set the property "flex" on every item inside a toolbar to have them take up the remaining space.

    Finally I just wanted to paste the code for the Spacer class to show you what it does.

    Code:
    Ext.Spacer = Ext.extend(Ext.Component, {
        initComponent : function() {
            if (!this.width) {
                this.flex = 1;
            }
    
            Ext.Spacer.superclass.initComponent.call(this);
        }
    });
    As you can see you can give a spacer a fixed width, and if you dont do that it will use a flex of one. This means that if you use the following order of items in your toolbar [button, spacer, button, spacer, button], you will get a button on the left, one in the center and one on the right with the spacers both taking up an equal amount of space.

    I hope this answered your question.

  3. #3
    Touch Premium Member
    Join Date
    Jun 2010
    Posts
    324
    Vote Rating
    2
    profunctional is on a distinguished road

      0  

    Default


    Thanks for the detailed explanation. The spacer did the trick.

  4. #4
    Sencha User
    Join Date
    Jan 2012
    Location
    Atlanta, Georgia
    Posts
    40
    Vote Rating
    2
    mbritton is on a distinguished road

      0  

    Default


    I had to explicitly set flex:1 to get the spacer to scale properly in Ext JS 4.

    Code:
    dockedItems:[{
        xtype:'toolbar',
        dock:'top',
        items:[
        {
            xtype:'tbspacer',
            flex:1
        },
        {
            id:'toggleSearchButton',
            enableToggle:true,
            type:'button',
            text:'Search',
            pressed:false
        }]
    }],

  5. #5
    Sencha User
    Join Date
    Jun 2012
    Posts
    2
    Vote Rating
    0
    jagadale11 is on a distinguished road

      0  

    Default http://www.sencha.com/forum/images/smilies/35.gif

    http://www.sencha.com/forum/images/smilies/35.gif


    Quote Originally Posted by mbritton View Post
    I had to explicitly set flex:1 to get the spacer to scale properly in Ext JS 4.

    Code:
    dockedItems:[{
        xtype:'toolbar',
        dock:'top',
        items:[
        {
            xtype:'tbspacer',
            flex:1
        },
        {
            id:'toggleSearchButton',
            enableToggle:true,
            type:'button',
            text:'Search',
            pressed:false
        }]
    }],

Similar Threads

  1. How to align a button inside a toolbar
    By shajeerkt in forum Ext GWT: Discussion
    Replies: 2
    Last Post: 1 Feb 2010, 1:22 AM
  2. Right align toolbar button
    By ncubeait in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 29 Jun 2009, 2:08 AM
  3. Button align in a toolbar.
    By joao_candido in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 12 Jan 2009, 7:13 AM
  4. Align div to toolbar button?
    By J. Brisbin in forum Ext 1.x: Help & Discussion
    Replies: 0
    Last Post: 17 Sep 2007, 6:54 AM

Thread Participants: 3