Reputation: 4693
In this example, we can see a rotation of the canvas. But clicking the button's corners isn't registered. How can I rotate the entire button?
Upvotes: 0
Views: 362
Reputation: 4693
Based on inclement's answer, I've created a button on a scatter layout, which has its hitbox set correctly.
from kivy.app import App
from kivy.lang import Builder
kv = '''
FloatLayout:
ScatterLayout:
size_hint: None, None
size: 200, 200
pos_hint: {'center_x': .5, 'center_y': .5}
rotation: 45
do_rotation: False
do_scale: False
do_translation: False
Button:
text: 'hello world'
'''
class RotationApp(App):
def build(self):
return Builder.load_string(kv)
RotationApp().run()
I used scatter layout instead of scatter, because it passes its size to children widgets. The do_x: False
aren't needed in this example, because button intercepts touching events, but if I placed a label, it would move on touch.
Upvotes: 0
Reputation: 29450
You can probably override its collide_point
method to account for the rotation by transforming the touch coordinates.
If you use the widget system (e.g. putting the Button in a Scatter), the collision is taken care of for you.
Upvotes: 3