core/modtrezorui: remove prefill from text functions

use display.bar where needed to prefill the areas
pull/1174/head
Pavol Rusnak 4 years ago
parent 2e5771db79
commit 4e11735d22

@ -294,13 +294,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorui_Display_print_obj,
/// font: int,
/// fgcolor: int,
/// bgcolor: int,
/// minwidth: int = None,
/// ) -> int:
/// ) -> None:
/// """
/// Renders left-aligned text at position (x,y) where x is left position and
/// y is baseline. Font font is used for rendering, fgcolor is used as
/// foreground color, bgcolor as background. Fills at least minwidth pixels
/// with bgcolor. Returns width of rendered text in pixels.
/// foreground color, bgcolor as background.
/// """
STATIC mp_obj_t mod_trezorui_Display_text(size_t n_args, const mp_obj_t *args) {
mp_int_t x = mp_obj_get_int(args[1]);
@ -310,16 +308,10 @@ STATIC mp_obj_t mod_trezorui_Display_text(size_t n_args, const mp_obj_t *args) {
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]);
mp_int_t minwidth = (n_args > 7) ? mp_obj_get_int(args[7]) : 0;
// prefill start
int w = display_text_width(text.buf, text.len, font);
int barwidth = MAX(w, minwidth);
display_bar(x, y - 18, barwidth, 23, bgcolor);
// prefill end
display_text(x, y, text.buf, text.len, font, fgcolor, bgcolor);
return mp_obj_new_int(w);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_obj, 7, 8,
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_obj, 7, 7,
mod_trezorui_Display_text);
/// def text_center(
@ -330,13 +322,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_obj, 7, 8,
/// font: int,
/// fgcolor: int,
/// bgcolor: int,
/// minwidth: int = None,
/// ) -> int:
/// ) -> None:
/// """
/// Renders text centered at position (x,y) where x is text center and y is
/// baseline. Font font is used for rendering, fgcolor is used as foreground
/// color, bgcolor as background. Fills at least minwidth pixels with
/// bgcolor. Returns width of rendered text in pixels.
/// color, bgcolor as background.
/// """
STATIC mp_obj_t mod_trezorui_Display_text_center(size_t n_args,
const mp_obj_t *args) {
@ -347,17 +337,11 @@ STATIC mp_obj_t mod_trezorui_Display_text_center(size_t n_args,
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]);
mp_int_t minwidth = (n_args > 7) ? mp_obj_get_int(args[7]) : 0;
// prefill start
int w = display_text_width(text.buf, text.len, font);
int barwidth = MAX(w, minwidth);
display_bar(x - barwidth / 2, y - 18, barwidth, 23, bgcolor);
// prefill end
display_text_center(x, y, text.buf, text.len, font, fgcolor, bgcolor);
return mp_obj_new_int(w);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_center_obj,
7, 8,
7, 7,
mod_trezorui_Display_text_center);
/// def text_right(
@ -368,13 +352,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_center_obj,
/// font: int,
/// fgcolor: int,
/// bgcolor: int,
/// minwidth: int = None,
/// ) -> int:
/// ) -> None:
/// """
/// Renders right-aligned text at position (x,y) where x is right position
/// and y is baseline. Font font is used for rendering, fgcolor is used as
/// foreground color, bgcolor as background. Fills at least minwidth pixels
/// with bgcolor. Returns width of rendered text in pixels.
/// foreground color, bgcolor as background.
/// """
STATIC mp_obj_t mod_trezorui_Display_text_right(size_t n_args,
const mp_obj_t *args) {
@ -385,17 +367,11 @@ STATIC mp_obj_t mod_trezorui_Display_text_right(size_t n_args,
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]);
mp_int_t minwidth = (n_args > 7) ? mp_obj_get_int(args[7]) : 0;
// prefill start
int w = display_text_width(text.buf, text.len, font);
int barwidth = MAX(w, minwidth);
display_bar(x - barwidth, y - 18, barwidth, 23, bgcolor);
// prefill end
display_text_right(x, y, text.buf, text.len, font, fgcolor, bgcolor);
return mp_obj_new_int(w);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorui_Display_text_right_obj,
7, 8,
7, 7,
mod_trezorui_Display_text_right);
/// def text_width(self, text: str, font: int) -> int:

@ -108,13 +108,11 @@ class Display:
font: int,
fgcolor: int,
bgcolor: int,
minwidth: int = None,
) -> int:
) -> None:
"""
Renders left-aligned text at position (x,y) where x is left position and
y is baseline. Font font is used for rendering, fgcolor is used as
foreground color, bgcolor as background. Fills at least minwidth pixels
with bgcolor. Returns width of rendered text in pixels.
foreground color, bgcolor as background.
"""
def text_center(
@ -125,13 +123,11 @@ class Display:
font: int,
fgcolor: int,
bgcolor: int,
minwidth: int = None,
) -> int:
) -> None:
"""
Renders text centered at position (x,y) where x is text center and y is
baseline. Font font is used for rendering, fgcolor is used as foreground
color, bgcolor as background. Fills at least minwidth pixels with
bgcolor. Returns width of rendered text in pixels.
color, bgcolor as background.
"""
def text_right(
@ -142,13 +138,11 @@ class Display:
font: int,
fgcolor: int,
bgcolor: int,
minwidth: int = None,
) -> int:
) -> None:
"""
Renders right-aligned text at position (x,y) where x is right position
and y is baseline. Font font is used for rendering, fgcolor is used as
foreground color, bgcolor as background. Fills at least minwidth pixels
with bgcolor. Returns width of rendered text in pixels.
foreground color, bgcolor as background.
"""
def text_width(self, text: str, font: int) -> int:

