def add_description(self, state, desc, title_y, title_h, bb, font_size): """ Add podcast description :param state: button state :param desc: description text :param title_y: y coordinate :param title_h: text height :param bb: bounding box :param font_size: """ desc_font_size = int(font_size * 0.7) font = self.util.get_font(desc_font_size) if self.config[SCREEN_INFO][WIDTH] <= 320: line_length = 56 elif self.config[SCREEN_INFO][WIDTH] > 320 and self.config[ SCREEN_INFO][WIDTH] <= 480: line_length = 58 else: line_length = 64 lines = textwrap.wrap(desc, line_length) for n, line in enumerate(lines[0:5]): label = font.render(line, 1, state.text_color_normal) c = Component(self.util, label) c.name = "desc." + str(title_y) + str(n) c.text = line c.text_size = desc_font_size c.text_color_normal = state.text_color_normal c.text_color_selected = state.text_color_selected c.text_color_disabled = state.text_color_disabled c.text_color_current = c.text_color_normal c.content_x = bb.x c.content_y = title_y + title_h + (n * desc_font_size) self.components.append(c)
def add_label(self, state, bb): """ Add button label :param state: button state :param bb: bounding box """ if not self.show_label: self.add_component(None) return font_size = int(state.label_text_height) font = self.util.get_font(font_size) label = state.l_name text = self.truncate_long_labels(label, bb, font) size = font.size(text) rendered_label = font.render(text, 1, self.text_color_normal) c = Component(self.util, rendered_label) c.name = label + ".label" c.text = text c.text_size = font_size c.text_color_normal = self.text_color_normal c.text_color_selected = self.text_color_selected c.text_color_disabled = self.text_color_disabled c.text_color_current = c.text_color_normal c.content_x = bb.x + (bb.width - size[0]) / 2 c.content_y = bb.y + (bb.height - size[1]) / 2 + self.padding * 1.5 self.components.append(c)
def add_label(self, state, bb): """ Add button label :param state: button state :param bb: bounding box """ if not self.show_label: self.add_component(None) return fixed_height = getattr(state, "fixed_height", None) if fixed_height: font_size = fixed_height else: font_size = int((bb.h * state.label_text_height) / 100.0) if font_size > self.config[MAXIMUM_FONT_SIZE]: font_size = self.config[MAXIMUM_FONT_SIZE] font = self.util.get_font(font_size) text = self.truncate_long_labels(state.l_name, bb, font) state.l_name = text size = font.size(text) label = font.render(text, 1, state.text_color_normal) c = Component(self.util, label) c.name = state.name + ".label" c.text = text c.text_size = font_size c.text_color_normal = state.text_color_normal c.text_color_selected = state.text_color_selected c.text_color_disabled = state.text_color_disabled c.text_color_current = c.text_color_normal h_align = getattr(state, H_ALIGN, None) if h_align != None: if h_align == H_ALIGN_LEFT: c.content_x = bb.x else: c.content_x = bb.x + (bb.width - size[0]) / 2 v_align = getattr(state, V_ALIGN, None) if v_align and v_align == V_ALIGN_TOP: v_offset = getattr(state, V_OFFSET, 0) if v_offset != 0: v_offset = int((bb.height / 100) * v_offset) c.content_y = bb.y + v_offset else: c.content_y = bb.y else: c.content_y = bb.y + (bb.height - size[1]) / 2 + 1 if len(self.components) == 2: self.components.append(c) else: self.components[2] = c desc = getattr(state, "description", None) if desc != None: self.add_description(state, desc, c.content_y, size[1], bb, font_size)
def create_one_line_label(self, state, bb, font, font_size, text, padding): state.l_name = text size = font.size(text) if getattr(self, "selected", False): color = state.text_color_selected else: color = state.text_color_normal label = font.render(text, 1, color) c = Component(self.util, label) c.name = state.name + ".label" c.text = text c.text_size = font_size c.text_color_normal = state.text_color_normal c.text_color_selected = state.text_color_selected c.text_color_disabled = state.text_color_disabled c.text_color_current = color c.content_x = self.get_label_x(state, bb, size, padding) c.content_y = self.get_label_y(state, bb, size) if len(self.components) == 2: self.components.append(c) else: self.components[2] = c
def add_label(self, state, bb): """ Add button label :param state: button state :param bb: bounding box """ if not self.show_label: self.add_component(None) return font_size = int((bb.h * state.label_text_height)/100.0) font = self.util.get_font(font_size) text = state.l_name size = font.size(text) label = font.render(text, 1, state.text_color_normal) c = Component(self.util, label) c.name = state.name + ".label" c.text = text c.text_size = font_size c.text_color_normal = state.text_color_normal c.text_color_selected = state.text_color_selected c.text_color_disabled = state.text_color_disabled c.text_color_current = c.text_color_normal c.content_x = bb.x + (bb.width - size[0])/2 c.content_y = bb.y + (bb.height - size[1])/2 if len(self.components) == 2: self.components.append(c) else: self.components[2] = c
def create_two_lines_label(self, state, bb, font, font_size, text, text_with_ellipses, padding): length = len(text_with_ellipses) - 3 first_line = text[0:length] if first_line: first_line = first_line.strip() second_line = self.truncate_long_labels(text[length:], bb, font) if second_line: second_line = second_line.strip() size = font.size(first_line) label = font.render(first_line, 1, state.text_color_normal) c = Component(self.util, label) c.name = first_line + ".label" c.text = first_line c.text_size = font_size c.text_color_normal = state.text_color_normal c.text_color_selected = state.text_color_selected c.text_color_disabled = state.text_color_disabled c.text_color_current = c.text_color_normal c.content_x = self.get_label_x(state, bb, size, padding) padding = (bb.h / 100) * 5 c.content_y = bb.y + padding if len(self.components) == 2: self.components.append(c) else: self.components[2] = c x = c.content_x f_size = font_size - int((font_size / 100) * 20) f = self.util.get_font(f_size) s = font.size(second_line) label = f.render(second_line, 1, state.text_color_disabled) c = Component(self.util, label) c.name = second_line + ".label" c.text = second_line c.text_size = f_size c.text_color_normal = state.text_color_disabled c.text_color_selected = state.text_color_selected c.text_color_disabled = state.text_color_disabled c.text_color_current = c.text_color_disabled c.content_x = x c.content_y = padding * 2 + bb.y + s[1] - s[1] / 3 self.components.append(c)
def add_description(self, state, desc, title_y, title_h, bb, font_size): """ Add episode description :param state: button state :param desc: description text :param title_y: y coordinate :param title_h: text height :param bb: bounding box :param font_size: """ if self.config[SCREEN_INFO][WIDTH] <= 320: desc_font_size = int(font_size * 0.8) line_length = 52 else: desc_font_size = int(font_size * 0.7) line_length = 70 lines = textwrap.wrap(desc, line_length) font = self.util.get_font(desc_font_size) for n, line in enumerate(lines[0:3]): try: label = font.render(line, 1, state.text_color_normal) except: continue c = Component(self.util, label) c.name = "desc." + str(title_y) + str(n) c.text = line c.text_size = desc_font_size c.text_color_normal = state.text_color_normal c.text_color_selected = state.text_color_selected c.text_color_disabled = state.text_color_disabled c.text_color_current = c.text_color_normal c.content_x = bb.x c.content_y = title_y + (title_h * 0.8) + (n * desc_font_size) self.components.append(c)