def pre_update(self, context): cr = context.cairo text = self.subject.name if text: width, height = text_extents(cr, text) self.min_width, self.min_height = width + 10, height + 20 super(UseCaseItem, self).pre_update(context)
def pre_update(self, context): """ Pre update, determine width and height of the compartment. """ self.width = self.height = 0 cr = context.cairo for item in self: item.pre_update(context) if self: # self (=list) contains items sizes = [(0, 0)] # to not throw exceptions by max and sum if self.title: w, h = text_extents(cr, self.title) self.title_height = h sizes.append((w, h)) sizes.extend(f.get_size(True) for f in self) self.width = max(size[0] for size in sizes) self.height = sum(size[1] for size in sizes) vspacing = self.owner.style.compartment_vspacing self.height += vspacing * (len(sizes) - 1) padding = self.owner.style.compartment_padding self.width += padding[1] + padding[3] self.height += padding[0] + padding[2]
def pre_update(self, context): cr = context.cairo text = self.subject.name if text: width, height = text_extents(cr, text) self.min_width, self.min_height = width + 10, height + 20 super(UseCaseItem, self).pre_update(context)
def pre_update(self, context): """ Pre update, determine width and height of the compartment. """ self.width = self.height = 0 cr = context.cairo for item in self: item.pre_update(context) if self: # self (=list) contains items sizes = [(0, 0)] # to not throw exceptions by max and sum if self.title: w, h = text_extents(cr, self.title) self.title_height = h sizes.append((w, h)) sizes.extend(f.get_size(True) for f in self) self.width = max(size[0] for size in sizes) self.height = sum(size[1] for size in sizes) vspacing = self.owner.style.compartment_vspacing self.height += vspacing * (len(sizes) - 1) padding = self.owner.style.compartment_padding self.width += padding[1] + padding[3] self.height += padding[0] + padding[2]
def pre_update(self, context): if not self.subject: return cr = context.cairo e = self.EAR o = self.OFFSET w, h = text_extents( cr, self.subject.body, self.style.font, width=self.width - e ) self.min_width = w + e + o * 2 self.min_height = h + o * 2 ElementItem.pre_update(self, context)
def post_update(self, context, p1, p2): """ Update label placement for association's name and multiplicity label. p1 is the line end and p2 is the last but one point of the line. """ cr = context.cairo ofs = 5 name_dx = 0.0 name_dy = 0.0 mult_dx = 0.0 mult_dy = 0.0 dx = float(p2[0]) - float(p1[0]) dy = float(p2[1]) - float(p1[1]) name_w, name_h = list( map(max, text_extents(cr, self._name, self.font), (10, 10)) ) mult_w, mult_h = list( map(max, text_extents(cr, self._mult, self.font), (10, 10)) ) if dy == 0: rc = 1000.0 # quite a lot... else: rc = dx / dy abs_rc = abs(rc) h = dx > 0 # right side of the box v = dy > 0 # bottom side if abs_rc > 6: # horizontal line if h: name_dx = ofs name_dy = -ofs - name_h mult_dx = ofs mult_dy = ofs else: name_dx = -ofs - name_w name_dy = -ofs - name_h mult_dx = -ofs - mult_w mult_dy = ofs elif 0 <= abs_rc <= 0.2: # vertical line if v: name_dx = -ofs - name_w name_dy = ofs mult_dx = ofs mult_dy = ofs else: name_dx = -ofs - name_w name_dy = -ofs - name_h mult_dx = ofs mult_dy = -ofs - mult_h else: # Should both items be placed on the same side of the line? r = abs_rc < 1.0 # Find out alignment of text (depends on the direction of the line) 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 )
def update_size(self, text, context): if text: cr = context.cairo self.width, self.height = text_extents(cr, text) else: self.width, self.height = 0, 0
def post_update(self, context, p1, p2): """ Update label placement for association's name and multiplicity label. p1 is the line end and p2 is the last but one point of the line. """ cr = context.cairo ofs = 5 name_dx = 0.0 name_dy = 0.0 mult_dx = 0.0 mult_dy = 0.0 dx = float(p2[0]) - float(p1[0]) dy = float(p2[1]) - float(p1[1]) name_w, name_h = map(max, text_extents(cr, self._name, self.font), (10, 10)) mult_w, mult_h = map(max, text_extents(cr, self._mult, self.font), (10, 10)) if dy == 0: rc = 1000.0 # quite a lot... else: rc = dx / dy abs_rc = abs(rc) h = dx > 0 # right side of the box v = dy > 0 # bottom side if abs_rc > 6: # horizontal line if h: name_dx = ofs name_dy = -ofs - name_h mult_dx = ofs mult_dy = ofs else: name_dx = -ofs - name_w name_dy = -ofs - name_h mult_dx = -ofs - mult_w mult_dy = ofs elif 0 <= abs_rc <= 0.2: # vertical line if v: name_dx = -ofs - name_w name_dy = ofs mult_dx = ofs mult_dy = ofs else: name_dx = -ofs - name_w name_dy = -ofs - name_h mult_dx = ofs mult_dy = -ofs - mult_h else: # Should both items be placed on the same side of the line? r = abs_rc < 1.0 # Find out alignment of text (depends on the direction of the line) 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)
def update_size(self, text, context): if text: cr = context.cairo self.width, self.height = text_extents(cr, text) else: self.width, self.height = 0, 0