Esempio n. 1
0
    def render(self):
        if not self.state & BTN_DIRTY:
            return
        state = self.state & ~BTN_DIRTY
        if state & BTN_DISABLED:
            s = self.disabled_style
        elif state & BTN_ACTIVE:
            s = self.active_style
        else:
            s = self.normal_style
        ax, ay, aw, ah = self.area
        tx = ax + aw // 2
        ty = ay + ah // 2 + 8
        display.bar_radius(ax, ay, aw, ah, s['border-color'], ui.BG,
                           s['radius'])
        display.bar_radius(ax + 4, ay + 4, aw - 8, ah - 8, s['bg-color'],
                           s['border-color'], s['radius'])

        if isinstance(self.content, str):
            display.text_center(tx, ty, self.content, s['text-style'],
                                s['fg-color'], s['bg-color'])

        else:
            display.icon(tx - 15, ty - 20, self.content, s['fg-color'],
                         s['bg-color'])

        self.state = state
Esempio n. 2
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)
Esempio n. 3
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,
            )
Esempio n. 4
0
 def render_background(self, s, ax, ay, aw, ah):
     radius = s['radius']
     bg_color = s['bg-color']
     border_color = s['border-color']
     if border_color != bg_color:
         # render border and background on top of it
         display.bar_radius(ax, ay, aw, ah, border_color, ui.BG, radius)
         display.bar_radius(ax + BORDER, ay + BORDER, aw - BORDER * 2,
                            ah - BORDER * 2, bg_color, border_color, radius)
     else:
         # render only the background
         display.bar_radius(ax, ay, aw, ah, bg_color, ui.BG, radius)
Esempio n. 5
0
 def render_background(self, s, ax, ay, aw, ah):
     radius = s.radius
     bg_color = s.bg_color
     border_color = s.border_color
     if border_color == bg_color:
         # we don't need to render the border
         display.bar_radius(ax, ay, aw, ah, bg_color, ui.BG, radius)
     else:
         # render border and background on top of it
         display.bar_radius(ax, ay, aw, ah, border_color, ui.BG, radius)
         display.bar_radius(
             ax + _BORDER,
             ay + _BORDER,
             aw - _BORDER * 2,
             ah - _BORDER * 2,
             bg_color,
             border_color,
             radius,
         )
Esempio n. 6
0
 def render_background(self, s: ButtonStyleStateType, ax: int, ay: int,
                       aw: int, ah: int) -> None:
     radius = s.radius
     bg_color = s.bg_color
     border_color = s.border_color
     if border_color == bg_color:
         # we don't need to render the border
         display.bar_radius(ax, ay, aw, ah, bg_color, ui.BG, radius)
     else:
         # render border and background on top of it
         display.bar_radius(ax, ay, aw, ah, border_color, ui.BG, radius)
         display.bar_radius(
             ax + _BORDER,
             ay + _BORDER,
             aw - _BORDER * 2,
             ah - _BORDER * 2,
             bg_color,
             border_color,
             radius,
         )
 def test_bar_radius(self):
     display.bar_radius(0, 0, 10, 10, 0xFFFF, 0x0000, 16)