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

        # 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.º 4
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.º 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

        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.º 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_content(self, s, ax, ay, aw, ah):
     c = self.content
     tx = ax + aw // 2
     ty = ay + ah // 2 + 8
     if isinstance(c, str):
         display.text_center(tx, ty, c, s["text-style"], s["fg-color"],
                             s["bg-color"])
     else:
         display.icon(tx - ICON // 2, ty - ICON, c, s["fg-color"],
                      s["bg-color"])
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_content(self, s, ax, ay, aw, ah):
     tx = ax + aw // 2
     ty = ay + ah // 2 + 8
     t = self.content
     if isinstance(t, str):
         display.text_center(tx, ty, t, s.text_style, s.fg_color,
                             s.bg_color)
     elif isinstance(t, bytes):
         display.icon(tx - _ICON // 2, ty - _ICON, t, s.fg_color,
                      s.bg_color)
Exemplo n.º 11
0
 def render_content(
     self, s: ButtonStyleStateType, ax: int, ay: int, aw: int, ah: int
 ) -> None:
     tx = ax + aw // 2
     ty = ay + ah // 2 + 8
     t = self.text
     if t:
         display.text_center(tx, ty, t, s.text_style, s.fg_color, s.bg_color)
         return
     i = self.icon
     if i:
         display.icon(tx - _ICON // 2, ty - _ICON, i, s.fg_color, s.bg_color)
         return