Skip to content

Commit

Permalink
move page indicator to nav area
Browse files Browse the repository at this point in the history
  • Loading branch information
bitgamma committed May 31, 2024
1 parent 3c7b044 commit b574640
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 39 deletions.
74 changes: 40 additions & 34 deletions app/ui/dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

#define TX_CONFIRM_TIMEOUT 30000
#define BIGNUM_STRING_LEN 84
#define UINT32_STRING_LEN 11
#define MAX_PAGE_COUNT 50
#define MESSAGE_MAX_X (SCREEN_WIDTH - TH_TEXT_HORIZONTAL_MARGIN)
#define MESSAGE_MAX_Y (SCREEN_HEIGHT - TH_TEXT_VERTICAL_MARGIN)
#define MAX_MSG_TITLE_LEN 80
#define MESSAGE_MAX_Y (SCREEN_HEIGHT - TH_NAV_HINT_HEIGHT)

const uint8_t ETH_ERC20_SIGNATURE[] = { 0xa9, 0x05, 0x9c, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
#define ETH_ERC20_SIGNATURE_LEN 16
Expand Down Expand Up @@ -100,6 +100,36 @@ app_err_t dialog_nav_hints_colors(icons_t left, icons_t right, uint16_t bg, uint
return ERR_OK;
}

static app_err_t dialog_pager(size_t page, size_t last_page) {
uint8_t page_indicator[UINT32_STRING_LEN * 2];
size_t total_len = 0;

uint8_t page_str[UINT32_STRING_LEN];
uint8_t* p = u32toa(page + 1, page_str, UINT32_STRING_LEN);
uint8_t p_len = strlen((char *) p);
memcpy(&page_indicator[total_len], p, p_len);
total_len += p_len;

page_indicator[total_len++] = '/';

p = u32toa(last_page + 1, page_str, UINT32_STRING_LEN);
p_len = strlen((char *) p);
memcpy(&page_indicator[total_len], p, p_len);
total_len += p_len;
page_indicator[total_len] = '\0';

screen_text_ctx_t ctx = {
.x = 0,
.y = SCREEN_HEIGHT - (TH_FONT_TITLE)->yAdvance,
.font = TH_FONT_TITLE,
.bg = TH_COLOR_BG,
.fg = TH_COLOR_FG,
};

screen_draw_centered_string(&ctx, (char*) page_indicator);
return ERR_OK;
}

app_err_t dialog_margin(uint16_t yOff, uint16_t height) {
screen_area_t area = { 0, yOff, SCREEN_WIDTH, height };
return screen_fill_area(&area, TH_COLOR_BG);
Expand Down Expand Up @@ -254,7 +284,6 @@ app_err_t dialog_confirm_tx() {
static void dialog_draw_message(const char* txt) {
dialog_title("");
dialog_footer(TH_TITLE_HEIGHT);
dialog_nav_hints(0, ICON_NAV_NEXT);

screen_text_ctx_t ctx = {
.font = TH_FONT_TEXT,
Expand All @@ -271,30 +300,6 @@ static void dialog_draw_message(const char* txt) {
screen_draw_text(&ctx, MESSAGE_MAX_X, SCREEN_HEIGHT, (uint8_t*) txt, len, false, true);
}

static inline void _dialog_paged_title(const char* base, char title[MAX_MSG_TITLE_LEN], size_t page, size_t last_page) {
size_t base_len = strlen(base);
assert(base_len < (MAX_MSG_TITLE_LEN - 9));

memcpy(title, base, base_len);
title[base_len++] = ' ';
title[base_len++] = '(';

uint8_t page_str[4];
uint8_t* p = u32toa(page + 1, page_str, 4);
uint8_t p_len = strlen((char *) p);
memcpy(&title[base_len], p, p_len);
base_len += p_len;

title[base_len++] = '/';

p = u32toa(last_page + 1, page_str, 4);
p_len = strlen((char *) p);
memcpy(&title[base_len], p, p_len);
base_len += p_len;
title[base_len++] = ')';
title[base_len] = '\0';
}

app_err_t dialog_confirm_text_based(const uint8_t* data, size_t len, eip712_domain_t* eip712) {
size_t pages[MAX_PAGE_COUNT];
size_t last_page = 0;
Expand Down Expand Up @@ -332,10 +337,8 @@ app_err_t dialog_confirm_text_based(const uint8_t* data, size_t len, eip712_doma

while(1) {
size_t offset = pages[page];
char title[MAX_MSG_TITLE_LEN];
_dialog_paged_title(LSTR(eip712 ? EIP712_CONFIRM_TITLE : MSG_CONFIRM_TITLE), title, page, last_page);

dialog_title(title);
dialog_title(LSTR(eip712 ? EIP712_CONFIRM_TITLE : MSG_CONFIRM_TITLE));

if (page == 0) {
ctx.y = TH_TITLE_HEIGHT;
Expand Down Expand Up @@ -374,6 +377,7 @@ app_err_t dialog_confirm_text_based(const uint8_t* data, size_t len, eip712_doma

screen_draw_text(&ctx, MESSAGE_MAX_X, MESSAGE_MAX_Y, &data[offset], (len - offset), false, false);
dialog_nav_hints(ICON_NAV_BACK, ICON_NAV_NEXT);
dialog_pager(page, last_page);

switch(ui_wait_keypress(pdMS_TO_TICKS(TX_CONFIRM_TIMEOUT))) {
case KEYPAD_KEY_LEFT:
Expand Down Expand Up @@ -413,7 +417,9 @@ app_err_t dialog_confirm_eip712() {
return dialog_confirm_text_based(g_camera_fb[0], len, &domain);
}

static inline app_err_t dialog_wait_dismiss() {
static app_err_t dialog_wait_dismiss() {
dialog_nav_hints(0, ICON_NAV_NEXT);

while(1) {
switch(ui_wait_keypress(portMAX_DELAY)) {
case KEYPAD_KEY_CONFIRM:
Expand All @@ -424,7 +430,9 @@ static inline app_err_t dialog_wait_dismiss() {
}
}

static inline app_err_t dialog_wait_dismiss_cancellable() {
static app_err_t dialog_wait_dismiss_cancellable() {
dialog_nav_hints(ICON_NAV_BACK, ICON_NAV_NEXT);

while(1) {
switch(ui_wait_keypress(portMAX_DELAY)) {
case KEYPAD_KEY_CANCEL:
Expand Down Expand Up @@ -457,7 +465,6 @@ app_err_t dialog_info() {
app_err_t dialog_prompt() {
dialog_title(g_ui_cmd.params.prompt.title);
dialog_footer(TH_TITLE_HEIGHT);
dialog_nav_hints(ICON_NAV_BACK, ICON_NAV_NEXT);

screen_text_ctx_t ctx = {
.font = TH_FONT_TEXT,
Expand Down Expand Up @@ -486,7 +493,6 @@ app_err_t dialog_dev_auth() {
app_err_t dialog_wrong_auth() {
dialog_title("");
dialog_footer(TH_TITLE_HEIGHT);
dialog_nav_hints(0, ICON_NAV_NEXT);

screen_text_ctx_t ctx = {
.font = TH_FONT_TEXT,
Expand Down
10 changes: 5 additions & 5 deletions app/ui/theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@
#define TH_PROGRESS_LEFT_MARGIN 10
#define TH_PROGRESS_VERTICAL_MARGIN 10

#define TH_NAV_HINT_LEFT_X TH_DEF_LEFT_MARGIN
#define TH_NAV_HINT_RIGHT_X (SCREEN_WIDTH - 28 - TH_DEF_LEFT_MARGIN)
#define TH_NAV_HINT_TOP (SCREEN_HEIGHT - TH_DEF_LEFT_MARGIN - 28)
#define TH_NAV_HINT_WIDTH 60
#define TH_NAV_HINT_HEIGHT 40
#define TH_NAV_HINT_LEFT_X 0
#define TH_NAV_HINT_RIGHT_X (SCREEN_WIDTH - 28)
#define TH_NAV_HINT_TOP (SCREEN_HEIGHT - 28)
#define TH_NAV_HINT_WIDTH 40
#define TH_NAV_HINT_HEIGHT 30

#endif

0 comments on commit b574640

Please sign in to comment.