@ -562,12 +562,9 @@ class Slip39NumInput(ui.Component):
else:
first_line_text = "Set the total number of"
second_line_text = "shares in Group %s." % (self.group_id + 1)
ui.display.text(
12, 130, first_line_text, ui.NORMAL, ui.FG, ui.BG, ui.WIDTH - 12
)
ui.display.text(
12, 156, second_line_text, ui.NORMAL, ui.FG, ui.BG, ui.WIDTH - 12
)
ui.display.bar(0, 110, ui.WIDTH, 52, ui.BG)
ui.display.text(12, 130, first_line_text, ui.NORMAL, ui.FG, ui.BG)
ui.display.text(12, 156, second_line_text, ui.NORMAL, ui.FG, ui.BG)
elif self.step is Slip39NumInput.SET_THRESHOLD:
if self.group_id is None:
first_line_text = "For recovery you need"
@ -580,29 +577,22 @@ class Slip39NumInput(ui.Component):
else:
first_line_text = "The required number of "
second_line_text = "shares to form Group %s." % (self.group_id + 1)
ui.display.bar(0, 110, ui.WIDTH, 52, ui.BG)
ui.display.text(12, 130, first_line_text, ui.NORMAL, ui.FG, ui.BG)
ui.display.text(
12, 156, second_line_text, ui.NORMAL, ui.FG, ui.BG, ui.WIDTH - 12
)
ui.display.text(12, 156, second_line_text, ui.NORMAL, ui.FG, ui.BG)
elif self.step is Slip39NumInput.SET_GROUPS:
ui.display.bar(0, 110, ui.WIDTH, 52, ui.BG)
ui.display.text(
12, 130, "A group is made up of", ui.NORMAL, ui.FG, ui.BG
)
ui.display.text(
12, 156, "recovery shares.", ui.NORMAL, ui.FG, ui.BG, ui.WIDTH - 12
)
ui.display.text(12, 156, "recovery shares.", ui.NORMAL, ui.FG, ui.BG)
elif self.step is Slip39NumInput.SET_GROUP_THRESHOLD:
ui.display.bar(0, 110, ui.WIDTH, 52, ui.BG)
ui.display.text(
12, 130, "The required number of", ui.NORMAL, ui.FG, ui.BG
)
ui.display.text(
12,
156,
"groups for recovery.",
ui.NORMAL,
ui.FG,
ui.BG,
ui.WIDTH - 12,
12, 156, "groups for recovery.", ui.NORMAL, ui.FG, ui.BG
)
self.repaint = False

@ -25,9 +25,7 @@ def show_pin_timeout(seconds: int, progress: int, message: str) -> bool:
# avoid overdraw in case of repeated progress calls
ui.display.clear()
_previous_seconds = None
ui.display.text_center(
ui.WIDTH // 2, 37, message, ui.BOLD, ui.FG, ui.BG, ui.WIDTH
)
ui.display.text_center(ui.WIDTH // 2, 37, message, ui.BOLD, ui.FG, ui.BG)
if not utils.DISABLE_ANIMATION:
ui.display.loader(progress, False, 0, ui.FG, ui.BG)
@ -39,8 +37,9 @@ def show_pin_timeout(seconds: int, progress: int, message: str) -> bool:
remaining = "1 second left"
else:
remaining = "%d seconds left" % seconds
ui.display.bar(0, ui.HEIGHT - 42, ui.WIDTH, 25, ui.BG)
ui.display.text_center(
ui.WIDTH // 2, ui.HEIGHT - 22, remaining, ui.BOLD, ui.FG, ui.BG, ui.WIDTH
ui.WIDTH // 2, ui.HEIGHT - 22, remaining, ui.BOLD, ui.FG, ui.BG
)
_previous_seconds = seconds

@ -197,18 +197,15 @@ class Label(ui.Component):
if self.repaint:
align = self.align
ax, ay, aw, ah = self.area
ui.display.bar(ax, ay, aw, ah, ui.BG)
tx = ax + aw // 2
ty = ay + ah // 2 + 8
if align is LABEL_LEFT:
ui.display.text(tx, ty, self.content, self.style, ui.FG, ui.BG, aw)
ui.display.text(tx, ty, self.content, self.style, ui.FG, ui.BG)
elif align is LABEL_CENTER:
ui.display.text_center(
tx, ty, self.content, self.style, ui.FG, ui.BG, aw
)
ui.display.text_center(tx, ty, self.content, self.style, ui.FG, ui.BG)
elif align is LABEL_RIGHT:
ui.display.text_right(
tx, ty, self.content, self.style, ui.FG, ui.BG, aw
)
ui.display.text_right(tx, ty, self.content, self.style, ui.FG, ui.BG)
self.repaint = False
if __debug__:

Loading…
Cancel
Save