def selection(self, start, stop, base=0): if start <= base + len(self.source) and base <= stop: start = clamp(0, len(self.source), start - base) stop = clamp(0, len(self.source), stop - base) (x0, y0), (w0, h0) = self.surface.selection(start, stop) (x1, y1), (w1, h1) = self.box.value return rectangle(vec2(x0, y1), vec2(w0, h1))
def selection(self, head, tail): head = clamp(0, len(self.offsets) - 1, head) tail = clamp(0, len(self.offsets) - 1, tail) start = min(head, tail) stop = max(head, tail) base = self.geometry.base size = self.geometry.size x0 = self.offsets[start] x1 = self.offsets[stop] return rectangle(base + vec2(x0-1, -1), vec2(x1 - x0 + 1, size.y+1))
def _selection(inner, outer, direction, start, stop, base=0): if start <= base + 1 and base <= stop: start = clamp(0, 1, start - base) stop = clamp(0, 1, stop - base) if direction == 'x': x0 = (inner.left.value, inner.right.value)[start] x1 = (inner.left.value, inner.right.value)[stop] y0 = outer.top.value y1 = outer.bottom.value else: x0 = outer.left.value x1 = outer.right.value y0 = (inner.top.value, inner.bottom.value)[start] y1 = (inner.top.value, inner.bottom.value)[stop] return rectangle(vec2(x0,y0), vec2(x1-x0, y1-y0)).offset((1,1,1,1))
def move(self, scroll): (w, h) = self.box.value.size self.scroll = vec2(clamp(self.viewport.x - w, 0, scroll.x), clamp(self.viewport.y - h, 0, scroll.y))
def caret(self, index): index = clamp(0, len(self.offsets) - 1, index) base = self.geometry.base size = self.geometry.size y = max(size.y, 8) return rectangle(base + vec2(self.offsets[index]-1, -1), vec2(1, y+1))
def move(self, position, drag): index = clamp(0, len(self.field), position) if drag: self.head = index else: self.head = self.tail = index