Welcome, Guest. Please login or register.
Did you miss your activation email?
03 Sep 2010, 17:29:02 UTC
Forum home
+  flexdeveloper.eu Forum
|-+  Flex and ActionScript 3.0
| |-+  Flex Builder, Flash Builder & Eclipse (Moderators: JMWhittaker, Jan K, thewarpedcoder, James)
| | |-+  Alignment of menu items in MenuBar
« previous next »
Pages: [1] Print
Author Topic: Alignment of menu items in MenuBar (Read 3035 times)
leviathan
Newbie FD
*
Posts: 5


« on: 24 Nov 2008, 23:53:14 UTC »

Hello:

This might be a dumb question, but I've scroured google and haven't found an answer. How can you change the alignment of menu items within a MenuBar? I have a MenuBar containing a few items (code below) but they always align to the left side of the bar. Is there a way to make then align to the right? Any help would be greatly appreciated!

MXML:

Code:
<mx:MenuBar id="menuBar" labelField="@label" height="35" top="-1" left="282" right="0" styleName="mainMenu">
<mx:filters>
        <mx:DropShadowFilter alpha="0.6" angle="5" distance="25"/>
      </mx:filters>
      <mx:XMLList>
         <menuitem label="Item 1">
          <menuitem label="Sub item 1" />
       </menuitem>
       <menuitem label="Item 2">
           
       </menuitem>
       <menuitem label="Item 3">
           <menuitem label="Sub 2">
           
           </menuitem>
       </menuitem>
   </mx:XMLList>
</mx:MenuBar>
      
« Last Edit: 25 Nov 2008, 11:03:24 UTC by flexy » Logged
prashant
Principal FD
****
Posts: 202


« Reply #1 on: 25 Nov 2008, 11:59:11 UTC »

I don't know what do you mean by menu alignment but there are following css properties in menuBAr
backgroundAlpha="1.0"
    backgroundColor
    backgroundSkin
    borderColor
    color
    cornerRadius
    disabledColor
    fillAlphas
    fillColors
    focusAlpha
    focusRoundedCorners
    fontAntiAliasType
    fontFamily
    fontGridFitType
    fontSharpness
    fontSize
    fontStyle
    fontThickness
    fontWeight
    highlightAlphas
    itemDownSkin
    itemOverSkin
    itemUpSkin
    leading
    rollOverColor
    selectionColor
    textAlign
    textDecoration
    textIndent read this it may help you ..http://livedocs.adobe.com/flex/201/langref/mx/controls/MenuBar.html
Logged
leviathan
Newbie FD
*
Posts: 5


« Reply #2 on: 25 Nov 2008, 14:13:46 UTC »

To be a bit more clear, what I mean by alignment is the placement if the menu items within the menu bar.

For example, if the menu is 500 pixels wide, but there are only two menu items on the bar, the 2 items will always be placed all the way to the far left of the menu bar, leaving empty space at the right. I would like to know whether there is any way to make the items align to the right, so that the empty space is on the left.

None of the CSS properties seem to address this, at least not that I can see. If anyone has any ideas, I would really appreciate it! 
Logged
flexy
flexdeveloper.eu
Guru/Addict FD
*****
Posts: 3,199


Recovering Coffee Addict & Adobe Expert


WWW
« Reply #3 on: 25 Nov 2008, 15:04:24 UTC »

Have you tried applying the style textAlign="center" ?
Logged

leviathan
Newbie FD
*
Posts: 5


« Reply #4 on: 25 Nov 2008, 16:17:15 UTC »

Yes, flexy, I did try that, using both CSS and putting it directly into the MXML. Resulting code and screenshot are attached. There's got to be a way to do it, right? Do I have to make a custom component that extend MenuBar?

<mx:MenuBar id="menuBar" labelField="@label" height="35" top="10" left="10" right="10" textAlign="center">
   <mx:filters>
           <mx:DropShadowFilter alpha="0.6" angle="5" distance="25"/>
         </mx:filters>
         <mx:XMLList>
               <menuitem label="Item 1">
                  <menuitem label="Sub item 1" />
             </menuitem>
             <menuitem label="Item 2">
                 
             </menuitem>
             <menuitem label="Item 3">
                 <menuitem label="Sub 2">
                    
                 </menuitem>
             </menuitem>
         </mx:XMLList>
      </mx:MenuBar>


* screenshot_menu.jpg (19.35 KB, 740x215 - viewed 289 times.)
Logged
flexy
flexdeveloper.eu
Guru/Addict FD
*****
Posts: 3,199


Recovering Coffee Addict & Adobe Expert


WWW
« Reply #5 on: 25 Nov 2008, 22:35:18 UTC »

Hi, if that style property doesn't do it, you're going to have to extend MenuBar and override the method that handles the positioning of menu items. Looks as though it doesn't natively support any alignment other than left (i.e. it directly extends UIComponent, so isn't afforded all the nice layout properties that Containers have)  Sad
Logged

leviathan
Newbie FD
*
Posts: 5


« Reply #6 on: 26 Nov 2008, 13:48:04 UTC »

Ahh - that makes sense. I'm surprised this doesn't come up more often - I found virtually no other discussion of it online. Guess I've got some digging through source code to do. Thanks for the help!
Logged
flexy
flexdeveloper.eu
Guru/Addict FD
*****
Posts: 3,199


Recovering Coffee Addict & Adobe Expert


WWW
« Reply #7 on: 26 Nov 2008, 14:20:16 UTC »

Hey no probs, shame there isn't a quick fix, but please let us know how you get on with extending it  Smiley
Logged

leviathan
Newbie FD
*
Posts: 5


« Reply #8 on: 26 Nov 2008, 16:29:37 UTC »

Just finished, actually. Attached is my quick and dirty extension, AlignableMenuBar. It has an extra property itemAlign which can be set to "left", "right" or "center". Default is left. The only problem is that it still displays as left aligned no matter what in flex builder design mode, but displays with the correct alignment at run time. I don't have time to fix the design mode display right now, but if anyone has any reason to do it, please improve on my work and post.

Also, for future reference, the textAlign property affects the alignment of the sub-items of each menu, so that if you have three items in one menu, you can control how they align within the drop-down rectangle.

Thanks for the help, guys!


* AlignableMenuBar.as (4.19 KB - downloaded 404 times.)

* rightAligned.jpg (19.31 KB, 742x205 - viewed 361 times.)
Logged
flexy
flexdeveloper.eu
Guru/Addict FD
*****
Posts: 3,199


Recovering Coffee Addict & Adobe Expert


WWW
« Reply #9 on: 27 Nov 2008, 10:04:06 UTC »

Great! I tend not to work in design mode at all, but I know that it does have limitations around what it can render... From what I gather, it will only work with extended MXML components, not those extended with ActionScript.
Logged

Pages: [1] Print
« previous next »
Share this on: Twitter Twitter Del.icio.us del.icio.us Digg Digg
Jump to:

©2006-2010 Flexdeveloper.eu/Jodie O'Rourke. All rights reserved.
Adobe®, Adobe® Flash™, Adobe® AIR™ and Adobe® Flex™ are registered trademarks of Adobe Systems Incorporated in the United States and other countries. All rights reserved.

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC