| 103 | return "(Left: "+str(self.left)+", Right: "+str(self.right)+", Top: "+str(self.top)+", Bottom: "+str(self.bottom)+")" |
| 104 | |
| 105 | class Label: |
| 106 | def __init__(self): |
| 107 | self.text = "" |
| 108 | self.width = 1000 |
| 109 | self.max_lines = 1 |
| 110 | self.text_size = 100 |
| 111 | self.line_height = 15 |
| 112 | self.color = (0.2, 0.2, 0.2, 1.0) |
| 113 | self.font_id = 0 |
| 114 | |
| 115 | def draw(self, position): |
| 116 | lines = self.get_draw_lines() |
| 117 | for i, line in enumerate(lines): |
| 118 | line_start_position = (position[0], position[1] - i * self.line_height) |
| 119 | draw_text(line, line_start_position, size = self.text_size, color = self.color, font_id = self.font_id) |
| 120 | |
| 121 | def get_draw_dimensions(self): |
| 122 | lines = self.get_draw_lines() |
| 123 | width = 0 |
| 124 | for line in lines: |
| 125 | width = max(width, self.get_text_width(line)) |
| 126 | height = len(lines) * self.line_height |
| 127 | return width, height |
| 128 | |
| 129 | def get_draw_lines(self): |
| 130 | text_lines = self.get_wrapped_lines() |
| 131 | draw_lines = text_lines[:self.max_lines] |
| 132 | |
| 133 | if len(text_lines) > self.max_lines: |
| 134 | last_line = draw_lines[-1] + "..." |
| 135 | if self.fits_in_line(last_line): |
| 136 | draw_lines[-1] = last_line |
| 137 | else: draw_lines[-1] = draw_lines[-1][:-3] + "..." |
| 138 | |
| 139 | return draw_lines |
| 140 | |
| 141 | def get_wrapped_lines(self): |
| 142 | lines = [] |
| 143 | text = self.text |
| 144 | while text != "": |
| 145 | next_line = self.get_text_to_line_end(text) |
| 146 | lines.append(next_line) |
| 147 | text = text[len(next_line):] |
| 148 | |
| 149 | for i in range(1, len(lines)): |
| 150 | lines[i] = lines[i].strip() |
| 151 | return lines |
| 152 | |
| 153 | def get_text_to_line_end(self, text): |
| 154 | index = 1 |
| 155 | fitting_index = 0 |
| 156 | while index > 0: |
| 157 | index = text.find(" ", index + 1) |
| 158 | if self.fits_in_line(text[:index]): |
| 159 | fitting_index = index |
| 160 | else: |
| 161 | return text[:fitting_index] |
| 162 | return text |
no outgoing calls
no test coverage detected