I’ve written some code for laying out nodepaths, for example lining them up side-by-side, using getTightBounds() to get the boundaries of the nodepath objects. It works, but not with DirectGUI objects. I want to make DirectGUI compatible with my code.
If you call getTightBounds() on a DirectGui object you just get (0,0,0,0), which is why my code doesn’t work. Looking at DirectGuiBase.py, although DirectGuiWidget inherits NodePath, it actually keeps a list of nodepaths in self.stateNodePath. I’m guessing those nodepaths in the list are where the geometry for the widget in each of its states gets put, so the nodepath self does not hold any geometry so its bounds are 0.
DirectGuiWidget overrides getBounds() and returns the bounds of the nodepath for the current state:
def getBounds(self, state = 0):
self.stateNodePath[state].calcTightBounds(self.ll, self.ur)
# Scale bounds to give a pad around graphics
self.bounds = [self.ll[0] - self['pad'][0],
self.ur[0] + self['pad'][0],
self.ll[2] - self['pad'][1],
self.ur[2] + self['pad'][1]]
return self.bounds
So getBounds returns some useful results for DirectGui objects. To make them compatible with my code a working getTightBounds is needed, so I tried to implement one based on getBounds in a class that wraps a DirectGui object:
class DirectGuiWrapper:
def __init__(self, dgui):
self._dgui = dgui
def __getattr__(self, n):
return getattr(self._dgui, n)
def getTightBounds(self):
l,r,b,t = self.getBounds()
bottom_left = Point3(l,0,b)
top_right = Point3(r,0,t)
return (bottom_left,top_right)
As you can see it just takes the result of getBounds() and translates it to the (Point3,Point3) type that getTightBounds() normally returns for nodepaths. But this doesn’t seem to work, the DirectGui objects still don’t get lined up right by my layout code, which works fine for other nodepaths. I know I don’t fully understand DirectGuiBase.py. There’s something going on with self.guiItem, for one thing.