toomuchcookies / pgu

Automatically exported from code.google.com/p/pgu
GNU Lesser General Public License v2.1
0 stars 0 forks source link

widget.get_abs_rect is not quite right #17

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Here is a fix that we use instead of the built in widget method. The one built 
into widget wasn't returning quite the right size.

def get_real_abs_rect(widget):
    """Get the absolute position and dimensions of a widget on the screen.                                                                                                          
    (Does what gui.Widget.get_abs_rect() claims to do, but actually does it                                                                                                         
    correctly.)"""

    # HACK: This gets into the PGU GUI implementation details quite a bit.                                                                                                          

    # The code here is copied from get_abs_rect(self) in pgu/gui/widget.py,                                                                                                         
    # without the lines that add self._rect_content.x/y to x/y.  This seems                                                                                                         
    # slightly less likely to break in a future PGU version than simply                                                                                                             
    # subtracting widget._rect_content.x/y from the results of                                                                                                                      
    # Widget.get_abs_rect(), because the bug in get_abs_rect may be fixed in a                                                                                                      
    # future version.                                                                                                                                                               

    x, y = widget.rect.x, widget.rect.y
    c = getattr(widget,'container',None)
    while c:
        x += c.rect.x
        y += c.rect.y
        if hasattr(c,'_rect_content'):
            x += c._rect_content.x
            y += c._rect_content.y
        c = getattr(c,'container',None)
    return pygame.Rect(x, y, widget.rect.w, widget.rect.h)

Original issue reported on code.google.com by sliverdr...@gmail.com on 6 Jul 2010 at 10:42

GoogleCodeExporter commented 9 years ago
Thanks for finding this - I've made changes in the repository, a release is 
forthcoming.

Original comment by peter.ro...@gmail.com on 2 Jan 2011 at 10:17