Пример #1
0
    def render(self):
        # pin matrix buttons
        for btn in self.pin_buttons:
            btn.render()

        if not self.tainted:
            return

        # clear canvas under input line
        display.bar(0, 0, ui.WIDTH, 52, ui.BG)

        if self.pin:
            # input line with pin
            l = len(self.pin)
            y = const(20)
            size = const(10)
            padding = const(14)
            box_w = const(240)
            x = (box_w - l * padding) // 2
            for i in range(0, l):
                ui.display.bar_radius(x + i * padding, y, size, size, ui.GREY,
                                      ui.BG, 4)
        elif self.sublabel:
            # input line with header label and sublabel
            display.text_center(ui.WIDTH // 2, 20, self.label, ui.BOLD,
                                ui.GREY, ui.BG)
            display.text_center(ui.WIDTH // 2, 46, self.sublabel, ui.NORMAL,
                                ui.GREY, ui.BG)
        else:
            # input line with header label
            display.text_center(ui.WIDTH // 2, 36, self.label, ui.BOLD,
                                ui.GREY, ui.BG)

        self.tainted = False
Пример #2
0
    def render_content(self, s: ButtonStyleStateType, ax: int, ay: int,
                       aw: int, ah: int) -> None:
        text_style = s.text_style
        fg_color = s.fg_color
        bg_color = s.bg_color

        p = self.pending  # should we draw the pending marker?
        t = self.text  # input content

        tx = ax + 24  # x-offset of the content
        ty = ay + ah // 2 + 8  # y-offset of the content
        maxlen = const(14)  # maximum text length

        # input content
        if len(t) > maxlen:
            t = "<" + t[-maxlen:]  # too long, align to the right
        width = display.text_width(t, text_style)
        display.text(tx, ty, t, text_style, fg_color, bg_color)

        if p:  # pending marker
            pw = display.text_width(t[-1:], text_style)
            px = tx + width - pw
            display.bar(px, ty + 2, pw + 1, 3, fg_color)
        else:  # cursor
            cx = tx + width + 1
            display.bar(cx, ty - 18, 2, 22, fg_color)
Пример #3
0
    def render_content(
        self, s: ButtonStyleStateType, ax: int, ay: int, aw: int, ah: int
    ) -> None:
        text_style = s.text_style
        fg_color = s.fg_color
        bg_color = s.bg_color

        tx = ax + 16  # x-offset of the content
        ty = ay + ah // 2 + 8  # y-offset of the content

        # entered content
        display.text(tx, ty, self.text, text_style, fg_color, bg_color)
        # word suggestion
        suggested_word = self.word[len(self.text) :]
        width = display.text_width(self.text, text_style)
        display.text(tx + width, ty, suggested_word, text_style, ui.GREY, bg_color)

        if self.pending:
            pw = display.text_width(self.text[-1:], text_style)
            px = tx + width - pw
            display.bar(px, ty + 2, pw + 1, 3, fg_color)

        if self.icon:
            ix = ax + aw - 16 * 2
            iy = ty - 16
            display.icon(ix, iy, self.icon, fg_color, bg_color)
Пример #4
0
    def render_content(self, s, ax, ay, aw, ah):
        text_style = s.text_style
        fg_color = s.fg_color
        bg_color = s.bg_color

        tx = ax + 16  # x-offset of the content
        ty = ay + ah // 2 + 8  # y-offset of the content

        if not self.keyboard.is_input_final():
            to_display = len(self.content) * "*"
            if self.pending_button:
                to_display = (to_display[:-1] +
                              self.pending_button.content[self.pending_index])
        else:
            to_display = self.word

        display.text(tx, ty, to_display, text_style, fg_color, bg_color)

        if self.pending_button and not self.keyboard.is_input_final():
            width = display.text_width(to_display, text_style)
            pw = display.text_width(self.content[-1:], text_style)
            px = tx + width - pw
            display.bar(px, ty + 2, pw + 1, 3, fg_color)

        if self.icon:
            ix = ax + aw - 16 * 2
            iy = ty - 16
            display.icon(ix, iy, res.load(self.icon), fg_color, bg_color)
