tuikit/core/container.py
author Radek Brich <radek.brich@devl.cz>
Wed, 26 Mar 2014 09:08:10 +0100
changeset 91 de80e140b0ec
parent 90 781774a8d568
child 92 b97c4e25ed6d
permissions -rw-r--r--
Add clipping for Buffer draw operations.

from tuikit.core.widget import Widget


class Container(Widget):

    """Container widget.

    Can contain other widgets to create hierarchical structure.

    """

    def __init__(self):
        Widget.__init__(self)
        #: List of child widgets.
        self.children = []

    def add(self, widget):
        """Add widget into container."""
        self.children.append(widget)
        widget.parent = self
        widget.window = self.window
        widget.set_theme(self.theme)

    def draw(self, buffer, x=0, y=0):
        """Draw child widgets."""
        for child in self.children:
            with buffer.clip(x, y, child.width, child.height):
                child.draw(buffer,
                           x + child.x,
                           y + child.y)

    def set_theme(self, theme):
        Widget.set_theme(self, theme)
        for child in self.children:
            child.set_theme(theme)