示例#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)
示例#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

        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)
示例#3
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)
示例#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()
示例#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)
示例#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

        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)
示例#8
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)
示例#9
0
 def test_two_lines(self):
     line_width = display.text_width("hello world", ui.NORMAL) - 1
     span = text.Span("hello world", line_width=line_width)
     self.checkSpanWithoutWidths(
         span,
         [
             ("hello", False),
             ("world", False),
         ],
     )
示例#10
0
 def test_break_words(self):
     line_width = display.text_width("hello w", ui.NORMAL) + text.DASH_WIDTH
     span = text.Span("hello world",
                      line_width=line_width,
                      break_words=True)
     self.checkSpanWithoutWidths(
         span,
         [
             ("hello w", True),
             ("orld", False),
         ],
     )
示例#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

        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)
示例#12
0
 def test_long_word(self):
     line_width = display.text_width("establishme",
                                     ui.NORMAL) + text.DASH_WIDTH
     span = text.Span("Down with the establishment!",
                      line_width=line_width,
                      break_words=False)
     self.checkSpanWithoutWidths(
         span,
         [
             ("Down with", False),
             ("the", False),
             ("establishme", True),
             ("nt!", False),
         ],
     )
示例#13
0
    def test_has_more_content(self):
        line_width = display.text_width("hello world", ui.NORMAL) - 1
        span = text.Span("hello world", line_width=line_width)
        self.assertTrue(span.has_more_content())
        self.assertTrue(span.next_line())
        self.assertEqual("hello",
                         span.string[span.start:span.start + span.length])

        # has_more_content is True because there's text remaining on the line
        self.assertTrue(span.has_more_content())
        # next_line is False because we should not continue iterating
        self.assertFalse(span.next_line())
        self.assertEqual("world",
                         span.string[span.start:span.start + span.length])

        self.assertFalse(span.has_more_content())
        self.assertFalse(span.next_line())
        self.assertEqual("world",
                         span.string[span.start:span.start + span.length])
示例#14
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_width(self):
     display.text_width('Test', 0)
示例#16
0
    def test_text_width(self):
        display.text_width('Test', 0)
        display.text_width('Test', 0, 2)
        display.text_width('Test', 0, 2, 1)
        display.text_width('Těst', 0, 2, 2)

        display.text_width("ǑǑǑǑǑǑǑǑ", 0)
        for off in (0, 2, 3, 8, 16):
            display.text_width("ǑǑǑǑǑǑǑǑ", 0, off)
            self.assertEqual(display.text_width("ǑǑǑǑǑǑǑǑ", 0, off, 0), 0)

        for off, tlen in ((0, 8), (0, 16), (2, 5), (2, 14), (3, 5), (3, 13)):
            display.text_width("ǑǑǑǑǑǑǑǑ", 0, off, tlen)

        self.assertEqual(display.text_width("ǑǑǑǑǑǑǑǑ", 8), 0)
        self.assertEqual(display.text_width("ǑǑǑǑǑǑǑǑ", 8, 1), 0)
        self.assertEqual(display.text_width("ǑǑǑǑǑǑǑǑ", 8, 8), 0)
        self.assertEqual(display.text_width("ǑǑǑǑǑǑǑǑ", 9), 0)
        self.assertEqual(display.text_width("ǑǑǑǑǑǑǑǑ", 9, 1), 0)
        self.assertEqual(display.text_width("ǑǑǑǑǑǑǑǑ", 15, 1), 0)