# length of texts/buttons

hello!

my menu (3 buttons) looks like this:
help | search | impressum

each button has its hardcoded position.

my program also supports other languages like german or italian, so it would then look like this:

hilfe | suche | impressum

so now the buttons have different lengths and are no more at the correct position.
i tried to calc the right end position of button1, and then set posX of button2 to that position (plus some small value for a little space between those two)
the problem is: nodePath.getBounds() gives me the local coordinate space of my button.

how can i calculate the bounds related to the whole pandawindow so that i can set button2 to (button1.getBounds[1] + 0.1) ?

ok, 5 minutes after my above post i found out.
for all others having the problem:

``````button1 = DirectButton(text = "Hilfe",text_align = TextNode.ALeft,pos = (-1.2, -1.4, -0.95))

nextX = 0.05 + button1.getPos()[0] + ((button1.getBounds()[1] + math.fabs(button1.getBounds()[0]))/2.666666)

button2 = DirectButton(text = "Produktregistrierung",text_align = TextNode.ALeft,pos = (nextX, -1.4, -0.95))``````

i calculate the local lenght of the first button (button1) by adding the positive values of its left and right bounds. then i transform the length to the window (divide it with 2.666666). then i just set the second buttons posX to (posXOfbutton1 + someSpace + transformedLengthOfButton1).

greets

you shouldnâ€™t hardcode the 2.66666

``````import direct.directbase.DirectStart
from direct.gui.DirectGui import DirectButton
from random import choice, randint
from string import ascii_letters

gap=.05 # gap between 2 buttons
x=-base.camLens.getAspectRatio()-gap*.5
for b in buttons:
# randomize text
b['text'] = '< -%s >' %((choice(ascii_letters)+'-')*randint(2,8))
b.resetFrameSize() # force update after changing text
bLen = gap + (b.getBounds()[1]-b.getBounds()[0])*b.getSx()
b.setX(x+bLen*.5)
x+=bLen