mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-17 11:58:13 +00:00
put ui.utils back in ui/__init__.py
This commit is contained in:
parent
f3c9715ff3
commit
c0313cc868
@ -1,5 +1,4 @@
|
|||||||
from trezor import ui
|
from trezor import ui
|
||||||
from trezor.ui import utils as ui_utils
|
|
||||||
from trezor.ui.swipe import Swipe
|
from trezor.ui.swipe import Swipe
|
||||||
from trezor import loop
|
from trezor import loop
|
||||||
|
|
||||||
@ -17,10 +16,10 @@ def layout_homescreen():
|
|||||||
|
|
||||||
def func(foreground):
|
def func(foreground):
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
ui.display.icon(0, 0, f.read(), foreground, ui_utils.BLACK)
|
ui.display.icon(0, 0, f.read(), foreground, ui.BLACK)
|
||||||
|
|
||||||
orientation = swipe_to_change_orientation()
|
orientation = swipe_to_change_orientation()
|
||||||
animation = ui_utils.animate_pulse(func, ui_utils.WHITE, ui_utils.GREY, speed=400000)
|
animation = ui.animate_pulse(func, ui.WHITE, ui.GREY, speed=400000)
|
||||||
timeout = loop.Sleep(5000 * 1000)
|
timeout = loop.Sleep(5000 * 1000)
|
||||||
|
|
||||||
yield loop.Wait([
|
yield loop.Wait([
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
from trezor import loop
|
from trezor import loop
|
||||||
from trezor import ui
|
from trezor import ui
|
||||||
from trezor.ui.swipe import Swipe
|
|
||||||
from trezor.ui.pin import PinDialog, PIN_CONFIRMED, PIN_CANCELLED
|
from trezor.ui.pin import PinDialog, PIN_CONFIRMED, PIN_CANCELLED
|
||||||
from trezor.utils import unimport_func
|
from trezor.utils import unimport_func
|
||||||
|
|
||||||
|
@ -1,3 +1,64 @@
|
|||||||
|
import math
|
||||||
|
import utime
|
||||||
|
|
||||||
from TrezorUi import Display
|
from TrezorUi import Display
|
||||||
|
from trezor import loop
|
||||||
|
|
||||||
|
|
||||||
display = Display()
|
display = Display()
|
||||||
|
|
||||||
|
|
||||||
|
def rgbcolor(r: int, g: int, b: int) -> int:
|
||||||
|
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3)
|
||||||
|
|
||||||
|
|
||||||
|
RED = rgbcolor(0xF4, 0x43, 0x36)
|
||||||
|
PINK = rgbcolor(0xE9, 0x1E, 0x63)
|
||||||
|
PURPLE = rgbcolor(0x9C, 0x27, 0xB0)
|
||||||
|
DEEP_PURPLE = rgbcolor(0x67, 0x3A, 0xB7)
|
||||||
|
INDIGO = rgbcolor(0x3F, 0x51, 0xB5)
|
||||||
|
BLUE = rgbcolor(0x21, 0x96, 0xF3)
|
||||||
|
LIGHT_BLUE = rgbcolor(0x03, 0xA9, 0xF4)
|
||||||
|
CYAN = rgbcolor(0x00, 0xBC, 0xD4)
|
||||||
|
TEAL = rgbcolor(0x00, 0x96, 0x88)
|
||||||
|
GREEN = rgbcolor(0x4C, 0xAF, 0x50)
|
||||||
|
LIGHT_GREEN = rgbcolor(0x8B, 0xC3, 0x4A)
|
||||||
|
LIME = rgbcolor(0xCD, 0xDC, 0x39)
|
||||||
|
YELLOW = rgbcolor(0xFF, 0xEB, 0x3B)
|
||||||
|
AMBER = rgbcolor(0xFF, 0xC1, 0x07)
|
||||||
|
ORANGE = rgbcolor(0xFF, 0x98, 0x00)
|
||||||
|
DEEP_ORANGE = rgbcolor(0xFF, 0x57, 0x22)
|
||||||
|
BROWN = rgbcolor(0x79, 0x55, 0x48)
|
||||||
|
GREY = rgbcolor(0x9E, 0x9E, 0x9E)
|
||||||
|
BLUE_GRAY = rgbcolor(0x60, 0x7D, 0x8B)
|
||||||
|
BLACK = rgbcolor(0x00, 0x00, 0x00)
|
||||||
|
WHITE = rgbcolor(0xFF, 0xFF, 0xFF)
|
||||||
|
|
||||||
|
MONO = const(0)
|
||||||
|
NORMAL = const(1)
|
||||||
|
BOLD = const(2)
|
||||||
|
|
||||||
|
|
||||||
|
def in_area(pos, area):
|
||||||
|
x, y = pos
|
||||||
|
ax, ay, aw, ah = area
|
||||||
|
return ax <= x <= ax + aw and ay <= y <= ay + ah
|
||||||
|
|
||||||
|
|
||||||
|
def lerpi(a: int, b: int, t: float) -> int:
|
||||||
|
return int(a + t * (b - a))
|
||||||
|
|
||||||
|
|
||||||
|
def blend(ca: int, cb: int, t: float) -> int:
|
||||||
|
return rgbcolor(lerpi((ca >> 8) & 0xF8, (cb >> 8) & 0xF8, t),
|
||||||
|
lerpi((ca >> 3) & 0xFC, (cb >> 3) & 0xFC, t),
|
||||||
|
lerpi((ca << 3) & 0xF8, (cb << 3) & 0xF8, t))
|
||||||
|
|
||||||
|
|
||||||
|
def animate_pulse(func, ca, cb, speed=200000, delay=30000):
|
||||||
|
while True:
|
||||||
|
# normalize sin from interval -1:1 to 0:1
|
||||||
|
y = 0.5 + 0.5 * math.sin(utime.ticks_us() / speed)
|
||||||
|
c = blend(ca, cb, y)
|
||||||
|
func(c)
|
||||||
|
yield loop.Sleep(delay)
|
||||||
|
@ -1,46 +1,45 @@
|
|||||||
from . import utils
|
from . import display, in_area
|
||||||
from . import display
|
from trezor import ui
|
||||||
from .utils import in_area
|
|
||||||
from trezor import loop
|
from trezor import loop
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_BUTTON = {
|
DEFAULT_BUTTON = {
|
||||||
'bg-color': utils.BLACK,
|
'bg-color': ui.BLACK,
|
||||||
'fg-color': utils.WHITE,
|
'fg-color': ui.WHITE,
|
||||||
'text-style': utils.NORMAL,
|
'text-style': ui.NORMAL,
|
||||||
'border-color': utils.blend(utils.BLACK, utils.WHITE, 0.1),
|
'border-color': ui.blend(ui.BLACK, ui.WHITE, 0.1),
|
||||||
}
|
}
|
||||||
DEFAULT_BUTTON_ACTIVE = {
|
DEFAULT_BUTTON_ACTIVE = {
|
||||||
'bg-color': utils.GREY,
|
'bg-color': ui.GREY,
|
||||||
'fg-color': utils.BLACK,
|
'fg-color': ui.BLACK,
|
||||||
'text-style': utils.BOLD,
|
'text-style': ui.BOLD,
|
||||||
'border-color': utils.GREY,
|
'border-color': ui.GREY,
|
||||||
}
|
}
|
||||||
|
|
||||||
CANCEL_BUTTON = {
|
CANCEL_BUTTON = {
|
||||||
'bg-color': utils.blend(utils.BLACK, utils.RED, 0.3),
|
'bg-color': ui.blend(ui.BLACK, ui.RED, 0.3),
|
||||||
'fg-color': utils.RED,
|
'fg-color': ui.RED,
|
||||||
'text-style': utils.NORMAL,
|
'text-style': ui.NORMAL,
|
||||||
'border-color': utils.blend(utils.BLACK, utils.RED, 0.6),
|
'border-color': ui.blend(ui.BLACK, ui.RED, 0.6),
|
||||||
}
|
}
|
||||||
CANCEL_BUTTON_ACTIVE = {
|
CANCEL_BUTTON_ACTIVE = {
|
||||||
'bg-color': utils.RED,
|
'bg-color': ui.RED,
|
||||||
'fg-color': utils.WHITE,
|
'fg-color': ui.WHITE,
|
||||||
'text-style': utils.BOLD,
|
'text-style': ui.BOLD,
|
||||||
'border-color': utils.RED,
|
'border-color': ui.RED,
|
||||||
}
|
}
|
||||||
|
|
||||||
CONFIRM_BUTTON = {
|
CONFIRM_BUTTON = {
|
||||||
'bg-color': utils.blend(utils.BLACK, utils.GREEN, 0.3),
|
'bg-color': ui.blend(ui.BLACK, ui.GREEN, 0.3),
|
||||||
'fg-color': utils.GREEN,
|
'fg-color': ui.GREEN,
|
||||||
'text-style': utils.NORMAL,
|
'text-style': ui.NORMAL,
|
||||||
'border-color': utils.blend(utils.BLACK, utils.GREEN, 0.6),
|
'border-color': ui.blend(ui.BLACK, ui.GREEN, 0.6),
|
||||||
}
|
}
|
||||||
CONFIRM_BUTTON_ACTIVE = {
|
CONFIRM_BUTTON_ACTIVE = {
|
||||||
'bg-color': utils.GREEN,
|
'bg-color': ui.GREEN,
|
||||||
'fg-color': utils.WHITE,
|
'fg-color': ui.WHITE,
|
||||||
'text-style': utils.BOLD,
|
'text-style': ui.BOLD,
|
||||||
'border-color': utils.GREEN,
|
'border-color': ui.GREEN,
|
||||||
}
|
}
|
||||||
|
|
||||||
BTN_CLICKED = const(1)
|
BTN_CLICKED = const(1)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import utime
|
import utime
|
||||||
|
|
||||||
from .utils import in_area
|
from . import in_area
|
||||||
from trezor import loop
|
from trezor import loop
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,60 +0,0 @@
|
|||||||
import math
|
|
||||||
import utime
|
|
||||||
|
|
||||||
from trezor import loop
|
|
||||||
|
|
||||||
|
|
||||||
def rgbcolor(r: int, g: int, b: int) -> int:
|
|
||||||
return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3)
|
|
||||||
|
|
||||||
|
|
||||||
RED = rgbcolor(0xF4, 0x43, 0x36)
|
|
||||||
PINK = rgbcolor(0xE9, 0x1E, 0x63)
|
|
||||||
PURPLE = rgbcolor(0x9C, 0x27, 0xB0)
|
|
||||||
DEEP_PURPLE = rgbcolor(0x67, 0x3A, 0xB7)
|
|
||||||
INDIGO = rgbcolor(0x3F, 0x51, 0xB5)
|
|
||||||
BLUE = rgbcolor(0x21, 0x96, 0xF3)
|
|
||||||
LIGHT_BLUE = rgbcolor(0x03, 0xA9, 0xF4)
|
|
||||||
CYAN = rgbcolor(0x00, 0xBC, 0xD4)
|
|
||||||
TEAL = rgbcolor(0x00, 0x96, 0x88)
|
|
||||||
GREEN = rgbcolor(0x4C, 0xAF, 0x50)
|
|
||||||
LIGHT_GREEN = rgbcolor(0x8B, 0xC3, 0x4A)
|
|
||||||
LIME = rgbcolor(0xCD, 0xDC, 0x39)
|
|
||||||
YELLOW = rgbcolor(0xFF, 0xEB, 0x3B)
|
|
||||||
AMBER = rgbcolor(0xFF, 0xC1, 0x07)
|
|
||||||
ORANGE = rgbcolor(0xFF, 0x98, 0x00)
|
|
||||||
DEEP_ORANGE = rgbcolor(0xFF, 0x57, 0x22)
|
|
||||||
BROWN = rgbcolor(0x79, 0x55, 0x48)
|
|
||||||
GREY = rgbcolor(0x9E, 0x9E, 0x9E)
|
|
||||||
BLUE_GRAY = rgbcolor(0x60, 0x7D, 0x8B)
|
|
||||||
BLACK = rgbcolor(0x00, 0x00, 0x00)
|
|
||||||
WHITE = rgbcolor(0xFF, 0xFF, 0xFF)
|
|
||||||
|
|
||||||
MONO = const(0)
|
|
||||||
NORMAL = const(1)
|
|
||||||
BOLD = const(2)
|
|
||||||
|
|
||||||
|
|
||||||
def in_area(pos, area):
|
|
||||||
x, y = pos
|
|
||||||
ax, ay, aw, ah = area
|
|
||||||
return ax <= x <= ax + aw and ay <= y <= ay + ah
|
|
||||||
|
|
||||||
|
|
||||||
def lerpi(a: int, b: int, t: float) -> int:
|
|
||||||
return int(a + t * (b - a))
|
|
||||||
|
|
||||||
|
|
||||||
def blend(ca: int, cb: int, t: float) -> int:
|
|
||||||
return rgbcolor(lerpi((ca >> 8) & 0xF8, (cb >> 8) & 0xF8, t),
|
|
||||||
lerpi((ca >> 3) & 0xFC, (cb >> 3) & 0xFC, t),
|
|
||||||
lerpi((ca << 3) & 0xF8, (cb << 3) & 0xF8, t))
|
|
||||||
|
|
||||||
|
|
||||||
def animate_pulse(func, ca, cb, speed=200000, delay=30000):
|
|
||||||
while True:
|
|
||||||
# normalize sin from interval -1:1 to 0:1
|
|
||||||
y = 0.5 + 0.5 * math.sin(utime.ticks_us() / speed)
|
|
||||||
c = blend(ca, cb, y)
|
|
||||||
func(c)
|
|
||||||
yield loop.Sleep(delay)
|
|
Loading…
Reference in New Issue
Block a user