mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
move text_center, text_right methods into display class
This commit is contained in:
parent
707b642954
commit
588be646c0
@ -332,6 +332,36 @@ STATIC mp_obj_t mod_TrezorUi_Display_text(size_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_text_obj, 7, 7, mod_TrezorUi_Display_text);
|
||||
|
||||
// def Display.text_center(self, x: int, y: int, text: bytes, font: int, fgcolor: int, bgcolor: int) -> None
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_text_center(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ);
|
||||
mp_int_t font = mp_obj_get_int(args[4]);
|
||||
mp_int_t fgcolor = mp_obj_get_int(args[5]);
|
||||
mp_int_t bgcolor = mp_obj_get_int(args[6]);
|
||||
uint32_t w = display_text_width(bufinfo.buf, bufinfo.len, font);
|
||||
display_text(x - w / 2, y, bufinfo.buf, bufinfo.len, font, fgcolor, bgcolor);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_text_center_obj, 7, 7, mod_TrezorUi_Display_text_center);
|
||||
|
||||
// def Display.text_right(self, x: int, y: int, text: bytes, font: int, fgcolor: int, bgcolor: int) -> None
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_text_right(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ);
|
||||
mp_int_t font = mp_obj_get_int(args[4]);
|
||||
mp_int_t fgcolor = mp_obj_get_int(args[5]);
|
||||
mp_int_t bgcolor = mp_obj_get_int(args[6]);
|
||||
uint32_t w = display_text_width(bufinfo.buf, bufinfo.len, font);
|
||||
display_text(x - w, y, bufinfo.buf, bufinfo.len, font, fgcolor, bgcolor);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_text_right_obj, 7, 7, mod_TrezorUi_Display_text_right);
|
||||
|
||||
// def Display.text_width(self, text: bytes, font: int) -> int
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_text_width(mp_obj_t self, mp_obj_t text, mp_obj_t font) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
@ -437,6 +467,8 @@ STATIC const mp_rom_map_elem_t mod_TrezorUi_Display_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_image), MP_ROM_PTR(&mod_TrezorUi_Display_image_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_icon), MP_ROM_PTR(&mod_TrezorUi_Display_icon_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&mod_TrezorUi_Display_text_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_text_center), MP_ROM_PTR(&mod_TrezorUi_Display_text_center_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_text_right), MP_ROM_PTR(&mod_TrezorUi_Display_text_right_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_text_width), MP_ROM_PTR(&mod_TrezorUi_Display_text_width_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_qrcode), MP_ROM_PTR(&mod_TrezorUi_Display_qrcode_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_loader), MP_ROM_PTR(&mod_TrezorUi_Display_loader_obj) },
|
||||
|
@ -17,7 +17,7 @@ def layout_tap_to_confirm(address, amount, currency):
|
||||
_background = ui.WHITE
|
||||
|
||||
def func(foreground):
|
||||
ui.display.text(68, 212, 'TAP TO CONFIRM', 2, foreground, _background)
|
||||
ui.display.text(68, 212, 'TAP TO CONFIRM', ui.BOLD, foreground, _background)
|
||||
|
||||
f.seek(0)
|
||||
ui.display.icon(3, 170, f.read(), _background, foreground)
|
||||
|
@ -8,7 +8,7 @@ def layout_homescreen():
|
||||
|
||||
ui.display.bar(0, 0, 240, 48 * 4, ui.BLACK)
|
||||
ui.display.bar(0, 48 * 4, 240, 48, c)
|
||||
ui.text_center(120, 240 - 18, 'Hold to confirm', 2, ui.WHITE, c)
|
||||
ui.display.text_center(120, 240 - 18, 'Hold to confirm', ui.BOLD, ui.WHITE, c)
|
||||
p = 0
|
||||
|
||||
def func(foreground):
|
||||
|
@ -36,17 +36,6 @@ MONO = const(0)
|
||||
NORMAL = const(1)
|
||||
BOLD = const(2)
|
||||
|
||||
def text(x: int, y: int, text: bytes, font: int, fgcolor: int, bgcolor: int) -> None:
|
||||
display.text(x, y, text, font, fgcolor, bgcolor)
|
||||
|
||||
def text_right(x: int, y: int, text: bytes, font: int, fgcolor: int, bgcolor: int) -> None:
|
||||
w = display.text_width(text, font)
|
||||
display.text(x - w, y, text, font, fgcolor, bgcolor)
|
||||
|
||||
def text_center(x: int, y: int, text: bytes, font: int, fgcolor: int, bgcolor: int) -> None:
|
||||
w = display.text_width(text, font)
|
||||
display.text(x - w // 2, y, text, font, fgcolor, bgcolor)
|
||||
|
||||
def lerpi(a: int, b: int, t: float) -> int:
|
||||
return int(a + t * (b - a))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user