mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-28 22:15:42 +00:00
trezor/ui: add experimental layout decorator
This commit is contained in:
parent
305d4d9cc5
commit
df995eae49
@ -62,13 +62,13 @@ def rotate(pos: tuple) -> tuple:
|
|||||||
return (240 - y, x)
|
return (240 - y, x)
|
||||||
|
|
||||||
|
|
||||||
def pulse(delay):
|
def pulse(delay: int):
|
||||||
while True:
|
while True:
|
||||||
# normalize sin from interval -1:1 to 0:1
|
# normalize sin from interval -1:1 to 0:1
|
||||||
yield 0.5 + 0.5 * math.sin(utime.ticks_us() / delay)
|
yield 0.5 + 0.5 * math.sin(utime.ticks_us() / delay)
|
||||||
|
|
||||||
|
|
||||||
async def alert(count=3):
|
async def alert(count: int=3):
|
||||||
short_sleep = loop.sleep(20000)
|
short_sleep = loop.sleep(20000)
|
||||||
long_sleep = loop.sleep(80000)
|
long_sleep = loop.sleep(80000)
|
||||||
current = display.backlight()
|
current = display.backlight()
|
||||||
@ -82,7 +82,7 @@ async def alert(count=3):
|
|||||||
display.backlight(current)
|
display.backlight(current)
|
||||||
|
|
||||||
|
|
||||||
async def backlight_slide(val, delay=20000):
|
async def backlight_slide(val: int, delay: int=20000):
|
||||||
sleep = loop.sleep(delay)
|
sleep = loop.sleep(delay)
|
||||||
current = display.backlight()
|
current = display.backlight()
|
||||||
for i in range(current, val, -1 if current > val else 1):
|
for i in range(current, val, -1 if current > val else 1):
|
||||||
@ -90,7 +90,18 @@ async def backlight_slide(val, delay=20000):
|
|||||||
await sleep
|
await sleep
|
||||||
|
|
||||||
|
|
||||||
def header(title, icon=ICON_RESET, fg=BLACK, bg=BLACK):
|
def layout(f):
|
||||||
|
async def inner(*args, **kwargs):
|
||||||
|
slider = backlight_slide(BACKLIGHT_NORMAL, 4000)
|
||||||
|
loop.schedule(slider)
|
||||||
|
await f(*args, **kwargs)
|
||||||
|
slider.close()
|
||||||
|
await backlight_slide(BACKLIGHT_DIM, 4000)
|
||||||
|
|
||||||
|
return inner
|
||||||
|
|
||||||
|
|
||||||
|
def header(title: str, icon: bytes=ICON_RESET, fg: int=BLACK, bg: int=BLACK):
|
||||||
display.bar(0, 0, 240, 32, bg)
|
display.bar(0, 0, 240, 32, bg)
|
||||||
if icon is not None:
|
if icon is not None:
|
||||||
display.icon(8, 4, res.load(icon), fg, bg)
|
display.icon(8, 4, res.load(icon), fg, bg)
|
||||||
@ -106,9 +117,9 @@ class Widget:
|
|||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
touch = loop.select(io.TOUCH)
|
touch = loop.select(io.TOUCH)
|
||||||
while True:
|
result = None
|
||||||
|
while result is None:
|
||||||
self.render()
|
self.render()
|
||||||
event, *pos = yield touch
|
event, *pos = yield touch
|
||||||
result = self.touch(event, pos)
|
result = self.touch(event, pos)
|
||||||
if result is not None:
|
return result
|
||||||
return result
|
|
||||||
|
Loading…
Reference in New Issue
Block a user