How to use the gaphas.geometry.Rectangle function in gaphas

To help you get started, we’ve selected a few gaphas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gaphor / gaphor / gaphor / diagram / presentation.py View on Github external
def shape_bounds(shape, align):
            if shape:
                size = shape.size(cr)
                x, y = text_point_at_line(points, size, align)
                return Rectangle(x, y, *size)
github gaphor / gaphor / gaphor / diagram / shapes.py View on Github external
def draw(self, context, bounding_box):
        padding = self.style("padding")
        vertical_spacing = self.style("vertical-spacing")
        x = bounding_box.x + padding[Padding.LEFT]
        y = bounding_box.y + padding[Padding.TOP]
        w = bounding_box.width - padding[Padding.RIGHT] - padding[Padding.LEFT]
        h = bounding_box.height - padding[Padding.TOP] - padding[Padding.BOTTOM]
        self.icon.draw(context, Rectangle(x, y, w, h))
        y = y + bounding_box.height + vertical_spacing
        for c, (cw, ch) in zip(self.children, self.sizes):
            mw = max(w, cw)
            c.draw(context, Rectangle(x - (mw - w) / 2, y, mw, ch))
            y += ch
github gaphor / gaphor / gaphor / diagram / classes / association.py View on Github external
def __init__(self, owner, end=None):
        super().__init__(id=False)  # Transient object
        self.canvas = None
        self._owner = owner
        self._end = end

        # Rendered text for name and multiplicity
        self._name = None
        self._mult = None

        self._name_bounds = Rectangle()
        self._mult_bounds = Rectangle()
        self.font = "sans 10"
github gaphor / gaphor / gaphor / diagram / classes / association.py View on Github external
align_left = (h and not r) or (r and not h)
            align_bottom = (v and not r) or (r and not v)
            if align_left:
                name_dx = ofs
                mult_dx = ofs
            else:
                name_dx = -ofs - name_w
                mult_dx = -ofs - mult_w
            if align_bottom:
                name_dy = -ofs - name_h
                mult_dy = -ofs - name_h - mult_h
            else:
                name_dy = ofs 
                mult_dy = ofs + mult_h

        self._name_bounds = Rectangle(p1[0] + name_dx,
                                      p1[1] + name_dy,
                                      width=name_w,
                                      height=name_h)

        self._mult_bounds = Rectangle(p1[0] + mult_dx,
                                      p1[1] + mult_dy,
                                      width=mult_w,
                                      height=mult_h)
github gaphor / gaphor / gaphor / diagram / textelement.py View on Github external
def __init__(self, attr, style=None, pattern=None, visible=None, editable=False):
        """
        Create new text element with bounds (0, 0, 10, 10) and empty text.

        Parameters:
         - visible: function, which evaluates to True/False if text should
                    be visible
        """
        super(TextElement, self).__init__()

        self._bounds = Rectangle(0, 0, width=15, height=10)

        # create default style for a text element
        self._style = Style()
        self._style.add("text-padding", (2, 2, 2, 2))
        self._style.add("text-align", (ALIGN_CENTER, ALIGN_TOP))
        self._style.add("text-outside", False)
        self._style.add("text-rotated", False)
        self._style.add("text-align-str", None)
        self._style.add("font", DEFAULT_TEXT_FONT)
        if style:
            self._style.update(style)

        self.attr = attr
        self._text = ""

        if visible:
github gaphor / gaphor / gaphor / diagram / classes / association.py View on Github external
mult_dx = ofs
            else:
                name_dx = -ofs - name_w
                mult_dx = -ofs - mult_w
            if align_bottom:
                name_dy = -ofs - name_h
                mult_dy = -ofs - name_h - mult_h
            else:
                name_dy = ofs
                mult_dy = ofs + mult_h

        self._name_bounds = Rectangle(
            p1[0] + name_dx, p1[1] + name_dy, width=name_w, height=name_h
        )

        self._mult_bounds = Rectangle(
            p1[0] + mult_dx, p1[1] + mult_dy, width=mult_w, height=mult_h
        )
github gaphor / gaphor / gaphor / diagram / classes / association.py View on Github external
def __init__(self, owner, end=None):
        super().__init__(id=False)  # Transient object
        self.canvas = None
        self._owner = owner
        self._end = end

        # Rendered text for name and multiplicity
        self._name = None
        self._mult = None

        self._name_bounds = Rectangle()
        self._mult_bounds = Rectangle()
        self.font = "sans 10"
github gaphor / gaphor / gaphor / diagram / inlineeditors.py View on Github external
def find(*shapes):
        for shape in shapes:
            if isinstance(shape, (_shapes.Box, _shapes.IconBox)):
                box = find(*shape.children)
                if box:
                    return box
            elif isinstance(shape, _shapes.EditableText):
                box = shape.bounding_box
                i2v = view.get_matrix_i2v(item)
                x, y = i2v.transform_point(box.x, box.y)
                w, h = i2v.transform_distance(box.width, box.height)
                # Add a little bit of padding, 'cause that makes it look so good
                return Rectangle(x - 6, y - 6, w + 12, h + 12)