def rectangle(self, topleft, width, height, style = '_polygon'): for s in self.styles[style]: a = Vector(topleft) b = a + Vector(width, 0) c = a + Vector(width, height) d = a + Vector(0, height) self._primitives.append(DP_Polygon([a,b,c,d], s))
def __init__(self, a, b, style='_path', stylesheet=default_styles): super().__init__(style, stylesheet) start = Vector(a) end = Vector(b) self._box = Box(min(start.y, end.y), max(start.x, end.x), max(start.y, end.y), min(start.x, end.x)) self.setanchor('start', start) self.setanchor('end', end)
def draw(self, canvas): right = Vector(60, 0) pos = self.globalposition() a = pos + self._a('start') b = pos + self._a('end') u = a + right v = b - right canvas.bezier([a, u, v, b])
def __init__(self, style='', stylesheet=default_styles, xy=(0, 0)): self._position = Vector(xy) self._box = Box(0, 0, 0, 0) self.anchor = defaultdict(Vector) self.tags = set() self.stylesheet = stylesheet self.style = style self.parent = None self.padding = float(next(stylesheet[style])['padding']) self.margin = float(next(stylesheet[style])['margin'])
def _align(self, anchor, point): return Vector(point) - self._a(anchor)
def setanchor(self, label, v): self.anchor[label] = Vector(v)
def __init__(self, elements, style='', stylesheet=default_styles): super().__init__(elements, style, stylesheet) for e in self.elements: e.setwidth(self.width) self.alignelements('top', 'bottom', Vector(0, 1))
def __init__(self, elements, style='', stylesheet=default_styles): super().__init__(elements, style, stylesheet) for e in self.elements: e.setheight(self.height) self.alignelements('left', 'right', Vector(1, 0))
def alignelements(self, anchor1, anchor2, gapvector=Vector(0, 0)): for i in range(1, len(self.elements)): e0 = self.elements[i - 1] e1 = self.elements[i] gap = gapvector * max(e0.padding, e1.padding) e1.align(anchor1, e0.a(anchor2) + gap)
def position(self, x, y=None): self._position = Vector(x, y)