8 Replies Latest reply on Nov 18, 2008 4:06 PM by netfish00

    dynamically position text/buttons


      I have a dynamic text "font size" between a "+" text button and a "-" text button. The "font size" text will change between English text "font size" and Spanish text "tamaño del texto". I have a very hard time dynamically positioning the "+" and the "-" text buttons so that the spacing between the buttons and the text is the same.

      The following code does not really work.

      spacing = 5;
      btFontIncrease._x = dtFontSize._x - btFontIncrease._width - spacing;
      btFontDecrease._x = dtFontSize._x + dtFontSize._width + spacing;

      The problem is that there are margins before and after the text even though the margin values default to 0.

      What else can I do?

        • 1. Re: dynamically position text/buttons
          Rothrock Level 5
          Well the margin values on all text boxes are something like 2 pixels on each side and that is a constant. So that shouldn't matter. Unless you have a large text field and you aren't resizing it.

          So be sure to set the autoSize property on you text field to true.

          And don't use a center aligned textfield. Use a left aligned text field. Then when it changes center it on the place it needs to go and position the other two relative to that.
          • 2. Re: dynamically position text/buttons
            netfish00 Level 1
            Thanks for the reply.

            Unfortunately, the margins on each side are different for each letter and for each font.
            • 3. Re: dynamically position text/buttons
              rlc5611 Level 1
              Why was getTextExtent deprecated?
              • 4. Re: dynamically position text/buttons
                netfish00 Level 1
                If getTextExtent still exists, it may help me position my +/- button:-(
                • 5. Re: dynamically position text/buttons
                  Rothrock Level 5
                  I just made 5 or 6 different text boxes and changed the size of each and selected a few random fonts from my list. If all the textfields lined up at 100 then all the words started within a fraction of a pixel of 102.

                  So I don't think you understand what I'm saying. Make sure you have your textfield autoSize set to true. In that case there will be no margins because the textfield will size itself to the size needed for the text. Then you will know how wide the text is.

                  Yes getTextExtent is still there it was a mistake in the documentation that said it was depreciated. However there are a few times where it doesn't actually work well and in those cases what you do is make an invisible textfield with autosize set to true and measure the sizes there. Exactly what I am telling you here.

                  • 6. Re: dynamically position text/buttons
                    netfish00 Level 1
                    Rothrock, I really appreciate your help. I understand what you mean. However, some fonts work like what you say. But some don't.

                    Can you try this font with this text "font size"? The font is free.

                    Here is the code that I use.

                    dtFontSize.text = "font size";
                    dtFontSize.autoSize = "left";
                    btFontDecrease._width = btFontIncrease._width;
                    btFontIncrease._x = dtFontSize._x - btFontIncrease._width;
                    btFontDecrease._x = dtFontSize._x + dtFontSize._width;

                    Here are 2 screenshots.


                    1.gif is the zoom in version in design mode. As you can see, the "spacing/margin" of the 1st and the last letter are different already.

                    2.gif is the version in run time. The calculated positions are even worse.

                    What do you think?
                    • 7. Re: dynamically position text/buttons
                      Rothrock Level 5
                      I haven't come up with a solution. My guess is that it is a combination of things.

                      First with free things you often get what you pay for. I'm not sure, but some fonts have some kinda crazy metrics and glyph placements.I tried experimenting with some of the more exuberant cursive fonts on my maching and the "f" didn't move over the way it seems to for your example. So I would suggest tyring it with just some regular font like Arial or Verdana and seeing if it works there.

                      I might also try turing on the border and background for the text fields and see if you can figure out anything regarding the placement for those.

                      I would probably also break apart the de/increase buttons from text fields so they are just artwork.
                      • 8. Re: dynamically position text/buttons
                        netfish00 Level 1

                        I think you are right that the font was not well designed. Thank you for your suggestion.