为什么看起来这些小部件在Kivy中共享相同的画布? [英] Why does it seem that the widgets share the same canvas in Kivy?

查看:77
本文介绍了为什么看起来这些小部件在Kivy中共享相同的画布?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Kivy文档指定"Kivy中的每个小部件都已经具有默认情况下是他们的画布" .但是,在实践中,这些小部件似乎拥有对整个窗口的共享画布的引用,而不是仅仅为它们自己拥有一个.

The Kivy documentation specifies that "each widget in Kivy already have by default their Canvas". However, in practice, it seems that the widgets hold a reference to a shared canvas of the whole window instead of having one just for themselves.

当我使用RotateTranslateScalecontext_instrucions时,这一点变得更加清楚.如果我在特定的Widget中使用Rotate,它将影响后续的小部件.一切似乎都在旋转.在绘制其他任何内容之前,我必须先取消Rotate画布.而且,它是否在旋转的画布中还是在下一个画布中并不重要.指令Color也会发生同样的情况.

This becomes more clear when I use the context_instrucions of Rotate, Translate or Scale. If I Rotate inside a particular Widget, it will affect subsequent widgets. Everything seems to have rotated. I have to un-Rotate the canvas before drawing anything else. Moreover, it doesn't really matter if it is in the rotated canvas or in the next one. The same happens with the instruction Color.

对此默认行为施加和例外的唯一方法似乎是RelativeLayout.在那种情况下,我刚才说的所有内容都与RelativeLayout有关,除了Color仍然是全局的.有人可以说颜色不是定位指令,并且 RelativeLayout 是相对的定位. RotateTranslate是位置指令,但它是Scale吗?

The only way to impose and exception to this default behaviour seems to be the RelativeLayout. In that case, all what I just said became relative to the RelativeLayout except Color which continue being global. One can argue that Color is not a positioning instruction and RelativeLayout is relative just to position. Rotate and Translate are position instructions but is it Scale?

我实际上只是用具体示例完成了博客文章

I actually just finish a blog post with an specific example

我显然丢失了一些东西,每个小部件的一部分都有自己的canvas.因此,基本上我的问题是,为什么这些小部件似乎在Kivy中共享相同的画布?

I am obviously missing something with the part of each Widget has its own canvas. So, basically my question is why does it seems that the widgets share the same canvas in Kivy?

推荐答案

我使自己陷入了一个大错误.这一切都是因为名称canvas令人困惑.我开始认为画布是我们可以绘制的空间.但不是,该文档实际上在这里非常清晰:

I drove myself into a big mistake. This all started because the name canvas is confusing. I started to think that a canvas was a space in which we can draw. But not, the documentation is actually very clear here:

使用此类添加要用于绘制图形或上下文的说明在这里:

画布是一个图形对象,其中包含用于小部件图形表示的所有绘图指令(因此,画布是一组指令(如果考虑canvas.beforecanvas.after,则是一组指令). 指令不会绘制或在canvas上执行,指令只会添加到canvas .指令在坐标空间中执行.例如,当画布中有Rotate指令时,它将在显示在坐标空间中之前应用于任何VertexInstruction(例如Line).

So, a canvas is a set of instructions (or sets if we think about canvas.before and canvas.after). The instructions don't draw or are executed on a canvas, the instructions are just added to a canvas. The instructions are executed in the coordinate space. For example, when there is a Rotate instruction in the canvas, it is going to be applied to any VertexInstruction (a Line for example) before being displayed in the coordinate space.

因此,小部件不共享canvas,但是我们添加到canvas的指令共享相同的坐标空间.

So, the widgets don't share a canvas but the instructions we add to the canvas share the same coordinate space.

这篇关于为什么看起来这些小部件在Kivy中共享相同的画布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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