def render(self, size, focus=False): fixed_size(size) # complain if parameter is wrong a = None ai = ak = 0 o = [] rows = self.font.height attrib = self.attrib+[(None,len(self.text))] for ch in self.text: if not ak: a, ak = attrib[ai] ai += 1 ak -= 1 width = self.font.char_width(ch) if not width: # ignore invalid characters continue c = self.font.render(ch) if a is not None: c = CompositeCanvas(c) c.fill_attr(a) o.append((c, None, False, width)) if o: canv = CanvasJoin(o) else: canv = TextCanvas([""]*rows, maxcol=0, check_width=False) canv = CompositeCanvas(canv) canv.set_depends([]) return canv
def render(self, size, focus=False): """Render columns and return canvas. size -- (maxcol,) if self.widget_list contains flow widgets or (maxcol, maxrow) if it contains box widgets. """ widths = self.column_widths( size ) if not widths: return SolidCanvas(" ", size[0], (size[1:]+(1,))[0]) box_maxrow = None if len(size)==1 and self.box_columns: box_maxrow = 1 # two-pass mode to determine maxrow for box columns for i in range(len(widths)): if i in self.box_columns: continue mc = widths[i] w = self.widget_list[i] rows = w.rows( (mc,), focus = focus and self.focus_col == i ) box_maxrow = max(box_maxrow, rows) l = [] for i in range(len(widths)): mc = widths[i] w = self.widget_list[i] if box_maxrow and i in self.box_columns: sub_size = (mc, box_maxrow) else: sub_size = (mc,) + size[1:] canv = w.render(sub_size, focus = focus and self.focus_col == i) if i < len(widths)-1: mc += self.dividechars l.append((canv, i, self.focus_col == i, mc)) canv = CanvasJoin(l) if canv.cols() < size[0]: canv.pad_trim_left_right(0, size[0]-canv.cols()) return canv