user2097818
user2097818

Reputation: 1881

Kivy Render Children Instructions

So if I have a Layout that contains several children widget instances, how and when does the parent make sure they are all drawn to the screen? Assume our children are being animated in some simple fashion, so they constantly need to be updated.

If my ParentLayout class is roughly like so:

class ParentLayout(ScatterLayout):
    def __init__(self):
        #
        with self.canvas.before:
            #hook A
            #switchout framebuffer here?
            pass
        with self.canvas:
            #hook B
            pass
        with self.canvas.after:
            #hook C
            #recover framebuffer with just this Widget?
            pass

Q1: Are child drawables ultimately drawn to the parent.canvas? A1: No they are not. canvas is full of instructions; its not a buffer.

It seems like children would be drawn somewhere around hook B, but I have no way to confirm or test this.

I am essentially trying to take a screenshot of certain groups of widgets after they have been freshly rendered into a buffer. I want to retrieve a texture representing the canvas of the ParentLayout and its children... no more, no less.

Upvotes: 1

Views: 123

Answers (1)

inclement
inclement

Reputation: 29460

Widget already has a method that does this, Widget.export_to_png.

The canvas is ultimately an ordered list of instructions (mapping to opengl instructions). Drawing the screen involves running through this list, and is guaranteed to happen once per frame, so a simple solution in general is to Clock.schedule_once(your_function, 0) which should run the next frame after everything is rendered.

Upvotes: 1

Related Questions