예제 #1
0
    def do_allocate(self, actor, allocation, flags):
        def get_visible_children(actor):
            n_visible_children = 0
            for child in actor:
                if not child.props.visible:
                    continue
                n_visible_children += 1

            return n_visible_children

        n_items = get_visible_children(actor)
        if n_items == 0:
            return

        x_offset, y_offset = allocation.get_origin()
        avail_width, avail_height = allocation.get_size()

        self.do_get_preferred_width(actor, avail_width)
        self.do_get_preferred_height(actor, avail_height)

        item_index = 0
        n_items_per_row = 0
        center = Clutter.Point()
        radius = 0
        if self._state == MultiLayout.GRID:
            n_items_per_row = self._get_items_per_row(avail_width)
            item_x = x_offset
            item_y = y_offset
        elif self._state == MultiLayout.CIRCLE:
            radius = min((avail_width - self._cell_width) / 2, (avail_height - self._cell_height) / 2)
            center.x = allocation.x2 / 2
            center.y = allocation.y2 / 2

        for child in actor:
            child_alloc = Clutter.ActorBox()

            if self._state == MultiLayout.GRID:
                if item_index == n_items_per_row:
                    item_index = 0
                    item_x = x_offset
                    item_y += self._cell_height + self._spacing

                child_alloc.x1 = item_x
                child_alloc.y1 = item_y
                item_x += self._cell_width + self._spacing
            elif self._state == MultiLayout.CIRCLE:
                theta = 2.0 * math.pi / n_items * item_index
                child_alloc.x1 = center.x + radius * math.sin(theta) - (self._cell_width / 2)
                child_alloc.y1 = center.y + radius * math.cos(theta) - (self._cell_height / 2)

            child_alloc.x2 = child_alloc.x1 + self._cell_width
            child_alloc.y2 = child_alloc.y1 + self._cell_height

            child.allocate(child_alloc, flags)

            item_index += 1
예제 #2
0
    def do_allocate(self, container, allocation, flags):
        n_items = MultiLayout._get_visible_children(container)
        if n_items == 0:
            return

        x_offset, y_offset = allocation.get_origin()
        avail_width, avail_height = allocation.get_size()

        self.get_preferred_width(container, avail_width)
        self.get_preferred_height(container, avail_height)

        item_index = 0

        if self.state == 0:
            n_items_per_row = MultiLayout._get_items_per_row(
                avail_width, self.cell_width, self.spacing)
            item_x = x_offset
            item_y = y_offset
        elif self.state == 1:
            center = Clutter.Point()
            center.x = allocation.x2 // 2
            center.y = allocation.y2 // 2
            radius = min((avail_width - self.cell_width) // 2,
                         (avail_height - self.cell_height) // 2)

        for child in container.get_children():
            child_allocation = Clutter.ActorBox()

            if not child.is_visible():
                continue

            if self.state == 0:
                if item_index == n_items_per_row:
                    item_index = 0
                    item_x = x_offset
                    item_y += self.cell_height + self.spacing

                child_allocation.x1 = item_x
                child_allocation.y1 = item_y
                child_allocation.x2 = child_allocation.x1 + self.cell_width
                child_allocation.y2 = child_allocation.y1 + self.cell_height

                item_x += self.cell_width + self.spacing
            elif self.state == 1:
                # Should be arythmetic operation for floating point.
                theta = 2 * math.pi / n_items * item_index
                child_allocation.x1 = center.x + radius * math.sin(theta) - (
                    self.cell_width // 2)
                child_allocation.y1 = center.y + radius * -1 * math.cos(
                    theta) - (self.cell_height // 2)
                child_allocation.x2 = child_allocation.x1 + self.cell_width
                child_allocation.y2 = child_allocation.y1 + self.cell_height

            child.allocate(child_allocation, flags)

            item_index += 1
    def do_allocate(self, actor, box, flags):
        for i, row in enumerate(actor.get_children()):
            row_box = Clutter.ActorBox()
            row_height = box.get_height() / VISIBLE_ROWS

            row_box.x1 = box.x1
            row_box.x2 = box.x2
            row_box.y1 = row_height * i
            row_box.y2 = (row_height * i) + row_height

            row.allocate(row_box, flags)
예제 #4
0
    def do_allocate(self, box, flags):
        print("allocate: %s %s %s %s" % (box.x1, box.y1, box.x2, box.y2))

        child_box = Clutter.ActorBox()
        child_box.x1 = 0
        child_box.y1 = 0
        child_box.x2 = box.get_width()
        child_box.y2 = box.get_height()

        self.__child.allocate(child_box, flags)

        Clutter.Actor.do_allocate(self, box, flags)
    def do_allocate(self, actor, box, flags):
        x1 = 0
        for item in actor.get_children():
            item_box = Clutter.ActorBox()

            item_width = item.length * box.get_width()

            item_box.x1 = x1
            item_box.x2 = x1 + item_width
            item_box.y1 = 0
            item_box.y2 = box.get_height()

            item.allocate(item_box, flags)

            x1 += item_width