1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-02 02:41:28 +00:00

add icon buttons, make PinMatrix nicer

This commit is contained in:
Jan Pochyla 2016-06-08 19:49:40 +02:00 committed by Pavol Rusnak
parent 1e4556d736
commit cf77aeb029
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 28 additions and 27 deletions

View File

@ -45,11 +45,11 @@ CLEAR_BUTTON = {
'bg-color': ui.BLACK, 'bg-color': ui.BLACK,
'fg-color': ui.WHITE, 'fg-color': ui.WHITE,
'text-style': ui.NORMAL, 'text-style': ui.NORMAL,
'border-color': ui.BLACK, 'border-color': ui.BLACK,
} }
CLEAR_BUTTON_ACTIVE = { CLEAR_BUTTON_ACTIVE = {
'bg-color': ui.BLACK, 'bg-color': ui.BLACK,
'fg-color': ui.WHITE, 'fg-color': ui.GREY,
'text-style': ui.NORMAL, 'text-style': ui.NORMAL,
'border-color': ui.BLACK, 'border-color': ui.BLACK,
} }
@ -63,9 +63,9 @@ BTN_DIRTY = const(4)
class Button(): class Button():
def __init__(self, area, text, normal_style=None, active_style=None, absolute=False): def __init__(self, area, content, normal_style=None, active_style=None, absolute=False):
self.area = area self.area = area
self.text = text self.content = content
self.normal_style = normal_style or DEFAULT_BUTTON self.normal_style = normal_style or DEFAULT_BUTTON
self.active_style = active_style or DEFAULT_BUTTON_ACTIVE self.active_style = active_style or DEFAULT_BUTTON_ACTIVE
self.absolute = absolute self.absolute = absolute
@ -81,16 +81,18 @@ class Button():
ty = ay + ah // 2 + 8 ty = ay + ah // 2 + 8
display.bar(ax, ay, aw, ah, style['border-color']) display.bar(ax, ay, aw, ah, style['border-color'])
display.bar(ax + 1, ay + 1, aw - 2, ah - 2, style['bg-color']) display.bar(ax + 1, ay + 1, aw - 2, ah - 2, style['bg-color'])
# How to do this smarter way?
if self.text == 'CLEAR': if isinstance(self.content, str):
ui.display.icon(ax, ay, res.load('trezor/res/close-button.toig'), display.text_center(tx, ty, self.content,
ui.blend(ui.BLACK, ui.WHITE, 0.95),
ui.BLACK)
else:
display.text_center(tx, ty, self.text,
style['text-style'], style['text-style'],
style['fg-color'], style['fg-color'],
style['bg-color']) style['bg-color'])
else:
display.icon(ax, ay, self.content,
style['fg-color'],
style['bg-color'])
self.state = state self.state = state
def send(self, event, pos): def send(self, event, pos):

View File

@ -1,9 +1,7 @@
from . import display, clear from . import display
from trezor import ui, loop from .button import Button, BTN_CLICKED, CLEAR_BUTTON, CLEAR_BUTTON_ACTIVE
from trezor import ui, res
from trezor.crypto import random from trezor.crypto import random
from .button import Button, BTN_CLICKED
from .button import CONFIRM_BUTTON, CONFIRM_BUTTON_ACTIVE
from .button import CANCEL_BUTTON, CANCEL_BUTTON_ACTIVE
def digit_area(i): def digit_area(i):
@ -25,13 +23,16 @@ class PinMatrix():
def __init__(self, label='Enter PIN', pin=''): def __init__(self, label='Enter PIN', pin=''):
self.label = label self.label = label
self.pin = pin self.pin = pin
self.clear_button = Button((240 - 35, 5, 30, 30), 'CLEAR') self.clear_button = Button((240 - 35, 5, 30, 30),
self.buttons = [Button(digit_area(i), str(d)) res.load('trezor/res/close-button.toig'),
for i, d in enumerate(generate_digits())] normal_style=CLEAR_BUTTON,
active_style=CLEAR_BUTTON_ACTIVE)
self.pin_buttons = [Button(digit_area(i), str(d))
for i, d in enumerate(generate_digits())]
def render(self): def render(self):
header = ''.join(['*' for _ in self.pin]) if self.pin else self.label header = '*' * len(self.pin) if self.pin else self.label
# clear canvas under input line # clear canvas under input line
display.bar(48, 0, 144, 48, ui.BLACK) display.bar(48, 0, 144, 48, ui.BLACK)
@ -42,9 +43,11 @@ class PinMatrix():
# render clear button # render clear button
if self.pin: if self.pin:
self.clear_button.render() self.clear_button.render()
else:
display.bar(240 - 48, 0, 48, 42, ui.BLACK)
# pin matrix buttons # pin matrix buttons
for btn in self.buttons: for btn in self.pin_buttons:
btn.render() btn.render()
# vertical border bars # vertical border bars
@ -58,10 +61,6 @@ class PinMatrix():
def send(self, event, pos): def send(self, event, pos):
if self.clear_button.send(event, pos) == BTN_CLICKED: if self.clear_button.send(event, pos) == BTN_CLICKED:
self.pin = '' self.pin = ''
self.label = 'Enter PIN' for btn in self.pin_buttons:
display.bar(240 - 48, 0, 48, 42, ui.BLACK)
for btn in self.buttons:
if btn.send(event, pos) == BTN_CLICKED: if btn.send(event, pos) == BTN_CLICKED:
self.pin += btn.text self.pin += btn.content