Пример #5
0
    def render_content(self, s, ax, ay, aw, ah):
        text_style = s['text-style']
        fg_color = s['fg-color']
        bg_color = s['bg-color']

        p = self.pending  # should we draw the pending marker?
        t = self.content  # input content
        w = self.word[len(t):]  # suggested word
        i = self.icon  # rendered icon

        tx = ax + 24  # x-offset of the content
        ty = ay + ah // 2 + 8  # y-offset of the content

        # input content and the suggested word
        display.text(tx, ty, t, text_style, fg_color, bg_color)
        width = display.text_width(t, text_style)
        display.text(tx + width, ty, w, text_style, ui.GREY, bg_color)

        if p:  # pending marker
            pw = display.text_width(t[-1:], text_style)
            px = tx + width - pw
            display.bar(px, ty + 2, pw + 1, 3, fg_color)

        if i:  # icon
            ix = ax + aw - ICON * 2
            iy = ty - ICON
            display.icon(ix, iy, res.load(i), fg_color, bg_color)
Пример #6
0
    def render_content(self, s, ax, ay, aw, ah):
        text_style = s.text_style
        fg_color = s.fg_color
        bg_color = s.bg_color

        tx = ax + 16  # x-offset of the content
        ty = ay + ah // 2 + 8  # y-offset of the content

        # entered content
        display.text(tx, ty, self.content, text_style, fg_color, bg_color)
        # word suggestion
        suggested_word = self.word[len(self.content):]
        width = display.text_width(self.content, text_style)
        display.text(tx + width, ty, suggested_word, text_style, ui.GREY,
                     bg_color)

        if self.pending:
            pw = display.text_width(self.content[-1:], text_style)
            px = tx + width - pw
            display.bar(px, ty + 2, pw + 1, 3, fg_color)

        if self.icon:
            ix = ax + aw - 16 * 2
            iy = ty - 16
            display.icon(ix, iy, res.load(self.icon), fg_color, bg_color)
Пример #7
0
    def render_content(self, s, ax, ay, aw, ah):
        text_style = s.text_style
        fg_color = s.fg_color
        bg_color = s.bg_color

        p = self.pending  # should we draw the pending marker?
        t = self.content  # input content
        w = self.word[len(t):]  # suggested word
        i = self.icon  # rendered icon

        if not t:
            # render prompt
            display.text(20, 40, self.prompt, ui.BOLD, ui.GREY, ui.BG)
            return

        tx = ax + 24  # x-offset of the content
        ty = ay + ah // 2 + 8  # y-offset of the content

        # input content and the suggested word
        display.text(tx, ty, t, text_style, fg_color, bg_color)
        width = display.text_width(t, text_style)
        display.text(tx + width, ty, w, text_style, ui.GREY, bg_color)

        if p:  # pending marker
            pw = display.text_width(t[-1:], text_style)
            px = tx + width - pw
            display.bar(px, ty + 2, pw + 1, 3, fg_color)

        if i:  # icon
            ix = ax + aw - 16 * 2
            iy = ty - 16
            display.icon(ix, iy, res.load(i), fg_color, bg_color)
Пример #8
0
    def render_content(self, s: ButtonStyleStateType, ax: int, ay: int,
                       aw: int, ah: int) -> None:
        text_style = s.text_style
        fg_color = s.fg_color
        bg_color = s.bg_color

        tx = ax + 16  # x-offset of the content
        ty = ay + ah // 2 + 8  # y-offset of the content

        if not self.keyboard.is_input_final():
            pending_button = self.pending_button
            pending_index = self.pending_index
            to_display = len(self.text) * "*"
            if pending_button and pending_index is not None:
                to_display = to_display[:-1] + pending_button.text[
                    pending_index]
        else:
            to_display = self.word

        display.text(tx, ty, to_display, text_style, fg_color, bg_color)

        if self.pending_button and not self.keyboard.is_input_final():
            width = display.text_width(to_display, text_style)
            pw = display.text_width(self.text[-1:], text_style)
            px = tx + width - pw
            display.bar(px, ty + 2, pw + 1, 3, fg_color)

        if self.icon:
            ix = ax + aw - 16 * 2
            iy = ty - 16
            display.icon(ix, iy, self.icon, fg_color, bg_color)
