Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 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

        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)
Exemplo n.º 4
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()
Exemplo n.º 5
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)
Exemplo n.º 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)
Exemplo n.º 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

        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)
Exemplo n.º 8
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()
Exemplo n.º 9
0
def header(
    title: str,
    icon: str = style.ICON_DEFAULT,
    fg: int = style.FG,
    bg: int = style.BG,
    ifg: int = style.GREEN,
) -> None:
    if icon is not None:
        display.icon(14, 15, res.load(icon), ifg, bg)
    display.text(44, 35, title, ui.BOLD, fg, bg)
Exemplo n.º 10
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()
Exemplo n.º 11
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)
Exemplo n.º 12
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)
Exemplo n.º 13
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,
            )
 def test_text(self):
     display.text(120, 120, 'Test', 0, 0xFFFF, 0x0000)
Exemplo n.º 15
0
    def test_text(self):
        display.text(120, 120, 'Test', 0, 0xFFFF, 0x0000)
        display.text(120, 120, 'Test', 0, 0xFFFF, 0x0000, 2)
        display.text(120, 120, 'Test', 0, 0xFFFF, 0x0000, 2, 1)
        display.text(120, 120, 'Těst', 0, 0xFFFF, 0x0000, 2, 2)

        display.text(120, 120, "ǑǑǑǑǑǑǑǑ", 0, 0xFFFF, 0x0000)
        for off in (0, 2, 3, 8, 16):
            display.text(120, 120, "ǑǑǑǑǑǑǑǑ", 0, 0xFFFF, 0x0000, off)
            display.text(120, 120, "ǑǑǑǑǑǑǑǑ", 0, 0xFFFF, 0x0000, off, 0)

        for off, tlen in ((2, 5), (2, 14), (3, 5), (3, 13), (8, 1), (8, 8)):
            display.text(120, 120, "ǑǑǑǑǑǑǑǑ", 0, 0xFFFF, 0x0000, off, tlen)
Exemplo n.º 16
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