length of texts/buttons


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) ?

thanks in advance

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).


you shouldn’t hardcode the 2.66666

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

def changeBtnText(task):
    gap=.05 # gap between 2 buttons
    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()
    task.delayTime=1 # set task delay
    return Task.again


# to avoid the first delay, don't use taskMgr.doMethodLater,
# add it normally, then set the delay in the task