Пример #9
0
 def render_input(self):
     if self.content:
         display.bar(0, 0, 200, 40, ui.BG)
     else:
         display.bar(0, 0, 240, 40, ui.BG)
     display.text(20, 30, self.content, ui.BOLD, ui.GREY, ui.BG)
     if self.content:
         self.bs_button.render()
Пример #10
0
 def render_prompt(self):
     display.bar(0, 0, ui.WIDTH, 50, ui.BG)
     if self.subprompt:
         display.text_center(ui.WIDTH // 2, 20, self.prompt, ui.BOLD, ui.GREY, ui.BG)
         display.text_center(
             ui.WIDTH // 2, 46, self.subprompt, ui.NORMAL, ui.GREY, ui.BG
         )
     else:
         display.text_center(ui.WIDTH // 2, 36, self.prompt, ui.BOLD, ui.GREY, ui.BG)
Пример #11
0
 def render_pin(self) -> None:
     display.bar(0, 0, ui.WIDTH, 50, ui.BG)
     count = len(self.pin)
     BOX_WIDTH = const(240)
     DOT_SIZE = const(10)
     PADDING = const(14)
     RENDER_Y = const(20)
     render_x = (BOX_WIDTH - count * PADDING) // 2
     for i in range(0, count):
         display.bar_radius(render_x + i * PADDING, RENDER_Y, DOT_SIZE,
                            DOT_SIZE, ui.GREY, ui.BG, 4)
Пример #12
0
    def render(self):
        # clear canvas under input line
        display.bar(0, 0, 240, 45, ui.BG)

        # input line with a header
        header = '*' * len(self.pin) if self.pin else self.label
        display.text_center(120, 36, header, ui.BOLD, ui.GREY, ui.BG)

        # pin matrix buttons
        for btn in self.pin_buttons:
            btn.render()
Пример #13
0
 def render(self):
     if self.input.content:
         # content button and backspace
         self.input.render()
         self.back.render()
     else:
         # prompt
         display.bar(0, 8, 240, 60, ui.BG)
         display.text(20, 40, self.prompt, ui.BOLD, ui.GREY, ui.BG)
     # key buttons
     for btn in self.keys:
         btn.render()
Пример #14
0
 def render(self):
     # passphrase or prompt
     if self.input.content:
         self.input.render()
     else:
         display.bar(0, 0, 240, 48, ui.BG)
         display.text_center(ui.SCREEN // 2, 32, self.prompt, ui.BOLD,
                             ui.GREY, ui.BG)
     render_scrollbar(self.page)
     # buttons
     self.back.render()
     self.done.render()
     for btn in self.keys:
         btn.render()
Пример #15
0
    def render(self):

        header = '*' * len(self.pin) if self.pin else self.label

        # clear canvas under input line
        display.bar(0, 0, 205, 48, ui.BG)

        # input line with a header
        display.text_center(120, 30, header, ui.NORMAL,
                            ui.blend(ui.BG, ui.FG, 0.5), ui.BG)

        # pin matrix buttons
        for btn in self.pin_buttons:
            btn.render()
Пример #16
0
    def render(self):

        header = '*' * len(self.pin) if self.pin else self.label

        # clear canvas under input line
        display.bar(0, 0, 205, 48, ui.BLACK)

        # input line with a header
        display.text_center(120, 30, header, ui.BOLD, ui.GREY, ui.BLACK)

        # render clear button
        if self.pin:
            self.clear_button.render()
        else:
            display.bar(240 - 48, 0, 48, 42, ui.BLACK)

        # pin matrix buttons
        for btn in self.pin_buttons:
            btn.render()
Пример #17
0
    def render(self):
        # clear canvas under input line
        display.bar(0, 0, ui.WIDTH, 45, ui.BG)

        if self.pin:
            # input line with pin
            l = len(self.pin)
            y = const(20)
            size = const(10)
            padding = const(14)
            box_w = const(240)
            x = (box_w - l * padding) // 2
            for i in range(0, l):
                ui.display.bar_radius(x + i * padding, y, size, size, ui.GREY, ui.BG, 4)
        else:
            # input line with header label
            display.text_center(ui.WIDTH // 2, 36, self.label, ui.BOLD, ui.GREY, ui.BG)

        # pin matrix buttons
        for btn in self.pin_buttons:
            btn.render()
Пример #18
0
    def render(self):

        # clear canvas under input line
        display.bar(0, 0, 205, 40, ui.BG)

        # input line
        content_width = display.text_width(self.content, ui.BOLD)
        display.text(20, 30, self.content, ui.BOLD, ui.FG, ui.BG)

        # pending marker
        if self.pending_button is not None:
            pending_width = display.text_width(self.content[-1:], ui.BOLD)
            pending_x = 20 + content_width - pending_width
            display.bar(pending_x, 33, pending_width + 2, 3, ui.FG)

        # auto-suggest
        if self.sugg_word is not None:
            sugg_rest = self.sugg_word[len(self.content):]
            sugg_x = 20 + content_width
            display.text(sugg_x, 30, sugg_rest, ui.BOLD, ui.GREY, ui.BG)

        # render backspace button
        if self.content:
            self.bs_button.render()
        else:
            display.bar(240 - 48, 0, 48, 42, ui.BG)

        # key buttons
        for btn in self.key_buttons:
            btn.render()
Пример #19
0
    def render_content(self, s, ax, ay, aw, ah):
        text_style = s['text-style']
        fg_color = s['fg-color']
        bg_color = s['bg-color']

        p = self.pending  # should we draw the pending marker?
        t = self.content  # input content

        tx = ax + 24  # x-offset of the content
        ty = ay + ah // 2 + 8  # y-offset of the content
        maxlen = const(14)  # maximum text length

        # input content
        if len(t) > maxlen:
            t = '<' + t[-maxlen:]  # too long, align to the right
        width = display.text_width(t, text_style)
        display.text(tx, ty, t, text_style, fg_color, bg_color)

        if p:  # pending marker
            pw = display.text_width(t[-1:], text_style)
            display.bar(tx + width - pw, ty + 2, pw + 1, 3, fg_color)
        else:  # cursor
            display.bar(tx + width + 1, ty - 18, 2, 22, fg_color)
Пример #20
0
    def render_pin(self) -> None:
        MAX_LENGTH = const(14)  # maximum length of displayed PIN
        CONTD_MARK = "<"
        BOX_WIDTH = const(240)
        DOT_SIZE = const(10)
        PADDING = const(4)
        RENDER_Y = const(20)
        TWITCH = const(3)

        display.bar(0, 0, ui.WIDTH, 50, ui.BG)

        if len(self.pin) > MAX_LENGTH:
            contd_width = display.text_width(CONTD_MARK, ui.BOLD) + PADDING
            twitch = TWITCH * (len(self.pin) % 2)
        else:
            contd_width = 0
            twitch = 0

        count = min(len(self.pin), MAX_LENGTH)
        render_x = (BOX_WIDTH - count *
                    (DOT_SIZE + PADDING) - contd_width) // 2

        if contd_width:
            display.text(render_x, RENDER_Y + DOT_SIZE, CONTD_MARK, ui.BOLD,
                         ui.GREY, ui.BG)

        for i in range(0, count):
            display.bar_radius(
                render_x + contd_width + twitch + i * (DOT_SIZE + PADDING),
                RENDER_Y,
                DOT_SIZE,
                DOT_SIZE,
                ui.GREY,
                ui.BG,
                4,
            )
Пример #21
0
 def on_render(self) -> None:
     if self.repaint:
         display.bar(0, 0, ui.WIDTH, 48, ui.BG)
         display.text_center(ui.WIDTH // 2, 32, self.text, ui.BOLD, ui.GREY,
                             ui.BG)
         self.repaint = False
Пример #22
0
 def render(self):
     if self.dirty:
         display.bar(0, 0, ui.WIDTH, 48, ui.BG)
         display.text_center(ui.WIDTH // 2, 32, self.text, ui.BOLD, ui.GREY,
                             ui.BG)
         self.dirty = False
 def test_bar(self):
     display.bar(0, 0, 10, 10, 0xFFFF)
Пример #24
0
 def on_render(self) -> None:
     if self.repaint:
         display.bar(0, 8, ui.WIDTH, 60, ui.BG)
         display.text(20, 40, self.prompt, ui.BOLD, ui.GREY, ui.BG)
         self.repaint = False