button border

This commit is contained in:
Jan Pochyla 2016-05-11 14:55:26 +02:00 committed by Pavol Rusnak
parent ef44e9ded8
commit 7bf92f118b
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
1 changed files with 14 additions and 9 deletions

View File

@ -10,34 +10,42 @@ def in_area(pos, area):
DEFAULT_BUTTON = { DEFAULT_BUTTON = {
'bg-color': ui.WHITE, 'bg-color': ui.BLACK,
'fg-color': ui.BLACK, 'fg-color': ui.WHITE,
'text-style': ui.NORMAL, 'text-style': ui.NORMAL,
'border-color': ui.blend(ui.BLACK, ui.WHITE, 0.1),
} }
DEFAULT_BUTTON_ACTIVE = { DEFAULT_BUTTON_ACTIVE = {
'bg-color': ui.GREY, 'bg-color': ui.GREY,
'fg-color': ui.BLACK, 'fg-color': ui.BLACK,
'text-style': ui.BOLD, 'text-style': ui.BOLD,
'border-color': ui.GREY,
} }
CANCEL_BUTTON = { CANCEL_BUTTON = {
'bg-color': ui.blend(ui.BLACK, ui.RED, 0.3), 'bg-color': ui.blend(ui.BLACK, ui.RED, 0.3),
'fg-color': ui.RED, 'fg-color': ui.RED,
'text-style': ui.NORMAL, 'text-style': ui.NORMAL,
'border-color': ui.blend(ui.BLACK, ui.RED, 0.6),
} }
CANCEL_BUTTON_ACTIVE = { CANCEL_BUTTON_ACTIVE = {
'bg-color': ui.RED, 'bg-color': ui.RED,
'fg-color': ui.WHITE, 'fg-color': ui.WHITE,
'text-style': ui.BOLD, 'text-style': ui.BOLD,
'border-color': ui.RED,
} }
CONFIRM_BUTTON = { CONFIRM_BUTTON = {
'bg-color': ui.blend(ui.BLACK, ui.GREEN, 0.3), 'bg-color': ui.blend(ui.BLACK, ui.GREEN, 0.3),
'fg-color': ui.GREEN, 'fg-color': ui.GREEN,
'text-style': ui.NORMAL, 'text-style': ui.NORMAL,
'border-color': ui.blend(ui.BLACK, ui.GREEN, 0.6),
} }
CONFIRM_BUTTON_ACTIVE = { CONFIRM_BUTTON_ACTIVE = {
'bg-color': ui.GREEN, 'bg-color': ui.GREEN,
'fg-color': ui.WHITE, 'fg-color': ui.WHITE,
'text-style': ui.BOLD, 'text-style': ui.BOLD,
'border-color': ui.GREEN,
} }
@ -64,8 +72,9 @@ class Button():
style = self.active_style if state & BTN_ACTIVE else self.normal_style style = self.active_style if state & BTN_ACTIVE else self.normal_style
ax, ay, aw, ah = self.area ax, ay, aw, ah = self.area
tx = ax + aw // 2 tx = ax + aw // 2
ty = ay + ah // 2 + 8 # offset to make the text vertically centered ty = ay + ah // 2 + 8
ui.display.bar(ax, ay, aw, ah, style['bg-color']) ui.display.bar(ax, ay, aw, ah, style['border-color'])
ui.display.bar(ax+1, ay+1, aw-2, ah-2, style['bg-color'])
ui.display.text_center(tx, ty, self.text, ui.display.text_center(tx, ty, self.text,
style['text-style'], style['text-style'],
style['fg-color'], style['fg-color'],
@ -92,13 +101,9 @@ class Button():
def digit_area(d): def digit_area(d):
width = const(80) width = const(80)
height = const(60) height = const(60)
margin = const(1)
x = ((d - 1) % 3) * width x = ((d - 1) % 3) * width
y = ((d - 1) // 3) * height y = ((d - 1) // 3) * height
return (x + margin, return (x, y, width, height)
y + margin,
width - margin,
height - margin)
PIN_CONFIRMED = const(1) PIN_CONFIRMED = const(1)