1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-22 05:10:56 +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,
'fg-color': ui.WHITE,
'text-style': ui.NORMAL,
'border-color': ui.BLACK,
'border-color': ui.BLACK,
}
CLEAR_BUTTON_ACTIVE = {
'bg-color': ui.BLACK,
'fg-color': ui.WHITE,
'fg-color': ui.GREY,
'text-style': ui.NORMAL,
'border-color': ui.BLACK,
}
@ -63,9 +63,9 @@ BTN_DIRTY = const(4)
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.text = text
self.content = content
self.normal_style = normal_style or DEFAULT_BUTTON
self.active_style = active_style or DEFAULT_BUTTON_ACTIVE
self.absolute = absolute
@ -81,16 +81,18 @@ class Button():
ty = ay + ah // 2 + 8
display.bar(ax, ay, aw, ah, style['border-color'])
display.bar(ax + 1, ay + 1, aw - 2, ah - 2, style['bg-color'])
# How to do this smarter way?
if self.text == 'CLEAR':
ui.display.icon(ax, ay, res.load('trezor/res/close-button.toig'),
ui.blend(ui.BLACK, ui.WHITE, 0.95),
ui.BLACK)
else:
display.text_center(tx, ty, self.text,
if isinstance(self.content, str):
display.text_center(tx, ty, self.content,
style['text-style'],
style['fg-color'],
style['bg-color'])
else:
display.icon(ax, ay, self.content,
style['fg-color'],
style['bg-color'])
self.state = state
def send(self, event, pos):

View File

@ -1,9 +1,7 @@
from . import display, clear
from trezor import ui, loop
from . import display
from .button import Button, BTN_CLICKED, CLEAR_BUTTON, CLEAR_BUTTON_ACTIVE
from trezor import ui, res
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):
@ -25,13 +23,16 @@ class PinMatrix():
def __init__(self, label='Enter PIN', pin=''):
self.label = label
self.pin = pin
self.clear_button = Button((240 - 35, 5, 30, 30), 'CLEAR')
self.buttons = [Button(digit_area(i), str(d))
for i, d in enumerate(generate_digits())]
self.clear_button = Button((240 - 35, 5, 30, 30),
res.load('trezor/res/close-button.toig'),
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):
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
display.bar(48, 0, 144, 48, ui.BLACK)
@ -42,9 +43,11 @@ class PinMatrix():
# render clear button
if self.pin:
self.clear_button.render()
else:
display.bar(240 - 48, 0, 48, 42, ui.BLACK)
# pin matrix buttons
for btn in self.buttons:
for btn in self.pin_buttons:
btn.render()
# vertical border bars
@ -58,10 +61,6 @@ class PinMatrix():
def send(self, event, pos):
if self.clear_button.send(event, pos) == BTN_CLICKED:
self.pin = ''
self.label = 'Enter PIN'
display.bar(240 - 48, 0, 48, 42, ui.BLACK)
for btn in self.buttons:
for btn in self.pin_buttons:
if btn.send(event, pos) == BTN_CLICKED:
self.pin += btn.text
self.pin += btn.content