Merge pull request #411 from akshayaurora/nested_widget

propagate on_touch_down on_touch_up and on_touch_move to kids in Button and Label
This commit is contained in:
qua-non 2012-02-29 22:27:03 -08:00
commit 349f3e22b2
2 changed files with 12 additions and 2 deletions

View File

@ -67,7 +67,8 @@ class Button(Label):
default to [1, 1, 1, 1].
'''
background_normal = StringProperty('atlas://data/images/defaulttheme/button')
background_normal = StringProperty(
'atlas://data/images/defaulttheme/button')
'''Background image of the button used for default graphical representation,
when the button is not pressed.
@ -77,7 +78,8 @@ class Button(Label):
default to 'atlas://data/images/defaulttheme/button'
'''
background_down = StringProperty('atlas://data/images/defaulttheme/button_pressed')
background_down = StringProperty(
'atlas://data/images/defaulttheme/button_pressed')
'''Background image of the button used for default graphical representation,
when the button is pressed.
@ -111,6 +113,8 @@ class Button(Label):
self.state = 'normal'
def on_touch_down(self, touch):
if super(Button, self).on_touch_down(touch):
return True
if not self.collide_point(touch.x, touch.y):
return False
if self in touch.ud:
@ -122,9 +126,13 @@ class Button(Label):
return True
def on_touch_move(self, touch):
if super(Button, self).on_touch_move(touch):
return True
return self in touch.ud
def on_touch_up(self, touch):
if super(Button, self).on_touch_up(touch):
return True
if touch.grab_current is not self:
return
assert(self in touch.ud)

View File

@ -179,6 +179,8 @@ class Label(Widget):
self.texture_size = list(self.texture.size)
def on_touch_down(self, touch):
if super(Label, self).on_touch_down(touch):
return True
if not len(self.refs):
return False
tx, ty = touch.pos