def render(self, size, focus=False): c = self._original_widget.render(size, focus) if focus: # create a new canvas so we can add a cursor c = CompositeCanvas(c) c.cursor = self.get_cursor_coords(size) return c
def render(self, size, focus=False): canvas = super().render(size, focus) if self._pop_up_widget: canvas = CompositeCanvas(canvas) canvas.set_pop_up(self._pop_up_widget, **self.get_pop_up_parameters(size=size)) return canvas
def render(self, size, focus=False): """ Render edit widget and return canvas. Include cursor when in focus. >>> c = Edit("? ","yes").render((10,), focus=True) >>> c.text # ... = b in Python 3 [...'? yes '] >>> c.cursor (5, 0) """ if self.has_focus and not focus: self.has_focus = False self.on_blur() self.has_focus = focus (maxcol,) = size self._shift_view_to_cursor = bool(focus) canv = Text.render(self,(maxcol,)) if focus: canv = CompositeCanvas(canv) canv.cursor = self.get_cursor_coords((maxcol,)) # .. will need to FIXME if I want highlight to work again #if self.highlight: # hstart, hstop = self.highlight_coords() # d.coords['highlight'] = [ hstart, hstop ] return canv
def render(self, size, focus): maxcols, maxrows = size rows = self._original_widget.rows((maxcols, ), focus) if rows <= maxrows: # no clipping, so just fill as normal return super().render(size, focus) # limit scroll_top to top of last page self.scroll_top = min(self.scroll_top, rows - maxrows) ocanv = self._original_widget.render((maxcols, ), focus) if ocanv.cursor is not None: # ensure selected field is within scroll window cx, cy = ocanv.cursor if self.scroll_top <= cy < self.scroll_top + maxrows: pass # already in view elif cy < maxrows / 2: self.scroll_top = 0 elif cy > rows - maxrows / 2: self.scroll_top = rows - maxrows else: self.scroll_top = int(cy - maxrows / 2) # calculate top / bottom values for pad_trim_top_bottom top = -self.scroll_top bottom = -(rows - self.scroll_top - maxrows) canv = CompositeCanvas(ocanv) canv.pad_trim_top_bottom(top, bottom) if rows != 0: # calculate top and bottom of scroll thumb as percentage of maxrows sf = maxrows / rows thumb_top = int(self.scroll_top * sf) thumb_bottom = int((rows - (self.scroll_top + maxrows)) * sf) thumb_size = maxrows - thumb_top - thumb_bottom else: thumb_size = maxrows thumb_top = thumb_bottom = 0 # create canvases to draw scrollbar scroll_top = SolidCanvas(self.trough_char, 1, thumb_top) scroll_thumb = SolidCanvas(self.thumb_char, 1, thumb_size) scroll_bottom = SolidCanvas(self.trough_char, 1, thumb_bottom) scroll_bar = CanvasCombine([ (scroll_top, None, False), (scroll_thumb, None, False), (scroll_bottom, None, False), ]) return CanvasJoin([ (canv, None, True, maxcols - 1), (scroll_bar, None, False, 1), ])