Skip to content

Commit 72296de

Browse files
author
Jamie C. Driver
committed
ui: handle up to 7 equal h/v splits to allow better grid display
Also make cell text alignment and font explicit
1 parent 5b90289 commit 72296de

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

main/ui.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ void populate_title_bar(
134134
gui_view_node_t* add_title_bar(
135135
gui_activity_t* activity, const char* title, btn_data_t* btns, size_t num_btns, gui_view_node_t** title_node);
136136

137-
// Helper to create an activity which is a grid of (up to 5x5) text items
137+
// Helper to create an activity which is a grid of (up to 7x7) text items
138138
gui_activity_t* make_text_grid_activity(const char* title, btn_data_t* hdrbtns, size_t num_hdrbtns, size_t toppad,
139-
uint8_t xcells, uint8_t ycells, const char* texts, size_t num_texts, const char** remaining_texts);
139+
uint8_t xcells, uint8_t ycells, const char* texts, size_t num_texts, uint32_t font, const char** remaining_texts);
140140

141141
// Helper to create a vertical menu of 2, 3 or 4 buttons
142142
gui_activity_t* make_menu_activity(

main/ui/confirm_address.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,20 @@
1111

1212
#if ADDRESS_STRING_GRID
1313

14+
#define ADDR_GRID_FONT GUI_DEFAULT_FONT
1415
#define ADDR_GRID_TOPPAD 12
1516
#define ADDR_GRID_X 5
1617
#define ADDR_GRID_Y 5
1718
#define ADDR_GRID_SIZE (ADDR_GRID_X * ADDR_GRID_Y)
1819
#define ADDR_TEXTSPLITLEN (MAX_DISPLAY_ADDRESS_LEN / ADDR_GRID_SIZE)
1920

21+
// The length of the required buffer to hold 'len' characters
22+
// with a nul-terminator injected every 'wordlen' characters, and
23+
// at the very end. eg. for "abcdefhij\0" -> "abc\0def\0ghi\0j\0"
2024
#define SPLIT_TEXT_LEN(len, wordlen) (len + (len / wordlen) + 1)
2125

2226
// Helper to copy text from one buffer to another, where the destination has terminators every
23-
// 'wordlen' chars, eg: "abc\0def\0ghi\0j\0"
27+
// 'wordlen' chars, eg: "abcdefghi\0" -> "abc\0def\0ghi\0j\0"
2428
// output 'num_words' is number of 'words' written - eg. 4
2529
// output 'written' is number iof bytes written, including all '\0's - eg. 14
2630
static void split_text(const char* src, const size_t len, const size_t wordlen, char* output, const size_t output_len,
@@ -89,8 +93,8 @@ gui_activity_t* make_display_address_activities(const char* title, const bool sh
8993
#if ADDRESS_STRING_GRID
9094
JADE_ASSERT(num_words <= ADDR_GRID_SIZE);
9195
const char* remaining_words = NULL;
92-
act = make_text_grid_activity(
93-
title, hdrbtns, 2, ADDR_GRID_TOPPAD, ADDR_GRID_X, ADDR_GRID_Y, address_words, num_words, &remaining_words);
96+
act = make_text_grid_activity(title, hdrbtns, 2, ADDR_GRID_TOPPAD, ADDR_GRID_X, ADDR_GRID_Y, address_words,
97+
num_words, ADDR_GRID_FONT, &remaining_words);
9498
JADE_ASSERT(remaining_words == address_words + words_len); // all words consumed (displayed)
9599
#else
96100
const int ret = snprintf(buf, sizeof(buf), "\n%s", address);
@@ -114,7 +118,7 @@ gui_activity_t* make_display_address_activities(const char* title, const bool sh
114118
JADE_ASSERT(num_words > ADDR_GRID_SIZE);
115119
const char* remaining_words = NULL;
116120
act = make_text_grid_activity(titlebuf, hdrbtns1, 2, ADDR_GRID_TOPPAD, ADDR_GRID_X, ADDR_GRID_Y, address_words,
117-
ADDR_GRID_SIZE, &remaining_words);
121+
ADDR_GRID_SIZE, ADDR_GRID_FONT, &remaining_words);
118122
JADE_ASSERT(remaining_words > address_words);
119123
JADE_ASSERT(remaining_words < address_words + words_len); // Some words remaining
120124
#else
@@ -136,7 +140,7 @@ gui_activity_t* make_display_address_activities(const char* title, const bool sh
136140
#if ADDRESS_STRING_GRID
137141
const size_t num_p2words = num_words - ADDR_GRID_SIZE;
138142
*actaddr2 = make_text_grid_activity(titlebuf, hdrbtns2, 2, ADDR_GRID_TOPPAD, ADDR_GRID_X, ADDR_GRID_Y,
139-
remaining_words, num_p2words, &remaining_words);
143+
remaining_words, num_p2words, ADDR_GRID_FONT, &remaining_words);
140144
JADE_ASSERT(remaining_words == address_words + words_len); // all words consumed (displayed)
141145
#else
142146
ret = snprintf(buf, sizeof(buf), "\n%s", address + MAX_DISPLAY_ADDRESS_LEN);

main/ui/dialogs.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void update_menu_item(gui_view_node_t* node, const char* label, const char* valu
2020
gui_update_text(node, buf);
2121
}
2222

23-
// Handles up to 5 splits, row or column.
23+
// Handles up to 7 splits, row or column.
2424
// layout == UI_ROW -> [ x | y | z ] items in a row -> an hsplit
2525
// layout == UI_COLUMN -> [ x / y / z ] items in a column -> a vsplit
2626
gui_view_node_t* make_even_split(const ui_button_layout_t layout, const uint8_t num_splits)
@@ -47,6 +47,12 @@ gui_view_node_t* make_even_split(const ui_button_layout_t layout, const uint8_t
4747
case 5:
4848
make_split(&split, GUI_SPLIT_RELATIVE, 5, 20, 20, 20, 20, 20);
4949
break;
50+
case 6:
51+
make_split(&split, GUI_SPLIT_RELATIVE, 6, 17, 16, 17, 17, 16, 17);
52+
break;
53+
case 7:
54+
make_split(&split, GUI_SPLIT_RELATIVE, 7, 14, 15, 14, 14, 14, 15, 14);
55+
break;
5056
default:
5157
JADE_ASSERT_MSG(false, "Unsupported split size");
5258
}
@@ -190,12 +196,12 @@ gui_view_node_t* add_title_bar(
190196
return vsplit;
191197
}
192198

193-
// Helper to create an activity which is a grid of (up to 5x5) text items
199+
// Helper to create an activity which is a grid of (up to 7x7) text items
194200
// NOTE: the text is passed as one char large array containing embedded terminators
195201
// to delineate the separate texts - eg: ... , "abc\0def\0ghi\0j\0", 4)
196202
gui_activity_t* make_text_grid_activity(const char* title, btn_data_t* hdrbtns, const size_t num_hdrbtns,
197203
const size_t toppad, const uint8_t xcells, const uint8_t ycells, const char* texts, const size_t num_texts,
198-
const char** remaining_texts)
204+
const uint32_t font, const char** remaining_texts)
199205
{
200206
// Title and header are optional
201207
JADE_ASSERT(hdrbtns || !num_hdrbtns);
@@ -229,7 +235,8 @@ gui_activity_t* make_text_grid_activity(const char* title, btn_data_t* hdrbtns,
229235
const int itxt = (y * xcells) + x;
230236
if (itxt < num_texts) {
231237
gui_view_node_t* node;
232-
gui_make_text(&node, text_item, TFT_WHITE);
238+
gui_make_text_font(&node, text_item, TFT_WHITE, font);
239+
gui_set_align(node, GUI_ALIGN_LEFT, GUI_ALIGN_MIDDLE);
233240
gui_set_parent(node, hsplit);
234241
text_item += strlen(text_item) + 1;
235242
}

0 commit comments

Comments
 (0)