旋转整个窗口小部件,不仅是画布 [英] rotate entire widget, not only its canvas

查看:74
本文介绍了旋转整个窗口小部件,不仅是画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此示例中,我们可以看到画布的旋转.但是,单击按钮的角未注册.如何旋转整个按钮?

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?

推荐答案

基于激进的回答,我在分散布局上创建了一个按钮,该按钮的 hitbox 设置正确.

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

我使用分散布局而不是分散布局,因为它会将其大小传递给子窗口小部件.在此示例中不需要do_x: False,因为按钮可以拦截触摸事件,但是如果我放置标签,它将在触摸时移动.

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.

这篇关于旋转整个窗口小部件,不仅是画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